173 lines
6.2 KiB
C++
173 lines
6.2 KiB
C++
#ifdef _WIN32
|
|
#include "lib/utils/bts_export.h"
|
|
#include "../coconut2.h"
|
|
#include "lib/config/config.h"
|
|
#include "lib/md/protos/co2.pb.h"
|
|
#include "lib/utils/TimeStamp.h"
|
|
#include <tuple>
|
|
#include <vector>
|
|
|
|
namespace bts {
|
|
namespace md {
|
|
namespace test {
|
|
|
|
using namespace co2;
|
|
|
|
std::vector<MDProducerHandle> create_test_securities(MDProducer& producer, const char* postfix = "M");
|
|
|
|
void assign_ids(std::vector<MDProducerHandle>::iterator begin, std::vector<MDProducerHandle>::iterator end, security_key start_key = 1000);
|
|
|
|
extern "C" BTS_EXPORT void co2_get_1234_handle(size_t& size, MDConsumerHandle& handle, uintptr_t* hotaddr, uintptr_t* coldaddr, uintptr_t* headeraddr) {
|
|
// Test that marshaling is working
|
|
auto phot = std::make_unique<HotEntry>();
|
|
auto pcold = std::make_unique<ColdEntry>(0);
|
|
std::vector<uint8_t> buffer;
|
|
buffer.resize(1024);
|
|
auto pheader = reinterpret_cast<ColdHeader*>(&buffer[0]);
|
|
pheader->has_depth = false;
|
|
size = sizeof(MDConsumerHandle);
|
|
handle.init(*pheader, *pcold, phot.get(), nullptr);
|
|
// Copy the addresses for comparison
|
|
*hotaddr = (uintptr_t)phot.get();
|
|
*coldaddr = (uintptr_t)pcold.get();
|
|
*headeraddr = (uintptr_t)pheader;
|
|
}
|
|
|
|
extern "C" BTS_EXPORT void co2_get_sample_hot(size_t& size, HotEntry& entry) {
|
|
size = sizeof(HotEntry);
|
|
entry.key = 1234;
|
|
entry.book = PriceLevel(
|
|
PriceSize_from_double<2>(7.2, 101),
|
|
PriceSize_from_double<2>(-9.7, 245));
|
|
entry.sequence = 777;
|
|
entry.status = COCONUTSECURITYSTATUS_PACKET_LOSS;
|
|
entry.settlement = IntPrice_from_double<7>(98.6);
|
|
entry.set_time(utils::TimeStamp::now());
|
|
}
|
|
|
|
extern "C" BTS_EXPORT void co2_get_sample_depth(size_t& size, HotDepthEntry& entry) {
|
|
size = sizeof(HotDepthEntry);
|
|
entry.key = 1234;
|
|
for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) {
|
|
entry.write_direct(x,
|
|
PriceSize_from_double<2>(x + 0.5, x + 1),
|
|
PriceSize_from_double<2>(x + 0.6, x + 2));
|
|
}
|
|
for (size_t x = 0; x < COCONUT_MAX_IMPLIED_DEPTH; ++x) {
|
|
entry.write_implied(x,
|
|
PriceSize_from_double<3>(77, x + 1),
|
|
PriceSize_from_double<3>(88, x + 2));
|
|
}
|
|
entry.set_time(utils::TimeStamp::now());
|
|
entry.status = COCONUTSECURITYSTATUS_PACKET_LOSS;
|
|
entry.sequence = 888;
|
|
entry.settlement = IntPrice_from_double<7>(98.6);
|
|
}
|
|
|
|
extern "C" BTS_EXPORT void co2_get_sample_cold(size_t& size, ColdEntry& entry) {
|
|
size = sizeof(entry);
|
|
entry.exchange_status = TRADINGSTATUS_NORMAL;
|
|
|
|
// Last trade
|
|
entry.last_trade.store(PriceSize_from_double<2>(4.2, 101));
|
|
entry.total_volume = 12345;
|
|
entry.last_trade_time = datetime::ll_now();
|
|
// Settlement
|
|
entry.misc.settlement_date = datetime::Date(2015, 9, 3);
|
|
entry.misc.previous_settlement_price = IntPrice_from_double<7>(3.3);
|
|
entry.misc.previous_settlement_date = datetime::Date(2015, 9, 2);
|
|
// Open/close
|
|
entry.misc.open_price = 4.4;
|
|
entry.misc.open_date = datetime::Date(2015, 8, 29);
|
|
entry.misc.close_price = 4.5;
|
|
entry.misc.close_date = datetime::Date(2015, 7, 7);
|
|
|
|
entry.misc.session_high = 1.1;
|
|
entry.misc.session_low = 2.2;
|
|
entry.misc.session_high_bid = 4.4;
|
|
entry.misc.session_low_offer = 5.5;
|
|
entry.misc.fixing_price = 6.6;
|
|
entry.deleted = true;
|
|
}
|
|
|
|
extern "C" BTS_EXPORT void co2_get_sample_cold_header(ColdHeader& header) {
|
|
header.segment_count = 1;
|
|
header.create_time = utils::TimeStamp::now();
|
|
header.heartbeat = utils::TimeStamp::now();
|
|
|
|
header.security_count = 77000;
|
|
header.has_depth = true;
|
|
header.platform = PLATFORM_SIM;
|
|
header.trade_count = 100;
|
|
header.coconut_status_count = 101;
|
|
header.exchange_status_count = 102;
|
|
header.rfq_count = 103;
|
|
header.gap_count = 104;
|
|
|
|
// Do not write to trade_buffer or rfq_buffer
|
|
}
|
|
|
|
struct TestProducer {
|
|
std::shared_ptr<MDProducer> md;
|
|
std::vector<MDProducerHandle> handles;
|
|
};
|
|
|
|
extern "C" BTS_EXPORT TestProducer* co2_produce_test_md() {
|
|
config::internal::initialize_for_test(
|
|
"PlatformMap {"
|
|
" value {"
|
|
" glbx_platform: 'PLATFORM_SIM'"
|
|
" }"
|
|
"}");
|
|
auto* tp = new TestProducer();
|
|
tp->md = std::make_shared<MDProducer>(PLATFORM_SIM, false);
|
|
tp->handles = create_test_securities(*(tp->md));
|
|
auto& producers = tp->handles;
|
|
assign_ids(producers.begin(), producers.end());
|
|
for (auto& p : producers) {
|
|
p.update_bbo(utils::TimeStamp::now(), PriceSize_from_double<3>(1.1, 101), PriceSize_from_double<3>(2.2,202));
|
|
p.add_trade(utils::TimeStamp::now(),
|
|
PriceSize_from_double<3>(5.5, 505),
|
|
datetime::ll_from_date(datetime::Date(2015, 9, 22)),
|
|
AGGRESSOR_SIDE_NONE, 4200);
|
|
p.update_settlement(utils::TimeStamp::now(), IntPrice_from_double<7>(6.6), datetime::Date(2000, 8, 8));
|
|
p.update_settlement(utils::TimeStamp::now(), IntPrice_from_double<7>(6.6), datetime::Date(2000, 8, 9));
|
|
|
|
p.update_opening(utils::TimeStamp::now(), 7.7, datetime::Date(2001, 1, 2));
|
|
auto t = utils::TimeStamp::now();
|
|
p.update_closing(t, 8.8, datetime::Date(2002, 3, 4));
|
|
p.update_session_high(t, 9.9);
|
|
p.update_session_low(t, 10.1);
|
|
p.update_session_high_bid(t, 12.12);
|
|
p.update_session_low_offer(t, 13.13);
|
|
p.update_fixing_price(t, 14.14);
|
|
}
|
|
|
|
return tp;
|
|
}
|
|
|
|
extern "C" BTS_EXPORT void co2_destroy_test_md(TestProducer* producer) {
|
|
if (producer != nullptr) delete producer;
|
|
config::internal::reset();
|
|
}
|
|
|
|
extern "C" BTS_EXPORT void co2_get_zero_and_nan_book(PriceLevel& price) {
|
|
price = { NO_MARKET, PriceSize_from_double<7>(0,1) };
|
|
}
|
|
extern "C" BTS_EXPORT void co2_get_nan_price_size(PriceSize& ps) {
|
|
ps = NO_MARKET;
|
|
}
|
|
extern "C" BTS_EXPORT void co2_test_get_constants(size_t& max_depth, size_t& max_implied_depth, uint8_t& nan_exponent) {
|
|
max_depth = COCONUT_MAX_DEPTH;
|
|
max_implied_depth = COCONUT_MAX_IMPLIED_DEPTH;
|
|
nan_exponent = INT_NAN.exponent();
|
|
}
|
|
|
|
extern "C" BTS_EXPORT void co2_get_sample_datetime(datetime::LLDateTime& now, datetime::LLDateTime& utc_now) {
|
|
now = datetime::ll_local_now();
|
|
utc_now = datetime::ll_now();
|
|
}
|
|
|
|
}}}//namespace
|
|
#endif
|