#ifdef SPARK_ENABLE_CCAPI #include "BinanceBookLevel.h" #include "lib/os/os.h" namespace bts::md::binance { bool operator==(const BinanceBookLevel &lhs, const BinanceBookLevel &rhs) { // return lhs.quantity == rhs.quantity && lhs.price == rhs.price; if (lhs.quantity != rhs.quantity) { return false; } if (lhs.price == rhs.price) { return true; } return os::is_nan(lhs.price) && os::is_nan(rhs.price); } bool operator!=(const BinanceBookLevel &lhs, const BinanceBookLevel &rhs) { return !(lhs == rhs); } std::ostream &operator<<( std::ostream &out, const BinanceBookLevel &book_level) noexcept { out << book_level.quantity << "@" << book_level.price; return out; } void from_json(const nlohmann::json &j, BinanceBookLevel &upd) { if (j.is_array() && j.size() == 2) { const nlohmann::json &jprice = j.at(0); const auto &price_str = jprice.get(); upd.price = std::stod(price_str); const nlohmann::json &jqty = j.at(1); const auto &qty_str = jqty.get(); upd.quantity = std::stod(qty_str); } } void to_json(nlohmann::json &j, const BinanceBookLevel &upd) { j.push_back(upd.price); j.push_back(upd.quantity); } } // namespace bts::md::binance #endif