commit | author | age
|
16b655
|
1 |
#include "strat.hpp" |
JG |
2 |
|
0b7aa0
|
3 |
#include "bom.hpp" |
JG |
4 |
#include "book.hpp" |
|
5 |
#include "json.hpp" |
|
6 |
#include "secrets.hpp" |
|
7 |
|
|
8 |
#include "protocol.hpp" |
|
9 |
#include <deque> |
|
10 |
#include <unordered_map> |
|
11 |
|
2c515f
|
12 |
namespace strat |
JG |
13 |
{ |
0b7aa0
|
14 |
std::unordered_map<std::string, json::Message*> orders; |
16b655
|
15 |
|
0b7aa0
|
16 |
void deleteOrder(json::AddedMessage* m); |
JG |
17 |
void freeMessages(std::deque<json::Message*>& m); |
|
18 |
void printFeed(std::deque<json::Message*>& m); |
|
19 |
void dumbHit(std::deque<json::Message*>& m); |
|
20 |
|
|
21 |
void initialise() |
|
22 |
{ |
|
23 |
bom::initialise(); |
|
24 |
protocol::createWebSocket(); |
16b655
|
25 |
} |
0b7aa0
|
26 |
|
JG |
27 |
void destroy() |
|
28 |
{ |
|
29 |
bom::destroy(); |
|
30 |
for (auto& i : orders) { |
|
31 |
switch (i.second->type) { |
|
32 |
case json::FUTURE_TYPE: |
|
33 |
case json::SPREAD_TYPE: |
|
34 |
case json::CALL_TYPE: |
|
35 |
case json::PUT_TYPE: |
|
36 |
deleteOrder((json::AddedMessage*)i.second); |
|
37 |
default:; |
|
38 |
} |
|
39 |
delete i.second; |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
void mainLoop() |
|
44 |
{ |
|
45 |
auto bs = protocol::recoverBook(); |
441abf
|
46 |
std::cout << "ready" << std::endl; |
0b7aa0
|
47 |
while (true) { |
JG |
48 |
auto messages = protocol::catchUp(bs); |
|
49 |
// bom::updateBom(bs); |
0bef19
|
50 |
// printFeed(messages); |
JG |
51 |
dumbHit(messages); |
0b7aa0
|
52 |
freeMessages(messages); |
JG |
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
void deleteOrder(json::AddedMessage* m) |
|
57 |
{ |
|
58 |
json::DeleteMessage a(json::DELETE, m->product, m->id); |
|
59 |
delete protocol::deleteOrder(a); |
|
60 |
} |
|
61 |
|
|
62 |
void printFeed(std::deque<json::Message*>& m) |
|
63 |
{ |
|
64 |
for (auto& i : m) { |
|
65 |
switch (i->type) { |
|
66 |
case json::FUTURE_TYPE: |
|
67 |
case json::SPREAD_TYPE: |
|
68 |
case json::CALL_TYPE: |
|
69 |
case json::PUT_TYPE: |
|
70 |
std::cout << ((json::AnnounceMessage*)i)->as_string() << std::endl; |
|
71 |
break; |
|
72 |
case json::SETTLEMENT: |
|
73 |
std::cout << ((json::SettleMessage*)i)->as_string() << std::endl; |
|
74 |
break; |
|
75 |
case json::ADDED: |
|
76 |
std::cout << ((json::AddedMessage*)i)->as_string() << std::endl; |
|
77 |
break; |
|
78 |
case json::DELETED: |
|
79 |
std::cout << ((json::DeletedMessage*)i)->as_string() << std::endl; |
|
80 |
break; |
|
81 |
case json::TRADE: |
|
82 |
std::cout << ((json::TradeMessage*)i)->as_string() << std::endl; |
|
83 |
break; |
|
84 |
case json::BROKER_REQUEST: |
|
85 |
std::cout << ((json::BrokerRequest*)i)->as_string() << std::endl; |
|
86 |
break; |
|
87 |
case json::BROKER_ACK: |
|
88 |
std::cout << ((json::BrokerAck*)i)->as_string() << std::endl; |
|
89 |
break; |
|
90 |
case json::BROKER_CONFIRM: |
|
91 |
std::cout << ((json::BrokerConfirm*)i)->as_string() << std::endl; |
|
92 |
break; |
|
93 |
default:; |
|
94 |
} |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
void freeMessages(std::deque<json::Message*>& m) |
|
99 |
{ |
|
100 |
for (auto i : m) { |
|
101 |
delete i; |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
void dumbHit(std::deque<json::Message*>& m) |
|
106 |
{ |
0bef19
|
107 |
for (auto& i : m) { |
JG |
108 |
if (i->type == json::ADDED) { |
|
109 |
json::AddedMessage* j = (json::AddedMessage*)i; |
441abf
|
110 |
if (j->owner == "nseow" || j->owner == "jgrunbau" || j->owner == "zoar" || j->owner == "aobrien") { |
0bef19
|
111 |
book::OrderSideEnum s = |
JG |
112 |
j->side == book::Buy ? book::Sell : book::Buy; |
|
113 |
json::AddMessage a(json::ADD, j->product, j->price, s, |
|
114 |
j->resting); |
|
115 |
auto b = protocol::addOrder(a); |
|
116 |
if (b->type == json::ADDED && |
|
117 |
((json::AddedMessage*)b)->resting > 0) { |
|
118 |
json::DeleteMessage d(json::DELETE, j->product, |
|
119 |
((json::AddedMessage*)b)->id); |
|
120 |
delete protocol::deleteOrder(d); |
|
121 |
} |
|
122 |
if (b->type == json::ADDED) { |
|
123 |
std::cout << "Hit " << j->owner << " for " |
|
124 |
<< ((json::AddedMessage*)b)->filled |
|
125 |
<< ", resting " |
|
126 |
<< ((json::AddedMessage*)b)->resting << std::endl; |
|
127 |
} |
|
128 |
delete b; |
|
129 |
} |
|
130 |
} |
|
131 |
} |
0b7aa0
|
132 |
} |
JG |
133 |
} // namespace strat |