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 { |
|
14 |
FUTURE_TYPE, |
|
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, |
|
28 |
NONE |
|
29 |
}; |
|
30 |
|
|
31 |
enum TradeTypeEnum { BUY_AGGRESSOR, SELL_AGGRESSOR }; |
|
32 |
|
|
33 |
struct Message { |
|
34 |
MessageTypes type; |
|
35 |
std::string product; |
|
36 |
Message(MessageTypes type, std::string product); |
|
37 |
Message(); |
|
38 |
virtual ~Message() = default; |
|
39 |
}; |
|
40 |
|
|
41 |
struct FromExchange : public Message { |
|
42 |
uint64_t sequence; |
|
43 |
double timestamp; |
|
44 |
FromExchange(MessageTypes type, std::string product, uint64_t sequence, |
|
45 |
double timestamp); |
|
46 |
virtual ~FromExchange() = default; |
|
47 |
}; |
|
48 |
|
|
49 |
struct ToExchange : public Message { |
|
50 |
ToExchange(MessageTypes type, std::string product); |
|
51 |
virtual ~ToExchange() = default; |
|
52 |
}; |
|
53 |
|
|
54 |
struct Broker : public Message { |
|
55 |
double price; |
|
56 |
book::OrderSideEnum side; |
|
57 |
uint64_t volume; |
|
58 |
std::string counterparty; |
|
59 |
Broker(MessageTypes type, std::string product, double price, |
|
60 |
book::OrderSideEnum side, uint64_t volume, std::string counterparty); |
|
61 |
virtual ~Broker() = default; |
|
62 |
}; |
|
63 |
|
|
64 |
struct AnnounceMessage : public FromExchange { |
|
65 |
std::string stationId; |
|
66 |
std::string stationName; |
|
67 |
std::string unit; |
|
68 |
std::chrono::nanoseconds expiry; |
|
69 |
double aggFee; |
|
70 |
double pasFee; |
|
71 |
double broFee; |
|
72 |
|
|
73 |
AnnounceMessage(MessageTypes type, std::string product, |
|
74 |
std::string stationId, std::string stationName, |
|
75 |
std::string unit, std::chrono::nanoseconds expiry, |
|
76 |
double aggFee, double pasFee, double broFee, |
|
77 |
uint64_t sequence, double timestamp); |
|
78 |
}; |
|
79 |
|
|
80 |
struct SettleMessage : public FromExchange { |
|
81 |
std::string stationName; |
|
82 |
std::chrono::nanoseconds expiry; |
|
83 |
double price; |
|
84 |
SettleMessage(MessageTypes type, std::string product, |
|
85 |
std::string stationName, std::chrono::nanoseconds expiry, |
|
86 |
double price, uint64_t sequence, double timestamp); |
|
87 |
}; |
|
88 |
|
|
89 |
struct AddMessage : public ToExchange { |
|
90 |
double price; |
|
91 |
book::OrderSideEnum side; |
|
92 |
uint64_t volume; |
|
93 |
AddMessage(MessageTypes type, std::string product, double price, |
|
94 |
book::OrderSideEnum side, uint64_t volume); |
|
95 |
std::string as_string(); |
|
96 |
}; |
|
97 |
|
|
98 |
struct AddedMessage : public FromExchange { |
|
99 |
std::string id; |
|
100 |
book::OrderSideEnum side; |
|
101 |
double price; |
|
102 |
uint64_t filled; |
|
103 |
uint64_t resting; |
|
104 |
AddedMessage(MessageTypes type, std::string product, std::string id, |
|
105 |
book::OrderSideEnum side, double price, uint64_t filled, |
|
106 |
uint64_t resting, uint64_t sequence, double timestamp); |
|
107 |
}; |
|
108 |
|
|
109 |
struct DeleteMessage : public ToExchange { |
|
110 |
std::string id; |
|
111 |
DeleteMessage(MessageTypes type, std::string product, std::string id); |
|
112 |
std::string as_string(); |
|
113 |
}; |
|
114 |
|
|
115 |
struct DeletedMessage : public FromExchange { |
|
116 |
std::string id; |
|
117 |
book::OrderSideEnum side; |
|
118 |
DeletedMessage(MessageTypes type, std::string product, std::string id, |
|
119 |
book::OrderSideEnum side, uint64_t sequence, |
|
120 |
double timestamp); |
|
121 |
}; |
|
122 |
|
|
123 |
struct RejectMessage : public FromExchange { |
|
124 |
std::string error; |
|
125 |
RejectMessage(MessageTypes type, std::string product, std::string error, |
|
126 |
uint64_t sequence, double timestamp); |
|
127 |
}; |
|
128 |
|
|
129 |
struct TradeMessage : public FromExchange { |
|
130 |
double price; |
|
131 |
uint64_t volume; |
|
132 |
std::string buyer; |
|
133 |
std::string seller; |
|
134 |
TradeTypeEnum tradeType; |
|
135 |
std::string passiveOrder; |
|
136 |
uint64_t passiveOrderRemaining; |
|
137 |
TradeMessage(MessageTypes type, std::string product, double price, |
|
138 |
uint64_t volume, std::string buyer, std::string seller, |
|
139 |
TradeTypeEnum tradeType, std::string passiveOrder, |
|
140 |
uint64_t passiveOrderRemaining, uint64_t sequence, |
|
141 |
double timestamp); |
|
142 |
}; |
|
143 |
|
|
144 |
struct BrokerRequest : public Broker { |
|
145 |
BrokerRequest(MessageTypes type, std::string product, double price, |
|
146 |
book::OrderSideEnum side, uint64_t volume, |
|
147 |
std::string counterparty); |
|
148 |
}; |
|
149 |
|
|
150 |
struct BrokerAck : public Broker { |
|
151 |
std::string id; |
|
152 |
std::string brokerTradeStatus; |
|
153 |
std::string owner; |
|
154 |
BrokerAck(MessageTypes type, std::string product, double price, |
|
155 |
book::OrderSideEnum side, uint64_t volume, |
|
156 |
std::string counterparty, std::string id, |
|
157 |
std::string brokerTradeStatus, std::string owner); |
|
158 |
}; |
|
159 |
|
|
160 |
struct BrokerConfirm : public Broker { |
|
161 |
std::string id; |
|
162 |
BrokerConfirm(MessageTypes type, std::string product, double price, |
|
163 |
book::OrderSideEnum side, uint64_t volume, |
|
164 |
std::string counterparty, std::string id); |
|
165 |
}; |
|
166 |
|
|
167 |
Message* parseSingle(std::string& str); |
|
168 |
std::queue<Message*> parseMany(std::string& str); |
|
169 |
} // namespace json |