Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
slick::sim::exch::CoinbaseExchange Class Reference

#include <venues/coinbase/coinbase_exchange.hpp>

Inheritance diagram for slick::sim::exch::CoinbaseExchange:
Collaboration diagram for slick::sim::exch::CoinbaseExchange:

Public Member Functions

 CoinbaseExchange (const nlohmann::json &config)
 ~CoinbaseExchange () override=default
std::vector< FeedInfo > enabledFeeds () const override
 The market-data feeds the config enables: those in md_feed_ and md_feeds_.
void onMarketDataConnected (WebSocketClient *client) override
void onMarketDataDisconnected (WebSocketClient *client) override
void onUserDataConnected (WebSocketClient *client) override
void onUserDataDisconnected (WebSocketClient *client) override
void onLevel2Snapshot (WebSocketClient *client, uint64_t seq_num, const coinbase::Level2UpdateBatch &snapshot) override
void onLevel2Updates (WebSocketClient *client, uint64_t seq_num, const coinbase::Level2UpdateBatch &updates) override
void onMarketTradesSnapshot (WebSocketClient *client, uint64_t seq_num, const std::vector< coinbase::MarketTrade > &snapshots) override
void onMarketTrades (WebSocketClient *client, uint64_t seq_num, const std::vector< coinbase::MarketTrade > &trades) override
void onTickerSnapshot (WebSocketClient *, uint64_t, uint64_t, const std::vector< coinbase::Ticker > &) override
void onTickers (WebSocketClient *, uint64_t, uint64_t, const std::vector< coinbase::Ticker > &) override
void onCandlesSnapshot (WebSocketClient *, uint64_t, uint64_t, const std::vector< coinbase::Candle > &) override
void onCandles (WebSocketClient *, uint64_t, uint64_t, const std::vector< coinbase::Candle > &) override
void onStatusSnapshot (WebSocketClient *, uint64_t, uint64_t, const std::vector< coinbase::Status > &) override
void onStatus (WebSocketClient *, uint64_t, uint64_t, const std::vector< coinbase::Status > &) override
void onMarketDataGap (WebSocketClient *client) override
void onUserDataGap (WebSocketClient *client) override
void onUserDataSnapshot (WebSocketClient *, uint64_t, const std::vector< coinbase::Order > &, const std::vector< coinbase::PerpetualFuturePosition > &, const std::vector< coinbase::ExpiringFuturePosition > &) override
void onOrderUpdates (WebSocketClient *, uint64_t, const std::vector< coinbase::Order > &) override
void onMarketDataError (WebSocketClient *client, std::string &&err) override
void onUserDataError (WebSocketClient *client, std::string &&err) override
Public Member Functions inherited from slick::sim::exch::Exchange
 Exchange (Venue venue, const nlohmann::json &config)
virtual ~Exchange ()
virtual void start ()
virtual void stop ()
queue< Request > & request_queue () noexcept
queue< OrderResponse > & response_queue () noexcept
queue< uint8_t > & md_queue () noexcept
virtual std::vector< cli::CliEndpoint * > cliEndpoints ()
 Where the CLI reaches this exchange's commands (cli/cli_endpoint.hpp), each named <venue>/<instance>[/...], and served on whichever thread owns what they change (for CME and ICE, the order gateways').
