Add: TBBO to databento
This commit is contained in:
1 parent
fd015577b2
commit
fc96b9e436
1 file changed
+96
-5
@@ -10,7 +10,6 @@
|
||||
#include "lib/api/domain/Venue.pb.h"
|
||||
#include "lib/api/md/MarketDataConfig.pb.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/system_config.pb.h"
|
||||
#include "lib/core/TimeStamp.h"
|
||||
#include "lib/domain/AggressorSide.h"
|
||||
#include "lib/domain/Book.h"
|
||||
@@ -332,6 +331,93 @@ void DatabentoDatahandler::run(
|
||||
return databento::KeepGoing::
|
||||
Continue; //only added so the same functions work with the threaded builder, not really need in the blocking version
|
||||
};
|
||||
auto process_tbbo = [&](const databento::Record &record) {
|
||||
const auto &msg = record.Get<databento::TbboMsg>();
|
||||
debug_log(msg);
|
||||
|
||||
// std::vector<std::tuple<uint64_t,std::string>>& times = all_times.emplace_back();
|
||||
// times.reserve(8);
|
||||
// return databento::KeepGoing::Continue; //only added so the same functions work with the threaded builder, not really need in the blocking version
|
||||
// The security type to is needed to get the id. Since the sec type isn't known,
|
||||
// check for an id using both types (OPTION and FUTURE). This is safe to do since
|
||||
// options and futures never have common names (instrument ids).
|
||||
// auto current = bts::datetime::unix_nano_now();
|
||||
// auto prev = current;
|
||||
// times.push_back({current-prev,"Start Process bbo"});
|
||||
|
||||
// prev = current;
|
||||
// current = bts::datetime::unix_nano_now();
|
||||
// times.push_back({current-prev,"MISC to check log time"});
|
||||
if (!sec_id_map.contains(msg.hd.instrument_id))
|
||||
return databento::KeepGoing::Continue;
|
||||
bts::domain::SecurityID sec_id = sec_id_map.at(msg.hd.instrument_id);
|
||||
|
||||
// prev = current;
|
||||
// current = bts::datetime::unix_nano_now();
|
||||
// times.push_back({current-prev,"Sec_ID done"});
|
||||
|
||||
// sleep_for(sleep_duration_updated);
|
||||
// prev = current;
|
||||
// current = bts::datetime::unix_nano_now();
|
||||
// times.push_back({current-prev,"Sleep done"});
|
||||
|
||||
domain::Book book;
|
||||
book.set_security_id(sec_id);
|
||||
// prev = current;
|
||||
// current = bts::datetime::unix_nano_now();
|
||||
// times.push_back({current-prev,"Empty Book Made"});
|
||||
|
||||
auto &bids = book.bids();
|
||||
auto &asks = book.asks();
|
||||
bids.begin()->price = bts::domain::Price(msg.levels[0].bid_px, -9);
|
||||
bids.begin()->total_quantity =
|
||||
bts::domain::Quantity(msg.levels[0].bid_sz);
|
||||
asks.begin()->price = bts::domain::Price(msg.levels[0].ask_px, -9);
|
||||
asks.begin()->total_quantity =
|
||||
bts::domain::Quantity(msg.levels[0].ask_sz);
|
||||
// prev = current;
|
||||
// current = bts::datetime::unix_nano_now();
|
||||
// times.push_back({current-prev,"Complete book done"});
|
||||
|
||||
auto recv_time = bts::core::TimeStamp::from_iso_string(
|
||||
databento::ToIso8601(msg.ts_recv));
|
||||
// prev = current;
|
||||
// current = bts::datetime::unix_nano_now();
|
||||
// times.push_back({current-prev,"Time converted"});
|
||||
|
||||
listener->on_book(
|
||||
book,
|
||||
utils::TimeStamp{datetime::ptime_to_timestamp(recv_time.to_ptime())});
|
||||
|
||||
|
||||
domain::TradeRecord trade;
|
||||
trade.trade_price = bts::domain::Price(msg.price, -9);
|
||||
trade.trade_quantity = bts::domain::Quantity(msg.size);
|
||||
trade.sec_id = sec_id;
|
||||
switch (msg.side) {
|
||||
case databento::Side::Ask:
|
||||
trade.agg_side = domain::AggressorSide::Sell;
|
||||
break;
|
||||
case databento::Side::Bid:
|
||||
trade.agg_side = domain::AggressorSide::Buy;
|
||||
break;
|
||||
case databento::Side::None:
|
||||
trade.agg_side = domain::AggressorSide::None;
|
||||
break;
|
||||
}
|
||||
trade.time_stamp = bts::core::TimeStamp::from_iso_string(
|
||||
databento::ToIso8601(msg.ts_recv));
|
||||
std::vector<const domain::TradeRecord *> trade_ptrs;
|
||||
trade_ptrs.push_back(&trade);
|
||||
listener->on_trades(trade_ptrs);
|
||||
|
||||
// prev = current;
|
||||
// current = bts::datetime::unix_nano_now();
|
||||
// times.push_back({current-prev,"On book done"});
|
||||
|
||||
return databento::KeepGoing::
|
||||
Continue; //only added so the same functions work with the threaded builder, not really need in the blocking version
|
||||
};
|
||||
|
||||
auto process_trades = [&](const databento::Record &record) {
|
||||
const auto &msg = record.Get<databento::TradeMsg>();
|
||||
@@ -439,8 +525,10 @@ void DatabentoDatahandler::run(
|
||||
databento::ILogReceiver::Default(), key, dataset, true,
|
||||
databento::VersionUpgradePolicy::UpgradeToV2, {}};
|
||||
for (std::vector vec : all_sec) {
|
||||
// client.Subscribe(
|
||||
// vec, databento::Schema::Tbbo, databento::SType::RawSymbol);
|
||||
client.Subscribe(
|
||||
vec, databento::Schema::Mbp1, databento::SType::RawSymbol);
|
||||
vec, databento::Schema::Mbp1, databento::SType::RawSymbol);
|
||||
client.Subscribe(
|
||||
vec, databento::Schema::Trades, databento::SType::RawSymbol);
|
||||
}
|
||||
@@ -460,13 +548,16 @@ void DatabentoDatahandler::run(
|
||||
if (record->Holds<databento::Mbp1Msg>()) {
|
||||
process_bbo(*record);
|
||||
}
|
||||
if (record->Holds<databento::TbboMsg>()) {
|
||||
process_tbbo(*record);
|
||||
}
|
||||
if (all_times.size() == 1001) {
|
||||
log_time_statistics(all_times);
|
||||
client.Stop();
|
||||
}
|
||||
// if (record->Holds<databento::InstrumentDefMsg>()) {
|
||||
// process_security(*record);
|
||||
// }
|
||||
if (record->Holds<databento::InstrumentDefMsg>()) {
|
||||
process_security(*record);
|
||||
}
|
||||
if (record->Holds<databento::TradeMsg>()) {
|
||||
process_trades(*record);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user