PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
pine_position_tail.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <memory>
6#include <string>
7#include <string_view>
8
9namespace pineforge {
10struct Trade;
11namespace source::detail {
12
13// DESIGN 3.4: private binary storage, never the text report sink. Records
14// have no padding: entry_id bytes followed by the 30-byte backwards footer.
15// A row holds offsets, not an owning string, so even an id larger than the
16// read window does not allocate another history-sized buffer.
18public:
19 static constexpr std::size_t kWindowBytes = 64 * 1024;
20 static constexpr std::size_t kFooterBytes = 30;
21
22 struct Row {
23 std::int64_t exit_time = 0;
24 double qty = 0.0;
25 std::uint64_t entry_incarnation = 0;
26 bool is_long = false;
27 bool margin_call = false;
28 std::uint64_t entry_id_offset = 0;
29 std::uint32_t entry_id_size = 0;
30 };
31
32 // A second unlinked file in L6b-4's bound scratch directory (DESIGN
33 // 3.8 explicitly permits this). The directory must already be resolved.
34 explicit PositionTailSpill(const std::string& scratch_directory);
38
39 void append(const Trade& trade);
40 void clear();
41 std::uint64_t size_bytes() const noexcept;
42 std::uint64_t row_count() const noexcept;
43
44 // Start cursor at size_bytes(); each successful call moves it to the
45 // preceding record. Separate cursors can repeat/interleave full walks.
46 bool previous(std::uint64_t& cursor, Row& row) const;
47 bool entry_id_equals(const Row& row, std::string_view entry_id) const;
48
49private:
50 struct State;
51 std::unique_ptr<State> state_;
52};
53
54} // namespace source::detail
55} // namespace pineforge
PositionTailSpill & operator=(const PositionTailSpill &)=delete
PositionTailSpill(const std::string &scratch_directory)
bool previous(std::uint64_t &cursor, Row &row) const
PositionTailSpill(const PositionTailSpill &)=delete
bool entry_id_equals(const Row &row, std::string_view entry_id) const