spark-187 Security Discovery

This commit is contained in:
Eric Harding committed 2017-09-26 08:45:00 -04:00
1 parent 6c017b809b
commit 1cc2aaa4cf
6 files changed
+486 -414

No files matched your search

-5
View File
@@ -41,14 +41,9 @@ public:
api::Venue exchange;
int8_t display_factor;
// int8_t strike_display_factor;
// uint32_t contract_size;
uint32_t cboe_class_key;
// uint32_t cme_display_decimals;
// uint32_t cme_denominator_sub_fraction;
// double cme_min_price_increment;
uint32_t cme_market_segment_id;
double cme_unit_of_measure_qty;
@@ -1 +1,394 @@
#include "MDP3Listener.h"
#include "lib/utils/datetime.h"
#include <vector>
using namespace std;
using namespace bts::co2;
namespace bts {
namespace md {
void decode_ticks(int vtt, double mintick, md2::FixedSecurity& dest) {
switch(vtt) {
default:
case 0:
dest.low_tick = mintick;
dest.high_tick = mintick;
dest.price_break = 0;
break;
case 1:
dest.price_break = 500;
dest.low_tick = 5;
dest.high_tick = 10;
break;
case 2:
dest.price_break = 5;
dest.low_tick = 0.5;
dest.high_tick = 1;
break;
case 3:
dest.price_break = 10;
dest.low_tick = 1;
dest.high_tick = 2;
break;
case 4:
dest.price_break = 500;
dest.low_tick = 5;
dest.high_tick = 25;
break;
case 10:
dest.price_break = 300;
dest.low_tick = 5;
dest.high_tick = 25;
break;
case 11:
dest.price_break = 300;
dest.low_tick = 5;
dest.high_tick = 10;
break;
case 12:
dest.price_break = 5;
dest.low_tick = 0.25;
dest.high_tick = 0.5;
break;
}
}
int floorlog10(int64_t m) {
bts_assert(m >= 0);
if (m < 10) return 0;
if (m < 100) return 1;
if (m < 1000) return 2;
if (m < 10000) return 3;
if (m < 100000) return 4;
if (m < 1000000) return 5;
if (m < 10000000) return 6;
if (m < 100000000) return 7;
if (m < 1000000000) return 8;
if (m < 10000000000) return 9;
if (m < 100000000000) return 10;
if (m < 1000000000000) return 11;
if (m < 10000000000000) return 12;
if (m < 100000000000000) return 13;
if (m < 1000000000000000) return 14;
if (m < 10000000000000000) return 15;
if (m < 100000000000000000) return 16;
if (m < 1000000000000000000) return 17;
return 19;
}
MDP3Listener::MDP3Listener(
CMESecurityIndex& index,
md2::MDProducer& producer,
md2::SecurityIDRecorder& recorder,
co2::SettlementRecorder& settles,
std::vector<md2::MDProducerChannel> channels,
utils::Dispatcher& disp) :
_index(index),
_producer(producer),
_packet_arrived(),
_latest_sequence(0),
_security_recorder(recorder),
_settlement_recorder(settles),
_symbol_filter_storage(),
_symbol_filter(),
_channels(channels),
_background(disp),
_security_recorder_input_timer(disp, 900, [&]() { dequeue_securities(); }),
_security_recorder_input(),
_concurrency_monitor(0),
_book_updates()
{
_book_updates.reserve(32);
_security_recorder_input_timer.start();
}
MDP3Listener::~MDP3Listener() {
_security_recorder_input_timer.stop();
}
//
// Warnings/Errors
void MDP3Listener::onError(onixs::Handler&, const onixs::ErrorArgs& error) {
LOG(MarketData,Warn, "OnixS Error: {} - {}", error.description(), error.source());
}
void MDP3Listener::onWarning(onixs::Handler&, const onixs::WarningArgs& warning) {
LOG(MarketData,Warn, "OnixS Warn: {} - {}", warning.description(), warning.source());
}
void MDP3Listener::onInstrumentRecovery(onixs::Handler&) {
LOG(MarketData,Info, "Beginning security definition recovery");
}
void MDP3Listener::onEndOfInstrumentRecovery(onixs::Handler&, const onixs::RecoveryCompletionArgs& args) {
LOG(MarketData,Info, "Security definition recovery complete. {}", args.details());
}
//
// Gap Recovery
void MDP3Listener::onMarketRecovery(onixs::Handler&) {
update_all_status(COCONUTSECURITYSTATUS_PACKET_LOSS);
}
void MDP3Listener::onEndOfMarketRecovery(onixs::Handler&, const onixs::RecoveryCompletionArgs&) {
update_all_status(COCONUTSECURITYSTATUS_OK);
}
void MDP3Listener::onTcpRecovery(onixs::Handler&) {
update_all_status(COCONUTSECURITYSTATUS_PACKET_LOSS);
LOG(MarketData,Info, "Beginning TCP recovery");
}
void MDP3Listener::onEndOfTcpRecovery(onixs::Handler&, const onixs::RecoveryCompletionArgs& args) {
update_all_status(COCONUTSECURITYSTATUS_OK);
LOG(MarketData,Info, "TCP recovery completed. {}", args.details());
}
//
// Mark the start/end of a packet
void MDP3Listener::onPacket(onixs::Handler&, const onixs::PacketArgs& args) {
// Mark the arrival of the packet
_packet_arrived = TimeStamp::now();
auto seq = args.packet().seqNumber();
if (!_book_updates.empty()) {
if (_latest_sequence != seq) {
LOG(MarketData, Error, "Expected sequence {} got {} did not flush {} book updates.",
_latest_sequence, seq, _book_updates.size());
}
}
_latest_sequence = seq;
}
void MDP3Listener::onEndOfPacket(onixs::Handler&, const onixs::PacketArgs&) {
flush_books();
}
//
// Security discovery
template <class Price>
double double_of_price(const Price& price) {
return price.mantissa() * pow10(price.exponent());
}
template <class Definition>
datetime::Date date_of_maturity(const Definition& def) {
datetime::Date result;
onixs::MaturityMonthYear exp;
if (def.maturityMonthYear(exp)) {
uint8_t day, month;
if (exp.day(day)) result.day = day;
if (exp.month(month)) result.month = month;
result.year = exp.year();
}
else { bts_assert(false); }
return result;
}
template <class Definition>
void set_security_common(const Definition& def, FixedSecurity& fsec) {
fsec.numeric_id = def.securityId();
fsec.symbol(def.asset().items(), def.asset().size());
fsec.cfi_code(def.cfiCode().items(), def.cfiCode().size());
fsec.alt_symbol(def.securityGroup().items(), def.securityGroup().size());
fsec.security_desc(def.symbol().items(), def.symbol().size());
fsec.exchange = api::Venue::VENUE_GLBX;
// tickRule not present in futures
fsec.cme_market_segment_id = def.marketSegmentId();
fsec.display_factor = def.displayFactor().exponent() + floorlog10(def.displayFactor().mantissa());
}
void MDP3Listener::onDefinition(onixs::Handler&, const onixs::Security& osec, const onixs::InstrumentDefinitionFutureArgs& def) {
const auto& sec = def.message();
auto exchange_id = sec.securityId();
if (filter_security(exchange_id, sec) != ADD) return;
bts_assert(exchange_id == osec.id());
FixedFutureSecurity fsec;
set_security_common(sec, fsec);
fsec.price_break = 0;
fsec.low_tick = fsec.high_tick = double_of_price(sec.minPriceIncrement());
auto expiration = date_of_maturity(sec);
fsec.expiration_year = expiration.year;
fsec.expiration_month = expiration.month;
fsec.expiration_day = expiration.day;
onixs::PRICE price;
if (sec.unitOfMeasureQty(price)) {
fsec.cme_unit_of_measure_qty = double_of_price(price);
}
add_security(fsec);
}
void MDP3Listener::onDefinition(onixs::Handler&, const onixs::Security&, const onixs::InstrumentDefinitionOptionArgs& def) {
const auto& sec = def.message();
auto exchange_id = sec.securityId();
if (filter_security(exchange_id, sec) != ADD) return;
FixedOptionSecurity fsec;
set_security_common(sec, fsec);
auto expiration = date_of_maturity(sec);
fsec.expiration_year = expiration.year;
fsec.expiration_month = expiration.month;
fsec.expiration_day = expiration.day;
onixs::PRICE price;
if (sec.unitOfMeasureQty(price)) {
fsec.cme_unit_of_measure_qty = double_of_price(price);
}
onixs::PRICE strike_price;
bts_assert(sec.strikePrice(strike_price));
fsec.strike = double_of_price(strike_price);
onixs::PRICE min_tick;
sec.minPriceIncrement(min_tick);
int8_t tick_rule;
if (sec.tickRule(tick_rule)) {
decode_ticks(tick_rule, double_of_price(min_tick), fsec);
}
fsec.call_put = sec.putOrCall() == onixs::PutOrCall::Call ? api::PUTORCALL_CALL : api::PUTORCALL_PUT;
add_security(fsec);
}
void MDP3Listener::onDefinition(onixs::Handler&, const onixs::Security&, const onixs::InstrumentDefinitionSpreadArgs& spread_args) {
const auto& sec = spread_args.message();
auto exchange_id = sec.securityId();
if (filter_security(exchange_id, sec) != ADD) return;
// Filter out any already expired spreads
auto expiration = date_of_maturity(sec);
if (expiration < datetime::today()) return;
FixedSpreadSecurityL fsec;
set_security_common(sec, fsec);
vector<uint32_t> leg_exchange_ids;
leg_exchange_ids.reserve(sec.legs().size());
fsec.set_leg_count(sec.legs().size());
for(size_t x = 0; x < fsec.leg_count(); ++x) {
const auto& leg = sec.legs()[x];
onixs::PRICE price;
if (leg.legPrice(price)) {
fsec.legs[x].leg_price = double_of_price(price);
}
onixs::DecimalQty qty;
if (leg.legOptionDelta(qty)) {
fsec.legs[x].leg_delta = double_of_price(qty);
}
fsec.legs[x].leg_quantity = leg.legRatioQty();
fsec.legs[x].leg_side = leg.legSide() == onixs::LegSide::BuySide ? api::SIDE_BUY : api::SIDE_SELL;
leg_exchange_ids.push_back(leg.legSecurityId());
}
add_security(fsec);
_index.add_spread_legs(fsec.numeric_id, leg_exchange_ids);
}
//
// Book
//
// Trades
//
// Volume
void MDP3Listener::onElectronicVolumn(onixs::Handler&, const onixs::Security& sec, const onixs::VolumeArgs& args) {
// This is really strange...
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
bts_assert_d( args.entry().entryType().value() == 'e');
bts_assert_d(args.entry().updateAction() == onixs::UpdateAction::New ||
args.entry().updateAction() == onixs::UpdateAction::Change);
data->electronic_volume = args.entry().entrySize();
}
}
//
// RFQ
//
// Misc
//
// Non-onixs calls
void MDP3Listener::add_filter_symbol(const std::string& symbol) {
_symbol_filter_storage.push_back(symbol);
_symbol_filter.clear();
for (const auto& str : _symbol_filter_storage) {
_symbol_filter.insert(onixs::StrRef(str.c_str(), str.size()));
}
}
void MDP3Listener::heartbeat() {
for (auto& c : _channels) { c.heartbeat(); }
}
//
// Private functions
void MDP3Listener::add_security(const FixedSecurity& security) {
// Set up the shared memory for this security
auto handle = _producer.add_security(security);
bts_assert(security.numeric_id != 0);
// Add it to the index so it can receive messages
SecurityData* data = _index.add_security(security.numeric_id, handle);
// Computing the descriptor may be expensive so defer that processing to the background worker thread (see dequeue_securities)
_security_recorder_input.push(data);
}
void MDP3Listener::dequeue_securities() {
// already running on '_background' thread
vector<SecurityData*> defer;
SecurityData* data = nullptr;
while (_security_recorder_input.try_pop(data)) {
bts_assert(data->handle.security().key == invalid_security_key);
string descriptor = security_descriptor(data->handle.security());
if (descriptor.empty()) {
defer.push_back(data);
}
else {
_security_recorder.get_key(descriptor, data->handle.security().type, [](void* pv_handle, security_key key) {
SecurityData* pdata = (SecurityData*)pv_handle;
pdata->handle.set_key(key);
}, data);
// Restore saved settlements
_settlement_recorder.restore_settlement(data->handle);
}
}
// try again later (when spread legs have resolved)
for (auto* retry : defer) {
_security_recorder_input.push(retry);
}
}
void MDP3Listener::flush_books() {
// This is called at the end of the packet
// Write all book updates to shared memory and reset for the next packet
for (auto& entry : _book_updates) {
// bbo first
uint16_t sequence = (_latest_sequence & 0xFFFF);
entry.handle.update_bbo(_packet_arrived, entry.bids[0], entry.asks[0], sequence);
// Perf Note: the remainder of the book update could be done (carefully) with a memcpy
for (size_t x = 1; x < COCONUT_MAX_DEPTH; ++x) {
entry.handle.update_bid(_packet_arrived, entry.bids[x], x);
entry.handle.update_ask(_packet_arrived, entry.asks[x], x);
}
}
// Reset pending updates
_book_updates.clear();
}
void MDP3Listener::update_all_status(CoconutSecurityStatus status) {
_index.walk_security_list([=](SecurityData& data) {
data.handle.set_status(status);
});
}
md::MDP3Listener::BookData::BookData(md2::MDProducerHandle & handle) : handle(handle), bids(), asks() { }
}}//namespace
@@ -20,6 +20,98 @@ class MDP3Listener :
public:
MDP3Listener(CMESecurityIndex& index, md2::MDProducer&, md2::SecurityIDRecorder&, co2::SettlementRecorder&, std::vector<md2::MDProducerChannel>, utils::Dispatcher&);
~MDP3Listener();
//
// Warnings/Errors/Info
void onError(onixs::Handler&, const onixs::ErrorArgs&) override;
void onWarning(onixs::Handler&, const onixs::WarningArgs&) override;
void onInstrumentRecovery(onixs::Handler&) override;
void onEndOfInstrumentRecovery(onixs::Handler&, const onixs::RecoveryCompletionArgs&) override;
//
// Gap Recovery
void onMarketRecovery(onixs::Handler&) override;
void onEndOfMarketRecovery(onixs::Handler&, const onixs::RecoveryCompletionArgs&) override;
void onTcpRecovery(onixs::Handler&) override;
void onEndOfTcpRecovery(onixs::Handler&, const onixs::RecoveryCompletionArgs&) override;
//
// Mark the start/end of a packet
void onPacket(onixs::Handler&, const onixs::PacketArgs&) override;
void onEndOfPacket(onixs::Handler&, const onixs::PacketArgs&) override;
//
// Security discovery
void onDefinition(onixs::Handler&, const onixs::Security&, const onixs::InstrumentDefinitionFutureArgs&) override;
void onDefinition(onixs::Handler&, const onixs::Security&, const onixs::InstrumentDefinitionOptionArgs&) override;
void onDefinition(onixs::Handler&, const onixs::Security&, const onixs::InstrumentDefinitionSpreadArgs&) override;
//
// Book
//
// Trades
//
// Volume
void onElectronicVolumn(onixs::Handler&, const onixs::Security&, const onixs::VolumeArgs&);
//
// RFQ
//
// Misc
//
// Discover securities
void add_filter_symbol(const std::string& symbol);
void heartbeat();
private:
void add_security(const md2::FixedSecurity& security);
void dequeue_securities();
enum SecurityFilterAction { ADD, SKIP, DELETE };
template <class Sec>
bool filter_security(int exchange_id, const Sec& sec) {
if (sec.securityUpdateAction() == onixs::SecurityUpdateAction::Delete) {
auto* data = _index.get_security(exchange_id);
if (data != nullptr) {
data->handle.mark_deleted();
}
return DELETE;
}
if (_index.has_security(exchange_id)) return SKIP;
onixs::SecurityTradingStatus::Enum trading_status;
if(sec.securityTradingStatus(trading_status) &&
trading_status == onixs::SecurityTradingStatus::NotAvailableForTrading) return SKIP;
return _symbol_filter.count(sec.asset()) == 0 ? ADD : SKIP;
}
void flush_books();
void update_all_status(co2::CoconutSecurityStatus status);
CMESecurityIndex& _index;
md2::MDProducer& _producer;
utils::TimeStamp _packet_arrived;
uint32_t _latest_sequence;
md2::SecurityIDRecorder& _security_recorder;
co2::SettlementRecorder& _settlement_recorder;
std::vector<std::string> _symbol_filter_storage;
std::set<onixs::StrRef> _symbol_filter;
std::vector<md2::MDProducerChannel> _channels;
utils::Dispatcher& _background;
utils::DispatcherTimer _security_recorder_input_timer;
tbb::concurrent_queue<SecurityData*> _security_recorder_input;
std::atomic<int> _concurrency_monitor;
struct BookData {
BookData(md2::MDProducerHandle& handle);
md2::MDProducerHandle handle;
md2::PriceSize bids[10];
md2::PriceSize asks[10];
};
std::vector<BookData> _book_updates;
};
}}//namespace
@@ -14,89 +14,6 @@
namespace bts {
// namespace md {
void set_ticks(int vtt, double mintick, md2::FixedSecurity& dest) {
switch(vtt) {
default:
case 0:
dest.low_tick = mintick;
dest.high_tick = mintick;
dest.price_break = 0;
break;
case 1:
dest.price_break = 500;
dest.low_tick = 5;
dest.high_tick = 10;
break;
case 2:
dest.price_break = 5;
dest.low_tick = 0.5;
dest.high_tick = 1;
break;
case 3:
dest.price_break = 10;
dest.low_tick = 1;
dest.high_tick = 2;
break;
case 4:
dest.price_break = 500;
dest.low_tick = 5;
dest.high_tick = 25;
break;
case 10:
dest.price_break = 300;
dest.low_tick = 5;
dest.high_tick = 25;
break;
case 11:
dest.price_break = 300;
dest.low_tick = 5;
dest.high_tick = 10;
break;
case 12:
dest.price_break = 5;
dest.low_tick = 0.25;
dest.high_tick = 0.5;
break;
}
}
// MDP3Listener::MDP3Listener(CMESecurityIndex& index, md2::MDProducer& producer, md2::SecurityIDRecorder& recorder, co2::SettlementRecorder& settles, std::vector<md2::MDProducerChannel> channels, utils::Dispatcher& disp) :
// _index(index),
// _producer(producer),
// _packet_arrived(),
// _latest_sequence(0),
// _security_recorder(recorder),
// _settlement_recorder(settles),
// _symbol_filter_storage(),
// _symbol_filter(),
// _channels(channels),
// _background(disp),
// _security_recorder_input_timer(disp, 900, [&]() { dequeue_securities(); }),
// _security_recorder_input(),
// _concurrency_monitor(0),
// _book_updates()
// {
// _book_updates.reserve(32);
// _security_recorder_input_timer.start();
// }
// MDP3Listener::~MDP3Listener() {
// _security_recorder_input_timer.stop();
// }
// void MDP3Listener::add_filter_symbol(const std::string& symbol) {
// _symbol_filter_storage.push_back(symbol);
// _symbol_filter.clear();
// for (const auto& str : _symbol_filter_storage) {
// _symbol_filter.insert(onixs::StringRef(str));
// }
// }
// bool MDP3Listener::filter_security(onixs::StringRef val) {
// return _symbol_filter.count(val) == 0;
// }
// //
// // MessageProcessingListener
// void MDP3Listener::onProcessingBegin(const Message& msg, const ChannelId&) {
@@ -153,68 +70,6 @@ void set_ticks(int vtt, double mintick, md2::FixedSecurity& dest) {
// return cfi_code[1] == 'C' ? PutOrCall::CALL : PutOrCall::PUT;
// }
// int floorlog10(onixs::DecimalMantissa m) {
// bts_assert(m >= 0);
// if (m < 10) return 0;
// if (m < 100) return 1;
// if (m < 1000) return 2;
// if (m < 10000) return 3;
// if (m < 100000) return 4;
// if (m < 1000000) return 5;
// if (m < 10000000) return 6;
// if (m < 100000000) return 7;
// if (m < 1000000000) return 8;
// if (m < 10000000000) return 9;
// if (m < 100000000000) return 10;
// if (m < 1000000000000) return 11;
// if (m < 10000000000000) return 12;
// if (m < 100000000000000) return 13;
// if (m < 1000000000000000) return 14;
// if (m < 10000000000000000) return 15;
// if (m < 100000000000000000) return 16;
// if (m < 1000000000000000000) return 17;
// return 19;
// }
// template <typename TSecurityType>
// void set_security_common(const onixs::SecurityDefinition& def, TSecurityType& security, uint32_t exchange_id) {
// security.numeric_id = exchange_id;
// security.symbol(def.asset().data(), def.asset().size()); // 1151-SecurityGroup changed to 6937-Asset in MDP3
// security.cfi_code(def.CFICode().data(), def.CFICode().size());
// security.alt_symbol(def.securityGroup().data(), def.securityGroup().size());
// security.security_desc(def.symbol().data(), def.symbol().size());
// security.exchange = Exchange::GLBX;
// def.tickRule(security.cme_vtt);
// onixs::FloatQuantity unit_qty;
// if (def.unitOfMeasureQty(unit_qty)) {
// security.cme_unit_of_measure_qty = unit_qty;
// }
// def.subFraction(security.cme_denominator_sub_fraction);
// def.mainFraction(security.cme_display_decimals);
// def.marketSegmentId(security.cme_market_segment_id);
// onixs::PriceFactor display;
// if (def.displayFactor(display)) {
// auto exp = display.exponent();
// auto mant = floorlog10(display.mantissa());
// security.display_factor = exp + mant;
// security.strike_display_factor = security.display_factor;
// }
// // mapping::display_factor((string)security.symbol(), &security.display_factor, security.type);
// // bool should_multiply_strike = false;
// // int8_t strike_factor = security.strike_display_factor;
// // if (security.type == SecurityType::OPTION &&
// // mapping::strike_display_factor(security.symbol(), nullptr, &strike_factor, security.type, nullptr, nullptr, nullptr, &should_multiply_strike) &&
// // should_multiply_strike) {
// // security.strike_display_factor = strike_factor;
// // }
// onixs::Price min_price_increment;
// def.minPriceIncrement(min_price_increment);
// security.cme_min_price_increment = min_price_increment;
// }
// datetime::Date get_expiration(const SecurityDefinition& def) {
// datetime::Date result;
@@ -232,115 +87,6 @@ void set_ticks(int vtt, double mintick, md2::FixedSecurity& dest) {
// }
// //
// // SecurityDefinitionListener
// void MDP3Listener::onSecurityDefinition(const SecurityDefinition& def, const ChannelId&) {
// LOG_IF_SLOW
// //
// auto exchange_id = def.securityId();
// // Ignore duplicate security defs
// if (_index.has_security(exchange_id)) return;
// if (filter_security(def.asset())) return;
// // Also any securities which are not elligible for trading
// if (def.tradingStatus() == SecurityTradingStatus::NotAvailableForTrading) return;
// StringRef cfi_code = def.CFICode();
// auto type = SecurityType::UNSET;
// if (def.legs().size() > 0) {
// type = SecurityType::SPREAD;
// }
// else {
// type = type_from_cfi(cfi_code);
// }
// switch (type) {
// //
// // Option
// case SecurityType::OPTION: {
// FixedOptionSecurity security;
// set_security_common(def, security, exchange_id);
// onixs::Price price;
// bts_assert(def.strikePrice(price));
// security.strike = (double)price * pow10(security.strike_display_factor);
// security.call_put = call_put(cfi_code);
// auto date = get_expiration(def);
// security.expiration_year = date.year;
// security.expiration_month = date.month;
// security.expiration_day = date.day;
// add_security(security);
// } break;
// //
// // Future
// case SecurityType::FUTURE: {
// FixedFutureSecurity security;
// set_security_common(def, security, exchange_id);
// auto date = get_expiration(def);
// security.expiration_year = date.year;
// security.expiration_month = date.month;
// security.expiration_day = date.day;
// add_security(security);
// } break;
// //
// // Spread
// case SecurityType::SPREAD: {
// // Sometimes our CFI parsing isn't correct. There's a MRRXXX on the 6E channel for example
// if (def.legs().size() == 0) return;
// // Filter out any already expired spreads
// auto date = get_expiration(def);
// if (date < datetime::today()) return;
// // Start simple
// FixedSpreadSecurityL security;
// vector<uint32_t> leg_exchange_ids;
// leg_exchange_ids.reserve(def.legs().size()); // TODOPERF: heap
// set_security_common(def, security, exchange_id);
// security.set_leg_count(def.legs().size());
// for (size_t x = 0; x < security.leg_count(); ++x) {
// const auto& leg = def.legs()[x];
// FloatQuantity f;
// if (leg.optionDelta(f)) {
// security.legs[x].leg_delta = f;
// }
// onixs::Price temp_price;
// leg.price(temp_price);
// security.legs[x].leg_price = (double)temp_price * pow10(security.display_factor);
// security.legs[x].leg_quantity = leg.ratioQty();
// security.legs[x].leg_side = leg.side() == LegSides::Buy ? Side::BUY : Side::SELL;
// if (leg.side() == LegSides::Undefined) return; // Do not add invalid spreads
// leg_exchange_ids.push_back(leg.getUInt32(onixs::Tags::LegSecurityID));
// //leg_exchange_ids.push_back(leg.securityId());
// }
// add_security(security);
// _index.add_spread_legs(security.numeric_id, leg_exchange_ids);
// } break;
// default:
// return;
// }
// }
// void MDP3Listener::onSecurityDefinitionDeleted(SecurityId id, const ChannelId&) {
// auto* data = _index.get_security(id);
// if (data != nullptr) {
// data->handle.mark_deleted();
// }
// }
// void MDP3Listener::onSecurityDefinitionsRecoveryStarted(const ChannelId& ch) {
// LOG(MarketData,Info,"Security definition recovery started on channel {}",ch);
// }
// void MDP3Listener::onSecurityDefinitionsRecoveryFinished(const ChannelId& chan) {
// LOG(MarketData,Info, "Security definition recovery finished on channel {}", chan);
// }
// //
// // SecurityStatusListener
// void MDP3Listener::onSecurityStatus(const SecurityStatus&, const ChannelId&) {
// }
// inline PriceSize convert(const onixs::Price price, int8_t display_factor, Size size) {
// PriceSize result = PriceSize(price.mantissa(), price.exponent() + display_factor, size);
// return result;
@@ -544,101 +290,5 @@ void set_ticks(int vtt, double mintick, md2::FixedSecurity& dest) {
// // noop
// }
// //
// // WarningListener
// void MDP3Listener::onWarning(const Warning& warning,const ChannelId& ch) {
// LOG_IF_SLOW
// if (warning.code() == KnownWarnings::PacketGap) {
// // Mark all securities on this channel as bad
// // This is probably not fast but should be faster than creating a security I think
// _index.walk_security_list([](SecurityData& data) {
// data.handle.set_status(CoconutSecurityStatus::PACKET_LOSS);
// });
// }
// // Logging to the console can be very expensive
// LOG(MarketData,Warn, "{} (Chanel {}) {}",
// warning.description(),ch ,warning.source());
// }
// //
// // ErrorListener
// void MDP3Listener::onError(const onixs::Error& error, const ChannelId& ch) {
// LOG(MarketData,Warn, "{} (Channel {}) {}",
// error.description(), ch ,error.source());
// }
// //
// // Private Functions
// //
// void MDP3Listener::heartbeat() {
// for (auto& c : _channels) { c.heartbeat(); }
// }
// void MDP3Listener::add_security(const FixedSecurity& security) {
// // Set up the shared memory for this security
// auto handle = _producer.add_security(security);
// bts_assert(security.numeric_id != 0);
// // Add it to the index so it can receive messages
// SecurityData* data = _index.add_security(security.numeric_id, handle);
// // Computing the descriptor may be expensive so defer that processing to the background worker thread (see dequeue_securities)
// _security_recorder_input.push(data);
// }
// void MDP3Listener::dequeue_securities() {
// // already running on '_background' thread
// vector<SecurityData*> defer;
// SecurityData* data = nullptr;
// while (_security_recorder_input.try_pop(data)) {
// bts_assert(data->handle.security().key == invalid_security_key);
// string descriptor = security_descriptor(data->handle.security());
// if (descriptor.empty()) {
// defer.push_back(data);
// }
// else {
// _security_recorder.get_key(descriptor, data->handle.security().type, [](void* pv_handle, security_key key) {
// SecurityData* pdata = (SecurityData*)pv_handle;
// pdata->handle.set_key(key);
// }, data);
// // Restore saved settlements
// _settlement_recorder.restore_settlement(data->handle);
// }
// }
// // try again later (when spread legs have resolved)
// for (auto* retry : defer) {
// _security_recorder_input.push(retry);
// }
// }
// void MDP3Listener::flush_books() {
// // This is called at the end of the packet
// // Write all book updates to shared memory and reset for the next packet
// for (auto& entry : _book_updates) {
// // bbo first
// uint16_t sequence = (_latest_sequence & 0xFFFF);
// entry.handle.update_bbo(_packet_arrived, entry.bids[0], entry.asks[0], sequence);
// // Perf Note: the remainder of the book update could be done (carefully) with a memcpy
// for (size_t x = 1; x < COCONUT_MAX_DEPTH; ++x) {
// entry.handle.update_bid(_packet_arrived, entry.bids[x], x);
// entry.handle.update_ask(_packet_arrived, entry.asks[x], x);
// }
// }
// // Reset pending updates
// _book_updates.clear();
// }
// }
// md::MDP3Listener::BookData::BookData(md2::MDProducerHandle & handle) : handle(handle), bids(), asks()
// { }
}//namespace
// #endif
@@ -30,23 +30,6 @@ public:
MDP3Listener(CMESecurityIndex& index, md2::MDProducer&, md2::SecurityIDRecorder&, co2::SettlementRecorder&, std::vector<md2::MDProducerChannel>, utils::Dispatcher&);
~MDP3Listener();
void add_filter_symbol(const std::string& symbol);
//
// MessageProcessingListener
/* Look for heartbeat and top of book update */
void onProcessingBegin(const onixs::Message& message, const onixs::ChannelId&);
void onProcessingEnd(const onixs::Message& Message, const onixs::ChannelId&);
void onProcessingSuspended(const onixs::ChannelId&);
//
// SecurityDefinitionListener
void onSecurityDefinition(const onixs::SecurityDefinition& definition, const onixs::ChannelId&);
void onSecurityDefinitionDeleted(onixs::SecurityId id, const onixs::ChannelId&);
void onSecurityDefinitionsRecoveryStarted(const onixs::ChannelId&);
void onSecurityDefinitionsRecoveryFinished(const onixs::ChannelId&);
void onSecurityStatus(const onixs::SecurityStatus& status, const onixs::ChannelId&);
//
// ConsolidatedBookUpdateListener
@@ -83,47 +66,7 @@ public:
void onStatistics(const onixs::FixingPrice& fixingPrice,const onixs::ChannelId&);
void onStatistics(const onixs::ThresholdLimits& limits,const onixs::ChannelId&);
//
// WarningListener
void onWarning(const onixs::Warning& warning,const onixs::ChannelId&);
//
// ErrorListener
void onError(const onixs::Error& error, const onixs::ChannelId&);
void heartbeat();
private:
BTS_NO_COPY(MDP3Listener);
void add_security(const md2::FixedSecurity& security);
void dequeue_securities();
bool filter_security(onixs::StringRef);
void flush_books();
CMESecurityIndex& _index;
md2::MDProducer& _producer;
utils::TimeStamp _packet_arrived;
uint64_t _latest_sequence;
md2::SecurityIDRecorder& _security_recorder;
co2::SettlementRecorder& _settlement_recorder;
std::vector<std::string> _symbol_filter_storage;
std::set<onixs::StringRef> _symbol_filter;
std::vector<md2::MDProducerChannel> _channels;
utils::Dispatcher& _background;
utils::DispatcherTimer _security_recorder_input_timer;
tbb::concurrent_queue<SecurityData*> _security_recorder_input;
std::atomic<int> _concurrency_monitor;
struct BookData {
BookData(md2::MDProducerHandle& handle);
md2::MDProducerHandle handle;
md2::PriceSize bids[10];
md2::PriceSize asks[10];
};
std::vector<BookData> _book_updates;
};
+1 -2
View File
@@ -40,8 +40,7 @@ void clean_dir(const std::string base_path) {
void run_relay() {
auto naggle_ms = config::get<md::RelayOptions>().naggle_ms();
// auto file = "http://mdreplay/c2/futures.coconut";
auto file = "http://10.96.18.45/c2/futures.coconut";
auto file = "http://mdreplay/spark/futures.coconut";
replay_recording(file, naggle_ms);
}