commit | author | age
|
16b655
|
1 |
#pragma once |
JG |
2 |
|
|
3 |
#include "book.hpp" |
|
4 |
|
|
5 |
#include <chrono> |
|
6 |
#include <cstdint> |
|
7 |
#include <ostream> |
|
8 |
#include <queue> |
|
9 |
#include <unordered_map> |
|
10 |
|
|
11 |
namespace json |
|
12 |
{ |
|
13 |
enum MessageTypes { |
2c515f
|
14 |
FUTURE_TYPE, |
JG |
15 |
SPREAD_TYPE, |
|
16 |
CALL_TYPE, |
|
17 |
PUT_TYPE, |
|
18 |
SETTLEMENT, |
|
19 |
ADD, |
|
20 |
ADDED, |
|
21 |
DELETE, |
|
22 |
DELETED, |
|
23 |
REJECT, |
|
24 |
TRADE, |
|
25 |
BROKER_REQUEST, |
|
26 |
BROKER_ACK, |
|
27 |
BROKER_CONFIRM, |
6bdd28
|
28 |
ERROR, |
2c515f
|
29 |
NONE |
16b655
|
30 |
}; |
JG |
31 |
|
4fdb65
|
32 |
enum TradeTypeEnum { BUY_AGGRESSOR, SELL_AGGRESSOR, BROKER_TRADE }; |
16b655
|
33 |
|
JG |
34 |
struct Message { |
2c515f
|
35 |
MessageTypes type; |
JG |
36 |
std::string product; |
|
37 |
Message(MessageTypes type, std::string product); |
|
38 |
Message(); |
|
39 |
virtual ~Message() = default; |
6bdd28
|
40 |
}; |
JG |
41 |
|
|
42 |
struct ErrorMessage : public Message { |
|
43 |
std::string message; |
|
44 |
ErrorMessage(std::string message); |
|
45 |
std::string as_string(); |
16b655
|
46 |
}; |
JG |
47 |
|
|
48 |
struct FromExchange : public Message { |
2c515f
|
49 |
uint64_t sequence; |
JG |
50 |
double timestamp; |
|
51 |
FromExchange(MessageTypes type, std::string product, uint64_t sequence, |
|
52 |
double timestamp); |
|
53 |
virtual ~FromExchange() = default; |
16b655
|
54 |
}; |
JG |
55 |
|
|
56 |
struct ToExchange : public Message { |
2c515f
|
57 |
ToExchange(MessageTypes type, std::string product); |
JG |
58 |
virtual ~ToExchange() = default; |
16b655
|
59 |
}; |
JG |
60 |
|
|
61 |
struct Broker : public Message { |
2c515f
|
62 |
double price; |
JG |
63 |
book::OrderSideEnum side; |
|
64 |
uint64_t volume; |
|
65 |
std::string counterparty; |
|
66 |
Broker(MessageTypes type, std::string product, double price, |
|
67 |
book::OrderSideEnum side, uint64_t volume, std::string counterparty); |
|
68 |
virtual ~Broker() = default; |
16b655
|
69 |
}; |
JG |
70 |
|
|
71 |
struct AnnounceMessage : public FromExchange { |
2c515f
|
72 |
int stationId; |
JG |
73 |
std::string stationName; |
|
74 |
std::string unit; |
|
75 |
std::chrono::nanoseconds expiry; |
|
76 |
double aggFee; |
|
77 |
double pasFee; |
|
78 |
double broFee; |
16b655
|
79 |
|
2c515f
|
80 |
AnnounceMessage(MessageTypes type, std::string product, int stationId, |
JG |
81 |
std::string stationName, std::string unit, |
|
82 |
std::chrono::nanoseconds expiry, double aggFee, |
|
83 |
double pasFee, double broFee, uint64_t sequence, |
|
84 |
double timestamp); |
0b7aa0
|
85 |
std::string as_string(); |
16b655
|
86 |
}; |
JG |
87 |
|
|
88 |
struct SettleMessage : public FromExchange { |
2c515f
|
89 |
std::string stationName; |
JG |
90 |
std::chrono::nanoseconds expiry; |
|
91 |
double price; |
|
92 |
SettleMessage(MessageTypes type, std::string product, |
|
93 |
std::string stationName, std::chrono::nanoseconds expiry, |
|
94 |
double price, uint64_t sequence, double timestamp); |
0b7aa0
|
95 |
std::string as_string(); |
16b655
|
96 |
}; |
JG |
97 |
|
|
98 |
struct AddMessage : public ToExchange { |
2c515f
|
99 |
double price; |
JG |
100 |
book::OrderSideEnum side; |
|
101 |
uint64_t volume; |
|
102 |
AddMessage(MessageTypes type, std::string product, double price, |
|
103 |
book::OrderSideEnum side, uint64_t volume); |
|
104 |
std::string as_string(); |
16b655
|
105 |
}; |
JG |
106 |
|
|
107 |
struct AddedMessage : public FromExchange { |
2c515f
|
108 |
std::string id; |
JG |
109 |
book::OrderSideEnum side; |
|
110 |
double price; |
|
111 |
uint64_t filled; |
|
112 |
uint64_t resting; |
0b7aa0
|
113 |
std::string owner; |
2c515f
|
114 |
AddedMessage(MessageTypes type, std::string product, std::string id, |
JG |
115 |
book::OrderSideEnum side, double price, uint64_t filled, |
0b7aa0
|
116 |
uint64_t resting, std::string owner, uint64_t sequence, double timestamp); |
6bdd28
|
117 |
std::string as_string(); |
16b655
|
118 |
}; |
JG |
119 |
|
|
120 |
struct DeleteMessage : public ToExchange { |
2c515f
|
121 |
std::string id; |
JG |
122 |
DeleteMessage(MessageTypes type, std::string product, std::string id); |
|
123 |
std::string as_string(); |
16b655
|
124 |
}; |
JG |
125 |
|
|
126 |
struct DeletedMessage : public FromExchange { |
2c515f
|
127 |
std::string id; |
JG |
128 |
book::OrderSideEnum side; |
|
129 |
DeletedMessage(MessageTypes type, std::string product, std::string id, |
|
130 |
book::OrderSideEnum side, uint64_t sequence, |
|
131 |
double timestamp); |
6bdd28
|
132 |
std::string as_string(); |
16b655
|
133 |
}; |
JG |
134 |
|
|
135 |
struct RejectMessage : public FromExchange { |
2c515f
|
136 |
std::string error; |
JG |
137 |
RejectMessage(MessageTypes type, std::string product, std::string error, |
|
138 |
uint64_t sequence, double timestamp); |
6bdd28
|
139 |
std::string as_string(); |
16b655
|
140 |
}; |
JG |
141 |
|
|
142 |
struct TradeMessage : public FromExchange { |
2c515f
|
143 |
double price; |
JG |
144 |
uint64_t volume; |
|
145 |
std::string buyer; |
|
146 |
std::string seller; |
|
147 |
TradeTypeEnum tradeType; |
|
148 |
std::string passiveOrder; |
|
149 |
uint64_t passiveOrderRemaining; |
|
150 |
TradeMessage(MessageTypes type, std::string product, double price, |
|
151 |
uint64_t volume, std::string buyer, std::string seller, |
|
152 |
TradeTypeEnum tradeType, std::string passiveOrder, |
|
153 |
uint64_t passiveOrderRemaining, uint64_t sequence, |
|
154 |
double timestamp); |
0b7aa0
|
155 |
std::string as_string(); |
16b655
|
156 |
}; |
JG |
157 |
|
|
158 |
struct BrokerRequest : public Broker { |
2c515f
|
159 |
BrokerRequest(MessageTypes type, std::string product, double price, |
JG |
160 |
book::OrderSideEnum side, uint64_t volume, |
|
161 |
std::string counterparty); |
0b7aa0
|
162 |
std::string as_string(); |
16b655
|
163 |
}; |
JG |
164 |
|
|
165 |
struct BrokerAck : public Broker { |
2c515f
|
166 |
std::string id; |
JG |
167 |
std::string brokerTradeStatus; |
|
168 |
std::string owner; |
|
169 |
BrokerAck(MessageTypes type, std::string product, double price, |
|
170 |
book::OrderSideEnum side, uint64_t volume, |
|
171 |
std::string counterparty, std::string id, |
|
172 |
std::string brokerTradeStatus, std::string owner); |
0b7aa0
|
173 |
std::string as_string(); |
16b655
|
174 |
}; |
JG |
175 |
|
|
176 |
struct BrokerConfirm : public Broker { |
2c515f
|
177 |
std::string id; |
JG |
178 |
BrokerConfirm(MessageTypes type, std::string product, double price, |
|
179 |
book::OrderSideEnum side, uint64_t volume, |
|
180 |
std::string counterparty, std::string id); |
0b7aa0
|
181 |
std::string as_string(); |
16b655
|
182 |
}; |
JG |
183 |
|
b4cf0a
|
184 |
std::queue<Message*> parse(std::string& str); |
16b655
|
185 |
} // namespace json |