In headers, this is an objectively bad practice, since the type aliases leak into dependent code and can cause unexpected naming conflicts. In source files, it is debatable, but I prefer explicit aliases of the form 'using Foo = Bar'. The intentions are clear, and the resulting code is naturally resistent to naming conflicts.
64 lines
2.1 KiB
C++
64 lines
2.1 KiB
C++
#include "CCAPIOrderCallbackMsgs.h"
|
|
#include "lib/io/JsonReader.h"
|
|
#include "lib/utils/bts_assert.h"
|
|
|
|
namespace bts::orderman {
|
|
|
|
const std::string &getm(
|
|
const std::map<std::string, std::string> &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
|