#include "spark/lib/logging/logging.h" #include "spark/lib/utils/init_spark_lib.h" #include "spark/lib/utils/bts_chrono.h" #include "spark/lib/md/MDProducer.h" #include "spark/lib/utils/PBUtils.h" #include "spark/lib/tracing/bts_trace.h" #include "spark/lib/md/cme/MDP3Utils.h" using namespace bts; using namespace bts::md; void produce() { // For Production use you should use provide a SecurityIDRecorder so security keys are generated md::MDProducer producer(co2::PLATFORM_SIM); // 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; // 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; md::FixedSpreadSecurityL fspread; fspread.numeric_id = 1200; fspread.symbol("ZF"); fsec.security_desc("ZFU8-ZFU9"); fsec.cfi_code("FMDXSX"); fspread.exchange = api::VENUE_GLBX; fspread.low_tick = 0.001; fspread.high_tick = 0.001; fspread.display_factor = 0; fspread.set_leg_count(2); for (size_t x = 0; x < 2; ++x) { auto& leg = fspread.legs[x]; leg.leg_price = 0.25;//optional LegPrice id=566 leg.leg_delta = 0.1;//optional LegOptionDelta id=1017 leg.leg_quantity = 1; // LegRatioQty id=623 leg.leg_side = api::SIDE_BUY; // LegSide id=624 } std::vector producer_handles; // 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 MDProducerHandle future_handle = producer.add_security(fsec); // future_handle is small and safe to copy producer_handles.push_back(future_handle); producer_handles.push_back(producer.add_security(fspread)); // The securities added though producer.add_security will not be visible to the rest of the system // until a security key has been generated. If you supplied SecurityIDRecorder to the MDProducer constructor // then this will happen automatically. // initialized bid side book data std::array bids {{ { {100000000, -7 }, 100}, { { 90000000, -7 }, 10 }, { { 80000000, -7 }, 20 }, { { 70000000, -7 }, 30 }, { { 60000000, -7 }, 40 }, { { 50000000, -7 }, 50 }, { { 40000000, -7 }, 60 }, { { 30000000, -7 }, 70 }, { { 20000000, -7 }, 80 }, { { 10000000, -7 }, 90 } }}; // initialized ask side book data std::array asks {{ { { 10000000, -7 }, 10 }, { { 20000000, -7 }, 20 }, { { 30000000, -7 }, 30 }, { { 40000000, -7 }, 40 }, { { 50000000, -7 }, 50 }, { { 60000000, -7 }, 60 }, { { 70000000, -7 }, 70 }, { { 80000000, -7 }, 80 }, { { 90000000, -7 }, 90 }, { {100000000, -7 }, 100} }}; // Update book - this call does not use locks so should not be called concurrently producer_handles[0].update_direct(utils::TimeStamp::now(), bids, asks); } int main() { // this is needed before using any part of the api utils::init_spark_lib(); // this is how we log, the first arg is the subsystem, md in your // case the second is the log level: Diag, Info, Warn, Error, Fatal // the third argument is a format string, followed by arguments // (this uses the fmt library see here: https://github.com/fmtlib/fmt LOG(md, Info, "Hello world, my pid is: {}",getpid()); // this is the tracing library we use for performance tuning. // first two args are special markers just use them as is second // arg is a const char *, next 3 args are long long see // https://lttng.org/ for details tracepoint (bts_trace,trace_order,(char*) "This is a trace example", 0,0, 0); // this is an example of our assert macro bts_assert(true); produce(); utils::finit_spark_lib(); return 0; }