|
exchange
Low-latency exchange in C++
|
#include <candlestick_publisher.hpp>
Public Member Functions | |
| CandlestickPublisher (ActionSpmcReceiver &&actionReceiver) | |
| void | loop () |
| void | processTrade (const TradeAction &tradeAction, SecurityId securityId, std::chrono::sys_seconds timestamp) |
| std::vector< Candle > | getCandles (SecurityId securityId, std::chrono::sys_seconds start, std::chrono::sys_seconds end, std::chrono::seconds resolution) const |
|
explicit |
|
nodiscard |
Compute a list of candles within a time range, at arbitrary resolution.
Assumes the input is valid (start < end, resolution >= 1).
All candles that would contain partial/no data are dropped from the result. If the end timestamp is within a closed candle (it does not align with the grid), the whole time interval of that candle is then considered, and the full candle is included in the final result, even though it might exceed the specified end time.
| securityId | The security whose candles are computed |
| start | The timestamp that indicates the start time of the first candle, inclusive |
| end | The timestamp that is one over the last timestamp at which a candle can start |
| resolution | Over what period a single candle is calculated, in seconds |

| void exchange::server::CandlestickPublisher::loop | ( | ) |
Perform one iteration of the candlestick publisher's workflow, which consumes one action from the SPMC queue and updates its internal state.


| void exchange::server::CandlestickPublisher::processTrade | ( | const TradeAction & | tradeAction, |
| SecurityId | securityId, | ||
| std::chrono::sys_seconds | timestamp ) |
Update second-precision candles with the data from an executed trade.
Assume trades arrive in non-decreasing order of timestamp and no trades are executed before the CandlePublisher is constructed.
Invariant: For each security, the only candle that is not closed is the most recent one.
| tradeAction | The data corresponding to a single trade, needed to process. |
| securityId | The security that was traded. |
| timestamp | The moment when the trade occurred. |
