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

Helpers for a venue whose one config entry describes several independent exchange instances, such as CME's market segments or ICE's silos. More...

Classes

class  Exchange
class  ExchangeRegistry
 Maps a key under the config's exchanges object (e.g. More...
struct  FeedInfo
 One enabled market-data feed, as Exchange::enabledFeeds() reports it. More...
struct  MarketOrderEvent
 One of the venue's own orders entering, changing or leaving the book, from an order-by-order feed, in the simulator's units. More...
struct  MarketTradeEvent
 One trade the venue reports, with the side that crossed the spread. More...
struct  OrderBookObserver
struct  TradedCredit
 Quantity one trade print removed from phantom liquidity at one price, kept until a level update stamped at or after it accounts for it. More...
struct  Symbol
class  CoinbaseExchange
class  HyperliquidExchange

Concepts

concept  MultiInstanceVenue
 A venue whose one config entry can describe several exchanges.

Typedefs

using WebSocketClient = coinbase::WebSocketClient

Enumerations

enum class  EventType : uint8_t { LEVEL_UPDATE , TRADE }
enum class  HyperliquidChannel : uint8_t { L2_BOOK = 0 , TRADES = 1 , L2 = 2 , __COUNT__ = 3 }
 The market-data channels the Hyperliquid adapter serves. More...

Functions

template<typename T, typename Base = Exchange>
std::vector< std::unique_ptr< Base > > make_exchanges (const nlohmann::json &config)
 The factory body SLICK_SIM_REGISTER_VENUE registers.
void reject_mixed_feeds (const std::vector< FeedInfo > &feeds)
 Throws when one venue has both live and pcap feeds, in whichever of its instances: a venue's market is either today's or a recorded one.
std::string list_feeds (const std::vector< FeedInfo > &feeds)
 <live|pcap> <name> per feed, one per line: the CLI's answer to feeds.
template<typename DefaultName>
std::vector< nlohmann::json > expand_instances (const nlohmann::json &config, std::string_view list_key, std::string_view venue, DefaultName &&default_name)
 Expands a venue's config entry into one config per instance listed under list_key.
template<typename T>
void claim (std::unordered_map< T, std::string > &claimed, const T &value, const std::string &owner, std::string_view what, std::string_view venue)
 Records that instance owner uses value.
std::string group_key (const nlohmann::json &group)
 "address:port" of a { "address", "port" } multicast group config, as claimed.
bool is_enabled_feed (const nlohmann::json &feed, std::string_view type)
 True for a md_feeds entry of type that is not disabled.
bool has_enabled_feed (const nlohmann::json &instance, std::string_view type)
 True when the instance's md_feeds has an enabled feed of type.
void claim_pcap_control_ports (std::unordered_map< uint16_t, std::string > &ports, const nlohmann::json &instance, std::string_view feed_type, const std::string &owner, std::string_view venue)
 Claims the TCP control port of each enabled pcap feed of instance for owner.
template<typename Queue>
std::shared_ptr< md_feed::ReplayGate > make_replay_gate (const nlohmann::json &instance, std::string_view feed_type, Queue &md_queue)
 The gate a replaying instance's publisher waits on, or null when its config has no enabled feed of feed_type.
void reject_pcap_with_live_feeds (bool has_pcap_feed, size_t live_feeds, std::string_view venue, std::string_view kind, const std::string &name)
 Throws when a replay and live feeds would both write the one book.
template<typename Event, typename Feed>
Event replay_stamped (Event event, const Feed *feed)
 event with its time set from the replay: a replay is stamped on the wall clock, not with the capture's own time.

Detailed Description

Helpers for a venue whose one config entry describes several independent exchange instances, such as CME's market segments or ICE's silos.

What a venue's exchange instance (CME segment, ICE silo) does for a pcap feed, the same way for every venue.

Each instance becomes its own Exchange, on its own thread.

None of it needs pcap support (zstd, zlib): a config that names a pcap feed has to be understood, and refused, in every build.

Typedef Documentation

◆ WebSocketClient

using slick::sim::exch::WebSocketClient = coinbase::WebSocketClient

Definition at line 15 of file coinbase_exchange.hpp.

Enumeration Type Documentation

◆ EventType

enum class slick::sim::exch::EventType : uint8_t
strong
Enumerator
LEVEL_UPDATE 
TRADE 

Definition at line 13 of file coinbase_exchange.hpp.

◆ HyperliquidChannel

enum class slick::sim::exch::HyperliquidChannel : uint8_t
strong

The market-data channels the Hyperliquid adapter serves.

Split out of hyperliquid_exchange.hpp so HyperliquidPublisher can name it without including the exchange: the publisher needs nothing but this enum, and pulling in the exchange header dragged HyperliquidExchange, <hyperliquid/info.hpp> and <hyperliquid/utils/l2_diff.hpp> into every translation unit that touched the publisher - an inverted dependency, since the exchange owns the publisher.

Enumerator
L2_BOOK 
TRADES 
L2 
__COUNT__ 

Definition at line 14 of file hyperliquid_channels.hpp.

Function Documentation

◆ claim()

