Enabling spot market data
This commit is contained in:
1 parent
8c6835a919
commit
b9b907490a
12 files changed
+94
-46
No files matched your search
@@ -1646,6 +1646,8 @@ api::SecurityType AdminServiceUtils::security_type(
|
||||
return api::SecurityType::SECURITYTYPE_FUTURE;
|
||||
case api::Security::ContractCase::kOption:
|
||||
return api::SecurityType::SECURITYTYPE_OPTION;
|
||||
case api::Security::ContractCase::kSpot:
|
||||
return api::SecurityType::SECURITYTYPE_STOCK;
|
||||
case api::Security::ContractCase::kSpread:
|
||||
return api::SecurityType::SECURITYTYPE_SPREAD;
|
||||
case api::Security::ContractCase::kSynthetic:
|
||||
|
||||
@@ -33,17 +33,32 @@ std::string descriptor(api::Security const &sec) {
|
||||
return "No descriptor for non glbx / ice exchange";
|
||||
}
|
||||
|
||||
api::SecurityType security_type(api::Security const &sec) {
|
||||
if (sec.has_future())
|
||||
api::SecurityType security_type(api::Security const &security) {
|
||||
switch (security.Contract_case()) {
|
||||
case api::Security::ContractCase::kFuture:
|
||||
return api::SecurityType::SECURITYTYPE_FUTURE;
|
||||
else if (sec.has_option())
|
||||
case api::Security::ContractCase::kOption:
|
||||
return api::SecurityType::SECURITYTYPE_OPTION;
|
||||
else if (sec.has_spread())
|
||||
case api::Security::ContractCase::kSpot:
|
||||
return api::SecurityType::SECURITYTYPE_STOCK;
|
||||
case api::Security::ContractCase::kSpread:
|
||||
return api::SecurityType::SECURITYTYPE_SPREAD;
|
||||
else if (sec.has_synthetic())
|
||||
case api::Security::ContractCase::kSynthetic:
|
||||
return api::SecurityType::SECURITYTYPE_SYNTHETIC;
|
||||
else
|
||||
case api::Security::ContractCase::CONTRACT_NOT_SET:
|
||||
return api::SecurityType::SECURITYTYPE_UNSET;
|
||||
}
|
||||
return api::SecurityType::SECURITYTYPE_UNSET;
|
||||
// if (sec.has_future())
|
||||
// return api::SecurityType::SECURITYTYPE_FUTURE;
|
||||
// else if (sec.has_option())
|
||||
// return api::SecurityType::SECURITYTYPE_OPTION;
|
||||
// else if (sec.has_spread())
|
||||
// return api::SecurityType::SECURITYTYPE_SPREAD;
|
||||
// else if (sec.has_synthetic())
|
||||
// return api::SecurityType::SECURITYTYPE_SYNTHETIC;
|
||||
// else
|
||||
// return api::SecurityType::SECURITYTYPE_UNSET;
|
||||
}
|
||||
|
||||
boost::gregorian::date smallest_leg(
|
||||
|
||||
@@ -142,6 +142,9 @@ message OptionContract {
|
||||
PutOrCall call_put = 5;
|
||||
}
|
||||
|
||||
message SpotContract{
|
||||
}
|
||||
|
||||
message ContractLeg {
|
||||
Security security = 10;
|
||||
double quantity = 20;
|
||||
@@ -194,6 +197,7 @@ message Security {
|
||||
oneof Contract {
|
||||
FutureContract future = 100;
|
||||
OptionContract option = 101;
|
||||
SpotContract spot = 102;
|
||||
SpreadContract spread = 110;
|
||||
SyntheticContract synthetic = 120;
|
||||
}
|
||||
|
||||
@@ -613,7 +613,8 @@ class MDConsumerImpl {
|
||||
|
||||
for (auto &s : symbols) {
|
||||
if (s.type() == SECURITYTYPE_FUTURE ||
|
||||
s.type() == SECURITYTYPE_OPTION) {
|
||||
s.type() == SECURITYTYPE_OPTION ||
|
||||
s.type() == api::SECURITYTYPE_STOCK) {
|
||||
_instances.push_back(make_shared<MDConsumerInst>(
|
||||
s.symbol(), s.type(), s.exchange(), shared, platform));
|
||||
}
|
||||
|
||||
@@ -248,6 +248,11 @@ size_t get_system_md_symbols(
|
||||
add_symbols_to_result(
|
||||
e.option(), api::VENUE_FTX, api::SECURITYTYPE_OPTION, &result);
|
||||
}
|
||||
if (type == api::SECURITYTYPE_STOCK ||
|
||||
type == api::SECURITYTYPE_UNSET) {
|
||||
add_symbols_to_result(
|
||||
e.option(), api::VENUE_FTX, api::SECURITYTYPE_STOCK, &result);
|
||||
}
|
||||
if (type == api::SECURITYTYPE_SPREAD ||
|
||||
type == api::SECURITYTYPE_UNSET)
|
||||
add_symbols_to_result(
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
#include "PriceSize.h"
|
||||
#include "UserSymbol.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/market_data.pb.h"
|
||||
#include "lib/config/protos/cme_reference_data.pb.h"
|
||||
#include "lib/config/protos/market_data.pb.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include "lib/utils/parse_enum.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <btree/map.h>
|
||||
|
||||
@@ -29,10 +30,12 @@ struct DisplayFactorMapper : public ISecurityMapper {
|
||||
UserSymbol{uppercase_copy(ov.symbol()), *venue, *type},
|
||||
-to_exponent(ov.price_multiplier())));
|
||||
} else {
|
||||
for (auto t :
|
||||
{SecurityType::SECURITYTYPE_FUTURE,
|
||||
SecurityType::SECURITYTYPE_SPREAD,
|
||||
SecurityType::SECURITYTYPE_OPTION}) {
|
||||
for (auto t : {
|
||||
SecurityType::SECURITYTYPE_FUTURE,
|
||||
SecurityType::SECURITYTYPE_SPREAD,
|
||||
SecurityType::SECURITYTYPE_OPTION,
|
||||
SecurityType::SECURITYTYPE_STOCK,
|
||||
}) {
|
||||
_mapped.insert(std::make_pair(
|
||||
UserSymbol{uppercase_copy(ov.symbol()), *venue, t},
|
||||
-to_exponent(ov.price_multiplier())));
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "lib/domain_model/Security.pb.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#ifndef NO_CPP0X
|
||||
|
||||
@@ -99,6 +100,9 @@ std::string security_descriptor(const api::Security &security) {
|
||||
result);
|
||||
break;
|
||||
}
|
||||
case Security::ContractCase::kSpot: {
|
||||
break;
|
||||
}
|
||||
case Security::ContractCase::kSpread: {
|
||||
// If the security key of a leg is invalid return an error
|
||||
const auto &s = security.spread();
|
||||
@@ -243,7 +247,11 @@ void convert_security(const FixedSecurity &source, Security *presult) {
|
||||
bts_assert(dest.symbol() == source.symbol());
|
||||
break;
|
||||
}
|
||||
case SECURITYTYPE_STOCK:
|
||||
case SECURITYTYPE_STOCK: {
|
||||
bts_assert(source.size == sizeof(FixedStockSecurity));
|
||||
dest.mutable_spot();
|
||||
break;
|
||||
}
|
||||
case SECURITYTYPE_UNSET:
|
||||
case SecurityType_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
case SecurityType_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
@@ -259,6 +267,8 @@ SecurityType securitytype_of_contractcase(Security::ContractCase cc) {
|
||||
return SECURITYTYPE_FUTURE;
|
||||
case Security::ContractCase::kOption:
|
||||
return SECURITYTYPE_OPTION;
|
||||
case Security::ContractCase::kSpot:
|
||||
return api::SECURITYTYPE_STOCK;
|
||||
case Security::ContractCase::kSpread:
|
||||
return SECURITYTYPE_SPREAD;
|
||||
case Security::ContractCase::kSynthetic:
|
||||
|
||||
@@ -219,6 +219,7 @@ void with_security(
|
||||
switch (type) {
|
||||
case api::SECURITYTYPE_STOCK: {
|
||||
FixedStockSecurity security;
|
||||
bts_assert(security.type == type);
|
||||
cb(security);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -69,25 +69,18 @@ CCMain::~CCMain() {}
|
||||
void CCMain::run() {
|
||||
LOG(md, Info, "Run::run_ccapi t_id:{} t_name:{}", os::get_thread_id(),
|
||||
os::get_thread_name());
|
||||
std::string conf_file = "/home/taha/sparkdata/conf/ftx.json";
|
||||
std::optional<api::md::MarketDataSubscriptionParams> subscriptions =
|
||||
core::ProtoReader::read_proto<api::md::MarketDataSubscriptionParams>(
|
||||
conf_file);
|
||||
if (!subscriptions.has_value()) {
|
||||
LOG(md, bts::Error,
|
||||
"run_ccapi Unable to parse MarketDataSubscriptionParams from file: "
|
||||
"'{}'",
|
||||
conf_file);
|
||||
return;
|
||||
}
|
||||
LOG(md, Info, "run_ccapi read proto: {}",
|
||||
bts::utils::pb::to_string(subscriptions.value()));
|
||||
bts::md::MarketDataSubscription md_sub{subscriptions.value()};
|
||||
bts::api::md::MarketDataConfig md_config;
|
||||
md_config.set_num_dispatcher_threads(1);
|
||||
auto it = md_config.mutable_depth_streams()->Add();
|
||||
it->set_venue(::bts::api::domain::Venue::FTX);
|
||||
it->set_num_levels(5);
|
||||
it->mutable_symbols()->Add("BTC-PERP");
|
||||
it->mutable_symbols()->Add("BTC/USD");
|
||||
|
||||
char ssl_cert_file[] = "SSL_CERT_FILE=/etc/ssl/cert/ca-certificates.crt";
|
||||
putenv(ssl_cert_file);
|
||||
|
||||
me->gw.subscribe(md_sub, &me->cc_listener);
|
||||
me->gw.subscribe(md_config, &me->cc_listener);
|
||||
|
||||
size_t n = 0;
|
||||
while (true) {
|
||||
@@ -98,4 +91,4 @@ void CCMain::run() {
|
||||
}
|
||||
|
||||
} // namespace bts::md
|
||||
#endif
|
||||
#endif
|
||||
@@ -157,19 +157,36 @@ CCMarketDataListener::CCMarketDataListener(
|
||||
void CCMarketDataListener::on_securities(
|
||||
const std::vector<domain::Security const *> &complete_security_list) {
|
||||
for (auto s_ptr : complete_security_list) {
|
||||
bool pursue = false;
|
||||
domain::Security sec = *s_ptr;
|
||||
const auto &s_comm = sec.security_common;
|
||||
// temp
|
||||
{
|
||||
sec.security_common.venue = api::domain::Venue::FTX;
|
||||
// TODO, adjusting the data while its gettign fixed
|
||||
if (sec.security_common.desc == "BTC-PERP") {
|
||||
domain::FutureSecurity fsec = {};
|
||||
fsec.expiration = get_ts_from_date(2022, 12, 25);
|
||||
sec.security = fsec;
|
||||
sec.security_common.min_price_increment_ammount = 1.0;
|
||||
pursue = true;
|
||||
}
|
||||
if (sec.security_common.desc == "BTC/USD") {
|
||||
domain::SpotSecurity ssec = {};
|
||||
sec.security = ssec;
|
||||
sec.security_common.min_price_increment_ammount = 1.0;
|
||||
pursue = true;
|
||||
}
|
||||
}
|
||||
const auto &s_comm = sec.security_common;
|
||||
auto search_result = _find_sec(sec, true);
|
||||
LOG(md, Info,
|
||||
"CCMarketDataListener::on_securities added new security, exchange: "
|
||||
"{} type: {} desc: {} id: {} spot: {} fut: {} spr: {} opt: {}",
|
||||
bts::api::domain::Venue_Name(s_comm.venue),
|
||||
bts::api::domain::SecurityType_Name(sec.security_type()), s_comm.desc,
|
||||
search_result.key,
|
||||
std::holds_alternative<bts::domain::SpotSecurity>(sec.security),
|
||||
std::holds_alternative<bts::domain::FutureSecurity>(sec.security),
|
||||
std::holds_alternative<bts::domain::SpreadSecurity>(sec.security),
|
||||
std::holds_alternative<bts::domain::OptionSecurity>(sec.security));
|
||||
if (search_result.existed_before) {
|
||||
LOG(md, Warn,
|
||||
"CCMarketDataListener::on_securities security already exists, "
|
||||
@@ -182,16 +199,8 @@ void CCMarketDataListener::on_securities(
|
||||
continue;
|
||||
}
|
||||
bts_assert(search_result.exists_now);
|
||||
LOG(md, Info,
|
||||
"CCMarketDataListener::on_securities added new security, exchange: "
|
||||
"{} type: {} desc: {} id: {}",
|
||||
bts::api::domain::Venue_Name(s_comm.venue),
|
||||
bts::api::domain::SecurityType_Name(sec.security_type()), s_comm.desc,
|
||||
search_result.key,
|
||||
std::holds_alternative<bts::domain::SpotSecurity>(sec.security),
|
||||
std::holds_alternative<bts::domain::FutureSecurity>(sec.security),
|
||||
std::holds_alternative<bts::domain::SpreadSecurity>(sec.security),
|
||||
std::holds_alternative<bts::domain::OptionSecurity>(sec.security));
|
||||
if (!pursue)
|
||||
continue;
|
||||
switch (sec.security_type()) {
|
||||
case bts::api::domain::SecurityType::SPOT:
|
||||
_add_spot(sec);
|
||||
@@ -227,6 +236,9 @@ void CCMarketDataListener::on_security_statistics(
|
||||
}
|
||||
|
||||
void CCMarketDataListener::on_book(const bts::domain::Book &book) {
|
||||
LOG(md, Info, "CCMarketDataListener::on_book sec_id: {}",
|
||||
book.security_id());
|
||||
//_temp_add_security();
|
||||
me->n_bk_updates++;
|
||||
auto handle = _find_handle(book.security_id());
|
||||
if (handle == nullptr) {
|
||||
@@ -366,11 +378,8 @@ void CCMarketDataListener::_add_option(const bts::domain::Security &sec) {
|
||||
}
|
||||
|
||||
void CCMarketDataListener::_add_spot(const bts::domain::Security &sec) {
|
||||
LOG(md, Info,
|
||||
"CCMarketDataListener::_add_spot (spots are disabled) ignoring spot: "
|
||||
"{}",
|
||||
LOG(md, Info, "CCMarketDataListener::_add_spot spot: {}",
|
||||
sec.security_common.desc);
|
||||
return;
|
||||
bts_assert(sec.security_type() == bts::api::domain::SecurityType::SPOT);
|
||||
auto search_result = _find_sec(sec, false);
|
||||
bts_assert(search_result.existed_before);
|
||||
|
||||
@@ -252,6 +252,9 @@ class RelayClient {
|
||||
case SecurityType::SECURITYTYPE_OPTION:
|
||||
log << "Opt ";
|
||||
break;
|
||||
case SecurityType::SECURITYTYPE_STOCK:
|
||||
log << "Spt ";
|
||||
break;
|
||||
case SecurityType::SECURITYTYPE_SYNTHETIC:
|
||||
log << "Syn ";
|
||||
break;
|
||||
|
||||
@@ -28,6 +28,8 @@ struct StaticLimiter {
|
||||
return api::SECURITYTYPE_FUTURE;
|
||||
else if (sec.has_option())
|
||||
return api::SECURITYTYPE_OPTION;
|
||||
else if (sec.has_spot())
|
||||
return api::SECURITYTYPE_STOCK;
|
||||
return api::SECURITYTYPE_UNSET;
|
||||
};
|
||||
for (const auto &r : rl.risk_limits()) {
|
||||
|
||||
Reference in new issue
Block a user