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
3
#include <
slick-trader/events/event.hpp
>
4
#include <
slick-trader/utils/types.hpp
>
5
#include <
slick-trader/utils/order_types.hpp
>
6
#include <cstddef>
7
#include <cstdint>
8
#include <type_traits>
9
10
namespace
slick::trader
{
11
12
// What happened to one order of a market-by-order (level 3) book.
13
enum 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)
21
struct
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
25
price_t
price
;
26
qty_t
quantity
;
// displayed quantity
27
Side
side
;
28
MboAction
action
;
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.
34
struct
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
39
MboOrder
orders
[0];
40
41
MboUpdateEvent
()
42
:
Event
(
EventType
::
MBO_UPDATE
)
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
56
static_assert
(std::is_trivially_copyable_v<MboUpdateEvent>,
"MboUpdateEvent must be trivially copyable"
);
57
58
}
// namespace slick::trader
event.hpp
slick::trader
Definition
coinbase_broker.hpp:11
slick::trader::EventType
EventType
Definition
event.hpp:26
slick::trader::EventType::MBO_UPDATE
@ MBO_UPDATE
Definition
event.hpp:49
slick::trader::MboAction
MboAction
Definition
mbo_update_event.hpp:13
slick::trader::MboAction::REMOVE
@ REMOVE
Definition
mbo_update_event.hpp:16
slick::trader::MboAction::ADD
@ ADD
Definition
mbo_update_event.hpp:14
slick::trader::MboAction::MODIFY
@ MODIFY
Definition
mbo_update_event.hpp:15
slick::trader::Side
Side
Definition
order_types.hpp:8
slick::trader::qty_t
int64_t qty_t
Definition
types.hpp:17
slick::trader::price_t
int64_t price_t
Definition
types.hpp:16
order_types.hpp
slick::trader::Event::Event
Event(EventType t=EventType::TRADE)
Definition
event.hpp:63
slick::trader::MboOrder
Definition
mbo_update_event.hpp:21
slick::trader::MboOrder::order_id
uint64_t order_id
Definition
mbo_update_event.hpp:22
slick::trader::MboOrder::price
price_t price
Definition
mbo_update_event.hpp:25
slick::trader::MboOrder::priority
uint64_t priority
Definition
mbo_update_event.hpp:23
slick::trader::MboOrder::quantity
qty_t quantity
Definition
mbo_update_event.hpp:26
slick::trader::MboOrder::action
MboAction action
Definition
mbo_update_event.hpp:28
slick::trader::MboOrder::side
Side side
Definition
mbo_update_event.hpp:27
slick::trader::MboUpdateEvent::num_orders
uint16_t num_orders
Definition
mbo_update_event.hpp:35
slick::trader::MboUpdateEvent::size_for
static constexpr uint32_t size_for(std::size_t count) noexcept
Definition
mbo_update_event.hpp:50
slick::trader::MboUpdateEvent::orders
MboOrder orders[0]
Definition
mbo_update_event.hpp:39
slick::trader::MboUpdateEvent::sequence_num
uint64_t sequence_num
Definition
mbo_update_event.hpp:36
slick::trader::MboUpdateEvent::is_last
bool is_last
Definition
mbo_update_event.hpp:38
slick::trader::MboUpdateEvent::MboUpdateEvent
MboUpdateEvent()
Definition
mbo_update_event.hpp:41
slick::trader::MboUpdateEvent::is_snapshot
bool is_snapshot
Definition
mbo_update_event.hpp:37
types.hpp
slick-trader
events
mbo_update_event.hpp
Generated by
1.15.0