Joel Grunbaum
2022-01-10 2c515f0de70ad675b5f5d25b6a496d67d8dc0463
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,
28     NONE
16b655 29 };
JG 30
31 enum TradeTypeEnum { BUY_AGGRESSOR, SELL_AGGRESSOR };
32
33 struct Message {
2c515f 34     MessageTypes type;
JG 35     std::string product;
36     Message(MessageTypes type, std::string product);
37     Message();
38     virtual ~Message() = default;
16b655 39 };
JG 40
41 struct FromExchange : public Message {
2c515f 42     uint64_t sequence;
JG 43     double timestamp;
44     FromExchange(MessageTypes type, std::string product, uint64_t sequence,
45                  double timestamp);
46     virtual ~FromExchange() = default;
16b655 47 };
JG 48
49 struct ToExchange : public Message {
2c515f 50     ToExchange(MessageTypes type, std::string product);
JG 51     virtual ~ToExchange() = default;
16b655 52 };
JG 53
54 struct Broker : public Message {
2c515f 55     double price;
JG 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;
16b655 62 };
JG 63
64 struct AnnounceMessage : public FromExchange {
2c515f 65     int stationId;
JG 66     std::string stationName;
67     std::string unit;
68     std::chrono::nanoseconds expiry;
69     double aggFee;
70     double pasFee;
71     double broFee;
16b655 72
2c515f 73     AnnounceMessage(MessageTypes type, std::string product, int stationId,
JG 74                     std::string stationName, std::string unit,
75                     std::chrono::nanoseconds expiry, double aggFee,
76                     double pasFee, double broFee, uint64_t sequence,
77                     double timestamp);
16b655 78 };
JG 79
80 struct SettleMessage : public FromExchange {
2c515f 81     std::string stationName;
JG 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);
16b655 87 };
JG 88
89 struct AddMessage : public ToExchange {
2c515f 90     double price;
JG 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();
16b655 96 };
JG 97
98 struct AddedMessage : public FromExchange {
2c515f 99     std::string id;
JG 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);
16b655 107 };
JG 108
109 struct DeleteMessage : public ToExchange {
2c515f 110     std::string id;
JG 111     DeleteMessage(MessageTypes type, std::string product, std::string id);
112     std::string as_string();
16b655 113 };
JG 114
115 struct DeletedMessage : public FromExchange {
2c515f 116     std::string id;
JG 117     book::OrderSideEnum side;
118     DeletedMessage(MessageTypes type, std::string product, std::string id,
119                    book::OrderSideEnum side, uint64_t sequence,
120                    double timestamp);
16b655 121 };
JG 122
123 struct RejectMessage : public FromExchange {
2c515f 124     std::string error;
JG 125     RejectMessage(MessageTypes type, std::string product, std::string error,
126                   uint64_t sequence, double timestamp);
16b655 127 };
JG 128
129 struct TradeMessage : public FromExchange {
2c515f 130     double price;
JG 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);
16b655 142 };
JG 143
144 struct BrokerRequest : public Broker {
2c515f 145     BrokerRequest(MessageTypes type, std::string product, double price,
JG 146                   book::OrderSideEnum side, uint64_t volume,
147                   std::string counterparty);
16b655 148 };
JG 149
150 struct BrokerAck : public Broker {
2c515f 151     std::string id;
JG 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);
16b655 158 };
JG 159
160 struct BrokerConfirm : public Broker {
2c515f 161     std::string id;
JG 162     BrokerConfirm(MessageTypes type, std::string product, double price,
163                   book::OrderSideEnum side, uint64_t volume,
164                   std::string counterparty, std::string id);
16b655 165 };
JG 166
b4cf0a 167 std::queue<Message*> parse(std::string& str);
16b655 168 } // namespace json