Joel Grunbaum
2022-01-10 2c515f0de70ad675b5f5d25b6a496d67d8dc0463
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#pragma once
 
#include "book.hpp"
 
#include <chrono>
#include <cstdint>
#include <ostream>
#include <queue>
#include <unordered_map>
 
namespace json
{
enum MessageTypes {
    FUTURE_TYPE,
    SPREAD_TYPE,
    CALL_TYPE,
    PUT_TYPE,
    SETTLEMENT,
    ADD,
    ADDED,
    DELETE,
    DELETED,
    REJECT,
    TRADE,
    BROKER_REQUEST,
    BROKER_ACK,
    BROKER_CONFIRM,
    NONE
};
 
enum TradeTypeEnum { BUY_AGGRESSOR, SELL_AGGRESSOR };
 
struct Message {
    MessageTypes type;
    std::string product;
    Message(MessageTypes type, std::string product);
    Message();
    virtual ~Message() = default;
};
 
struct FromExchange : public Message {
    uint64_t sequence;
    double timestamp;
    FromExchange(MessageTypes type, std::string product, uint64_t sequence,
                 double timestamp);
    virtual ~FromExchange() = default;
};
 
struct ToExchange : public Message {
    ToExchange(MessageTypes type, std::string product);
    virtual ~ToExchange() = default;
};
 
struct Broker : public Message {
    double price;
    book::OrderSideEnum side;
    uint64_t volume;
    std::string counterparty;
    Broker(MessageTypes type, std::string product, double price,
           book::OrderSideEnum side, uint64_t volume, std::string counterparty);
    virtual ~Broker() = default;
};
 
struct AnnounceMessage : public FromExchange {
    int stationId;
    std::string stationName;
    std::string unit;
    std::chrono::nanoseconds expiry;
    double aggFee;
    double pasFee;
    double broFee;
 
    AnnounceMessage(MessageTypes type, std::string product, int stationId,
                    std::string stationName, std::string unit,
                    std::chrono::nanoseconds expiry, double aggFee,
                    double pasFee, double broFee, uint64_t sequence,
                    double timestamp);
};
 
struct SettleMessage : public FromExchange {
    std::string stationName;
    std::chrono::nanoseconds expiry;
    double price;
    SettleMessage(MessageTypes type, std::string product,
                  std::string stationName, std::chrono::nanoseconds expiry,
                  double price, uint64_t sequence, double timestamp);
};
 
struct AddMessage : public ToExchange {
    double price;
    book::OrderSideEnum side;
    uint64_t volume;
    AddMessage(MessageTypes type, std::string product, double price,
               book::OrderSideEnum side, uint64_t volume);
    std::string as_string();
};
 
struct AddedMessage : public FromExchange {
    std::string id;
    book::OrderSideEnum side;
    double price;
    uint64_t filled;
    uint64_t resting;
    AddedMessage(MessageTypes type, std::string product, std::string id,
                 book::OrderSideEnum side, double price, uint64_t filled,
                 uint64_t resting, uint64_t sequence, double timestamp);
};
 
struct DeleteMessage : public ToExchange {
    std::string id;
    DeleteMessage(MessageTypes type, std::string product, std::string id);
    std::string as_string();
};
 
struct DeletedMessage : public FromExchange {
    std::string id;
    book::OrderSideEnum side;
    DeletedMessage(MessageTypes type, std::string product, std::string id,
                   book::OrderSideEnum side, uint64_t sequence,
                   double timestamp);
};
 
struct RejectMessage : public FromExchange {
    std::string error;
    RejectMessage(MessageTypes type, std::string product, std::string error,
                  uint64_t sequence, double timestamp);
};
 
struct TradeMessage : public FromExchange {
    double price;
    uint64_t volume;
    std::string buyer;
    std::string seller;
    TradeTypeEnum tradeType;
    std::string passiveOrder;
    uint64_t passiveOrderRemaining;
    TradeMessage(MessageTypes type, std::string product, double price,
                 uint64_t volume, std::string buyer, std::string seller,
                 TradeTypeEnum tradeType, std::string passiveOrder,
                 uint64_t passiveOrderRemaining, uint64_t sequence,
                 double timestamp);
};
 
struct BrokerRequest : public Broker {
    BrokerRequest(MessageTypes type, std::string product, double price,
                  book::OrderSideEnum side, uint64_t volume,
                  std::string counterparty);
};
 
struct BrokerAck : public Broker {
    std::string id;
    std::string brokerTradeStatus;
    std::string owner;
    BrokerAck(MessageTypes type, std::string product, double price,
              book::OrderSideEnum side, uint64_t volume,
              std::string counterparty, std::string id,
              std::string brokerTradeStatus, std::string owner);
};
 
struct BrokerConfirm : public Broker {
    std::string id;
    BrokerConfirm(MessageTypes type, std::string product, double price,
                  book::OrderSideEnum side, uint64_t volume,
                  std::string counterparty, std::string id);
};
 
std::queue<Message*> parse(std::string& str);
} // namespace json