SPARK-1437 Simple market data producer sample

This commit is contained in:
Eric Harding committed 2018-07-10 17:41:52 -04:00
1 parent 724243c762
commit f621d08f72
1 file changed
+26 -32
+26 -32
View File
@@ -5,44 +5,38 @@
#include "spark/lib/utils/PBUtils.h"
using namespace bts;
using namespace bts::md;
void produce()
{
md::MDProducer producer(co2::PLATFORM_SIM);
auto s = utils::pb::from_string<api::Security> (
"id: 16\n"
"symbol: \"ZF\"\n"
"exchange: VENUE_GLBX\n"
"contract_spec {\n"
"low_tick: 0.0078125\n"
"high_tick: 0.0078125\n"
"cash_per_point: 0.012799999999999999\n"
"price_multiplier: 1\n"
"}\n"
"future {\n"
"expiration_year: 2018\n"
"expiration_month: 9\n"
"expiration_day: 28\n"
"}\n"
"glbx {\n"
"exchange_id: 164760\n"
"security_desc: \"ZFU8\"\n"
"cfi_code: \"FFDXSX\"\n"
"cme_symbol: \"ZF\"\n"
"main_fraction: 32\n"
"sub_fraction: 4\n"
"price_display_format: 3\n"
"market_segment_id: 84\n"
"}\n"
);
// Create temporary security (on the stack)
md::FixedFutureSecurity fsec;
fsec.numeric_id = 12345; // Exchange ID
fsec.symbol("ZF");
fsec.exchange = api::VENUE_GLBX;
fsec.low_tick = 0.0078125;
fsec.high_tick = 0.0078125;
fsec.cash_per_point = 0.0128;
// display price is price * pow10(display_factor)
fsec.display_factor = 0;
fsec.expiration_year = 2018;
fsec.expiration_month = 9;
fsec.expiration_day = 28;
fsec.security_desc("ZFU8");
fsec.cfi_code("FFDXSX");
fsec.alt_symbol("ZF");
fsec.cme_main_fraction = 32;
fsec.cme_sub_fraction = 4;
fsec.cme_price_display_format = 3;
fsec.cme_market_segment_id = 84;
// create security and obtain handle so we can update it later
std::vector<md::MDProducerHandle> producer_handles;
md::with_security_like(s, [&s,&producer,&producer_handles](auto &fs) {
md::convert_security(s, fs, true);
producer_handles.push_back(producer.add_security(fs));
});
// Add the security to the producer (this copies fsec) and get a handle to update it
// This call is thread safe and may take a symbol specific lock internally
producer_handles.push_back(producer.add(fsec));
// initialized bid side book data
std::array<md::PriceSize, md::COCONUT_MAX_DEPTH> bids = {
@@ -72,7 +66,7 @@ void produce()
md::PriceSize::from_double<7> (10.0,100)
};
// update book
// Update book - this call does not use locks so should not be called concurrently
producer_handles[0].update_book(utils::TimeStamp::now(), bids, asks);
}