#include "CCAPIOrderCallbackMsgs.h" #include "lib/io/JsonReader.h" #include "lib/utils/bts_assert.h" namespace bts::orderman { const std::string &getm( const std::map &map, char const *key_name) { auto it = map.find(key_name); bts_assert_msg( it != map.end(), "Could not find key_name" + std::string(key_name)); return it->second; } bts::api::orderman::OrderStatus convert_ccapi_status( const std::string &status) { // TODO, find the other status'es if (status == "open") return bts::api::orderman::OrderStatus::ORDER_STATUS_WORKING; else if (status == "cancelled") return bts::api::orderman::OrderStatus::ORDER_STATUS_CANCELED; return bts::api::orderman::OrderStatus::ORDER_STATUS_COMPLETED; } void DeribitOpenPosition::parse( const nlohmann::json &j, DeribitOpenPosition &op) { bts::io::JsonReader jr{&j}; jr.read("total_profit_loss", op.total_profit_loss); jr.read("size_currency", op.size_currency); jr.read("size", op.size); jr.read("settlement_price", op.settlement_price); jr.read("realized_profit_loss", op.realized_profit_loss); jr.read("instrument_name", op.instrument_name); jr.read("kind", op.kind); jr.read("direction", op.direction); jr.read("average_price", op.average_price); } void from_json(const nlohmann::json &j, DeribitOpenPosition &dop) { bts::io::JsonReader jr{&j}; jr.read("instrument_name", dop.instrument_name); jr.read("direction", dop.direction); jr.read("size", dop.size); jr.read("average_price", dop.average_price); } void to_json(nlohmann::json &j, const DeribitOpenPosition &dop) { j = nlohmann::json{ {"instrument_name", dop.instrument_name}, {"direction", dop.direction}, {"size", dop.size}, {"average_price", dop.average_price}}; } std::ostream &operator<<( std::ostream &out, const DeribitOpenPosition &dop) noexcept { std::string sep = " "; out << "instrument_name: " << dop.instrument_name << sep << "direction: " << dop.direction << sep << "size: " << dop.size << sep << "average_price: " << dop.average_price; return out; } } // namespace bts::orderman