1 files deleted
12 files modified
| | |
| | | --- |
| | | BasedOnStyle: LLVM |
| | | IndentWidth: 4 |
| | | TabWidth: 4 |
| | | UseTab: AlignWithSpaces |
| | | AllowShortIfStatementsOnASingleLine: true |
| | | BreakBeforeBraces: Linux |
| | | IndentCaseLabels: false |
| | | PointerAlignment: Left |
| | | AllowShortIfStatementsOnASingleLine: true |
| | | IndentCaseBlocks: true |
| | |
| | | { |
| | | } |
| | | |
| | | Book::Book(ProductTypeEnum productType, std::string product, |
| | | int stationId, std::string unit, |
| | | std::chrono::nanoseconds expiry, double aggFee, double pasFee, |
| | | double broFee) |
| | | Book::Book(ProductTypeEnum productType, std::string product, int stationId, |
| | | std::string unit, std::chrono::nanoseconds expiry, double aggFee, |
| | | double pasFee, double broFee) |
| | | : bidSide{}, askSide{}, productType{productType}, product(product), |
| | | stationId(stationId), unit(unit), expiry(expiry), aggFee(aggFee), |
| | | pasFee(pasFee), broFee(broFee) |
| | |
| | | } |
| | | } |
| | | if (order.remaining_volume > 0) { |
| | | this->askSide.emplace(this->askSide.begin(), order); |
| | | this->askSide.emplace_back(order); |
| | | std::make_heap(this->askSide.begin(), this->askSide.end(), |
| | | std::greater<Level>()); |
| | | } |
| | |
| | | } |
| | | } |
| | | if (order.remaining_volume > 0) { |
| | | this->bidSide.emplace(this->bidSide.begin(), order); |
| | | this->bidSide.emplace_back(order); |
| | | std::make_heap(this->bidSide.begin(), this->bidSide.end(), |
| | | std::less<Level>()); |
| | | } |
| | |
| | | std::vector<Level> askCopy(this->askSide); |
| | | std::size_t count = 0; |
| | | std::sort(askCopy.begin(), askCopy.end()); |
| | | for (auto i = askCopy.rbegin(); i != askCopy.rend() && count < numOrders; i++, count++) { |
| | | std::cout << *i << std::endl; |
| | | std::reverse(askCopy.begin(), askCopy.end()); |
| | | uint64_t volume = 0; |
| | | double price = askCopy.front().price; |
| | | for (auto i : askCopy) { |
| | | std::cout << i << std::endl; |
| | | count++; |
| | | if (count > numOrders) break; |
| | | } |
| | | std::cout << "Buy side: " << this->bidSide.size() << std::endl; |
| | | std::vector<Level> bidCopy(this->bidSide); |
| | | count = 0; |
| | | std::sort(bidCopy.begin(), bidCopy.end()); |
| | | for (auto i = bidCopy.rbegin(); i != bidCopy.rend() && count < numOrders; i++, count++) { |
| | | std::cout << *i << std::endl; |
| | | std::reverse(bidCopy.begin(), bidCopy.end()); |
| | | price = bidCopy.front().price; |
| | | for (auto i : bidCopy) { |
| | | std::cout << i << std::endl; |
| | | count++; |
| | | if (count > numOrders) break; |
| | | } |
| | | } |
| | | |
| | |
| | | double broFee; |
| | | |
| | | Book(); |
| | | Book(ProductTypeEnum productType, std::string product, |
| | | int stationId, std::string unit, |
| | | std::chrono::nanoseconds expiry, double aggFee, double pasFee, |
| | | double broFee); |
| | | Book(ProductTypeEnum productType, std::string product, int stationId, |
| | | std::string unit, std::chrono::nanoseconds expiry, double aggFee, |
| | | double pasFee, double broFee); |
| | | void ask(Order& order); |
| | | void bid(Order& order); |
| | | void printBook(std::size_t numOrders = 10); |
| | |
| | | #include "strat.hpp" |
| | | |
| | | int main(void) |
| | | { |
| | | |
| | | } |
| | | int main(void) {} |
| | |
| | | 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); |
| | | 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::unordered_map<std::string, book::Book> recoverBook() |
| | | { |
| | | std::unordered_map<std::string, book::Book> bs; |
| | | std::ifstream sampleFile("../data.test"); |
| | | std::stringstream ss; |
| | | ss << sampleFile.rdbuf(); |
| | | // httplib::Client cli("http://" + server); |
| | | // auto res = cli.Get("/recover"); |
| | | // std::ifstream sampleFile("../data.test"); |
| | | // std::stringstream ss; |
| | | // ss << sampleFile.rdbuf(); |
| | | httplib::Client cli("http://" + server); |
| | | auto res = cli.Get("/recover"); |
| | | std::string l; |
| | | l = ss.str(); |
| | | // l = ss.str(); |
| | | l = res->body; |
| | | std::queue<json::Message*> a(json::parse(l)); |
| | | while (!a.empty()) { |
| | | protocol::handleMessage(bs, a.front()); |
| | |
| | | if (message->side == book::Buy) { |
| | | for (std::size_t i = 0; i < bs[message->product].bidSide.size(); i++) { |
| | | if (bs[message->product].bidSide[i].id == message->id) { |
| | | bs[message->product].bidSide[i] = bs[message->product].bidSide.back(); |
| | | bs[message->product].bidSide.erase(bs[message->product].bidSide.end()); |
| | | bs[message->product].bidSide[i] = |
| | | bs[message->product].bidSide.back(); |
| | | bs[message->product].bidSide.pop_back(); |
| | | std::make_heap(bs[message->product].bidSide.begin(), |
| | | bs[message->product].bidSide.end(), |
| | | std::less<book::Level>()); |
| | |
| | | } else { |
| | | for (std::size_t i = 0; i < bs[message->product].askSide.size(); i++) { |
| | | if (bs[message->product].askSide[i].id == message->id) { |
| | | bs[message->product].askSide[i] = bs[message->product].askSide.back(); |
| | | bs[message->product].askSide.erase(bs[message->product].askSide.end()); |
| | | bs[message->product].askSide[i] = |
| | | bs[message->product].askSide.back(); |
| | | bs[message->product].askSide.pop_back(); |
| | | std::make_heap(bs[message->product].askSide.begin(), |
| | | bs[message->product].askSide.end(), |
| | | std::greater<book::Level>()); |
| | |
| | | |
| | | #include <string> |
| | | |
| | | #define TEST |
| | | // #define TEST |
| | | |
| | | constexpr const char* HOST="sytev070"; |
| | | #ifdef TEST |
| | |
| | | #include "strat.hpp" |
| | | |
| | | namespace strat { |
| | | namespace strat |
| | | { |
| | | |
| | | } |
| | |
| | | #pragma once |
| | | |
| | | #include "book.hpp" |
| | | #include <unordered_map> |
| | | #include <string> |
| | | #include <unordered_map> |
| | | |
| | | namespace strat { |
| | | namespace strat |
| | | { |
| | | } |
| | |
| | | |
| | | int main(void) |
| | | { |
| | | book::Book b = book::testBook(10, true); |
| | | // book::Book b = book::testBook(10, true); |
| | | auto bs = protocol::recoverBook(); |
| | | std::cout << bs.size() << std::endl; |
| | | for (auto i : bs) { |