algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
clock.hpp
1#pragma once
2
3#include "./market.hpp"
4
5#include <chrono>
6
7namespace algotradelib {
8namespace mock {
9
17public:
22 explicit MarketClock(Market& market) : market_(&market) {}
23
28 std::chrono::system_clock::time_point now() const noexcept {
29 return market_->now();
30 }
31
36 std::chrono::steady_clock::time_point monotonic_now() const noexcept {
37 return std::chrono::steady_clock::time_point(
38 std::chrono::duration_cast<std::chrono::steady_clock::duration>(market_->now().time_since_epoch())
39 );
40 }
41
46 void wait_for(std::chrono::nanoseconds duration) {
47 if (duration.count() > 0) {
48 market_->advance_to(market_->now() + std::chrono::duration_cast<std::chrono::system_clock::duration>(duration));
49 }
50 }
51
52private:
53 Market* market_;
54};
55
56} // namespace mock
57} // namespace algotradelib
std::chrono::steady_clock::time_point monotonic_now() const noexcept
Returns a reading that moves with the market's time and never backwards.
Definition clock.hpp:36
void wait_for(std::chrono::nanoseconds duration)
Advances the market by a duration instead of sleeping.
Definition clock.hpp:46
std::chrono::system_clock::time_point now() const noexcept
Returns the market's time.
Definition clock.hpp:28
MarketClock(Market &market)
Builds a clock over a market.
Definition clock.hpp:22
A market in memory: bars the caller gives, a clock the caller moves, one account's cash,...
Definition market.hpp:143
The mock broker: an in-memory market over bars the caller gives, bound like any broker.
Definition client.hpp:11
The library: broker-neutral types (core), and the modules below.