59 lines
2.0 KiB
C++
59 lines
2.0 KiB
C++
#include "server/sparkd/cmds/PrintHedgeOrders.h"
|
|
#include "lib/api/services/OrderService.pb.h"
|
|
#include "lib/persistence/SqliteStore.h"
|
|
#include "lib/utils/PBUtils.h"
|
|
|
|
namespace bts {
|
|
namespace cmd {
|
|
|
|
int PrintHedgeOrders::execute(std::vector<std::string> const &) {
|
|
persistence::SqliteStore order_store("orders");
|
|
auto all_orders = order_store.retrieve_all()["orders"];
|
|
|
|
std::map<uint32_t, std::pair<std::string, double>> fill_times;
|
|
persistence::SqliteStore fill_store("fills");
|
|
auto all_fills = fill_store.retrieve_all()["fills"];
|
|
for (auto const &kvp : all_fills) {
|
|
api::orderman::Fill fill_rec;
|
|
if (utils::pb::from_string<api::orderman::Fill>(kvp.second, &fill_rec)) {
|
|
auto ts = utils::pb::to_double_time(fill_rec.timestamp());
|
|
auto &p = fill_times[fill_rec.order_key()];
|
|
auto &min_time = p.second;
|
|
if (min_time < ts) {
|
|
p.first = kvp.first;
|
|
min_time = ts;
|
|
}
|
|
}
|
|
}
|
|
|
|
std::cout << "order_key,time_to_first_fill,fill_id"
|
|
<< "\n";
|
|
api::orderman::OrderRecord rec;
|
|
for (auto const &kvp : all_orders)
|
|
if (utils::pb::from_string<api::orderman::OrderRecord>(kvp.second,
|
|
&rec)) {
|
|
auto &def = rec.def();
|
|
auto &state = rec.state();
|
|
if (rec.parent_key() && def.custom_def().has_limit() &&
|
|
def.sub_type() ==
|
|
api::orderman::OrderSubType::ORDER_SUB_TYPE_HEDGING_LEG) {
|
|
auto create_ts = utils::pb::to_double_time(state.created());
|
|
auto &first_fill = fill_times[rec.key()];
|
|
auto delta = first_fill.second - create_ts;
|
|
if (first_fill.first.size())
|
|
std::cout << kvp.first << "," << delta << ","
|
|
<< first_fill.first << "\n";
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
std::string PrintHedgeOrders::help() {
|
|
return "Print out order ids for all hedge orders"
|
|
"which were completed at least one second being created";
|
|
}
|
|
|
|
} // namespace cmd
|
|
} // namespace bts
|