* Run 'sparkd tests' outside of the CLI::App framework (delegate to 'catch', which has a solid cli). This fixes a bug which prevented callers from specifying test tags (in the form of '[<tag>]'), as the CLI::App's parse method removes square brackets from cli options. * Bind cli options to instance members of their subcommand's CLI::App derived class. This seems to fix a bug which caused the [static instance] binding source to be destructed twice. * Add help text for several subcommands
57 lines
2.1 KiB
C++
57 lines
2.1 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::cmds {
|
|
|
|
PrintHedgeOrders::PrintHedgeOrders()
|
|
: CLI::App(
|
|
"Print out order ids for all hedge orders"
|
|
"which were completed at least one second being created",
|
|
"print-hedge-orders") {
|
|
callback([&] {
|
|
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";
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
} // namespace bts::cmds
|