std::vector< cli::CliEndpoint * > feedCliEndpoints () const
 The CLI endpoints of md_feed_ and md_feeds_ (a pcap feed's pcap/<venue>/<feed>).

Protected Member Functions

void handleMdSubscription (const Request &request) override
void handleMdUnsubscription (const Request &request) override
void poll () override
 One iteration of the exchange thread's loop, called continuously between start() and stop().
void processSequencedEvents (bool force=false)
Protected Member Functions inherited from slick::sim::exch::Exchange
FeedInfo feedInfo (md_feed::FeedKind kind, std::string_view name={}) const
 This exchange's feed of kind, by the feed's name or, when empty, the exchange's own.
virtual OrdRejectReason newOrderAdmission () const noexcept
void processRequest ()
void handleNewOrderRequest (const Request &request)
void handleModifyOrderRequest (const Request &request)
void handleCancelOrderRequest (const Request &request)
void rejectMdSubscription (const Request &request, MDSubscriptionRejectReason reason)
void publishMdSubscriptionResponse (const symbol_name_t &symbol, uint8_t channel)
 Publishes an accepted subscription response without a snapshot payload.
void rejectNewOrderRequest (const Request &request, OrdRejectReason reason)
void rejectModifyOrderRequest (const Request &request, OrdRejectReason reason)
void rejectCancelOrderRequest (const Request &request, OrdRejectReason reason)
void sendOrderNewPending (const Order *order, time_t request_time)
void sendOrderReplacePending (const Order *order, time_t request_time)
void sendOrderCancelPending (const Order *order, time_t request_time)
void flushMarketDataCaches (Symbol *symbol)
 Publish and clear whatever market data the book produced while handling a request.
void publishMDBookUpdate (symid_t sid, OrderBook &order_book, const std::array< uint8_t, 2 > &indices)
void publishLevelUpdate (const symbol_name_t &symbol, const std::vector< MDLevel > &level_updates)
void publishMDOrderUpdate (const symbol_name_t &symbol, const std::vector< MDOrder > &order_updates)
void publishTradeSummary (Symbol *symbol, const TradeSummaryInfo &trade_summary)
 Publishes one trade onto the instrument's public tape and records it in the symbol's recent-trade history, which serves the subscribe snapshot.
void publishTradeSubscriptionResponse (Symbol *symbol, uint8_t channel)
 Frames the SUB_RESPONSE for a venue's trade channel from the symbol's recent-trade history, split against the book snapshot the subscriber receives with it.
void reconcilePhantomQty (Symbol *symbol, Side side, price_t price, qty_t target_qty, time_t event_time, uint64_t seq_num, bool end_event)
 Adjusts the phantom (market-mirroring) quantity at an existing (side, price) level toward target_qty, leaving the simulator's own orders alone.
void applyMarketOrder (Symbol *symbol, const MarketOrderEvent &event)
 Rests, changes or removes a market order as a phantom order.
void replayMarketTrade (Symbol *symbol, const MarketTradeEvent &event)
 Replays a market trade as an aggressor order at the trade's price and quantity, so a client order queued ahead of the market orders it filled is filled first.
void flushMarketEvents ()
 Publishes every symbol a market event changed since the last call.
uint64_t nextVenueTradeId () noexcept
 Public trade ids, one independent sequence per venue.
int clientIdFor (const char *user_id)
 Resolves an order's user_id to the integer identity self-match prevention compares.
void configureMatching (const nlohmann::json &config)
 Reads matching_algorithm and pro_rata from the venue's config.
const engine::MatchingConfig & matchingConfig () const noexcept
void assignMatching (Symbol *symbol)
 Points a new symbol at the venue's configured engine, creating the engine on first use, and stamps the venue's SMP mode on it.
template<typename Fn>
void forEachFeed (Fn &&fn) const
 Calls fn(MDFeed &) on md_feed_ and each of md_feeds_.
void restMarketOrder (Symbol *symbol, const MarketOrderEvent &event)
void markMarketChanged (Symbol *symbol)

Additional Inherited Members

Protected Attributes inherited from slick::sim::exch::Exchange
Venue venue_
std::string instance_
 The config's name, one per instance of a venue that has several. Empty without one.
queue< Request > request_queue_
queue< OrderResponse > response_queue_
queue< uint8_t > md_queue_
std::shared_ptr< md_feed::MDFeed > md_feed_
std::vector< std::shared_ptr< md_feed::MDFeed > > md_feeds_
 Feeds owned by the exchange and managed by base start()/stop().
std::thread thread_
std::thread md_thread_
std::atomic_bool run_ {true}
uint_fast64_t order_request_cursor_ {0}
std::array< std::unique_ptr< engine::MatchingEngine >, engine::MatchingEngine::Type::__count__ > matching_engines_
std::vector< std::unique_ptr< order_gateway::OrderGateway > > order_gateways_
std::unique_ptr< md_publisher::MarketDataPublisher > md_publisher_
bool enabled_ = true
bool publish_order_updates_ = false
 Whether flushMarketDataCaches publishes the per-order (MDUpdateType::ORDER) frames the book produces.
uint64_t next_trade_id_ {1}
std::vector< PhantomReduction > phantom_reductions_
std::vector< Symbol * > market_changed_symbols_
 Symbols a market event has changed and not yet published.
SelfMatchPreventionMode smp_mode_ = SelfMatchPreventionMode::NONE
 Self-match prevention mode applied to every symbol on this venue, from the self_match_prevention config key.
engine::MatchingConfig matching_
 The engine assignMatching hands out. FIFO unless configureMatching says otherwise.
bool matching_keys_unread_ = false
 The config sets matching keys and configureMatching has not read them, so start() warns that this venue matches FIFO regardless.
std::unordered_map< utils::fixed_string< sizeof(AddOrderMessage::user_id)>, int, utils::StringViewHash, utils::StringViewEq > client_ids_
 Keys use the width of AddOrderMessage::user_id.
int next_client_id_ = 0

Detailed Description

Definition at line 17 of file coinbase_exchange.hpp.

Constructor & Destructor Documentation

◆ CoinbaseExchange()

◆ ~CoinbaseExchange()

slick::sim::exch::CoinbaseExchange::~CoinbaseExchange ( )
overridedefault

Member Function Documentation

◆ enabledFeeds()

std::vector< FeedInfo > CoinbaseExchange::enabledFeeds ( ) const
nodiscardoverridevirtual

The market-data feeds the config enables: those in md_feed_ and md_feeds_.

A venue that creates its feeds later says what it will have. Call before start(), as above.

Reimplemented from slick::sim::exch::Exchange.

Definition at line 59 of file coinbase_exchange.cpp.

References slick::sim::exch::Exchange::enabled_, slick::sim::exch::Exchange::feedInfo(), and slick::sim::md_feed::LIVE.

◆ handleMdSubscription()

◆ handleMdUnsubscription()

void CoinbaseExchange::handleMdUnsubscription ( const Request & request)
overrideprotectedvirtual

◆ onCandles()

void slick::sim::exch::CoinbaseExchange::onCandles ( WebSocketClient * ,
uint64_t ,
uint64_t ,
const std::vector< coinbase::Candle > &  )
inlineoverride

Definition at line 36 of file coinbase_exchange.hpp.

◆ onCandlesSnapshot()

void slick::sim::exch::CoinbaseExchange::onCandlesSnapshot ( WebSocketClient * ,
uint64_t ,
uint64_t ,
const std::vector< coinbase::Candle > &  )
inlineoverride

Definition at line 35 of file coinbase_exchange.hpp.

◆ onLevel2Snapshot()

void CoinbaseExchange::onLevel2Snapshot ( WebSocketClient * client,
uint64_t seq_num,
const coinbase::Level2UpdateBatch & snapshot )
override

◆ onLevel2Updates()

void CoinbaseExchange::onLevel2Updates ( WebSocketClient * client,
uint64_t seq_num,
const coinbase::Level2UpdateBatch & updates )
override

◆ onMarketDataConnected()

void CoinbaseExchange::onMarketDataConnected ( WebSocketClient * client)
override

Definition at line 16 of file coinbase_feed_callbacks.cpp.

◆ onMarketDataDisconnected()

void CoinbaseExchange::onMarketDataDisconnected ( WebSocketClient * client)
override

◆ onMarketDataError()

void CoinbaseExchange::onMarketDataError ( WebSocketClient * client,
std::string && err )
override

Definition at line 334 of file coinbase_feed_callbacks.cpp.

◆ onMarketDataGap()

void CoinbaseExchange::onMarketDataGap ( WebSocketClient * client)
override

Definition at line 326 of file coinbase_feed_callbacks.cpp.

◆ onMarketTrades()

void CoinbaseExchange::onMarketTrades ( WebSocketClient * client,
uint64_t seq_num,
const std::vector< coinbase::MarketTrade > & trades )
override

◆ onMarketTradesSnapshot()

◆ onOrderUpdates()

void slick::sim::exch::CoinbaseExchange::onOrderUpdates ( WebSocketClient * ,
uint64_t ,
const std::vector< coinbase::Order > &  )
inlineoverride

Definition at line 42 of file coinbase_exchange.hpp.

◆ onStatus()

void slick::sim::exch::CoinbaseExchange::onStatus ( WebSocketClient * ,
uint64_t ,
uint64_t ,
const std::vector< coinbase::Status > &  )
inlineoverride

Definition at line 38 of file coinbase_exchange.hpp.

◆ onStatusSnapshot()

void slick::sim::exch::CoinbaseExchange::onStatusSnapshot ( WebSocketClient * ,
uint64_t ,
uint64_t ,
const std::vector< coinbase::Status > &  )
inlineoverride

Definition at line 37 of file coinbase_exchange.hpp.

◆ onTickers()

void slick::sim::exch::CoinbaseExchange::onTickers ( WebSocketClient * ,
uint64_t ,
uint64_t ,
const std::vector< coinbase::Ticker > &  )
inlineoverride

Definition at line 34 of file coinbase_exchange.hpp.

◆ onTickerSnapshot()

void slick::sim::exch::CoinbaseExchange::onTickerSnapshot ( WebSocketClient * ,
uint64_t ,
uint64_t ,
const std::vector< coinbase::Ticker > &  )
inlineoverride

Definition at line 33 of file coinbase_exchange.hpp.

◆ onUserDataConnected()

void CoinbaseExchange::onUserDataConnected ( WebSocketClient * client)
override

Definition at line 81 of file coinbase_feed_callbacks.cpp.

◆ onUserDataDisconnected()

void CoinbaseExchange::onUserDataDisconnected ( WebSocketClient * client)
override

Definition at line 86 of file coinbase_feed_callbacks.cpp.

◆ onUserDataError()

void CoinbaseExchange::onUserDataError ( WebSocketClient * client,
std::string && err )
override

Definition at line 339 of file coinbase_feed_callbacks.cpp.

◆ onUserDataGap()

void CoinbaseExchange::onUserDataGap ( WebSocketClient * client)
override

Definition at line 330 of file coinbase_feed_callbacks.cpp.

◆ onUserDataSnapshot()

void slick::sim::exch::CoinbaseExchange::onUserDataSnapshot ( WebSocketClient * ,
uint64_t ,
const std::vector< coinbase::Order > & ,
const std::vector< coinbase::PerpetualFuturePosition > & ,
const std::vector< coinbase::ExpiringFuturePosition > &  )
inlineoverride

Definition at line 41 of file coinbase_exchange.hpp.

◆ poll()

void CoinbaseExchange::poll ( )
overrideprotectedvirtual

One iteration of the exchange thread's loop, called continuously between start() and stop().

Override it to drain the venue SDK and release any feed events it queued; the base loop calls processRequest() immediately after it on every tick, so an adapter never rewrites the loop itself.

Runs on the exchange thread - the only thread that touches books - so an override may mutate them directly. An adapter with no feed leaves this alone and still serves clients matching against each other.

Reimplemented from slick::sim::exch::Exchange.

Definition at line 66 of file coinbase_exchange.cpp.

References slick::sim::exch::Exchange::md_feed_, slick::sim::exch::Exchange::md_feeds_, and processSequencedEvents().

◆ processSequencedEvents()

void CoinbaseExchange::processSequencedEvents ( bool force = false)
protected

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