algotradelib
0.0.0.9000
C++ header-only library for algorithmic trading
Toggle main menu visibility
Loading...
Searching...
No Matches
data.hpp
1
#pragma once
2
3
#include <algorithm>
4
#include <chrono>
5
#include <cstddef>
6
#include <optional>
7
#include <utility>
8
#include <vector>
9
10
namespace
algotradelib
{
11
namespace
mock
{
12
28
template
<
typename
T>
29
class
DataFeed
{
30
public
:
32
using
Entry
= std::pair<std::chrono::system_clock::time_point, T>;
33
38
explicit
DataFeed
(std::vector<Entry> entries) : entries_(std::move(entries)) {
39
std::stable_sort(entries_.begin(), entries_.end(), [](
const
Entry
& a,
const
Entry
& b) {
40
return a.first < b.first;
41
});
42
}
43
49
std::optional<std::vector<T>>
operator()
(std::chrono::system_clock::time_point now) {
50
std::vector<T> out;
51
while
(next_ < entries_.size() && !(now < entries_[next_].first)) {
52
out.push_back(entries_[next_].second);
53
++next_;
54
}
55
return
out;
56
}
57
62
std::size_t
remaining
() const noexcept {
63
return
entries_.size() - next_;
64
}
65
66
private
:
67
std::vector<Entry> entries_;
68
std::size_t next_{0};
69
};
70
71
}
// namespace mock
72
}
// namespace algotradelib
algotradelib::mock::DataFeed::DataFeed
DataFeed(std::vector< Entry > entries)
Builds a feed over records in any order; records published at one instant keep their order.
Definition
data.hpp:38
algotradelib::mock::DataFeed::Entry
std::pair< std::chrono::system_clock::time_point, T > Entry
A record and when it was published.
Definition
data.hpp:32
algotradelib::mock::DataFeed::operator()
std::optional< std::vector< T > > operator()(std::chrono::system_clock::time_point now)
Returns the records published at or before now and not returned before, in time order.
Definition
data.hpp:49
algotradelib::mock::DataFeed::remaining
std::size_t remaining() const noexcept
Returns how many records are still to be released.
Definition
data.hpp:62
algotradelib::mock
The mock broker: an in-memory market over bars the caller gives, bound like any broker.
Definition
client.hpp:11
algotradelib
The library: broker-neutral types (core), and the modules below.
Definition
conversion.hpp:13
algotradelib
src
brokers
mock
data.hpp
Generated by
1.18.0