diff --git a/src/sdk/example/example.cpp b/src/sdk/example/example.cpp index 4b502b839..e3b603d1b 100644 --- a/src/sdk/example/example.cpp +++ b/src/sdk/example/example.cpp @@ -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 ( - "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 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 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); }