FastMM documentation
FastMM C++ API 0.6.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; the whole file is read once at
5// construction and next() allocates nothing.
7
8#include <cstddef>
9#include <string>
10#include <string_view>
11
12namespace fastmm::bt {
13
14class CsvSource final : public MdSource {
15 public:
16 // Throws std::runtime_error when the file cannot be read or a row is malformed.
17 explicit CsvSource(const std::string& path, VenueId venue = VenueId{0});
18 // Parses in-memory text (tests).
19 static CsvSource from_text(std::string text, VenueId venue = VenueId{0});
20
21 const EventHeader* next() override;
22 void reset() override;
23 [[nodiscard]] Timestamp start_ts() const override { return first_ts_; }
24 [[nodiscard]] std::size_t rows() const noexcept { return rows_; }
26 // Parses one CSV line into a Row; false for blank/comment lines. Throws on bad fields.
27 static bool parse_row(std::string_view line, Row& out);
28
29 private:
30 CsvSource(std::string text, VenueId venue, int /*tag*/);
31 bool provide(Row& r);
32
33 std::string text_;
34 std::size_t pos_ = 0;
35 std::size_t line_no_ = 0;
36 std::size_t rows_ = 0;
37 Timestamp first_ts_{};
38 RowAssembler asm_;
39};
40
41} // namespace fastmm::bt
Definition csv_source.hpp:16
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:26
Timestamp start_ts() const override
Definition csv_source.hpp:25
Builds messages from a row stream. Provider is bool(Row&) returning false at end.
Definition data_source.hpp:56
DataSource (8.4): a timestamp-ordered stream of normalized market-data events consumed by the simulat...
Definition backtest_config.hpp:39
Definition messages.hpp:37
Definition time.hpp:45
Definition data_source.hpp:45