Slick Trader 0.11.0
Multi-broker algorithmic trading engine with plugin strategies and a live web dashboard
Loading...
Searching...
No Matches
trading_engine.hpp
Go to the documentation of this file.
1#pragma once
2
8#include <slick/stream_buffer_multiplexer.hpp>
11#include <memory>
12#include <string>
13#include <string_view>
14#include <unordered_map>
15#include <atomic>
16#include <nlohmann/json.hpp>
17#include <chrono>
18#include <vector>
19
20namespace slick::trader {
21
22class WebServer;
23
24using json = nlohmann::json;
25
26class TradingEngine {
27public:
28 static TradingEngine& instance() {
29 static TradingEngine instance;
30 return instance;
31 }
32
33 // Lifecycle
34 bool initialize(const std::string& config_path);
35
36 // Lifecycle
37 void start();
38 void shutdown();
39
40 bool is_running() const { return running_.load(std::memory_order_relaxed); }
41
42private:
45
46 TradingEngine(const TradingEngine&) = delete;
47 TradingEngine(TradingEngine&&) = delete;
48 TradingEngine& operator=(const TradingEngine&) = delete;
49 TradingEngine& operator=(TradingEngine&&) = delete;
50
51 void publish_regiter_end(uint32_t num_producers);
52 bool wait_for_brokers_ready(std::chrono::seconds timeout = std::chrono::seconds(30));
53
54 std::atomic_bool running_{false};
55
56 // Message queues
57 std::unique_ptr<slick::stream_buffer_multiplexer> event_mux_;
58 std::unique_ptr<slick::queue<uint8_t>> control_queue_;
59 std::unique_ptr<MdRequestQueues> md_request_queues_;
60 std::unique_ptr<slick::queue<uint8_t>> order_request_queue_;
61
62 std::vector<std::shared_ptr<IBroker>> brokers_;
63
64 // Positions on disk, when `position_store` is configured. Declared before the tracker
65 // that writes to it, so it outlives it.
66 std::unique_ptr<PositionStore> position_store_;
67 PositionTracker position_tracker_;
68 PnLCalculator pnl_calculator_;
69 RiskManager risk_manager_;
70
71 std::unique_ptr<StrategyManager> strategy_manager_;
72 std::unique_ptr<WebServer> web_server_;
73};
74
75} // namespace slick::trader
static TradingEngine & instance()
bool initialize(const std::string &config_path)
nlohmann::json json