Joel Grunbaum
2022-01-10 2c515f0de70ad675b5f5d25b6a496d67d8dc0463
Fixed indentation
1 files deleted
12 files modified
102 ■■■■ changed files
.clang-format 2 ●●● patch | view | raw | blame | history
book.cpp 28 ●●●●● patch | view | raw | blame | history
book.hpp 7 ●●●●● patch | view | raw | blame | history
bot.cpp 5 ●●●● patch | view | raw | blame | history
click.cpp patch | view | raw | blame | history
json.cpp patch | view | raw | blame | history
json.hpp 10 ●●●● patch | view | raw | blame | history
main.cpp 15 ●●●●● patch | view | raw | blame | history
protocol.cpp 23 ●●●●● patch | view | raw | blame | history
secrets.hpp 2 ●●● patch | view | raw | blame | history
strat.cpp 3 ●●●● patch | view | raw | blame | history
strat.hpp 5 ●●●●● patch | view | raw | blame | history
test.cpp 2 ●●● patch | view | raw | blame | history
.clang-format
@@ -1,10 +1,10 @@
---
BasedOnStyle: LLVM
IndentWidth: 4
TabWidth: 4
UseTab: AlignWithSpaces
AllowShortIfStatementsOnASingleLine: true
BreakBeforeBraces: Linux
IndentCaseLabels: false
PointerAlignment: Left
AllowShortIfStatementsOnASingleLine: true
IndentCaseBlocks: true
book.cpp
@@ -80,10 +80,9 @@
{
}
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)
@@ -108,7 +107,7 @@
    }
    }
    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>());
    }
@@ -132,7 +131,7 @@
    }
    }
    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>());
    }
@@ -144,15 +143,24 @@
    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;
    }
    }
book.hpp
@@ -54,10 +54,9 @@
    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);
bot.cpp
@@ -1,6 +1,3 @@
#include "strat.hpp"
int main(void)
{
}
int main(void) {}
click.cpp
json.cpp
json.hpp
@@ -70,11 +70,11 @@
    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 {
main.cpp
File was deleted
protocol.cpp
@@ -30,13 +30,14 @@
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());
@@ -126,8 +127,9 @@
    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>());
@@ -136,8 +138,9 @@
    } 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>());
secrets.hpp
@@ -2,7 +2,7 @@
#include <string>
#define TEST
// #define TEST
constexpr const char* HOST="sytev070";
#ifdef TEST
strat.cpp
@@ -1,5 +1,6 @@
#include "strat.hpp"
namespace strat {
namespace strat
{
}
strat.hpp
@@ -1,8 +1,9 @@
#pragma once
#include "book.hpp"
#include <unordered_map>
#include <string>
#include <unordered_map>
namespace strat {
namespace strat
{
}
test.cpp
@@ -5,7 +5,7 @@
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) {