Files
spark/src/sdk/example/example.cpp
T
2018-07-11 12:23:06 -04:00

81 lines
2.6 KiB
C++

#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"
using namespace bts;
using namespace bts::md;
void produce()
{
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;
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;
std::vector<md::MDProducerHandle> 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
producer_handles.push_back(producer.add_security(fsec));
// initialized bid side book data
std::array<md::PriceSize, md::COCONUT_MAX_DEPTH> bids = {
md::PriceSize::from_double<7> (1.0,10),
md::PriceSize::from_double<7> (2.0,20),
md::PriceSize::from_double<7> (3.0,30),
md::PriceSize::from_double<7> (4.0,40),
md::PriceSize::from_double<7> (5.0,50),
md::PriceSize::from_double<7> (6.0,60),
md::PriceSize::from_double<7> (7.0,70),
md::PriceSize::from_double<7> (8.0,80),
md::PriceSize::from_double<7> (9.0,90),
md::PriceSize::from_double<7> (10.0,100)
};
// initialized ask side book data
std::array<md::PriceSize, md::COCONUT_MAX_DEPTH> asks = {
md::PriceSize::from_double<7> (1.0,10),
md::PriceSize::from_double<7> (2.0,20),
md::PriceSize::from_double<7> (3.0,30),
md::PriceSize::from_double<7> (4.0,40),
md::PriceSize::from_double<7> (5.0,50),
md::PriceSize::from_double<7> (6.0,60),
md::PriceSize::from_double<7> (7.0,70),
md::PriceSize::from_double<7> (8.0,80),
md::PriceSize::from_double<7> (9.0,90),
md::PriceSize::from_double<7> (10.0,100)
};
// Update book - this call does not use locks so should not be called concurrently
producer_handles[0].update_book(utils::TimeStamp::now(), bids, asks);
}
int main()
{
utils::init_spark_lib();
LOG(md, Info, "Hello world");
produce();
utils::finit_spark_lib();
return 0;
}