Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
coinbase_publisher.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <uwebsockets/App.h>
5#include <coinbase/websocket.hpp>
6#include <nlohmann/json.hpp>
8#include <unordered_set>
9#include <unordered_map>
10#include <vector>
11
12struct us_listen_socket_t;
13
14namespace slick::sim::exch {
15 struct Symbol;
16}
17
19
20using json = nlohmann::json;
21
22// Per-socket data structure for uWebSockets
24 uint64_t seq_num;
25 std::chrono::steady_clock::time_point last_pong; // Track last pong received
27 static uint_fast64_t heartbeat_count;
28
30 std::unordered_set<std::string> active_subscriptions;
31 std::unordered_set<std::string> pending_subscriptions;
32 std::vector<std::string> received_subscriptions;
33 };
34 std::array<SubscriptionInfo, (uint8_t)coinbase::WebSocketChannel::_CHANNEL_COUNT_> subscription_info;
35};
36
38 using wsT = uWS::WebSocket<false, true, PerSocketData>;
39
40public:
41 CoinbasePublisher(const json &config, slick::queue<Request> &request_queue, slick::queue<uint8_t> &market_data_queue);
42 // void start() override;
43 // void stop() override;
44
45private:
46 void setup_routes(uWS::App &app) override;
47 // void schedulePublishProcessing();
48 void publish_market_data_update(MarketDataUpdate *update) override;
49 void handle_message(wsT *ws, std::string_view message);
50 void publish_subscription_response(MarketDataUpdate *update);
51 void publish_level_snapshot(MarketDataUpdate *update);
52 void publish_level_update(MarketDataUpdate *update);
53 void publish_order_update(MarketDataUpdate *update);
54 void publish_trade_summary(MarketDataUpdate *update);
55 void check_heartbeats() override;
56 void handle_close(wsT *ws, int code, std::string_view message);
57 void send_error(wsT *ws, const std::string& error_msg);
58 void unsubscribe_md(wsT *ws);
59
60private:
61 // std::thread ws_thread_;
62 // us_listen_socket_t* listen_socket_ = nullptr;
63 // uWS::Loop* loop_ = nullptr;
64 // us_timer_t* heartbeat_timer_ = nullptr;
65 // uint32_t port_ = 5000;
66 // std::atomic<bool> running_{false};
67
68 // uint64_t data_cursor_ = 0;
69
70 std::unordered_set<wsT*> clients_;
71 std::unordered_map<std::string, std::unordered_multimap<uint8_t, wsT*>> symbol_channel_client_;
72 std::array<std::unordered_map<std::string, std::unordered_set<wsT*>>, (uint8_t)coinbase::WebSocketChannel::_CHANNEL_COUNT_> subscription_info_;
73
74 // Heartbeat configuration
75 // int ping_interval_ms_{15000}; // Send ping every 30 seconds (in milliseconds)
76 // std::chrono::seconds pong_timeout_{60}; // Disconnect if no pong for 60 seconds
77};
78
79} // end namespace slick::sim::md_publisher
CoinbasePublisher(const json &config, slick::queue< Request > &request_queue, slick::queue< uint8_t > &market_data_queue)
WebsocketMarketDataPublisher(Venue venue, slick::queue< Request > &request_queue, slick::queue< uint8_t > &market_data_queue, uint32_t port)
Helpers for a venue whose one config entry describes several independent exchange instances,...
Definition exchange.hpp:30
std::array< SubscriptionInfo,(uint8_t) coinbase::WebSocketChannel::_CHANNEL_COUNT_ > subscription_info
std::chrono::steady_clock::time_point last_pong