gabirel1 / Epitech-Principe-financier-de-base-et-architecture

MIT License
2 stars 1 forks source link

OrderBook add #9

Closed DipStax closed 7 months ago

DipStax commented 8 months ago

Problem:

When adding a bid when taking their is an higher ask, it never sell.

Reason:

Because we use a template function (add<T>) to manage the OrderBook bid and ask, the condition when exiting the while is wrong when the order type is Ask:

    for (auto &[_key, _val] : _book) {
        if (_key > _price)  // this condition is wrong
            break;
        OrderList &ol = _book.at(_key);

Full code here

The actual reason of this behavior is because we use 2 differents sorting algorithm for BidBook and AskBook:

using AskBook = std::map<Price, OrderList, std::greater<Price>>;
using BidBook = std::map<Price, OrderList, std::less<Price>>;

ref here