Reformat and change send to x-www-form-urlencoded
| | |
| | | std::exit(0); |
| | | } |
| | | |
| | | void no(int signum) |
| | | { |
| | | std::cout << "no." << std::endl; |
| | | } |
| | | void no(int signum) { std::cout << "no." << std::endl; } |
| | | |
| | | int main(void) |
| | | { |
| | |
| | | std::cout << static_cast<json::RejectMessage*>(d)->as_string() |
| | | << std::endl; |
| | | } else if (d->type == json::ERROR) { |
| | | std::cout << static_cast<json::ErrorMessage*>(d)->as_string() << std::endl; |
| | | std::cout << static_cast<json::ErrorMessage*>(d)->as_string() |
| | | << std::endl; |
| | | } |
| | | delete b; |
| | | delete d; |
| | |
| | | exit(0); |
| | | } |
| | | } |
| | | for (std::uint64_t i = 0; i < times; i++) |
| | | { |
| | | for (std::uint64_t i = 0; i < times; i++) { |
| | | switch (click) { |
| | | case Buy: |
| | | buy(product, price, volume); |
| | |
| | | std::string owner; |
| | | AddedMessage(MessageTypes type, std::string product, std::string id, |
| | | book::OrderSideEnum side, double price, uint64_t filled, |
| | | uint64_t resting, std::string owner, uint64_t sequence, double timestamp); |
| | | uint64_t resting, std::string owner, uint64_t sequence, |
| | | double timestamp); |
| | | std::string as_string(); |
| | | }; |
| | | |
| | |
| | | json::DeletedMessage* message) |
| | | { |
| | | if (message->side == book::Buy) { |
| | | for (auto i = bs[message->product].bidSide.begin(); i != bs[message->product].bidSide.end(); i++) { |
| | | for (auto i = bs[message->product].bidSide.begin(); |
| | | i != bs[message->product].bidSide.end(); i++) { |
| | | if (i->id == message->id) { |
| | | bs[message->product].bidSide.erase(i); |
| | | break; |
| | | } |
| | | } |
| | | } else { |
| | | for (auto i = bs[message->product].askSide.begin(); i != bs[message->product].askSide.end(); i++) { |
| | | for (auto i = bs[message->product].askSide.begin(); |
| | | i != bs[message->product].askSide.end(); i++) { |
| | | if (i->id == message->id) { |
| | | bs[message->product].askSide.erase(i); |
| | | break; |
| | |
| | | } |
| | | } |
| | | } else { |
| | | for (auto i = bs[message->product].askSide.begin(); i != bs[message->product].askSide.end(); i++) { |
| | | for (auto i = bs[message->product].askSide.begin(); |
| | | i != bs[message->product].askSide.end(); i++) { |
| | | if (i->id == message->passiveOrder) { |
| | | bs[message->product].askSide.erase(i); |
| | | break; |
| | |
| | | } |
| | | } |
| | | } else { |
| | | for (auto i = bs[message->product].bidSide.begin(); i != bs[message->product].bidSide.end(); i++) { |
| | | for (auto i = bs[message->product].bidSide.begin(); |
| | | i != bs[message->product].bidSide.end(); i++) { |
| | | if (i->id == message->passiveOrder) { |
| | | bs[message->product].bidSide.erase(i); |
| | | break; |
| | |
| | | httplib::MultipartFormDataItems a = {{"message", message, "", ""}, |
| | | {"username", USER, "", ""}, |
| | | {"password", PASS, "", ""}}; |
| | | auto res = cli.Post("/execution", a); |
| | | auto res = cli.Post("/execution", |
| | | "message=" + message + "&username=" + USER + |
| | | "&password=" + PASS, |
| | | "application/x-www-form-urlencoded"); |
| | | std::string b = res->body; |
| | | std::queue<json::Message*> c = json::parse(b); |
| | | return c.front(); |
| | |
| | | while (true) { |
| | | auto messages = protocol::catchUp(bs); |
| | | // bom::updateBom(bs); |
| | | printFeed(messages); |
| | | // printFeed(messages); |
| | | dumbHit(messages); |
| | | freeMessages(messages); |
| | | } |
| | | } |
| | |
| | | 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); |
| | | 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); |
| | | 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; |
| | | std::cout << "Hit " << j->owner << " for " |
| | | << ((json::AddedMessage*)b)->filled |
| | | << ", resting " |
| | | << ((json::AddedMessage*)b)->resting << std::endl; |
| | | } |
| | | delete b; |
| | | } |
| | |
| | | void initialise(); |
| | | void destroy(); |
| | | void mainLoop(); |
| | | } |
| | | } // namespace strat |
| | |
| | | int main(void) |
| | | { |
| | | std::chrono::nanoseconds time(0); |
| | | for (int i = 0; i < trials; i++) |
| | | { |
| | | for (int i = 0; i < trials; i++) { |
| | | auto s = std::chrono::high_resolution_clock::now(); |
| | | book::Book b = book::testBook(100, false); |
| | | auto e = std::chrono::high_resolution_clock::now(); |
| | |
| | | // protocol::catchUp(bs); |
| | | // std::cout << bs.size() << std::endl; |
| | | // for (auto& i : bs) { |
| | | // std::cout << i.first << ", " << i.second.expiry.count() << ", " << i.second.bomPrice << std::endl; |
| | | // i.second.printBook(); |
| | | // std::cout << i.first << ", " << i.second.expiry.count() << ", " << |
| | | // i.second.bomPrice << std::endl; i.second.printBook(); |
| | | // } |
| | | } |
| | |
| | | import book |
| | | import protocol |
| | | |
| | | test = False |
| | | test = True |
| | | |
| | | HOST: str = 'sytev070' |
| | | if (test): |
| | |
| | | so_far_today = f.read(); |
| | | for message in so_far_today: |
| | | protocol.handleMessage(bs, message) |
| | | |
| | | |
| | | message = {"type": "ADD", "product": "F_THS_APP0119T2230", "price": 99.0, |
| | | "side": "BUY", "volume": 1} |
| | | |
| | | # print(json.dumps(message)) |
| | | # print(send(message)) |
| | | print(protocol.send(message)) |
| | | # printRecoveryLog() |
| | | # logAllIncomingMessages() |
| | | # print(getInformation()) |
| | | # wstest() |
| | | |
| | | bs = {} |
| | | # bs = {} |
| | | # recoverBook(bs) |
| | | testRecoverBook(bs) |
| | | print(list(bs)) |
| | | for i in bs: |
| | | print(bs[i].product) |
| | | bs[i].printBook() |
| | | print() |
| | | if (len(bs[i].askSide.levels) > 0): |
| | | print(bs[i].askSide.levels[0]) |
| | | if (len(bs[i].bidSide.levels)): |
| | | print(bs[i].bidSide.levels[0]) |
| | | print() |
| | | # testRecoverBook(bs) |
| | | # print(list(bs)) |
| | | # for i in bs: |
| | | # print(bs[i].product) |
| | | # bs[i].printBook() |
| | | # print() |
| | | # if (len(bs[i].askSide.levels) > 0): |
| | | # print(bs[i].askSide.levels[0]) |
| | | # if (len(bs[i].bidSide.levels)): |
| | | # print(bs[i].bidSide.levels[0]) |
| | | # print() |
| | | # book.testBook() |