-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.h
113 lines (94 loc) · 2.72 KB
/
message.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#pragma once
#include <cstddef>
#include <cstdint>
#include "floatOp.h"
#include "type.h"
static constexpr int16_t skDefaultIDLen = 32;
union uCombinedAcctID {
uint32_t id_ = 0;
struct {
uint16_t traderID_ : 16;
uint16_t logicAcctID_ : 16;
} breakdown;
uCombinedAcctID(uint32_t v) : id_(v) {}
uCombinedAcctID &operator=(uint32_t v) {
id_ = v;
return *this;
}
} __attribute__((packed));
union ClientOrderID {
uint64_t value_ = 0;
struct {
uint32_t combAcctID_;
// second range from 0 to 86,400 = 24*60*60
uint64_t timeSec_ : 18;
// counter range from 0 to 32768 = 2^15
uint64_t seqNum_ : 14;
} breakdown;
ClientOrderID(uint64_t v) : value_(v) {}
ClientOrderID &operator=(uint64_t v) {
value_ = v;
return *this;
}
} __attribute__((packed));
struct Trade {
uint64_t tradeId_ = 0;
Price price_ = 0;
Qty qty_ = 0;
int32_t bidOrderId_ = 0;
int32_t askOrderId_ = 0;
} __attribute__((packed));
struct InsertOrder {
ClientOrderID coid_ = 0;
Nanoseconds tsNs_ = 0;
uint32_t sid_ = 0;
Price price_ = 0;
Qty qty_ = 0;
Offset offset_ = Offset::Open;
QuoteType side_ = QuoteType::Buy;
OrderType type_ = OrderType::Limit;
TimeInForce tif_ = TimeInForce::IOC;
} __attribute__((packed));
struct Order {
uint64_t coid_ = 0;
// sid_ ==> symbol(instrumentid)
int32_t sid_ = -1;
QuoteType side_ = QuoteType::Buy;
OrderStatus orderStatus_ = OrderStatus::Unknown;
OrderType type_ = OrderType::Limit;
Offset offset_ = Offset::Unknown;
TimeInForce tif_ = TimeInForce::Unknown;
// char reserve_[3] = {'\0'};
float price_ = 0.0;
int32_t qty_ = 0.0;
int32_t remainQty_ = 0.0;
uint64_t createTimeNs_ = 0;
uint64_t updateTimeNs_ = 0;
/*
float latestExecPrice_ = 0.0;
int32_t latestExecQty_ = 0.0;
float latestExecfee_ = 0.0;
int32_t feeSid_ = -1;
double cumExecFee_ = 0.0;
int32_t cumExecQty_ = 0.0;
float avgExecPrice_ = 0.0;*/
char eoid_[skDefaultIDLen] = {'\0'};
// char latestFillId_[skDefaultIDLen] = {'\0'};
} __attribute__((packed));
struct PriceLevel {
Price price_ = 0;
Qty qty_ = 0;
} __attribute__((packed));
template <size_t N>
struct Orderbook {
static constexpr size_t skMaxDepth = N;
using SelfT = Orderbook<N>;
uint16_t bidSize_ = 0;
uint16_t askSize_ = 0;
PriceLevel bids_[N];
PriceLevel asks_[N];
PriceLevel &bid(uint32_t i) { return bids_[i]; }
PriceLevel &ask(uint32_t i) { return asks_[i]; }
const PriceLevel &bid(uint32_t i) const { return bids_[i]; }
const PriceLevel &ask(uint32_t i) const { return asks_[i]; }
} __attribute__((packed));