Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
coinbase_live_ws_feed.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <md_feed/md_feed.hpp>
4#include <coinbase/websocket.hpp>
5#include <memory>
6#include <slick/queue.hpp>
7
8namespace slick::sim::md_feed {
9
11{
12 std::shared_ptr<coinbase::WebSocketClient> ws_client_;
13 std::vector<std::string> symbols_;
14
15public:
17 slick::stream_buffer_multiplexer& mux,
18 coinbase::UserThreadWebsocketCallbacks *callbacks,
19 const std::vector<std::string> &symbols = {},
20 uint32_t producer_offset = 0
21 )
22 : ws_client_(std::make_shared<coinbase::WebSocketClient>(
23 callbacks,
24 mux,
25 "wss://advanced-trade-ws.coinbase.com",
26 "wss://advanced-trade-ws-user.coinbase.com",
27 producer_offset
28 ))
29 , symbols_(std::move(symbols))
30 {
31 ws_client_->logData("logs/coinbase_data");
32 }
33 ~CoinbaseLiveWSFeed() override = default;
34
35 void start() override;
36 void stop() override;
37
38 coinbase::WebSocketClient* getClient() const { return ws_client_.get(); }
39};
40
41
43 if (!symbols_.empty()) {
44 ws_client_->subscribe(symbols_, {coinbase::WebSocketChannel::LEVEL2, coinbase::WebSocketChannel::MARKET_TRADES});
45 }
46}
47
49 if (ws_client_) {
50 ws_client_->unsubscribe(symbols_, {coinbase::WebSocketChannel::LEVEL2, coinbase::WebSocketChannel::MARKET_TRADES});
51 }
52}
53
54
55} // end nanespace slick::sim::md_feed
CoinbaseLiveWSFeed(slick::stream_buffer_multiplexer &mux, coinbase::UserThreadWebsocketCallbacks *callbacks, const std::vector< std::string > &symbols={}, uint32_t producer_offset=0)
coinbase::WebSocketClient * getClient() const