template<typename T>
void slick::sim::exch::claim ( std::unordered_map< T, std::string > & claimed,
const T & value,
const std::string & owner,
std::string_view what,
std::string_view venue )

Records that instance owner uses value.

Throws if another instance already does, or if this one claims it twice. Instances run side by side in one process, so an instrument, port or multicast group can belong to one only.

Definition at line 71 of file instance_expansion.hpp.

Referenced by claim_pcap_control_ports().

◆ claim_pcap_control_ports()

void slick::sim::exch::claim_pcap_control_ports ( std::unordered_map< uint16_t, std::string > & ports,
const nlohmann::json & instance,
std::string_view feed_type,
const std::string & owner,
std::string_view venue )
inline

Claims the TCP control port of each enabled pcap feed of instance for owner.

Port 0 asks the OS for a free one, so any number of feeds may use it.

Definition at line 38 of file pcap_exchange.hpp.

References claim(), and is_enabled_feed().

◆ expand_instances()

template<typename DefaultName>
std::vector< nlohmann::json > slick::sim::exch::expand_instances ( const nlohmann::json & config,
std::string_view list_key,
std::string_view venue,
DefaultName && default_name )

Expands a venue's config entry into one config per instance listed under list_key.

Without list_key, the entry is the only instance. With it, each instance starts from the entry's other keys, which all instances share, merge-patched with the instance's own. RFC 7386 merges objects key by key and replaces anything else, arrays included. An instance with "enabled": false is skipped.

An instance without a name gets default_name(instance, index); the single entry without list_key gets venue.

Definition at line 28 of file instance_expansion.hpp.

◆ group_key()

std::string slick::sim::exch::group_key ( const nlohmann::json & group)
inline

"address:port" of a { "address", "port" } multicast group config, as claimed.

Definition at line 84 of file instance_expansion.hpp.

◆ has_enabled_feed()

bool slick::sim::exch::has_enabled_feed ( const nlohmann::json & instance,
std::string_view type )
inlinenodiscard

True when the instance's md_feeds has an enabled feed of type.

Definition at line 27 of file pcap_exchange.hpp.

References is_enabled_feed().

Referenced by make_replay_gate().

◆ is_enabled_feed()

bool slick::sim::exch::is_enabled_feed ( const nlohmann::json & feed,
std::string_view type )
inlinenodiscard

True for a md_feeds entry of type that is not disabled.

Definition at line 22 of file pcap_exchange.hpp.

Referenced by claim_pcap_control_ports(), and has_enabled_feed().

◆ list_feeds()

std::string slick::sim::exch::list_feeds ( const std::vector< FeedInfo > & feeds)
inline

<live|pcap> <name> per feed, one per line: the CLI's answer to feeds.

Definition at line 36 of file feed_info.hpp.

References slick::sim::md_feed::kind_name().

Referenced by main().

◆ make_exchanges()

template<typename T, typename Base = Exchange>
std::vector< std::unique_ptr< Base > > slick::sim::exch::make_exchanges ( const nlohmann::json & config)

The factory body SLICK_SIM_REGISTER_VENUE registers.

A template because only there does if constexpr discard the branch that does not apply - in the macro's plain function, a single-instance venue's missing create_instances would still fail to compile.

Base is always Exchange. It is a parameter only to make the vector's type dependent: unique_ptr's destructor is constexpr in C++23, and clang instantiates a constexpr destructor as soon as it sees a non-dependent use of it, so a plain vector<unique_ptr<Exchange>> local would need Exchange complete wherever this header is included. Dependent, it waits for instantiation, where T is complete.

Definition at line 74 of file exchange_registry.hpp.

◆ make_replay_gate()

template<typename Queue>
std::shared_ptr< md_feed::ReplayGate > slick::sim::exch::make_replay_gate ( const nlohmann::json & instance,
std::string_view feed_type,
Queue & md_queue )
nodiscard

The gate a replaying instance's publisher waits on, or null when its config has no enabled feed of feed_type.

md_queue is the one the publisher reads.

Definition at line 53 of file pcap_exchange.hpp.

References has_enabled_feed().

◆ reject_mixed_feeds()

void slick::sim::exch::reject_mixed_feeds ( const std::vector< FeedInfo > & feeds)
inline

Throws when one venue has both live and pcap feeds, in whichever of its instances: a venue's market is either today's or a recorded one.

Definition at line 22 of file feed_info.hpp.

References slick::sim::md_feed::LIVE, and slick::sim::md_feed::PCAP.

Referenced by main().

◆ reject_pcap_with_live_feeds()

void slick::sim::exch::reject_pcap_with_live_feeds ( bool has_pcap_feed,
size_t live_feeds,
std::string_view venue,
std::string_view kind,
const std::string & name )
inline

Throws when a replay and live feeds would both write the one book.

Definition at line 62 of file pcap_exchange.hpp.

◆ replay_stamped()

template<typename Event, typename Feed>
Event slick::sim::exch::replay_stamped ( Event event,
const Feed * feed )
nodiscard

event with its time set from the replay: a replay is stamped on the wall clock, not with the capture's own time.

feed is the instance's pcap feed (null: the event as it is).

Definition at line 72 of file pcap_exchange.hpp.