Caching volume on statistics_change and passing it over to handl.add_trade
This commit is contained in:
1 parent
088c5bc0b9
commit
aa768fabc0
1 file changed
+25
-8
@@ -189,10 +189,13 @@ void get_date_from_epoch_secs(
|
||||
day = ptm->tm_mday;
|
||||
}
|
||||
|
||||
struct SecuritySubStatus {
|
||||
uint64_t locked_key;
|
||||
std::string symbol;
|
||||
bool subsribed;
|
||||
struct SecurityAuxData {
|
||||
const uint64_t locked_key;
|
||||
const std::string symbol;
|
||||
bool subsribed = false;
|
||||
double volume = 0.0;
|
||||
SecurityAuxData(uint64_t locked_key, const std::string &symbol)
|
||||
: locked_key(locked_key), symbol(symbol) {}
|
||||
};
|
||||
|
||||
struct EmMDListener::PImpl {
|
||||
@@ -200,13 +203,22 @@ struct EmMDListener::PImpl {
|
||||
emumba::deribit_connector::deribit_handler *handler = nullptr;
|
||||
EmumbaSecurityIndex &index;
|
||||
MDProducer &md_producer;
|
||||
std::unordered_map<std::string, SecuritySubStatus> sec_map = {};
|
||||
std::unordered_map<std::string, SecurityAuxData> sec_map = {};
|
||||
MDArray bids = {};
|
||||
MDArray asks = {};
|
||||
explicit PImpl(EmumbaSecurityIndex &index_a, MDProducer &md_producer_a)
|
||||
: index(index_a), md_producer(md_producer_a) {}
|
||||
};
|
||||
|
||||
SecurityAuxData &get_sud(
|
||||
const emumba::market_data::security_id &sec_id,
|
||||
std::unordered_map<std::string, SecurityAuxData> &sec_map) {
|
||||
const std::string &id = extract_security_desc(sec_id);
|
||||
auto it = sec_map.find(id);
|
||||
bts_assert(it != sec_map.end());
|
||||
return it->second;
|
||||
}
|
||||
|
||||
EmMDListener::EmMDListener(EmumbaSecurityIndex &index, MDProducer &md_producer)
|
||||
: me(std::make_unique<PImpl>(index, md_producer)) {}
|
||||
|
||||
@@ -345,6 +357,10 @@ void EmMDListener::on_security_statistics(
|
||||
sec_data->handle.update_settlement(
|
||||
now, IntPrice_from_double<8>(market_data_stats.settle.to_double()),
|
||||
date_temp);
|
||||
// since volume can also be passed in the handle.add_trade, therefore caching
|
||||
// it for that call
|
||||
auto &sud = get_sud(market_data_stats.sec_id, me->sec_map);
|
||||
sud.volume = market_data_stats.volume;
|
||||
}
|
||||
|
||||
void EmMDListener::on_quote(
|
||||
@@ -409,12 +425,12 @@ void EmMDListener::on_trades(
|
||||
// assuming millisecs
|
||||
auto trade_ts =
|
||||
datetime::ll_from_unix_epoch_ms(t->timestamp.get_timestamp());
|
||||
auto &sud = get_sud(t->sec_id, me->sec_map);
|
||||
sec_data->handle.add_trade(
|
||||
now_ts,
|
||||
PriceSize(
|
||||
convert_price(t->trade_price), convert_qty(t->trade_quantity)),
|
||||
// TODO: volume
|
||||
trade_ts, convert_trade_side(*t), 0, false);
|
||||
trade_ts, convert_trade_side(*t), sud.volume, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -548,7 +564,8 @@ DescSearchResult EmMDListener::_find_by_desc(
|
||||
auto new_key_opt = me->id_gen.get_id("exchange_key", desc, true);
|
||||
bts_assert(new_key_opt.has_value());
|
||||
auto new_key = new_key_opt.value();
|
||||
me->sec_map[desc] = {new_key, symbol, false};
|
||||
// me->sec_map.insert({desc, SecuritySubStatus(new_key, symbol)});
|
||||
me->sec_map.insert({desc, {new_key, symbol}});
|
||||
LOG(md, Info, "Adding new sec desc:{} key:{}", desc, new_key);
|
||||
return {new_key, false, true};
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user