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

#include <venues/hyperliquid/hyperliquid_exchange.hpp>

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

Public Member Functions

 HyperliquidExchange (const nlohmann::json &config)
 ~HyperliquidExchange () override=default
void onL2BookUpdate (const nlohmann::json &msg) override
void onTradesUpdate (const nlohmann::json &msg) override
void onHyperliquidDisconnected () 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>).
virtual std::vector< FeedInfo > enabledFeeds () const
 The market-data feeds the config enables: those in md_feed_ and md_feeds_.
Public Member Functions inherited from slick::sim::md_feed::HyperliquidFeedCallbacks
virtual ~HyperliquidFeedCallbacks ()=default

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 drainEventQueue ()
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 16 of file hyperliquid_exchange.hpp.

Constructor & Destructor Documentation

◆ HyperliquidExchange()

◆ ~HyperliquidExchange()

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

Member Function Documentation

◆ drainEventQueue()

void HyperliquidExchange::drainEventQueue ( )
protected

Definition at line 97 of file hyperliquid_exchange.cpp.

References slick::sim::exch::Exchange::md_feeds_.

Referenced by poll().

◆ handleMdSubscription()

◆ handleMdUnsubscription()

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

◆ onHyperliquidDisconnected()

void HyperliquidExchange::onHyperliquidDisconnected ( )
overridevirtual

◆ onL2BookUpdate()

void HyperliquidExchange::onL2BookUpdate ( const nlohmann::json & msg)
overridevirtual

◆ onTradesUpdate()

void HyperliquidExchange::onTradesUpdate ( const nlohmann::json & msg)
overridevirtual

◆ poll()

void HyperliquidExchange::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 58 of file hyperliquid_exchange.cpp.

References drainEventQueue().


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