| | |
| | | void mainLoop() |
| | | { |
| | | auto bs = protocol::recoverBook(); |
| | | std::cout << "ready" << std::endl; |
| | | while (true) { |
| | | auto messages = protocol::catchUp(bs); |
| | | // bom::updateBom(bs); |
| | | printFeed(messages); |
| | | // printFeed(messages); |
| | | dumbHit(messages); |
| | | freeMessages(messages); |
| | | } |
| | | } |
| | |
| | | |
| | | void dumbHit(std::deque<json::Message*>& m) |
| | | { |
| | | for (auto& i : m) { |
| | | if (i->type == json::ADDED) { |
| | | json::AddedMessage* j = (json::AddedMessage*) i; |
| | | if (j->owner == "jgrunbau") { |
| | | book::OrderSideEnum s = j->side == book::Buy ? book::Sell : book::Buy; |
| | | json::AddMessage a(json::ADD, j->product, j->price, s, j->resting); |
| | | auto b = protocol::addOrder(a); |
| | | if (b->type == json::ADDED && ((json::AddedMessage*) b)->resting > 0) { |
| | | json::DeleteMessage d(json::DELETE, j->product, ((json::AddedMessage*) b)->id); |
| | | delete protocol::deleteOrder(d); |
| | | } |
| | | if (b->type == json::ADDED) { |
| | | std::cout << "Hit " << j->owner << " for " << ((json::AddedMessage*) b)->filled << ", resting " << ((json::AddedMessage*) b)->resting << std::endl; |
| | | } |
| | | delete b; |
| | | } |
| | | } |
| | | } |
| | | for (auto& i : m) { |
| | | if (i->type == json::ADDED) { |
| | | json::AddedMessage* j = (json::AddedMessage*)i; |
| | | if (j->owner == "nseow" || j->owner == "jgrunbau" || j->owner == "zoar" || j->owner == "aobrien") { |
| | | book::OrderSideEnum s = |
| | | j->side == book::Buy ? book::Sell : book::Buy; |
| | | json::AddMessage a(json::ADD, j->product, j->price, s, |
| | | j->resting); |
| | | auto b = protocol::addOrder(a); |
| | | if (b->type == json::ADDED && |
| | | ((json::AddedMessage*)b)->resting > 0) { |
| | | json::DeleteMessage d(json::DELETE, j->product, |
| | | ((json::AddedMessage*)b)->id); |
| | | delete protocol::deleteOrder(d); |
| | | } |
| | | if (b->type == json::ADDED) { |
| | | std::cout << "Hit " << j->owner << " for " |
| | | << ((json::AddedMessage*)b)->filled |
| | | << ", resting " |
| | | << ((json::AddedMessage*)b)->resting << std::endl; |
| | | } |
| | | delete b; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } // namespace strat |