47 int64_t ts = std::strtol(line_buffer, &end, 10);
48 double o = std::strtod(end, &end);
49 double h = std::strtod(end, &end);
50 double l = std::strtod(end, &end);
51 double c = std::strtod(end, &end);
52 double v = std::strtod(end, &end);
53 if (*end !=
'\0' && *end !=
'\n')
return false;
54 out =
Ohlcv(ts, o, h, l, c, v);
65 static bool parse(
const char* line_buffer,
Tick& out) {
67 int64_t ts = std::strtol(line_buffer, &end, 10);
68 double price = std::strtod(end, &end);
69 double volume = std::strtod(end, &end);
70 Side side =
static_cast<Side>(std::strtol(end, &end, 10));
71 if (*end !=
'\0' && *end !=
'\n')
return false;
72 out =
Tick{ts, price, volume,
static_cast<Side>(side)};
85 int64_t ts = std::strtol(line_buffer, &end, 10);
86 double value = std::strtod(end, &end);
87 if (*end !=
'\0' && *end !=
'\n')
return false;
97template<
typename T,
typename Parser>
108 : input_(input), end_(end) {
109 if (!end_) { ++(*this); }
118 std::array<char, MAX_BUFFER_SIZE> line_buffer;
122 static_cast<std::streamsize
>(line_buffer.size()))) {
123 char* buf = line_buffer.data();
124 size_t len = std::strlen(buf);
125 while (len > 0 && (buf[len - 1] ==
'\r' || buf[len - 1] ==
'\n')) {
130 for (
size_t i = 0; i < len; ++i) {
131 if (buf[i] ==
',') buf[i] =
' ';
133 if (Parser::parse(buf, current_)) {
159 return end_ == other.end_;
166 return !(*
this == other);
177 std::istream& input_;
180 explicit Csv(std::istream& input,
bool has_headers =
true)
181 : input_(input), has_headers_(has_headers) {
183 std::string header_line;
184 std::getline(input_, header_line);
Csv(std::istream &input, bool has_headers=true)
Definition streamers.h:180
Iterator begin()
Definition streamers.h:188
ParseIterator< T, CsvParseTraits< T > > Iterator
Definition streamers.h:187
Iterator end()
Definition streamers.h:189
Definition streamers.h:98
const T & operator*() const
Definition streamers.h:145
ParseIterator(std::istream *input, bool end=false)
Definition streamers.h:107
bool operator==(const ParseIterator &other) const
Definition streamers.h:158
ParseIterator & operator++()
Definition streamers.h:117
bool operator!=(const ParseIterator &other) const
Definition streamers.h:165
const T * operator->() const
Definition streamers.h:151
Core data structures and types for the tzutrader library.
constexpr size_t MAX_BUFFER_SIZE
Definition streamers.h:29
Side
Trade direction enumeration.
Definition defs.h:28
static bool parse(const char *line_buffer, Ohlcv &out)
Definition streamers.h:45
static bool parse(const char *line_buffer, SingleValue &out)
Definition streamers.h:83
static bool parse(const char *line_buffer, Tick &out)
Definition streamers.h:65
Definition streamers.h:37
Open-High-Low-Close-Volume candlestick data.
Definition defs.h:84