SPARK-1514, Server side SDK code complete.

This commit is contained in:
Pedro Pinto committed 2018-09-12 18:43:17 +00:00
1 parent 2885d929a8
commit e29ea5d89b
39 files changed
+936 -234

No files matched your search

+99
View File
@@ -0,0 +1,99 @@
#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_c.c"
#include "spark/lib/md/cme/MDP3Utils.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_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;
}