Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
hyperliquid_live_ws_feed.cpp
Go to the documentation of this file.
1#include <slick/logger.hpp>
3
4using namespace slick::sim::md_feed;
5
6void HyperliquidLiveWSFeed::on_l2(const nlohmann::json& msg) {
7 const auto data_ptr = msg.find("data");
8 if (data_ptr == msg.end()) return;
9
10 try {
11 const auto& data = *data_ptr;
12
13 // First message after subscribing is an uncompressed full snapshot
14 // under "s" — no decode_l2_diff needed, it's already plain JSON.
15 if (const auto s_ptr = data.find("s"); s_ptr != data.end()) {
16 callbacks_->onL2BookUpdate(*s_ptr);
17 return;
18 }
19
20 const auto c_ptr = data.find("c");
21 if (c_ptr == data.end() || !c_ptr->is_string()) return;
22
23 const auto diff = hyperliquid::decode_l2_diff(c_ptr->get<std::string>());
24 callbacks_->onL2BookUpdate(diff);
25 } catch (const std::exception& e) {
26 LOG_ERROR("Hyperliquid MD: Failed to parse l2 diff: {}", e.what());
27 }
28}