exchange
Low-latency exchange in C++
Loading...
Searching...
No Matches
exchange::server::CandlestickPublisher Class Reference

#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

Constructor & Destructor Documentation

◆ CandlestickPublisher()

exchange::server::CandlestickPublisher::CandlestickPublisher ( ActionSpmcReceiver && actionReceiver)
explicit

Member Function Documentation

◆ getCandles()

std::vector< Candle > exchange::server::CandlestickPublisher::getCandles ( SecurityId securityId,
std::chrono::sys_seconds start,
std::chrono::sys_seconds end,
std::chrono::seconds resolution ) const
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.

Parameters
securityIdThe security whose candles are computed
startThe timestamp that indicates the start time of the first candle, inclusive
endThe timestamp that is one over the last timestamp at which a candle can start
resolutionOver what period a single candle is calculated, in seconds
Returns
The list of valid candles in the specified interval. If the input is invalid or the security has not been traded yet, an empty vector is returned.
Here is the call graph for this function:

◆ loop()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processTrade()

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.

Parameters
tradeActionThe data corresponding to a single trade, needed to process.
securityIdThe security that was traded.
timestampThe moment when the trade occurred.
Here is the caller graph for this function:

The documentation for this class was generated from the following files: