Joel Grunbaum
2022-01-19 0bef191acd5a77544852e6a3daae2df05bd34a31
Reformat and change send to x-www-form-urlencoded
10 files modified
93 ■■■■■ changed files
book.cpp patch | view | raw | blame | history
bot.cpp 5 ●●●● patch | view | raw | blame | history
click.cpp 6 ●●●● patch | view | raw | blame | history
json.cpp patch | view | raw | blame | history
json.hpp 3 ●●●● patch | view | raw | blame | history
protocol.cpp 17 ●●●● patch | view | raw | blame | history
strat.cpp 20 ●●●● patch | view | raw | blame | history
strat.hpp 2 ●●● patch | view | raw | blame | history
test.cpp 7 ●●●●● patch | view | raw | blame | history
test.py 33 ●●●●● patch | view | raw | blame | history
book.cpp
bot.cpp
@@ -9,10 +9,7 @@
    std::exit(0);
}
void no(int signum)
{
    std::cout << "no." << std::endl;
}
void no(int signum) { std::cout << "no." << std::endl; }
int main(void)
{
click.cpp
@@ -76,7 +76,8 @@
        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;
@@ -141,8 +142,7 @@
            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);
json.cpp
json.hpp
@@ -113,7 +113,8 @@
    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();
};
protocol.cpp
@@ -175,14 +175,16 @@
                  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;
@@ -202,7 +204,8 @@
                }
            }
        } 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;
@@ -218,7 +221,8 @@
                }
            }
        } 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;
@@ -238,7 +242,10 @@
    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();
strat.cpp
@@ -46,7 +46,8 @@
    while (true) {
        auto messages = protocol::catchUp(bs);
        // bom::updateBom(bs);
        printFeed(messages);
        // printFeed(messages);
        dumbHit(messages);
        freeMessages(messages);
    }
}
@@ -106,15 +107,22 @@
        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;
            }
strat.hpp
@@ -5,4 +5,4 @@
    void initialise();
    void destroy();
    void mainLoop();
}
} // namespace strat
test.cpp
@@ -12,8 +12,7 @@
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();
@@ -33,7 +32,7 @@
    // 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();
    // }
}
test.py
@@ -6,7 +6,7 @@
import book
import protocol
test = False
test = True
HOST: str = 'sytev070'
if (test):
@@ -45,24 +45,29 @@
    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()