601 lines
23 KiB
C++
601 lines
23 KiB
C++
#include "lib/domain_model/Security.h"
|
|
#include "lib/utils/bts_array_size.h"
|
|
#include "lib/utils/bts_assert.h"
|
|
#ifndef NO_CPP0X
|
|
|
|
#include "../PriceSize.h"
|
|
#include "FixedSecurity.h"
|
|
#include <iomanip>
|
|
|
|
#ifdef _WIN32
|
|
#pragma warning(disable : 4351)
|
|
#endif
|
|
|
|
using namespace std;
|
|
using namespace bts::api;
|
|
using std::size_t;
|
|
|
|
namespace bts {
|
|
namespace md {
|
|
|
|
FixedSecurity::FixedSecurity()
|
|
: size(sizeof(FixedSecurity)), key(invalid_security_key), numeric_id(0),
|
|
type(api::SECURITYTYPE_SPOT), exchange(api::VENUE_UNSET),
|
|
display_factor(0), price_break(0), low_tick(0), high_tick(0),
|
|
cash_per_point(0), cboe_class_key(0), cme_market_segment_id(0),
|
|
cme_main_fraction(0), cme_sub_fraction(0), cme_price_display_format(0),
|
|
ice_price_denominator(0), ice_deal_denominator(0),
|
|
ice_settle_denominator(0), is_ice_strip(false), _symbol(), _cfi_code(),
|
|
_security_desc(), _alt_symbol(), _qty_info_size(0) {
|
|
memset(_symbol, 0, BTS_ARRAYSIZE(_symbol));
|
|
memset(_alt_symbol, 0, BTS_ARRAYSIZE(_alt_symbol));
|
|
memset(_cfi_code, 0, BTS_ARRAYSIZE(_cfi_code));
|
|
memset(_security_desc, 0, BTS_ARRAYSIZE(_security_desc));
|
|
memset(_platform_id, 0, BTS_ARRAYSIZE(_platform_id));
|
|
memset(_currency, 0, BTS_ARRAYSIZE(_currency));
|
|
|
|
memset(_ice_market_description, 0, BTS_ARRAYSIZE(_ice_market_description));
|
|
memset(_ice_cleared_alias, 0, BTS_ARRAYSIZE(_ice_cleared_alias));
|
|
memset(_ice_product_name, 0, BTS_ARRAYSIZE(_ice_product_name));
|
|
memset(_ice_hub_alias, 0, BTS_ARRAYSIZE(_ice_hub_alias));
|
|
memset(_ice_strip_name, 0, BTS_ARRAYSIZE(_ice_strip_name));
|
|
memset(_mic_code, 0, BTS_ARRAYSIZE(_mic_code));
|
|
memset(_qty_min_value, 0, BTS_ARRAYSIZE_T(_qty_min_value));
|
|
memset(_qty_max_value, 0, BTS_ARRAYSIZE_T(_qty_max_value));
|
|
memset(_qty_tick_unit, 0, BTS_ARRAYSIZE_T(_qty_tick_unit));
|
|
memset(_qty_tick_base, 0, BTS_ARRAYSIZE_T(_qty_tick_base));
|
|
memset(_qty_multiplier, 0, BTS_ARRAYSIZE_T(_qty_multiplier));
|
|
memset(_qty_max_price, 0, BTS_ARRAYSIZE_T(_qty_max_price));
|
|
memset(_qty_is_notional, 0, BTS_ARRAYSIZE_T(_qty_is_notional));
|
|
}
|
|
|
|
FixedSecurity::~FixedSecurity() {}
|
|
|
|
bool FixedSecurity::add_quantity_info(
|
|
float min_value,
|
|
float max_value,
|
|
float tick_unit,
|
|
float tick_base,
|
|
float max_price,
|
|
bool is_notional) {
|
|
if (_qty_info_size >= QTY_INFO_CAPACITY) {
|
|
return false;
|
|
}
|
|
_qty_min_value[_qty_info_size] = min_value;
|
|
_qty_max_value[_qty_info_size] = max_value;
|
|
_qty_tick_unit[_qty_info_size] = tick_unit;
|
|
_qty_tick_base[_qty_info_size] = tick_base;
|
|
_qty_max_price[_qty_info_size] = max_price;
|
|
_qty_is_notional[_qty_info_size] = is_notional;
|
|
_qty_info_size++;
|
|
return true;
|
|
}
|
|
|
|
bool FixedSecurity::get_quantity_info(
|
|
uint8_t index,
|
|
float &min_value,
|
|
float &max_value,
|
|
float &tick_unit,
|
|
float &tick_base,
|
|
float &max_price,
|
|
bool &is_notional) const {
|
|
if (index >= _qty_info_size) {
|
|
return false;
|
|
}
|
|
min_value = _qty_min_value[index];
|
|
max_value = _qty_max_value[index];
|
|
tick_unit = _qty_tick_unit[index];
|
|
tick_base = _qty_tick_base[index];
|
|
max_price = _qty_max_price[index];
|
|
is_notional = _qty_is_notional[index];
|
|
return true;
|
|
}
|
|
|
|
FixedFutureSecurity::FixedFutureSecurity()
|
|
: expiration_year(0), expiration_month(0), expiration_day(0) {
|
|
type = api::SECURITYTYPE_FUTURE;
|
|
size = sizeof(FixedFutureSecurity);
|
|
}
|
|
|
|
FixedOptionSecurity::FixedOptionSecurity()
|
|
: expiration_year(0), expiration_month(0), expiration_day(0), strike(0) {
|
|
type = api::SECURITYTYPE_OPTION;
|
|
size = sizeof(FixedOptionSecurity);
|
|
}
|
|
|
|
FixedSpreadLeg::FixedSpreadLeg()
|
|
: key(invalid_security_key), leg_side(Side_MIN), leg_quantity(0),
|
|
leg_price(0), leg_delta(1) {}
|
|
|
|
void get_contract_spec(
|
|
const FixedSecurity &source, /*out*/ api::ContractSpecification &spec) {
|
|
spec.set_price_break(source.price_break);
|
|
spec.set_low_tick(source.low_tick);
|
|
spec.set_high_tick(source.high_tick);
|
|
spec.set_cash_per_point(source.cash_per_point);
|
|
// Account for price multiplier
|
|
spec.set_price_multiplier(pow10(source.display_factor));
|
|
spec.set_price_break(spec.price_break() * spec.price_multiplier());
|
|
spec.set_low_tick(spec.low_tick() * spec.price_multiplier());
|
|
spec.set_high_tick(spec.high_tick() * spec.price_multiplier());
|
|
|
|
// Tick info
|
|
spec.set_main_fraction(source.cme_main_fraction);
|
|
spec.set_sub_fraction(source.cme_sub_fraction);
|
|
spec.set_price_display_format(source.cme_price_display_format);
|
|
|
|
// Qty info
|
|
spec.clear_quantity_infos();
|
|
spec.clear_notional_quantity_infos();
|
|
float min_value;
|
|
float max_value;
|
|
float tick_unit;
|
|
float tick_base;
|
|
float max_price;
|
|
bool is_notional;
|
|
for (uint8_t i = 0; source.get_quantity_info(
|
|
i, min_value, max_value, tick_unit, tick_base, max_price,
|
|
is_notional);
|
|
i++) {
|
|
ContractQuantityInfo *qty_info = is_notional
|
|
? spec.add_notional_quantity_infos()
|
|
: spec.add_quantity_infos();
|
|
qty_info->set_min_value(min_value);
|
|
qty_info->set_max_value(max_value);
|
|
qty_info->set_tick_unit(tick_unit);
|
|
qty_info->set_tick_base(tick_base);
|
|
qty_info->set_max_price(max_price);
|
|
}
|
|
}
|
|
|
|
Security convert_security(const FixedSecurity &security) {
|
|
Security res;
|
|
convert_security(security, &res);
|
|
return res;
|
|
}
|
|
void convert_security(const FixedSecurity &source, Security *presult) {
|
|
bts_assert(presult);
|
|
Security &dest = *presult;
|
|
dest.set_id(source.key);
|
|
dest.set_exchange(source.exchange);
|
|
dest.set_symbol(source.symbol());
|
|
dest.set_currency(source.currency());
|
|
|
|
switch (source.exchange) {
|
|
case Venue::VENUE_GLBX:
|
|
case Venue::VENUE_SIM:
|
|
dest.mutable_glbx()->set_exchange_id(source.numeric_id);
|
|
dest.mutable_glbx()->set_security_desc(source.security_desc());
|
|
dest.mutable_glbx()->set_cfi_code(source.cfi_code());
|
|
dest.mutable_glbx()->set_cme_symbol(source.alt_symbol());
|
|
if (source.cme_market_segment_id != 0)
|
|
dest.mutable_glbx()->set_market_segment_id(
|
|
source.cme_market_segment_id);
|
|
break;
|
|
case Venue::VENUE_ICE:
|
|
dest.mutable_ice()->set_exchange_id(source.numeric_id);
|
|
dest.mutable_ice()->set_security_desc(source.security_desc());
|
|
dest.mutable_ice()->set_price_denominator(source.ice_price_denominator);
|
|
dest.mutable_ice()->set_deal_denominator(source.ice_deal_denominator);
|
|
dest.mutable_ice()->set_settle_denominator(source.ice_settle_denominator);
|
|
|
|
dest.mutable_ice()->set_market_description(
|
|
source.ice_market_description());
|
|
dest.mutable_ice()->set_cleared_alias(source.ice_cleared_alias());
|
|
dest.mutable_ice()->set_product_name(source.ice_product_name());
|
|
dest.mutable_ice()->set_hub_alias(source.ice_hub_alias());
|
|
dest.mutable_ice()->set_strip_name(source.ice_strip_name());
|
|
dest.mutable_ice()->set_mic_code(source.mic_code());
|
|
dest.mutable_ice()->set_is_strip(source.is_ice_strip);
|
|
break;
|
|
case Venue::VENUE_DERIBIT:
|
|
dest.mutable_deribit()->set_security_desc(source.security_desc());
|
|
dest.mutable_deribit()->set_exchange_id(source.numeric_id);
|
|
break;
|
|
case Venue::VENUE_FTX:
|
|
dest.mutable_ftx()->set_security_desc(source.security_desc());
|
|
dest.mutable_ftx()->set_exchange_id(source.numeric_id);
|
|
break;
|
|
case Venue::VENUE_BINANCE:
|
|
dest.mutable_binance()->set_security_desc(source.security_desc());
|
|
dest.mutable_binance()->set_exchange_id(source.numeric_id);
|
|
break;
|
|
case Venue::VENUE_BINANCE_COIN_FUTURES:
|
|
dest.mutable_binance_coin_futures()->set_security_desc(
|
|
source.security_desc());
|
|
dest.mutable_binance_coin_futures()->set_exchange_id(source.numeric_id);
|
|
break;
|
|
case Venue::VENUE_BINANCE_US:
|
|
dest.mutable_binance_us()->set_security_desc(source.security_desc());
|
|
dest.mutable_binance_us()->set_exchange_id(source.numeric_id);
|
|
break;
|
|
case Venue::VENUE_COINBASE:
|
|
dest.mutable_coinbase()->set_security_desc(source.security_desc());
|
|
dest.mutable_coinbase()->set_exchange_id(source.numeric_id);
|
|
break;
|
|
case Venue::VENUE_BINANCE_USDS_FUTURES:
|
|
dest.mutable_binance_usds_futures()->set_security_desc(
|
|
source.security_desc());
|
|
dest.mutable_binance_usds_futures()->set_exchange_id(source.numeric_id);
|
|
break;
|
|
case Venue::VENUE_OKX:
|
|
dest.mutable_okx()->set_security_desc(source.security_desc());
|
|
dest.mutable_okx()->set_exchange_id(source.numeric_id);
|
|
break;
|
|
case Venue::VENUE_TAIFEX:
|
|
dest.mutable_taifex()->set_security_desc(source.security_desc());
|
|
dest.mutable_taifex()->set_exchange_id(source.numeric_id);
|
|
break;
|
|
case Venue::VENUE_CBOE:
|
|
dest.mutable_cboe()->set_security_desc(source.security_desc());
|
|
dest.mutable_cboe()->set_exchange_id(source.numeric_id);
|
|
break;
|
|
case Venue::VENUE_BTS:
|
|
break;
|
|
default:
|
|
bts_assert(false);
|
|
}
|
|
|
|
switch (source.type) {
|
|
case SECURITYTYPE_FUTURE: {
|
|
bts_assert(source.size == sizeof(FixedFutureSecurity));
|
|
const auto *psec = static_cast<const FixedFutureSecurity *>(&source);
|
|
dest.mutable_future()->set_expiration_day(psec->expiration_day);
|
|
dest.mutable_future()->set_expiration_month(psec->expiration_month);
|
|
dest.mutable_future()->set_expiration_year(psec->expiration_year);
|
|
break;
|
|
}
|
|
case SECURITYTYPE_OPTION: {
|
|
bts_assert(source.size == sizeof(FixedOptionSecurity));
|
|
const auto *psec = static_cast<const FixedOptionSecurity *>(&source);
|
|
dest.mutable_option()->set_expiration_day(psec->expiration_day);
|
|
dest.mutable_option()->set_expiration_month(psec->expiration_month);
|
|
dest.mutable_option()->set_expiration_year(psec->expiration_year);
|
|
dest.mutable_option()->set_strike(psec->strike);
|
|
dest.mutable_option()->set_call_put(psec->call_put);
|
|
break;
|
|
}
|
|
case SECURITYTYPE_SPREAD: {
|
|
const auto *psec = static_cast<const FixedSpreadSecurityL *>(&source);
|
|
auto *spread = dest.mutable_spread();
|
|
spread->set_normalized(true);
|
|
for (size_t leg_index = 0; leg_index < psec->leg_count(); ++leg_index) {
|
|
const FixedSpreadLeg &fleg = psec->legs[leg_index];
|
|
auto *leg = spread->add_legs();
|
|
leg->set_side(fleg.leg_side);
|
|
leg->set_quantity(fleg.leg_quantity);
|
|
leg->set_price_multiplier(fleg.leg_price);
|
|
leg->set_leg_delta(fleg.leg_delta);
|
|
leg->mutable_security()->set_id(fleg.key);
|
|
leg->mutable_security()->set_exchange(source.exchange);
|
|
}
|
|
break;
|
|
}
|
|
case SECURITYTYPE_SYNTHETIC: {
|
|
const auto *psec = static_cast<const FixedSyntheticSecurity *>(&source);
|
|
psec->deserialize(dest);
|
|
bts_assert(dest.id() == source.key);
|
|
bts_assert(dest.exchange() == source.exchange);
|
|
bts_assert(dest.symbol() == source.symbol());
|
|
break;
|
|
}
|
|
case SECURITYTYPE_SPOT: {
|
|
bts_assert(source.size == sizeof(FixedSpotSecurity));
|
|
dest.mutable_spot();
|
|
break;
|
|
}
|
|
case SECURITYTYPE_UNSET:
|
|
case SecurityType_INT_MAX_SENTINEL_DO_NOT_USE_:
|
|
case SecurityType_INT_MIN_SENTINEL_DO_NOT_USE_:
|
|
break;
|
|
}
|
|
|
|
get_contract_spec(source, *dest.mutable_contract_spec());
|
|
}
|
|
|
|
SecurityType securitytype_of(const Security &s) {
|
|
auto type = bts::securities::security_type(s.Contract_case());
|
|
bts_assert(type != api::SecurityType::SECURITYTYPE_UNSET);
|
|
return type;
|
|
}
|
|
|
|
size_t num_legs(const Security &sec) {
|
|
if (sec.Contract_case() == api::Security::ContractCase::kSpread) {
|
|
return sec.spread().legs_size();
|
|
} else if (sec.Contract_case() == api::Security::ContractCase::kSynthetic) {
|
|
return sec.synthetic().legs_size();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
uint64_t exchange_id(const Security &security) {
|
|
switch (security.ExchangeData_case()) {
|
|
case Security::ExchangeDataCase::kCboe:
|
|
return security.cboe().exchange_id();
|
|
case Security::ExchangeDataCase::kGlbx:
|
|
return security.glbx().exchange_id();
|
|
case Security::ExchangeDataCase::kCfe:
|
|
return security.cfe().exchange_id();
|
|
case Security::ExchangeDataCase::kIce:
|
|
return security.ice().exchange_id();
|
|
case Security::ExchangeDataCase::kDeribit:
|
|
return security.deribit().exchange_id();
|
|
case Security::ExchangeDataCase::kFtx:
|
|
return security.ftx().exchange_id();
|
|
case Security::ExchangeDataCase::kBinance:
|
|
return security.binance().exchange_id();
|
|
case Security::ExchangeDataCase::kBinanceCoinFutures:
|
|
return security.binance_coin_futures().exchange_id();
|
|
case Security::ExchangeDataCase::kBinanceUs:
|
|
return security.binance_us().exchange_id();
|
|
case Security::ExchangeDataCase::kCoinbase:
|
|
return security.coinbase().exchange_id();
|
|
case Security::ExchangeDataCase::kBinanceUsdsFutures:
|
|
return security.binance_usds_futures().exchange_id();
|
|
case Security::ExchangeDataCase::kOkx:
|
|
return security.okx().exchange_id();
|
|
case Security::ExchangeDataCase::kTaifex:
|
|
return security.taifex().exchange_id();
|
|
// Debatable whether this should be an error or not.
|
|
// If is possible that we might create a spread with no exchange in the
|
|
// future and if we did this would be a runtime error.
|
|
case Security::ExchangeDataCase::EXCHANGEDATA_NOT_SET:
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
void convert_security(
|
|
const Security &src, FixedSecurity &dest, bool set_security_key) {
|
|
dest.key = set_security_key ? src.id() : invalid_security_key;
|
|
dest.type = bts::securities::security_type(src.Contract_case());
|
|
dest.symbol(src.symbol());
|
|
dest.currency(src.currency());
|
|
dest.exchange = src.exchange();
|
|
dest.display_factor = to_exponent(src.contract_spec().price_multiplier());
|
|
|
|
switch (src.ExchangeData_case()) {
|
|
case Security::ExchangeDataCase::kGlbx:
|
|
dest.numeric_id = src.glbx().exchange_id();
|
|
dest.security_desc(src.glbx().security_desc());
|
|
dest.cfi_code(src.glbx().cfi_code());
|
|
dest.alt_symbol(src.glbx().cme_symbol());
|
|
dest.cme_market_segment_id = src.glbx().market_segment_id();
|
|
break;
|
|
case Security::ExchangeDataCase::kCboe:
|
|
dest.numeric_id = src.cboe().exchange_id();
|
|
dest.security_desc(src.cboe().security_desc());
|
|
dest.cboe_class_key = src.cboe().class_key();
|
|
break;
|
|
case Security::ExchangeDataCase::kTaifex:
|
|
dest.numeric_id = src.deribit().exchange_id();
|
|
dest.security_desc(src.deribit().security_desc());
|
|
dest.cboe_class_key = src.taifex().class_key();
|
|
break;
|
|
case Security::ExchangeDataCase::kCfe:
|
|
dest.cboe_class_key = src.cfe().class_key();
|
|
break;
|
|
case Security::ExchangeDataCase::kIce:
|
|
dest.numeric_id = src.ice().exchange_id();
|
|
dest.security_desc(src.ice().security_desc());
|
|
dest.ice_price_denominator = src.ice().price_denominator();
|
|
dest.ice_deal_denominator = src.ice().deal_denominator();
|
|
dest.ice_settle_denominator = src.ice().settle_denominator();
|
|
dest.is_ice_strip = src.ice().is_strip();
|
|
|
|
dest.ice_market_description(src.ice().market_description());
|
|
dest.ice_cleared_alias(src.ice().cleared_alias());
|
|
dest.ice_product_name(src.ice().product_name());
|
|
dest.ice_hub_alias(src.ice().hub_alias());
|
|
dest.ice_strip_name(src.ice().strip_name());
|
|
dest.mic_code(src.ice().mic_code());
|
|
break;
|
|
case Security::ExchangeDataCase::kDeribit:
|
|
dest.numeric_id = src.deribit().exchange_id();
|
|
dest.security_desc(src.deribit().security_desc());
|
|
break;
|
|
case Security::ExchangeDataCase::kFtx:
|
|
dest.numeric_id = src.ftx().exchange_id();
|
|
dest.security_desc(src.ftx().security_desc());
|
|
break;
|
|
case Security::ExchangeDataCase::kBinance:
|
|
dest.numeric_id = src.binance().exchange_id();
|
|
dest.security_desc(src.binance().security_desc());
|
|
break;
|
|
case Security::ExchangeDataCase::kBinanceCoinFutures:
|
|
dest.numeric_id = src.binance_coin_futures().exchange_id();
|
|
dest.security_desc(src.binance_coin_futures().security_desc());
|
|
break;
|
|
case Security::ExchangeDataCase::kBinanceUs:
|
|
dest.numeric_id = src.binance_us().exchange_id();
|
|
dest.security_desc(src.binance_us().security_desc());
|
|
break;
|
|
case Security::ExchangeDataCase::kCoinbase:
|
|
dest.numeric_id = src.coinbase().exchange_id();
|
|
dest.security_desc(src.coinbase().security_desc());
|
|
break;
|
|
case Security::ExchangeDataCase::kBinanceUsdsFutures:
|
|
dest.numeric_id = src.binance_usds_futures().exchange_id();
|
|
dest.security_desc(src.binance_usds_futures().security_desc());
|
|
break;
|
|
case Security::ExchangeDataCase::kOkx:
|
|
dest.numeric_id = src.okx().exchange_id();
|
|
dest.security_desc(src.okx().security_desc());
|
|
break;
|
|
case Security::ExchangeDataCase::EXCHANGEDATA_NOT_SET:
|
|
break;
|
|
}
|
|
dest.price_break = src.contract_spec().price_break() /
|
|
src.contract_spec().price_multiplier();
|
|
dest.low_tick =
|
|
src.contract_spec().low_tick() / src.contract_spec().price_multiplier();
|
|
dest.high_tick =
|
|
src.contract_spec().high_tick() / src.contract_spec().price_multiplier();
|
|
dest.cash_per_point = src.contract_spec().cash_per_point();
|
|
dest.cme_main_fraction = src.contract_spec().main_fraction();
|
|
dest.cme_sub_fraction = src.contract_spec().sub_fraction();
|
|
dest.cme_price_display_format = src.contract_spec().price_display_format();
|
|
|
|
for (const auto &q : src.contract_spec().quantity_infos()) {
|
|
bts_assert(dest.add_quantity_info(
|
|
q.min_value(), q.max_value(), q.tick_unit(), q.tick_base(),
|
|
q.max_price(), false));
|
|
}
|
|
for (const auto &q : src.contract_spec().notional_quantity_infos()) {
|
|
bts_assert(dest.add_quantity_info(
|
|
q.min_value(), q.max_value(), q.tick_unit(), q.tick_base(),
|
|
q.max_price(), true));
|
|
}
|
|
switch (securitytype_of(src)) {
|
|
case SECURITYTYPE_FUTURE: {
|
|
FixedFutureSecurity &future = static_cast<FixedFutureSecurity &>(dest);
|
|
future.expiration_year = src.future().expiration_year();
|
|
future.expiration_month = src.future().expiration_month();
|
|
future.expiration_day = src.future().expiration_day();
|
|
break;
|
|
}
|
|
case SECURITYTYPE_OPTION: {
|
|
FixedOptionSecurity &option = static_cast<FixedOptionSecurity &>(dest);
|
|
option.expiration_year = src.option().expiration_year();
|
|
option.expiration_month = src.option().expiration_month();
|
|
option.expiration_day = src.option().expiration_day();
|
|
option.strike = src.option().strike();
|
|
option.call_put = src.option().call_put();
|
|
break;
|
|
}
|
|
case SECURITYTYPE_SPREAD: {
|
|
FixedSpreadSecurityXL &spread =
|
|
static_cast<FixedSpreadSecurityXL &>(dest);
|
|
// set_leg_count sets up the size of the spread and verified that the
|
|
// number of legs does not exceed the allocated space
|
|
spread.set_leg_count(
|
|
src.spread()
|
|
.legs_size()); // NOT recursive as Co2 spreads are normalized
|
|
for (int x = 0; x < src.spread().legs_size(); ++x) {
|
|
const auto &src_leg = src.spread().legs(x);
|
|
spread.legs[x].key =
|
|
set_security_key ? src_leg.security().id() : invalid_security_key;
|
|
spread.legs[x].exchange_key =
|
|
ExchangeKey(exchange_id(src_leg.security()));
|
|
spread.legs[x].leg_side = src_leg.side();
|
|
spread.legs[x].leg_quantity = src_leg.quantity();
|
|
spread.legs[x].leg_price = src_leg.price_multiplier();
|
|
spread.legs[x].leg_delta = src_leg.leg_delta();
|
|
}
|
|
break;
|
|
}
|
|
case SECURITYTYPE_SYNTHETIC: {
|
|
FixedSyntheticSecurity &synth =
|
|
static_cast<FixedSyntheticSecurity &>(dest);
|
|
bts_assert(synth.buffer_size() > 0);
|
|
// Due to how we create a FixedSecurity this FixedSecurity should already
|
|
// be populated
|
|
bts_assert(synth.leg_count() == (unsigned)src.synthetic().legs_size());
|
|
#ifndef NDEBUG
|
|
{
|
|
Security temp;
|
|
static_cast<FixedSyntheticSecurity *>(&dest)->deserialize(temp);
|
|
bts_assert_d(temp.SerializeAsString() == src.SerializeAsString());
|
|
}
|
|
#endif
|
|
break;
|
|
}
|
|
case SECURITYTYPE_SPOT:
|
|
break;
|
|
case SECURITYTYPE_UNSET:
|
|
case SecurityType_INT_MAX_SENTINEL_DO_NOT_USE_:
|
|
case SecurityType_INT_MIN_SENTINEL_DO_NOT_USE_:
|
|
bts_assert(false);
|
|
}
|
|
}
|
|
|
|
void to_json(nlohmann::json &j, const FixedSecurity &f) {
|
|
j = nlohmann::json{
|
|
{"key", f.key},
|
|
{"symbol", f.symbol()},
|
|
{"type", api::SecurityType_Name(f.type)},
|
|
{"venue", api::Venue_Name(f.exchange)},
|
|
{"alt_symbol", f.alt_symbol()},
|
|
{"cfi_code", f.cfi_code()},
|
|
{"security_desc", f.security_desc()},
|
|
{"platform_id", f.platform_id()},
|
|
{"display_factor", f.display_factor},
|
|
{"numeric_id", f.numeric_id},
|
|
{"cboe_class_key", f.cboe_class_key},
|
|
{"main_frac", (int)f.cme_main_fraction},
|
|
{"sub_frac", (int)f.cme_sub_fraction},
|
|
{"price_format", (int)f.cme_price_display_format},
|
|
{"market_segment", (int)f.cme_market_segment_id},
|
|
|
|
{"price_break", f.price_break},
|
|
{"low_tick", f.low_tick},
|
|
{"high_tick", f.high_tick},
|
|
{"cpp", f.cash_per_point},
|
|
|
|
{"ice_market_description", f.ice_market_description()},
|
|
{"ice_cleared_alias", f.ice_cleared_alias()},
|
|
{"ice_product_name", f.ice_product_name()},
|
|
{"ice_hub_alias", f.ice_hub_alias()},
|
|
{"ice_strip_name", f.ice_strip_name()},
|
|
{"mic_code", f.mic_code()},
|
|
};
|
|
// Qty Info
|
|
{
|
|
auto qty_infos_j = nlohmann::json::array();
|
|
float min_value, max_value, tick_unit, tick_base, max_price;
|
|
bool is_notional;
|
|
for (int8_t i = 0; f.get_quantity_info(
|
|
i, min_value, max_value, tick_unit, tick_base, max_price,
|
|
is_notional);
|
|
i++) {
|
|
auto qty_info_j = nlohmann::json::object();
|
|
qty_info_j["min_value"] = min_value;
|
|
qty_info_j["max_value"] = max_value;
|
|
qty_info_j["tick_unit"] = tick_unit;
|
|
qty_info_j["tick_base"] = tick_base;
|
|
qty_info_j["max_price"] = max_price;
|
|
qty_info_j["is_notional"] = is_notional;
|
|
qty_infos_j.push_back(std::move(qty_info_j));
|
|
}
|
|
j["qty_infos"] = std::move(qty_infos_j);
|
|
}
|
|
|
|
switch (f.type) {
|
|
case api::SECURITYTYPE_SPOT:
|
|
break;
|
|
case api::SECURITYTYPE_FUTURE: {
|
|
auto *fut = static_cast<const FixedFutureSecurity *>(&f);
|
|
core::TimeStamp exp;
|
|
core::TimeStamp::from_ymd(
|
|
fut->expiration_year, fut->expiration_month, fut->expiration_day,
|
|
&exp);
|
|
j["expiration"] = exp.to_iso_string();
|
|
break;
|
|
}
|
|
case api::SECURITYTYPE_OPTION: {
|
|
auto *opt = static_cast<const FixedOptionSecurity *>(&f);
|
|
core::TimeStamp exp;
|
|
core::TimeStamp::from_ymd(
|
|
opt->expiration_year, opt->expiration_month, opt->expiration_day,
|
|
&exp);
|
|
j["expiration"] = exp.to_iso_string();
|
|
j["strike"] = opt->strike;
|
|
j["callput"] = api::PutOrCall_Name(opt->call_put);
|
|
break;
|
|
}
|
|
case api::SECURITYTYPE_SPREAD: {
|
|
auto *spd = static_cast<const FixedSpreadSecurityXL *>(&f);
|
|
std::vector<FixedSpreadLeg> legs{spd->legs, spd->legs + spd->leg_count()};
|
|
j["legs"] = legs;
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
} // namespace md
|
|
} // namespace bts
|
|
|
|
#endif
|