FastMM documentation
FastMM C++ API 0.14.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
csv_source.hpp
Go to the documentation of this file.
1#pragma once
2// CsvSource: hand-rolled parser for the row format documented in data_source.hpp
3// (`ts_ns,type,inst,side,price,qty,seq`, optional header line, '#' comments). Prices and
4// quantities are parsed exactly with Fixed::from_decimal. A file is streamed through
5// CsvLineReader, read once at construction to validate it and count its rows, then again from
6// the start; next() allocates nothing.
7#include "fastmm/backtest/binance_source.hpp"
9
10#include <cstddef>
11#include <memory>
12#include <string>
13#include <string_view>
14
15namespace fastmm::bt {
16
17class CsvSource final : public MdSource {
18 public:
19 // Throws std::runtime_error when the file cannot be read or a row is malformed.
20 explicit CsvSource(const std::string& path, VenueId venue = VenueId{0});
21 // Parses in-memory text (tests).
22 static CsvSource from_text(std::string text, VenueId venue = VenueId{0});
23
24 const EventHeader* next() override;
25 void reset() override;
26 [[nodiscard]] Timestamp start_ts() const override { return first_ts_; }
27 [[nodiscard]] std::size_t rows() const noexcept { return rows_; }
29 // Parses one CSV line into a Row; false for blank/comment lines. Throws on bad fields.
30 static bool parse_row(std::string_view line, Row& out);
31
32 private:
33 CsvSource(std::string text, std::unique_ptr<CsvLineReader> file, VenueId venue);
34 bool next_line(std::string_view& line);
35 bool provide(Row& r);
36
37 std::string text_; // from_text(): the whole input
38 std::unique_ptr<CsvLineReader> file_; // a path: read a buffer at a time
39 std::size_t pos_ = 0;
40 std::size_t line_no_ = 0;
41 std::size_t rows_ = 0;
42 Timestamp first_ts_{};
43 RowAssembler asm_;
44};
45
46} // namespace fastmm::bt
Definition csv_source.hpp:19
void reset() override
static CsvSource from_text(std::string text, VenueId venue=VenueId{0})
Parses in-memory text (tests).
const EventHeader * next() override
static bool parse_row(std::string_view line, Row &out)
Parses one CSV line into a Row; false for blank/comment lines. Throws on bad fields.
std::size_t rows() const noexcept
Definition csv_source.hpp:29
Timestamp start_ts() const override
Definition csv_source.hpp:28
Builds messages from a row stream. Provider is bool(Row&) returning false at end.
Definition data_source.hpp:58
DataSource (8.4): a timestamp-ordered stream of normalized market-data events consumed by the simulat...
Definition backtest_config.hpp:44
Definition messages.hpp:38
Definition time.hpp:45
Definition data_source.hpp:47