Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
order_book.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <cstdint>
5#include <iterator>
6#include <string>
7#include <set>
8#include <sstream>
9#include <tuple>
10#include <chrono>
11#include <unordered_map>
12#include <type_traits>
13#include <slick/object_pool.hpp>
14#include <slick/queue.hpp>
15#include <common/order.hpp>
17#include <common/types.hpp>
18#include <slick/orderbook/orderbook_l3.hpp>
19#include <utils/order.hpp>
20#include <slick/orderbook/observer.hpp>
21#include <boost/uuid/uuid.hpp>
22#include <boost/uuid/uuid_io.hpp>
23#include <boost/uuid/random_generator.hpp>
24#include <boost/lexical_cast.hpp>
25#include <utils/order.hpp>
26
27namespace slick::sim {
28
29using OrderBookL3 = slick::orderbook::OrderBookL3;
30using IOrderBookObserver = slick::orderbook::IOrderBookObserver;
31using PriceLevelUpdate = slick::orderbook::PriceLevelUpdate;
32using OrderUpdate = slick::orderbook::OrderUpdate;
33using TopOfBook = slick::orderbook::TopOfBook;
34using SymbolId = slick::orderbook::SymbolId;
35using Timestamp = slick::orderbook::Timestamp;
36
37inline orderbook::Side to_book_side(Side side) {
38 return static_cast<orderbook::Side>(side);
39}
40
41class OrderBook;
42
43class OrderBook : public OrderBookL3, public orderbook::IOrderBookObserver, public std::enable_shared_from_this<OrderBook> {
44public:
45 OrderBook(symid_t sid, std::string_view symbol, Venue venue, uint_fast32_t buffer_size = 65536)
46 : OrderBookL3(sid, buffer_size, 500)
47 , venue_(venue)
48 , symbol_(symbol)
49 , order_buffer_(buffer_size)
50 {
51 orders_.reserve(1024);
52 orders_by_client_order_id_.reserve(1024);
53 orders_by_order_id_.reserve(1024);
54 }
55 ~OrderBook() override = default;
56
58 void freeOrder(Order* order) {
59 order_buffer_.free(order);
60 }
61 Order* findOrderByClientOrderId(std::string_view client_order_id);
62 Order* findOrderByOrderId(std::string_view order_id);
63 Order* findOrder(uint64_t id);
64
67 const symbol_name_t& symbolName() const noexcept {
68 return symbol_;
69 }
70
71 symid_t sid() const noexcept {
72 return symbol();
73 }
74
75 void onPriceLevelUpdate(const PriceLevelUpdate& update) override;
76 void onOrderUpdate(const OrderUpdate& update) override;
77
78 // The level quantity excludes exchange orders
79 qty_t getMDLevelQty(price_t price) const;
80
81 virtual void populateL2SubscriptionResponse(slick::queue<uint8_t> &md_update_queue, uint8_t channel) = 0;
82 virtual void populateL2Snapshot(slick::queue<uint8_t> &md_update_queue) = 0;
83 virtual void populateMDBookUpdate(MDBookUpdate &book_update) = 0;
84
85 using OrderBookL3::addOrder;
86 using OrderBookL3::modifyOrder;
87 using OrderBookL3::deleteOrder;
88
89 void addOrder(Order* order, uint64_t timestamp, uint64_t seq_num = 0, bool is_last_in_batch = true) {
90 order->priority = nextOrderPriority();
91 orders_.emplace(order->id, order);
92 if (!order->client_order_id.empty()) {
93 orders_by_client_order_id_.emplace(order->client_order_id, order);
94 }
95 if (!order->order_id.empty()) {
96 orders_by_order_id_.emplace(order->order_id, order);
97 }
98 addOrder(order->id, to_book_side(order->side), order->price, order->leaves_quantity, timestamp, order->priority,
99 seq_num, is_last_in_batch);
100 }
101
106 virtual void addBookOrder(uint64_t order_id, slick::orderbook::Side book_side, price_t price, qty_t qty, uint64_t timestamp, uint64_t seq_num, bool is_last_in_batch = true) = 0;
107
108 void deleteOrder(Order* order, uint64_t timestamp, uint64_t seq_num = 0, bool is_last_in_batch = true) {
109 deleteOrder(order->id, timestamp, seq_num, is_last_in_batch);
110 auto it = orders_.find(order->id);
111 if (it != orders_.end()) {
112 if (!order->client_order_id.empty()) {
114 }
115 if (!order->order_id.empty()) {
116 orders_by_order_id_.erase(order->order_id);
117 }
118 orders_.erase(it);
119 }
120 }
121
122 void deleteOrder(Order* order) {
123 auto it = orders_.find(order->id);
124 if (it != orders_.end()) {
125 if (!order->client_order_id.empty()) {
127 }
128 if (!order->order_id.empty()) {
129 orders_by_order_id_.erase(order->order_id);
130 }
131 orders_.erase(it);
132 }
133 freeOrder(order);
134 }
135
136 void modifyOrder(Order* order, price_t new_price, qty_t new_qty, uint64_t timestamp,
137 uint64_t seq_num = 0, bool is_last_in_batch = true) {
138 auto it = orders_.find(order->id);
139 if (it == orders_.end()) [[unlikely]] {
140 order->price = new_price;
141 order->priority = nextOrderPriority();
142 if (new_qty) {
143 it = orders_.emplace(order->id, order).first;
144 if (!order->client_order_id.empty()) {
145 orders_by_client_order_id_.emplace(order->client_order_id, order);
146 }
147 if (!order->order_id.empty()) {
148 orders_by_order_id_.emplace(order->order_id, order);
149 }
150 }
151 }
152 else if (new_price != order->price) {
153 order->price = new_price;
154 order->priority = nextOrderPriority();
155 }
156 order->quantity = new_qty;
157 modifyOrder(order->id, new_price, order->leaves_quantity, timestamp, order->priority, seq_num, is_last_in_batch);
158
159 if (order->leaves_quantity == 0 && it != orders_.end()) {
160 if (!order->client_order_id.empty()) {
162 }
163 if (!order->order_id.empty()) {
164 orders_by_order_id_.erase(order->order_id);
165 }
166 orders_.erase(it);
167 }
168 }
169
170 // Clears only phantom (market-data) orders from the L3 book, then re-inserts
171 // active simulator orders so they remain available for matching. Call this
172 // instead of clear() when rebuilding from a full book snapshot (e.g. Hyperliquid).
174 std::vector<std::tuple<uint64_t, orderbook::Side, price_t, qty_t, time_t, uint64_t>> sim_orders;
175 sim_orders.reserve(orders_.size());
176 for (auto& [id, order] : orders_) {
177 if (order->leaves_quantity > 0) {
178 sim_orders.emplace_back(id, to_book_side(order->side), order->price,
179 order->leaves_quantity, order->last_update_time, order->priority);
180 }
181 }
182 OrderBookL3::clear();
184 for (auto& [id, side, price, qty, ts, prio] : sim_orders) {
185 OrderBookL3::addOrder(id, side, price, qty, ts, prio, 0, false);
186 }
187 }
188
189 bool executeOrder(slick::orderbook::OrderId order_id, slick::orderbook::Quantity executed_quantity, uint64_t timestamp, uint64_t seq_num = 0, bool is_last_in_batch = true) override {
190 // OrderBookL3 discards a mutation whose sequence regresses, but it does so
191 // *after* the fill below has already been booked onto our own Order - which
192 // reported a fill to the client that the book never took, and once
193 // leaves_quantity reached zero erased the order from the lookup maps while
194 // the L3 book kept it resting: permanently invisible phantom liquidity.
195 // Mirror the base's condition and fail before touching anything. The order
196 // of the two mutations below cannot simply be swapped instead: the base
197 // fires onOrderUpdate, which zeroes leaves_quantity on a full execution, and
198 // utils::executeOrder would then subtract from zero.
199 if (seq_num > 0 && seq_num < getLastSeqNum()) {
200 return false;
201 }
202 auto *order = findOrder(order_id);
203 if (order) {
204 utils::executeOrder(order, order->price, executed_quantity, timestamp);
205 }
206 auto rt = OrderBookL3::executeOrder(order_id, executed_quantity, timestamp, seq_num, is_last_in_batch);
207 if (order && order->leaves_quantity == 0) {
208 if (!order->client_order_id.empty()) {
209 orders_by_client_order_id_.erase(order->client_order_id);
210 }
211 if (!order->order_id.empty()) {
212 orders_by_order_id_.erase(order->order_id);
213 }
214 orders_.erase(order_id);
215 }
216 return rt;
217 }
218
219 time_t lastUpdateTime() const noexcept {
220 return last_update_time_;
221 }
222
223 uint64_t lastSeqNum() const noexcept {
224 return last_seq_num_;
225 }
226
227 void setLastUpdate(time_t timestamp, uint64_t seq_num) noexcept {
228 last_update_time_ = timestamp;
229 last_seq_num_ = seq_num;
230 }
231
232 virtual std::string to_string() const = 0;
233
242 static uint64_t nextOrderPriority() noexcept {
243 return next_priority_.fetch_add(1, std::memory_order_relaxed) + 1;
244 }
245
246protected:
247 friend struct Observer;
248 static std::atomic<uint64_t> next_priority_;
250 uint64_t last_seq_num_ = 0;
256
257 slick::ObjectPool<Order> order_buffer_;
258 std::unordered_map<uint64_t, Order*> orders_;
259 // Use fixed_string keys to avoid a separate heap allocation for each id.
260 // The transparent functors accept string_view, which fixed_string converts
261 // to, so callers can still look up orders by string_view.
262 std::unordered_map<utils::fixed_string<37>, Order*, StringViewHash, StringViewEq> orders_by_client_order_id_;
263 std::unordered_map<utils::fixed_string<37>, Order*, StringViewHash, StringViewEq> orders_by_order_id_;
265 std::unordered_map<price_t, qty_t> feed_md_level_quantity_; // Level quantity excluding simulator orders
266};
267
268struct Empty {};
269
270enum class OrderBookType {
273};
274
275template<OrderBookType BookType>
276class OrderBookImpl : public OrderBook {
277public:
278 OrderBookImpl(symid_t sid, std::string_view symbol, Venue venue, uint_fast32_t buffer_size = 65536)
279 : OrderBook(sid, symbol, venue, buffer_size)
280 {
281 }
282 ~OrderBookImpl() override = default;
283
284 void addBookOrder(uint64_t order_id, slick::orderbook::Side book_side, price_t price, qty_t qty, uint64_t timestamp, uint64_t seq_num, bool is_last_in_batch = true) override;
285
286 void populateMDBookUpdate(MDBookUpdate &book_update) override;
287 void populateL2SubscriptionResponse(slick::queue<uint8_t> &md_update_queue, uint8_t channel) override;
288 void populateL2Snapshot(slick::queue<uint8_t> &md_update_queue) override;
289
290 // void modifyOrder(Order* order, price_t new_price, qty_t new_qty) override {}
291
292
293 std::string to_string() const override;
294};
295
296
297
298inline std::atomic<uint64_t> OrderBook::next_priority_{0};
299
301 auto *order = order_buffer_.allocate();
302
303 // Keep one generator per thread. Constructing it seeds a Mersenne twister
304 // from OS entropy, which costs more than generating an id. Orders currently
305 // allocate on the exchange thread; thread_local also supports other callers.
306 static thread_local boost::uuids::random_generator uuid_gen;
307 const boost::uuids::uuid u = uuid_gen();
308
309 // Write the 36-character UUID directly into the id field, whose capacity
310 // matches it, without constructing a temporary std::string.
311 static_assert(decltype(Order::order_id)::capacity() == 36,
312 "order_id must hold a rendered UUID exactly");
313 boost::uuids::to_chars(u, order->order_id.data());
314 order->order_id.data()[36] = '\0';
315
316 order->id = utils::nextOrderId();
317 order->request_tag = 0;
318 order->created_time = utils::get_current_time_ns();
319 order->last_update_time = order->created_time;
320 order->resetFillAccounting();
321 return order;
322}
323
325 auto it = feed_md_level_quantity_.find(price);
326 if (it == feed_md_level_quantity_.end()) {
327 return 0;
328 }
329
330 return it->second;
331}
332
334 if (update.quantity == 0) {
335 SLICK_ASSERT(feed_md_level_quantity_.find(update.price) != feed_md_level_quantity_.end()
336 || feed_md_level_quantity_[update.price] == 0);
337 }
338}
339
340inline void OrderBook::onOrderUpdate(const OrderUpdate& update) {
341 auto *our_order = findOrder(update.order_id);
342 if (!our_order) {
343 // This is a MD order, update md_level_qty
344 if (update.price != update.old_price) {
345 auto it = feed_md_level_quantity_.find(update.old_price);
346 if (it != feed_md_level_quantity_.end()) {
347 it->second -= update.old_qty;
348 }
349
350 it = feed_md_level_quantity_.find(update.price);
351 if (it != feed_md_level_quantity_.end()) {
352 it->second += update.quantity;
353 } else if (update.quantity) {
354 feed_md_level_quantity_[update.price] = update.quantity;
355 }
356 }
357 else {
358 auto it = feed_md_level_quantity_.find(update.price);
359 if (it != feed_md_level_quantity_.end()) {
360 it->second += update.quantity - update.old_qty;
361 }
362 else if (update.quantity) {
363 feed_md_level_quantity_[update.price] = update.quantity;
364 }
365 }
366 }
367 else if (update.quantity == 0 && our_order->quantity != update.quantity) {
368 our_order->leaves_quantity = 0;
369 }
370}
371
372inline Order* OrderBook::findOrderByClientOrderId(std::string_view client_order_id) {
373 auto it = orders_by_client_order_id_.find(client_order_id);
374 return it == orders_by_client_order_id_.end() ? nullptr : it->second;
375}
376
377inline Order* OrderBook::findOrderByOrderId(std::string_view client_order_id) {
378 auto it = orders_by_order_id_.find(client_order_id);
379 return it == orders_by_order_id_.end() ? nullptr : it->second;
380}
381
382inline Order* OrderBook::findOrder(uint64_t order_id) {
383 auto it = orders_.find(order_id);
384 return it != orders_.end() ? it->second : nullptr;
385}
386
387
388template<OrderBookType BookType>
390 uint64_t order_id,
391 slick::orderbook::Side book_side,
392 price_t price,
393 qty_t qty,
394 uint64_t timestamp,
395 uint64_t seq_num,
396 bool is_last_in_batch) {
397 addOrder(order_id, book_side, price, qty, timestamp, nextOrderPriority(), seq_num, is_last_in_batch);
398}
399
400template<OrderBookType BookType>
401inline std::string OrderBookImpl<BookType>::to_string() const {
402 std::stringstream ss;
403 ss << "OrderBook: " << symbol_ << "\n";
404 auto &sell_levels = getLevelsL3(orderbook::Side::Sell);
405 // Best 20 asks, worst first. ranges::next clamps to end() and is O(1) on flat_map.
406 auto it_sell = std::make_reverse_iterator(std::ranges::next(sell_levels.begin(), 20, sell_levels.end()));
407 for (; it_sell != sell_levels.rend(); ++it_sell) {
408 ss << std::right << std::setw(50) << std::format("{:.2f}", to_price_double(it_sell->first));
409 ss << std::right << std::setw(20) << std::format("{:.8f}", to_qty_double(it_sell->second.total_quantity));
410 ss << std::right << std::setw(10) << it_sell->second.orderCount() << "\n";
411 }
412
413 auto &buy_levels = getLevelsL3(orderbook::Side::Buy);
414 uint32_t i = 0;
415 for (auto it_buy = buy_levels.begin(); it_buy != buy_levels.end() && i < 20; ++it_buy, ++i) {
416 ss << std::right << std::setw(10) << it_buy->second.orderCount();
417 ss << std::right << std::setw(20) << std::format("{:.8f}", to_qty_double(it_buy->second.total_quantity));
418 ss << std::right << std::setw(20) << std::format("{:.2f}", to_price_double(it_buy->first)) << "\n";
419 }
420 return ss.str();
421}
422
423// L2 Book Implementation
424template<>
426 auto &ask_levels = getLevelsL3(orderbook::Side::Sell);
427 uint32_t i = 0;
428 for (auto it = ask_levels.begin(); it != ask_levels.end() && i < 10; ++it, ++i) {
429 auto &levels = book_update.sell;
430 levels[i].price = it->first;
431 levels[i].qty = it->second.getTotalQuantity();
432 levels[i].num_orders = static_cast<uint32_t>(it->second.orderCount());
433 }
434 i = 0;
435 auto &bid_levels = getLevelsL3(orderbook::Side::Buy);
436 for (auto it = bid_levels.begin(); it != bid_levels.end() && i < 10; ++it, ++i) {
437 auto &levels = book_update.buy;
438 levels[i].price = it->first;
439 levels[i].qty = it->second.getTotalQuantity();
440 levels[i].num_orders = static_cast<uint32_t>(it->second.orderCount());
441 }
442}
443
444template<>
445inline void OrderBookImpl<OrderBookType::L2>::populateL2SubscriptionResponse(slick::queue<uint8_t> &md_update_queue, uint8_t channel) {
446 auto &ask_levels = getLevelsL3(orderbook::Side::Sell);
447 auto &bid_levels = getLevelsL3(orderbook::Side::Buy);
448 auto sz = sizeof(MarketDataUpdate) + sizeof(MDSubscriptionResponse) + sizeof(BookSnapshot) + (bid_levels.size() + ask_levels.size()) * sizeof(MDLevel);
449 auto index = md_update_queue.reserve(static_cast<uint32_t>(sz));
450 auto *update = reinterpret_cast<MarketDataUpdate*>(md_update_queue[index]);
451 memcpy(update->symbol, symbol_.data(), sizeof(update->symbol));
452 update->venue = venue_;
453 update->type = MDUpdateType::SUB_RESPONSE;
454
455 auto *response = reinterpret_cast<MDSubscriptionResponse*>(update->data);
456 response->channel = channel;
457 // Set explicitly, never left to the recycled slot: this frame does carry a book
458 // snapshot, and the publisher decides whether to read one from this field.
459 response->reject_reason = MDSubscriptionRejectReason::NONE;
460
461 auto *snapshot = reinterpret_cast<BookSnapshot*>(response->data);
462 snapshot->num_bid = static_cast<uint32_t>(bid_levels.size());
463 snapshot->num_ask = static_cast<uint32_t>(ask_levels.size());
464
465 auto *levels = reinterpret_cast<MDLevel*>(snapshot->levels);
466
467 for (auto it = bid_levels.begin(); it != bid_levels.end(); ++it, ++levels) {
468 levels->price = it->first;
469 levels->qty = it->second.total_quantity;
470 levels->num_orders = static_cast<uint32_t>(it->second.orderCount());
471 }
472 for (auto it = ask_levels.begin(); it != ask_levels.end(); ++it, ++levels) {
473 levels->price = it->first;
474 levels->qty = it->second.total_quantity;
475 levels->num_orders = static_cast<uint32_t>(it->second.orderCount());
476 }
477 md_update_queue.publish(index, static_cast<uint32_t>(sz));
478}
479
480template<>
481inline void OrderBookImpl<OrderBookType::L2>::populateL2Snapshot(slick::queue<uint8_t> &md_update_queue) {
482 auto &ask_levels = getLevelsL3(orderbook::Side::Sell);
483 auto &bid_levels = getLevelsL3(orderbook::Side::Buy);
484 auto sz = sizeof(MarketDataUpdate) + sizeof(BookSnapshot) + (bid_levels.size() + ask_levels.size()) * sizeof(MDLevel);
485 auto index = md_update_queue.reserve(static_cast<uint32_t>(sz));
486 auto *update = reinterpret_cast<MarketDataUpdate*>(md_update_queue[index]);
487 memcpy(update->symbol, symbol_.data(), sizeof(update->symbol));
488 update->venue = venue_;
489 update->type = MDUpdateType::BOOK_SNAPSHOT;
490
491 auto *snapshot = reinterpret_cast<BookSnapshot*>(update->data);
492 snapshot->num_bid = static_cast<uint32_t>(bid_levels.size());
493 snapshot->num_ask = static_cast<uint32_t>(ask_levels.size());
494
495 auto *levels = reinterpret_cast<MDLevel*>(snapshot->levels);
496
497 for (auto it = bid_levels.begin(); it != bid_levels.end(); ++it, ++levels) {
498 levels->price = it->first;
499 levels->qty = it->second.total_quantity;
500 levels->num_orders = static_cast<uint32_t>(it->second.orderCount());
501 }
502 for (auto it = ask_levels.begin(); it != ask_levels.end(); ++it, ++levels) {
503 levels->price = it->first;
504 levels->qty = it->second.total_quantity;
505 levels->num_orders = static_cast<uint32_t>(it->second.orderCount());
506 }
507 md_update_queue.publish(index, static_cast<uint32_t>(sz));
508}
509
510// L3 Book Implementation
511
512
513template<>
514inline void OrderBookImpl<OrderBookType::L3>::populateL2SubscriptionResponse([[maybe_unused]] slick::queue<uint8_t>& md_update_queue, [[maybe_unused]] uint8_t channel) {
515 // Stub implementation for testing
516 // In production, this would populate subscription response
517}
518
519template<>
521 // Stub implementation for testing
522 // In production, this would populate MD book update
523}
524
525template<>
526inline void OrderBookImpl<OrderBookType::L3>::populateL2Snapshot([[maybe_unused]] slick::queue<uint8_t> &md_update_queue) {
527}
528
529
530} // end namespace slick::sim::order_book
void populateL2Snapshot(slick::queue< uint8_t > &md_update_queue) override
void populateMDBookUpdate(MDBookUpdate &book_update) override
std::string to_string() const override
void populateL2SubscriptionResponse(slick::queue< uint8_t > &md_update_queue, uint8_t channel) override
~OrderBookImpl() override=default
OrderBookImpl(symid_t sid, std::string_view symbol, Venue venue, uint_fast32_t buffer_size=65536)
void addBookOrder(uint64_t order_id, slick::orderbook::Side book_side, price_t price, qty_t qty, uint64_t timestamp, uint64_t seq_num, bool is_last_in_batch=true) override
Rest phantom (market-data) liquidity.
Order * findOrderByClientOrderId(std::string_view client_order_id)
utils::StringViewEq StringViewEq
static uint64_t nextOrderPriority() noexcept
One sequence shared by every book, so it is drawn from atomically: each exchange runs on its own thre...
Order * findOrder(uint64_t id)
void onPriceLevelUpdate(const PriceLevelUpdate &update) override
qty_t getMDLevelQty(price_t price) const
std::unordered_map< utils::fixed_string< 37 >, Order *, StringViewHash, StringViewEq > orders_by_order_id_
~OrderBook() override=default
virtual std::string to_string() const =0
friend struct Observer
uint64_t lastSeqNum() const noexcept
symbol_name_t symbol_
virtual void populateL2SubscriptionResponse(slick::queue< uint8_t > &md_update_queue, uint8_t channel)=0
OrderUpdate last_order_update_
slick::ObjectPool< Order > order_buffer_
Order * findOrderByOrderId(std::string_view order_id)
std::unordered_map< utils::fixed_string< 37 >, Order *, StringViewHash, StringViewEq > orders_by_client_order_id_
utils::StringViewHash StringViewHash
void onOrderUpdate(const OrderUpdate &update) override
time_t lastUpdateTime() const noexcept
OrderBook(symid_t sid, std::string_view symbol, Venue venue, uint_fast32_t buffer_size=65536)
const symbol_name_t & symbolName() const noexcept
Wire-ready, so publishers copy it as a fixed block instead of reading sizeof(field) bytes out of a sh...
void modifyOrder(Order *order, price_t new_price, qty_t new_qty, uint64_t timestamp, uint64_t seq_num=0, bool is_last_in_batch=true)
virtual void populateMDBookUpdate(MDBookUpdate &book_update)=0
virtual void addBookOrder(uint64_t order_id, slick::orderbook::Side book_side, price_t price, qty_t qty, uint64_t timestamp, uint64_t seq_num, bool is_last_in_batch=true)=0
Rest phantom (market-data) liquidity.
bool executeOrder(slick::orderbook::OrderId order_id, slick::orderbook::Quantity executed_quantity, uint64_t timestamp, uint64_t seq_num=0, bool is_last_in_batch=true) override
void deleteOrder(Order *order, uint64_t timestamp, uint64_t seq_num=0, bool is_last_in_batch=true)
static std::atomic< uint64_t > next_priority_
void freeOrder(Order *order)
symid_t sid() const noexcept
std::unordered_map< price_t, qty_t > feed_md_level_quantity_
void deleteOrder(Order *order)
void setLastUpdate(time_t timestamp, uint64_t seq_num) noexcept
virtual void populateL2Snapshot(slick::queue< uint8_t > &md_update_queue)=0
void addOrder(Order *order, uint64_t timestamp, uint64_t seq_num=0, bool is_last_in_batch=true)
std::unordered_map< uint64_t, Order * > orders_
bool empty() const noexcept
uint64_t nextOrderId() noexcept
Definition order.hpp:10
void executeOrder(Order *order, price_t price, qty_t executed_quantity, time_t timestamp)
Definition order.hpp:15
uint64_t get_current_time_ns()
Definition timestamp.hpp:93
slick::orderbook::Timestamp Timestamp
slick::orderbook::SymbolId SymbolId
slick::orderbook::PriceLevelUpdate PriceLevelUpdate
uint_fast64_t time_t
Definition types.hpp:23
slick::orderbook::TopOfBook TopOfBook
constexpr double to_price_double(price_t price)
Definition types.hpp:46
slick::orderbook::OrderUpdate OrderUpdate
slick::orderbook::OrderBookL3 OrderBookL3
slick::orderbook::IOrderBookObserver IOrderBookObserver
uint16_t symid_t
Definition types.hpp:24
utils::fixed_string< sizeof(MarketDataUpdate::symbol)> symbol_name_t
An instrument name at its wire width.
orderbook::Side to_book_side(Side side)
int_fast64_t qty_t
Definition types.hpp:22
constexpr double to_qty_double(qty_t qty)
Definition types.hpp:54
int_fast64_t price_t
Definition types.hpp:21
utils::fixed_string< 37 > client_order_id
Definition order.hpp:291
utils::fixed_string< 37 > order_id
Definition order.hpp:292
uint64_t priority
Definition order.hpp:301
qty_t leaves_quantity
Definition order.hpp:316
Transparent hash/equality for maps keyed by fixed_string.