Slick Trader 0.11.0
Multi-broker algorithmic trading engine with plugin strategies and a live web dashboard
Loading...
Searching...
No Matches
mbo_update_event.hpp
Go to the documentation of this file.
1#pragma once
2
6#include <cstddef>
7#include <cstdint>
8#include <type_traits>
9
10namespace slick::trader {
11
12// What happened to one order of a market-by-order (level 3) book.
13enum class MboAction : uint8_t {
14 ADD, // a new order
15 MODIFY, // its price, quantity or priority changed
16 REMOVE, // gone - cancelled or fully filled; only order_id is read
17};
18
19// MboUpdateEvent - POD struct for lock-free queue
20#pragma pack(push, 1)
21struct MboOrder {
22 uint64_t order_id; // the exchange's order id - the number an OrderAckEvent carries as text
23 uint64_t priority; // place in the queue at its price: lower trades first. 0 = the exchange
24 // gives none, and orders queue in the order they arrive
26 qty_t quantity; // displayed quantity
29};
30
31// Order-by-order changes to one instrument's book. An exchange event that does not fit one
32// record is spread over several: only the last has is_last set, and the book is consistent -
33// and handed to strategies - only then.
34struct MboUpdateEvent : public Event {
35 uint16_t num_orders;
36 uint64_t sequence_num;
37 bool is_snapshot; // the book starts over from these orders; set on a snapshot's first record
38 bool is_last; // the last record of the exchange event or snapshot
40
43 , num_orders(0)
44 , sequence_num(0)
45 , is_snapshot(false)
46 , is_last(true)
47 {}
48
49 // Bytes a record carrying `count` orders takes - what to publish it with.
50 static constexpr uint32_t size_for(std::size_t count) noexcept {
51 return static_cast<uint32_t>(sizeof(MboUpdateEvent) + count * sizeof(MboOrder));
52 }
53};
54#pragma pack(pop)
55
56static_assert(std::is_trivially_copyable_v<MboUpdateEvent>, "MboUpdateEvent must be trivially copyable");
57
58} // namespace slick::trader
int64_t qty_t
Definition types.hpp:17
int64_t price_t
Definition types.hpp:16
Event(EventType t=EventType::TRADE)
Definition event.hpp:63
static constexpr uint32_t size_for(std::size_t count) noexcept