BetaTrader
A HFT Eco-System
Loading...
Searching...
No Matches
CandleAggregator.h
Go to the documentation of this file.
1#pragma once
2
3#include "common/Types.h"
5#include <map>
6#include <mutex>
7#include <vector>
8#include <functional>
9
10namespace ohlc {
11
12 using namespace data; // For Candle struct
13
19 public:
20 using CandleCallback = std::function<void(int interval, const Candle&)>;
21
23 ~CandleAggregator() = default;
24
25 // Process a new trade update
26 void onTrade(const std::string& symbol, double price, uint64_t qty, int64_t timestampNs);
27
28 void setCandleCallback(CandleCallback cb) { mCallback = std::move(cb); }
29
30 private:
33
34 struct Aggregate {
36 bool active = false;
37 };
38
39 // symbol -> interval -> Aggregate
40 std::map<std::string, std::map<int, Aggregate>> mAggregates;
41 std::mutex mMutex;
42
43 void updateAggregate(Aggregate& agg, int interval, const std::string& symbol, double price, uint64_t qty, int64_t timestampNs);
44 };
45
46} // namespace ohlc
Persists OHLC candle data to the database.
Definition MarketHistoryRepository.h:24
Aggregates trade updates into OHLC candles and persists them.
Definition CandleAggregator.h:18
std::mutex mMutex
Definition CandleAggregator.h:41
std::function< void(int interval, const Candle &)> CandleCallback
Definition CandleAggregator.h:20
void setCandleCallback(CandleCallback cb)
Definition CandleAggregator.h:28
CandleCallback mCallback
Definition CandleAggregator.h:32
std::map< std::string, std::map< int, Aggregate > > mAggregates
Definition CandleAggregator.h:40
void onTrade(const std::string &symbol, double price, uint64_t qty, int64_t timestampNs)
Definition CandleAggregator.cpp:8
MarketHistoryRepository & mRepo
Definition CandleAggregator.h:31
void updateAggregate(Aggregate &agg, int interval, const std::string &symbol, double price, uint64_t qty, int64_t timestampNs)
Definition CandleAggregator.cpp:16
Repository for managing sequence numbers.
Definition Constant.h:13
Definition CandleAggregator.h:10
Definition MarketHistoryRepository.h:10
Definition CandleAggregator.h:34
bool active
Definition CandleAggregator.h:36
Candle current
Definition CandleAggregator.h:35