Fixed a number of bugs.
This commit is contained in:
1 parent
1b4ed339d6
commit
f7ca1efdb8
10 files changed
+357
-138
No files matched your search
@@ -7,7 +7,13 @@
|
||||
#include "lib/utils/datetime.h"
|
||||
|
||||
#include "lib/domain_model/sod.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/utils/datetime.h"
|
||||
#include "server/sparkd/cmds/spartan/analysis/RunAnalysis.h"
|
||||
#include "server/sparkd/cmds/spartan/md/mdp3/common/InstrumentSnapshot.h"
|
||||
#include "server/sparkd/cmds/spartan/md/mdp3/common/mdp3_common.h"
|
||||
#include "server/sparkd/cmds/spartan/md/mdp3/handler/IChannelObserver.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
@@ -17,20 +23,94 @@
|
||||
namespace bts {
|
||||
namespace cmd {
|
||||
using namespace bts::orderman;
|
||||
using namespace spartan::mdp3;
|
||||
|
||||
Book get_mbo_book(InstrumentSnapshot const &snap, api::Side side) {
|
||||
auto &orders = snap.orders();
|
||||
auto invert = side == api::SIDE_BUY ? -1 : 1;
|
||||
auto book_idx = std::map<int64_t, BookLevel>();
|
||||
for (auto &o : orders)
|
||||
if (o.second.side == side) {
|
||||
auto &order = o.second;
|
||||
auto &level = book_idx[invert * order.price.mantissa()];
|
||||
level.n_orders++;
|
||||
level.price = order.price;
|
||||
level.quantity.value() += order.quantity.value();
|
||||
}
|
||||
|
||||
Book mbo_book;
|
||||
size_t i = 0;
|
||||
for (auto &p : book_idx)
|
||||
if (i < mbo_book.size())
|
||||
mbo_book[i++] = p.second;
|
||||
|
||||
return mbo_book;
|
||||
}
|
||||
|
||||
auto get_orders(InstrumentSnapshot const &snap, api::Side side) {
|
||||
std::map<md::IntPrice, std::vector<MDP3Order>> idx;
|
||||
for (auto &o : snap.orders()) {
|
||||
auto &order = o.second;
|
||||
if (order.side == side)
|
||||
idx[order.price].push_back(order);
|
||||
}
|
||||
std::vector<MDP3Order> result;
|
||||
for (auto const &p : idx)
|
||||
for (auto &o : p.second)
|
||||
result.push_back(o);
|
||||
return result;
|
||||
}
|
||||
|
||||
int QuickTest::execute(std::vector<std::string> const &) {
|
||||
using namespace bts::spartan::mdp3;
|
||||
|
||||
auto sftp_file_name = std::string("2019-08-05.adatmny.csv");
|
||||
std::regex rx("(\\d\\d\\d\\d)");
|
||||
std::smatch matches;
|
||||
if (!std::regex_match(sftp_file_name, matches, rx))
|
||||
return {};
|
||||
auto y = std::stoi(matches[0]);
|
||||
auto m = std::stoi(matches[1]);
|
||||
auto d = std::stoi(matches[2]);
|
||||
struct Obs : IChannelObserver {
|
||||
void on_recovery_complete(
|
||||
std::vector<InstrumentSnapshot const *> const &) override {
|
||||
LOG(Spartan, Info, "Recovery completed");
|
||||
}
|
||||
|
||||
const auto &sod = config::get<config::SODTime>();
|
||||
std::cout << datetime::make_ptime(y, m, d, sod.sod_hh(), sod.has_sod_mm(), 0, 0) << "\n";
|
||||
void on_real_time_event(MDP3EventInfo const &ei) override {
|
||||
for (auto s : ei.affected_securities) {
|
||||
if (s->security_id() == MDP3SecurityID{12181}) {
|
||||
auto &book = s->book(api::SIDE_SELL);
|
||||
auto mbo_book = get_mbo_book(*s, api::SIDE_SELL);
|
||||
|
||||
bool consistent = false;
|
||||
if (s->trading_status() == ::mdp3::SecurityTradingStatus::Close ||
|
||||
s->trading_status() == ::mdp3::SecurityTradingStatus::PreOpen)
|
||||
consistent = book[0] == mbo_book[0];
|
||||
else
|
||||
consistent = book == mbo_book;
|
||||
|
||||
std::cout << "--------------------------------------------------"
|
||||
"------------------------------\n";
|
||||
std::cout << s->last_processed_sn() << "\n";
|
||||
std::cout << s->trading_status() << "\n";
|
||||
std::cout << (consistent ? "Consistent" : "Inconsistent")
|
||||
<< "\n";
|
||||
std::cout << "MBP: \n";
|
||||
for (auto &l : book)
|
||||
std::cout << "\t" << l << "\n";
|
||||
std::cout << "MBO: \n";
|
||||
for (auto &l : mbo_book)
|
||||
std::cout << "\t" << l << "\n";
|
||||
if (!consistent) {
|
||||
std::cout << "Orders: \n";
|
||||
auto orders = get_orders(*s, api::SIDE_SELL);
|
||||
for (auto &order : orders)
|
||||
std::cout << "\t" << order << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void on_real_time_channel_loss() override {
|
||||
LOG(Spartan, Info, "Loss detected");
|
||||
}
|
||||
} obs;
|
||||
|
||||
spartan::observe_channel("/home/ppinto/es_md/es_all.pcap", obs);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user