Compare commits

...
20 changed files with 400 additions and 169 deletions

No files matched your search

+13 -10
View File
@@ -65,18 +65,21 @@ namespace bts {
_merge_and_post();
}
private void _merge_and_post() {
Func<SecurityMD, bool> is_active = (sec_md) => {
if (sec_md.security.HasFuture || sec_md.security.HasOption) {
var exp = sec_md.security.security_expiration();
if (exp.HasValue) {
return exp.Value.Date >= DateTime.Now.Date.AddDays(-1);
}
return true;
private static bool _is_active(SecurityMD sec_md) {
if (sec_md.security.Exchange == Venue.Sim)
return true;
if (sec_md.security.HasFuture || sec_md.security.HasOption) {
var exp = sec_md.security.security_expiration();
if (exp.HasValue) {
return exp.Value.Date >= DateTime.Now.Date.AddDays(-1);
}
return true;
};
var to_pub = _server_sec_map.Where(kv => is_active(kv.Value)).ToDictionary(kv => kv.Key, kv => kv.Value);
}
return true;
}
private void _merge_and_post() {
var to_pub = _server_sec_map.Where(kv => _is_active(kv.Value)).ToDictionary(kv => kv.Key, kv => kv.Value);
foreach (var kv in _fake_sec_map) {
to_pub[kv.Key] = kv.Value;
}
@@ -5,7 +5,9 @@
#include "lib/config/protos/jetfix.pb.h"
#include "lib/config/protos/system.pb.h"
#include "lib/domain_model/Security.pb.h"
#include "lib/logging/logging.h"
#include "lib/md/get_symbols.h"
#include "lib/utils/PBUtils.h"
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/predicate.hpp>
@@ -186,7 +188,12 @@ void AdminServiceUtils::fill_connections_from_config(
bts::api::admin::AdminData &admin_data) {
admin_data.clear_connections();
auto &all_connections = config::get<config::JetFIX>().connection();
LOG(Gen, Info,
"AdminServiceUtils::fill_connections_from_config, n_conns: {}",
all_connections.size());
for (auto const &c : all_connections) {
LOG(Gen, Info, "AdminServiceUtils::fill_connections_from_config conn: {}",
utils::pb::to_string(c));
bts::api::admin::ExchangeConnection connection;
uint32_t new_id = find_max_connection_id(admin_data) + 1;
connection.set_id(new_id);
@@ -214,6 +221,10 @@ void AdminServiceUtils::fill_connections_from_config(
c.sender_compid());
add_connection(admin_data, connection);
break;
case config::JetFIX::Connection::DERIBIT:
connection.mutable_sim_connection();
add_connection(admin_data, connection);
break;
}
}
for (int i = 0; i < admin_data.accounts_size(); i++)
@@ -525,7 +536,7 @@ bts::api::orderman::RoutingRecord AdminServiceUtils::get_routing_record(
}
switch (sec.exchange()) {
case api::Venue::VENUE_DERIBIT: {
rv.set_session("sim");
rv.set_session("deribit_em");
rv.set_account(account_ptr->name());
rv.set_operator_id(user_ptr->name());
AdminServiceUtils::ExchangeSubAccountResolver resolver;
+6 -7
View File
@@ -5,7 +5,6 @@
MarketDataConfig {
rule: "DeploymentType.type == 'PROD'"
value {
use_sim: false
}
}
@@ -45,12 +44,12 @@ CMEOptions {
}
}
ICEPublisherOptions {
value {
network_interface: "eth1"
}
}
ICEPublisherOptions {
value {
network_interface: "eth1"
}
}
#to make this work in dev clone the operations repo
#go here: c:\\code\\bts\\operations\\ice\\ICE_iMpactMulticastFeed_GettingStarted-1_1_36\\bin\\easyTunnel>
#modify the easyTunnelProxy.properties file to replace
+57 -58
View File
@@ -3,65 +3,64 @@ SymbolList {
value {
# This key is here for backwards compatability ONLY.
# If you need to update symbols you should update SymbolLists (plural)
# symbol: "6B"
# symbol: "6E"
# symbol: "6J"
# symbol: "6P"
# symbol: "ARE"
# symbol: "BK"
# symbol: "BOB"
# symbol: "BUB"
# symbol: "BZ"
# symbol: "BZT"
# symbol: "CL"
# symbol: "CLT"
# symbol: "EH"
# symbol: "ES"
# symbol: "FYT"
# symbol: "FOB"
# symbol: "GC"
# symbol: "GE"
# symbol: "HE"
# symbol: "HG"
# symbol: "HO"
# symbol: "HOT"
# symbol: "KE"
# symbol: "LE"
# symbol: "NB"
# symbol: "NBY"
# symbol: "NOB"
# symbol: "NON"
# symbol: "NG"
# symbol: "NGT"
# symbol: "NQ"
# symbol: "NUB"
# symbol: "RB"
# symbol: "RBT"
# symbol: "SI"
# symbol: "SOM"
# symbol: "SR1"
# symbol: "SR3"
# symbol: "TN"
# symbol: "TUF"
# symbol: "TUT"
# symbol: "UB"
# symbol: "XC"
# symbol: "XK"
# symbol: "YM"
# symbol: "ZB"
# symbol: "ZC"
# symbol: "ZCW"
# symbol: "ZF"
# symbol: "ZL"
# symbol: "ZM"
# symbol: "ZN"
# symbol: "ZO"
# symbol: "ZQ"
# symbol: "ZR"
# symbol: "ZS"
# symbol: "ZT"
# symbol: "ZW"
symbol: "6B"
symbol: "6E"
symbol: "6J"
symbol: "6P"
symbol: "ARE"
symbol: "BK"
symbol: "BOB"
symbol: "BUB"
symbol: "BZ"
symbol: "BZT"
symbol: "CL"
symbol: "CLT"
symbol: "EH"
symbol: "ES"
symbol: "FYT"
symbol: "FOB"
symbol: "GC"
symbol: "GE"
symbol: "HE"
symbol: "HG"
symbol: "HO"
symbol: "HOT"
symbol: "KE"
symbol: "LE"
symbol: "NB"
symbol: "NBY"
symbol: "NOB"
symbol: "NON"
symbol: "NG"
symbol: "NGT"
symbol: "NQ"
symbol: "NUB"
symbol: "RB"
symbol: "RBT"
symbol: "SI"
symbol: "SOM"
symbol: "SR1"
symbol: "SR3"
symbol: "TN"
symbol: "TUF"
symbol: "TUT"
symbol: "UB"
symbol: "XC"
symbol: "XK"
symbol: "YM"
symbol: "ZB"
symbol: "ZC"
symbol: "ZCW"
symbol: "ZF"
symbol: "ZL"
symbol: "ZM"
symbol: "ZN"
symbol: "ZO"
symbol: "ZQ"
symbol: "ZR"
symbol: "ZS"
symbol: "ZT"
symbol: "ZW"
symbol: "BTC"
symbol: "ETH"
}
+1
View File
@@ -12,6 +12,7 @@ message JetFIX {
SIM = 2;
ICE = 3;
SIMICE = 4;
DERIBIT = 5;
}
optional JetFIXPlatform platform = 15 [ default = GLBX ];
+14 -4
View File
@@ -1,14 +1,24 @@
syntax = 'proto2';
package bts.md;
import "lib/domain_model/Security.proto";
message MarketDataConfig {
// Allows you to turn off in-proc market data entirely
enum MarketDataMode {
Live = 0;
Replay = 10;
}
// Allows you to turn off in-proc market data entirely, is use_md == false
// then none of the market data machinery is loaded (except cleanup)
optional bool use_md = 1 [ default = true ];
optional bool use_onixs = 2 [ default = true ];
optional bool use_replay = 3 [ default = false ];
optional bool use_sim = 4 [ default = true ];
// Replay will assert right now, 07/29/2022 (replay != sim, it runs only for CME
// and needs access to a Chicago machine)
optional MarketDataMode mode = 2 [ default = Live ];
// All the exchanges for which the market data will run
repeated bts.api.Venue md_venues = 3;
}
message PlatformMap {
// PLATFORM_MDP3ONIXS
optional string glbx_platform = 1 [ default = "PLATFORM_SIM" ];
+3
View File
@@ -1,6 +1,7 @@
#include "lib/domain_model/Security.pb.h"
#include "lib/logging/logging.h"
#include "lib/md/UserSymbol.h"
#include "lib/md/protos/co2.pb.h"
#ifndef NO_CPP0X
#include "PlatformLoader.h"
@@ -263,6 +264,8 @@ std::set<UserSymbol> get_system_md_symbols() {
}
extern "C" BTS_EXPORT Platform platform_for_exchange(Venue v) {
if (v == bts::api::VENUE_DERIBIT)
return co2::PLATFORM_DERIBIT;
const auto &pmap = config::get<PlatformMap>();
co2::Platform platform;
if (v == VENUE_SIM)
@@ -58,6 +58,8 @@ struct SessionServicesData {
: session(cfg.name()), gw_connected(false), cfg(cfg),
governor(cfg.max_order_msgs_per_window(), cfg.window_duration_msecs()),
gw(ExecutionGatewayFactory::create_gateway(cfg, log, o)) {
LOG(OrderMan, Info, "SessionServicesData::cons\nconn: {}",
utils::pb::to_string(cfg));
buffered_order_msgs.reserve(1000);
}
@@ -1,4 +1,5 @@
#include "ExecutionGatewayFactory.h"
#include "lib/logging/logging.h"
#include "lib/md/SecurityOracle.h"
#include "lib/orderman/gateways/EMExecutionGateway.h"
#include "lib/orderman/gateways/FakeExecutionGateway.h"
@@ -6,6 +7,7 @@
#include "lib/orderman/gateways/GLBXiLink3ExecutionGateway.h"
#include "lib/orderman/gateways/ICEExecutionGateway.h"
#include "lib/tracing/PerfLog.h"
#include "lib/utils/PBUtils.h"
#include "lib/utils/ValueWrapper.h"
#include <variant>
@@ -15,15 +17,17 @@ std::unique_ptr<IExecutionGateway> ExecutionGatewayFactory::create_gateway(
const config::JetFIX::Connection &conn,
trace::PerfLog &pl,
md::SecurityOracle o) {
LOG(OrderMan, Info, "ExecutionGatewayFactory::create_gateway\nconn: {}",
utils::pb::to_string(conn));
if (conn.platform() == bts::config::JetFIX_Connection_JetFIXPlatform_ICE ||
conn.platform() == bts::config::JetFIX_Connection_JetFIXPlatform_SIMICE)
return std::make_unique<ICEExecutionGateway>(conn, pl, o);
else if (conn.use_ilink3())
return std::make_unique<ilink3::GLBXiLink3ExecutionGateway>(conn, pl, o);
else
else if (conn.platform() == bts::config::JetFIX_Connection::DERIBIT)
return std::make_unique<EMExecutionGateway>(o);
// return std::make_unique<FakeExecutionGateway>(o);
// return std::make_unique<GLBXExecutionGateway>(conn, pl, o);
else
return std::make_unique<GLBXExecutionGateway>(conn, pl, o);
}
} // namespace bts::orderman
@@ -124,17 +124,17 @@ NativeOrderBase *OrderFactory::make_order(const api::Venue exchange) {
if (exchange == api::Venue::VENUE_ICE ||
exchange == api::Venue::VENUE_SIMICE)
return new ICENativeOrder();
else
// return new GLBXNativeOrder();
else if (exchange == api::VENUE_DERIBIT)
return new EMNativeOrder();
else
return new GLBXNativeOrder();
}
NativeOrderBase *OrderFactory::make_native_order(
const api::orderman::OrderDefinition &def) {
auto secptr = me->sec_db.resolve(SecurityKey(def.security_key()));
if (secptr == nullptr)
// return new GLBXNativeOrder(); // GLBX Native can handle unresolved
return new EMNativeOrder();
return new GLBXNativeOrder(); // GLBX Native can handle unresolved
// securities
else
return make_order(secptr->exchange());
+1 -1
View File
@@ -474,7 +474,7 @@ OrderOpResult EMNativeOrder::_on_activate(
me->session_services = &me->services->get_session_services(
get_native_state(me->state).routing_record().session());
// TODO: just to get going
me->session_services = &me->services->get_session_services("sim");
me->session_services = &me->services->get_session_services("deribit_em");
// Checks for the following:
// 1. Gateway connection
@@ -0,0 +1,110 @@
#include "lib/orderman/orders/algo/algo_orders/MomentumAlgo.h"
#include "lib/domain_model/Security.h"
#include "lib/domain_model/SecurityKey.h"
#include "lib/logging/logging.h"
#include "lib/orderman/actors/SODPosition.h"
#include "lib/orderman/order_factory/IOrderFactory.h"
#include "lib/orderman/orderman_utils/Book.h"
#include "lib/orderman/orderman_utils/orderman_utils.h"
#include "lib/orderman/orders/algo/IAlgoServices.h"
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
#include "lib/os/os.h"
#include "lib/utils/PBUtils.h"
#include "lib/utils/datetime.h"
#include <boost/tokenizer.hpp>
#include <google/protobuf/util/time_util.h>
#include <optional>
#include <stdint.h>
namespace bts {
namespace orderman {
using namespace api::orderman;
using namespace google::protobuf;
using namespace boost;
struct MomentumAlgoParams {
SecurityKey security_key;
};
struct MomentumAlgo::PImpl {
IAlgoServices *algo_services = nullptr;
enum MomentumMeasure { GAN = 0 };
enum EdgeCapture { SIGNAL_TO_SIGNAL = 0, FIXED_EDGE };
size_t renko_ticks = 8;
size_t gan_buffer_sz = 100;
bool open_position_on_previous_close = false;
size_t edge_ticks = 4;
MomentumAlgoParams algo_params;
PImpl() {}
};
// ChildTemplate *_get_template(
// IBeforeLaunchAlgoServices &serv,
// const CustomOrderDefinition &cod,
// SecurityKey key,
// api::Side side) {
// OrderDefinition rv = serv.definition();
// rv.set_security_key(key.value());
// rv.set_side(side);
// rv.mutable_custom_def()->CopyFrom(cod);
// return &(serv.make_child_template(rv));
// }
bool _convert_params(
IBeforeLaunchAlgoServices &,
const CustomOrderDefinition &,
MomentumAlgoParams &out_p) {
out_p.security_key = SecurityKey(0);
return true;
}
MomentumAlgo::MomentumAlgo() : me(new PImpl()) {}
MomentumAlgo::~MomentumAlgo() {}
OrderOpResult MomentumAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv) {
auto &def = serv.definition();
if (def.has_custom_def() && def.custom_def().has_dynamic())
return {};
return {
OrderError::ORDER_ERROR_INVALID_PARAMETER,
std::string("Parameters are not well formed")};
}
void MomentumAlgo::do_launch(IAlgoServices &algo_services) {
me->algo_services = &algo_services;
}
void MomentumAlgo::do_launch_attached(
IAlgoServices &algo_services, OrderKey, ChildState) {
me->algo_services = &algo_services;
_cxl_and_end(true, "OnSignal Algo can not be attached to working orders");
}
void MomentumAlgo::do_update(api::orderman::Update const &) {
LOG(OrderMan, Warn,
"MomentumAlgo::do_update order: {} update not allowed, please "
"cxl and re-enter ",
me->algo_services->order_key().value());
}
void MomentumAlgo::on_child_change(OrderKey key, const ChildState &st) {
LOG(OrderMan, Info,
"MomentumAlgo::on_child_change key:{} child_key:{} status:{} "
"total_fills:{} last_price:{}",
me->algo_services->order_key(), key, static_cast<int>(st.status),
st.total_fills, st.last_price);
}
void MomentumAlgo::on_status(SecurityKey key, co2::TradingStatus s) {
LOG(OrderMan, Info, "MomentumAlgo::on_status key: {} status: {}", key,
static_cast<int>(s));
}
void MomentumAlgo::on_timer() {}
void MomentumAlgo::_fire_orders() {}
void MomentumAlgo::_cxl_and_end(bool is_error, const std::string &err_msg) {
if (is_error)
me->algo_services->terminate_error(err_msg);
else
me->algo_services->complete();
}
} // namespace orderman
} // namespace bts
@@ -0,0 +1,31 @@
#pragma once
#include "lib/orderman/orders/algo/IAlgoOrder.h"
namespace bts {
namespace orderman {
class MomentumAlgo : public IAlgoOrder {
public:
MomentumAlgo();
~MomentumAlgo();
OrderOpResult do_before_launch(IBeforeLaunchAlgoServices &) override;
void do_launch(IAlgoServices &) override;
void do_launch_attached(IAlgoServices &, OrderKey, ChildState) override;
void do_update(api::orderman::Update const &) override;
void on_child_change(OrderKey, ChildState const &) override;
void on_status(SecurityKey, co2::TradingStatus) override;
void on_timer() override;
private:
struct PImpl;
std::unique_ptr<PImpl> me;
private:
IAlgoServices &_algo() const;
void _fire_orders();
void _cxl_and_end(bool is_error, const std::string &err_msg);
};
} // namespace orderman
} // namespace bts
@@ -11,6 +11,7 @@
#include "lib/logging/logging.h"
#include "lib/orderman/orderman_utils/orderman_utils.h"
#include "lib/orderman/orders/algo/algo_orders/LimitCoverAlgo.h"
#include "lib/orderman/orders/algo/algo_orders/MomentumAlgo.h"
#include "lib/orderman/orders/algo/algo_orders/limit_cover/LimitCoverAdapter.h"
#include "lib/plugin/SparkServices.h"
@@ -23,14 +24,15 @@ namespace bts {
namespace orderman {
namespace dorman {
template <class OK, class ERR> using Result = std::variant<OK, ERR>;
template <class OK, class ERR>
using Result = std::variant<OK, ERR>;
Result<AlgoParams, OrderOpResult> bad_definition(const char *msg) {
return {OrderOpResult{ORDER_ERROR_INVALID_ORDER_DEFINITON, msg}};
}
// Validate DynamicOrderDefinition and construct parameter object
Result<AlgoParams, OrderOpResult>
to_dorman_params(const api::orderman::DynamicOrderDefinition &def) {
Result<AlgoParams, OrderOpResult> to_dorman_params(
const api::orderman::DynamicOrderDefinition &def) {
const auto &params = def.order_params();
AlgoParams res;
@@ -252,7 +254,7 @@ extern "C" void init_on_signal_plugin(bts::SparkServices &srv) {
}
extern "C" void init_sniper_plugin(bts::SparkServices &srv) {
DynamicOrderDescriptor sniper;
DynamicOrderDescriptor sniper;
sniper.set_dynamic_order_type("Sniper");
// contracts
*sniper.add_param_desc() = param_string("File");
@@ -274,12 +276,28 @@ extern "C" void init_sniper_plugin(bts::SparkServices &srv) {
*sniper.add_param_desc() = param_uint32("Min Cumm Qty");
*sniper.add_param_desc() = param_bool("Shoot At Implieds");
// misc
*sniper.add_param_desc() = param_bool("Use Trade Summary");
*sniper.add_param_desc() = param_bool("Use Trade Summary");
srv.register_dynamic_algo_order(
sniper, []() { return std::make_unique<orderman::SniperAlgo>(); });
}
extern "C" void init_momentum_algo_plugin(bts::SparkServices &srv) {
DynamicOrderDescriptor momentum;
momentum.set_dynamic_order_type("Momentum");
*momentum.add_param_desc() = param_bool("Signal To Signal?");
*momentum.add_param_desc() = param_bool("Edge Target?");
*momentum.add_param_desc() = param_uint32("Renko Ticks");
*momentum.add_param_desc() = param_uint32("Gan Buffer Size");
*momentum.add_param_desc() = param_bool("Open Position On Close");
*momentum.add_param_desc() = param_uint32("Edge To Capture");
srv.register_dynamic_algo_order(
momentum, []() { return std::make_unique<orderman::MomentumAlgo>(); });
}
extern "C" void init_spark_plugin(bts::SparkServices &srv) {
auto &dyn_algo_config = config::get<config::toggles::DynamicAlgos>();
if (dyn_algo_config.enable_dorman())
@@ -295,6 +313,7 @@ extern "C" void init_spark_plugin(bts::SparkServices &srv) {
if (dyn_algo_config.enable_onsignal())
init_on_signal_plugin(srv);
init_sniper_plugin(srv);
init_momentum_algo_plugin(srv);
}
} // namespace dorman
+8 -3
View File
@@ -362,6 +362,7 @@ struct UtcTimeStamp {
int month;
int year;
};
bool is_digit_or_empty(char c) { return isdigit(c) || c == ' '; }
struct UtcTimeStampConvertor {
static UtcTimeStamp convert(const std::string &value) {
@@ -401,7 +402,7 @@ struct UtcTimeStampConvertor {
if (value[i++] != '.')
bts_assert(false);
for (c = 0; c < 3; ++c)
if (!isdigit(value[i++]))
if (!is_digit_or_empty(value[i++]))
bts_assert(false);
}
@@ -450,9 +451,13 @@ struct UtcTimeStampConvertor {
bts_assert(false);
if (haveMilliseconds) {
auto ms_c = [&value](auto i) {
auto c = value[i];
return c == ' ' ? '0' : c;
};
millis =
(100 * (value[i + 1] - '0') + 10 * (value[i + 2] - '0') +
(value[i + 3] - '0'));
(100 * (ms_c(i + 1) - '0') + 10 * (ms_c(i + 2) - '0') +
(ms_c(i + 3) - '0'));
} else
millis = 0;
+3 -2
View File
@@ -38,10 +38,11 @@ void clean_dir(std::string base_path) {
void Cleanup::execute() {
clean_dir("/dev/shm");
clean_dir("/run/shm");
}
Cleanup::Cleanup() :
CLI::App("Remove all persisted market data shared memory", "cleanup") {
Cleanup::Cleanup()
: CLI::App("Remove all persisted market data shared memory", "cleanup") {
callback(execute);
}
+96 -67
View File
@@ -1,10 +1,15 @@
#include "Run.h"
#include "Cleanup.h"
#include "lib/config/protos/market_data.pb.h"
#include "lib/domain_model/Security.pb.h"
#include "lib/logging/logging.h"
#include "lib/md/UserSymbol.h"
#include "lib/md/cme/MDP3Utils.h"
#include "lib/md/relay/RelayRecorder.h"
#include "lib/os/os.h"
#include "lib/utils/PBUtils.h"
#include "lib/utils/Puid.h"
#include "lib/utils/bts_assert.h"
#include "lib/utils/thread_manager.h"
#include "server/sparkd/exchange_sim/ExchangeSim.h"
#include "server/sparkd/md/platforms/IMDPlatform.h"
@@ -55,30 +60,50 @@ static void run_replay() {
}
static void run_onixs(
const std::set<bts::api::Venue> &venue_map,
bts::md::MBOWriter *mbo_writer,
bts::md::TradeSummarySignalDispatcher *tss_dispatcher) {
auto has_venue = [&venue_map](auto venue) {
return venue_map.find(venue) != venue_map.end();
};
LOG(md, Info, "Run::run_onixs t_id:{} t_name", os::get_thread_id(),
get_thread_name());
std::vector<std::shared_ptr<bts::md::IMDPlatform>> platforms;
// get all glbx symbols
std::vector<bts::md::UserSymbol> cme_symbols;
get_system_md_symbols(
api::VENUE_GLBX, api::SECURITYTYPE_UNSET, &cme_symbols);
if (cme_symbols.size() > 0) {
auto *main = new bts::md::MDP3Main();
main->start(cme_symbols, mbo_writer, tss_dispatcher);
platforms.emplace_back(main);
// glbx
if (has_venue(bts::api::VENUE_GLBX)) {
std::vector<bts::md::UserSymbol> cme_symbols;
get_system_md_symbols(
api::VENUE_GLBX, api::SECURITYTYPE_UNSET, &cme_symbols);
if (cme_symbols.size() > 0) {
LOG(md, Info,
"Run::run_onixs starting CME OnyxS market data, n_symbols: {}",
cme_symbols.size());
auto *main = new bts::md::MDP3Main();
main->start(cme_symbols, mbo_writer, tss_dispatcher);
platforms.emplace_back(main);
}
}
// ice
std::vector<bts::md::UserSymbol> ice_symbols;
get_system_md_symbols(api::VENUE_ICE, api::SECURITYTYPE_UNSET, &ice_symbols);
if (ice_symbols.size() > 0) {
auto *imain = new bts::md::ice::ICEMain();
imain->start(ice_symbols);
platforms.emplace_back(imain);
if (has_venue(bts::api::VENUE_ICE)) {
std::vector<bts::md::UserSymbol> ice_symbols;
get_system_md_symbols(
api::VENUE_ICE, api::SECURITYTYPE_UNSET, &ice_symbols);
if (ice_symbols.size() > 0) {
LOG(md, Info,
"Run::run_onixs starting ICE OnyxS market data, n_symbols: {}",
ice_symbols.size());
auto *imain = new bts::md::ice::ICEMain();
imain->start(ice_symbols);
platforms.emplace_back(imain);
}
}
if (platforms.empty()) {
LOG(md, Info,
"Run::run_onixs exited because no OnyxS exchange was enabled (or "
"their "
"symbols were not)");
return;
}
// deribit
// auto *d_platform = new bts::md::EmMDListener()
// Timers
auto &disp = utils::Dispatcher::current();
utils::DispatcherTimer heartbeat_timer(disp, 250, [&]() {
@@ -90,9 +115,29 @@ static void run_onixs(
disp.run();
}
static void run_emumba() {
static void run_sim(
const std::set<bts::api::Venue> &venue_map,
bts::md::MBOWriter *mbo_writer) {
LOG(md, Info, "Run::run_sim t_id:{} t_name", os::get_thread_id(),
get_thread_name());
if (venue_map.find(api::VENUE_SIM) == venue_map.end()) {
LOG(md, Info, "Run::run_sim exited because no sim exchanges was enabled");
return;
}
LOG(md, Info, "Run::run_sim starting sim market data");
sim::start_exchange_sim(api::Venue::VENUE_SIM, mbo_writer);
}
static void run_emumba(const std::set<bts::api::Venue> &venue_map) {
LOG(md, Info, "Run::run_emumba t_id:{} t_name:{}", os::get_thread_id(),
get_thread_name());
if (venue_map.find(api::VENUE_DERIBIT) == venue_map.end()) {
LOG(md, Info,
"Run::run_emumba exited because no Emymba driven exchanges were "
"enabled");
return;
}
LOG(md, Info, "Run::run_emumba starting Emumba market data");
bts::md::EmumbaMain em_main = {};
em_main.run();
}
@@ -100,61 +145,45 @@ static void run_emumba() {
void Run::run(
bts::md::MBOWriter *mbo_writer,
bts::md::TradeSummarySignalDispatcher *tss_dispatcher,
Run::MDType type,
Run::MDType,
bool cleanup,
bool run_on_md_thread) {
LOG(md, Info, "Run::run cleanup:{} run_on_md_thread:{} t_id:{} t_name:{}",
cleanup, run_on_md_thread, os::get_thread_id(), get_thread_name());
if (type == Run::MDType::Configured &&
!config::get<bts::md::MarketDataConfig>().use_md()) {
// bts::md::MarketDataConfig test_conf = {};
// test_conf.add_md_venues(::bts::api::Venue::VENUE_DERIBIT);
// test_conf.add_md_venues(::bts::api::Venue::VENUE_SIM);
// LOG(md, Info, "Ye lo: {}", utils::pb::to_string(test_conf));
auto conf = config::get<bts::md::MarketDataConfig>();
LOG(md, Info,
"Run::run conf: {} cleanup: {} run_on_md_thread: {} t_id: {} t_name: {}",
utils::pb::to_string(conf), cleanup, run_on_md_thread,
os::get_thread_id(), get_thread_name());
if (!config::get<bts::md::MarketDataConfig>().use_md()) {
LOG(md, Info, "Ignoring request to run md: 'use_md' is configured false");
return;
}
auto impl = [&mbo_writer, &tss_dispatcher, &type, &cleanup]() {
LOG(md, Info, "Run::impl lambda t_id:{} t_name", os::get_thread_id(),
get_thread_name());
if (cleanup)
md::cmds::Cleanup::execute();
if (type == Run::MDType::Configured) {
const auto &conf = config::get<bts::md::MarketDataConfig>();
if (conf.use_replay())
type = Run::MDType::Replay;
else if (conf.use_onixs())
type = Run::MDType::Onixs;
}
switch (type) {
case Run::MDType::Replay:
run_replay();
break;
case Run::MDType::Onixs:
run_onixs(mbo_writer, tss_dispatcher);
break;
default:
bts_assert_msg(false, "Unexpected md type");
}
return;
};
if (run_on_md_thread) {
bts_assert(_md_thread == std::nullopt);
// start a thread for the md
// _md_thread =
// std::optional(bts::threading::make_thread("MDPublisher", impl));
bool is_run_emumba = true;
if (is_run_emumba) {
threading::make_thread("Emumba", []() { run_emumba(); }).detach();
}
if (bts::config::get<bts::md::MarketDataConfig>().use_sim()) {
threading::make_thread("ExchangeSimGLBX", [&mbo_writer]() {
sim::start_exchange_sim(api::Venue::VENUE_SIM, mbo_writer);
}).detach();
}
boot_sleep();
} else {
impl();
if (cleanup) {
md::cmds::Cleanup::execute();
}
// bts_assert_msg(false, "run_replay is not enabled");
std::set<bts::api::Venue> venue_map;
for (auto i = 0; i < conf.md_venues_size(); i++)
venue_map.insert(conf.md_venues(i));
// EMumba
threading::make_thread("Emumba", [&venue_map]() {
run_emumba(venue_map);
}).detach();
// OnixS
threading::make_thread(
"Onixs",
[&venue_map, &mbo_writer, &tss_dispatcher]() {
run_onixs(venue_map, mbo_writer, tss_dispatcher);
})
.detach();
// Sim
threading::make_thread("Sim", [&venue_map, &mbo_writer]() {
run_sim(venue_map, mbo_writer);
}).detach();
boot_sleep();
}
Run::Run()
@@ -165,7 +194,7 @@ Run::Run()
"run") {
add_subcommand("replay", "Run replay market data")->callback(run_replay);
add_subcommand("onixs", "Run onixs market data")->callback([] {
run_onixs(nullptr, nullptr);
run_onixs({}, nullptr, nullptr);
});
callback([] { run(nullptr, nullptr, MDType::Configured, true, true); });
}
@@ -1,4 +1,5 @@
#include "PlatformOption.h"
#include "lib/md/protos/co2.pb.h"
namespace bts::cmds::md {
@@ -7,9 +8,9 @@ namespace bts::cmds::md {
EnumOptionNames<bts::co2::Platform> PlatformOption::names() {
return {
NAME_PAIR(co2::PLATFORM_CELOXICA), NAME_PAIR(co2::PLATFORM_ICEONIXS),
NAME_PAIR(co2::PLATFORM_CELOXICA), NAME_PAIR(co2::PLATFORM_ICEONIXS),
NAME_PAIR(co2::PLATFORM_MDP3EMUMBA), NAME_PAIR(co2::PLATFORM_MDP3ONIXS),
NAME_PAIR(co2::PLATFORM_SIM)};
NAME_PAIR(co2::PLATFORM_SIM), NAME_PAIR(co2::PLATFORM_DERIBIT)};
}
std::string PlatformOption::name(bts::co2::Platform platform) {
@@ -24,6 +25,8 @@ std::string PlatformOption::name(bts::co2::Platform platform) {
return "mdp3onixs";
case co2::PLATFORM_SIM:
return "sim";
case co2::PLATFORM_DERIBIT:
return "deribit";
default:
return std::to_string(static_cast<int32_t>(platform));
}
@@ -157,7 +157,8 @@ int start_exchange_sim(bts::api::Venue venue, md::MBOWriter *mbo) {
bts_assert_msg(false, "Not a valid sim venue");
}
boost::replace_all(str_settings, "$EXCHANGE_SIM_FIX_PORT", port_string);
LOG(md, Info, "start_exchange_sim venue: {} port: {} settings: {}",
venue_string, port_string, str_settings);
std::istringstream str{str_settings};
FIX::SessionSettings settings(str);
@@ -43,7 +43,7 @@ struct EmumbaMain::PImpl {
[=](ExchangeKey k) {
return SecurityKey(sec_index.get_key(k.value()));
}}),
producer(bts::co2::PLATFORM_SIM, recorder),
producer(bts::co2::PLATFORM_DERIBIT, recorder),
listener(sec_index, producer) {
auto config_path =
os::sparkdata_path("conf") + "deribit_demo_config.json";