Adding options securities for Deribit
This commit is contained in:
1 parent
fef2b64933
commit
ad530c242d
4 files changed
+83
-40
No files matched your search
@@ -101,6 +101,7 @@ Symbols {
|
||||
glbx {
|
||||
future: @SymbolLists.list[GLBX].symbol
|
||||
spread: @SymbolLists.list[GLBX].symbol
|
||||
option: @SymbolLists.list[GLBX].symbol
|
||||
}
|
||||
ice {
|
||||
future: @SymbolLists.list[ICE].symbol
|
||||
@@ -114,10 +115,12 @@ Symbols {
|
||||
glbx {
|
||||
future: @SymbolLists.list[GLBX].symbol
|
||||
spread: @SymbolLists.list[GLBX].symbol
|
||||
option: @SymbolLists.list[GLBX].symbol
|
||||
}
|
||||
sim {
|
||||
future: @SymbolLists.list[GLBX].symbol
|
||||
spread: @SymbolLists.list[GLBX].symbol
|
||||
option: @SymbolLists.list[GLBX].symbol
|
||||
}
|
||||
ice {
|
||||
future: @SymbolLists.list[ICE].symbol
|
||||
|
||||
@@ -25,8 +25,9 @@ struct MDClientImpl {
|
||||
void _log_cons() {
|
||||
std::string log_str = "";
|
||||
for (const auto &s : _symbols) {
|
||||
log_str += "exch:" + std::to_string(static_cast<int>(s.exchange())) +
|
||||
" sym:" + s.symbol() + " ";
|
||||
log_str += "exch: " + Venue_Name(s.exchange()) +
|
||||
" sym: " + s.symbol() +
|
||||
" type: " + SecurityType_Name(s.type()) + ", ";
|
||||
}
|
||||
LOG(md, Info, "MDClientImpl::MDClientImpl symbols: {}", log_str);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "lib/domain_model/Security.pb.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#ifndef NO_CPP0X
|
||||
#include "MBOProcessor.h"
|
||||
@@ -611,7 +612,8 @@ class MDConsumerImpl {
|
||||
msg.str(), co2::Platform_Name(platform));
|
||||
|
||||
for (auto &s : symbols) {
|
||||
if (s.type() == SECURITYTYPE_FUTURE) {
|
||||
if (s.type() == SECURITYTYPE_FUTURE ||
|
||||
s.type() == SECURITYTYPE_OPTION) {
|
||||
_instances.push_back(make_shared<MDConsumerInst>(
|
||||
s.symbol(), s.type(), s.exchange(), shared, platform));
|
||||
}
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
#include "EmMDListener.h"
|
||||
#include "EmumbaMDListener.h"
|
||||
#include "lib/domain/AggressorSide.h"
|
||||
#include "lib/domain/Book.h"
|
||||
#include "lib/domain/FutureSecurity.h"
|
||||
#include "lib/domain/IndexSecurity.h"
|
||||
#include "lib/domain/OptionSecurity.h"
|
||||
#include "lib/domain/RFQ.h"
|
||||
#include "lib/domain/Security.h"
|
||||
#include "lib/domain/SecurityMarketDataStatistics.h"
|
||||
#include "lib/domain/SecurityState.h"
|
||||
#include "lib/domain/Side.h"
|
||||
#include "lib/domain/SpreadSecurity.h"
|
||||
#include "lib/domain/TradeRecord.h"
|
||||
#include "lib/domain/Venue.h"
|
||||
#include "lib/domain_model/Security.pb.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/md/IntPrice.h"
|
||||
@@ -127,6 +114,17 @@ bts::co2::AggressorSide convert_trade_side(
|
||||
return co2::AggressorSide::AGGRESSOR_SIDE_NONE;
|
||||
}
|
||||
|
||||
bts::api::PutOrCall convert_call_put(emumba::market_data::option_type cp) {
|
||||
switch (cp) {
|
||||
case emumba::market_data::option_type::call:
|
||||
return api::PutOrCall::PUTORCALL_CALL;
|
||||
case emumba::market_data::option_type::put:
|
||||
return api::PutOrCall::PUTORCALL_CALL;
|
||||
}
|
||||
bts_assert(false);
|
||||
return api::PutOrCall::PUTORCALL_CALL;
|
||||
}
|
||||
|
||||
/* #endregion */
|
||||
|
||||
void clear_books(MDArray &md_side) {
|
||||
@@ -310,10 +308,10 @@ void EmMDListener::on_securities(
|
||||
_add_future(sec);
|
||||
break;
|
||||
case (api::SecurityType::SECURITYTYPE_STOCK):
|
||||
//_add_spot(sec);
|
||||
_add_spot(sec);
|
||||
break;
|
||||
case (api::SecurityType::SECURITYTYPE_OPTION):
|
||||
//_add_option(sec);
|
||||
_add_option(sec);
|
||||
break;
|
||||
default: {
|
||||
bts_assert_msg(false, "Unknown security type");
|
||||
@@ -366,6 +364,11 @@ void EmMDListener::on_book(
|
||||
extract_security_desc(book.sec_id));
|
||||
return;
|
||||
}
|
||||
// TODO
|
||||
if (sec_data->handle.security().type ==
|
||||
api::SecurityType::SECURITYTYPE_OPTION) {
|
||||
return;
|
||||
}
|
||||
LOG(md, Diag, "EmMDListener::on_book id:{}",
|
||||
extract_security_desc(book.sec_id));
|
||||
// return;
|
||||
@@ -390,7 +393,6 @@ void EmMDListener::on_security_state(
|
||||
}
|
||||
|
||||
void EmMDListener::on_trades(
|
||||
__attribute__((unused))
|
||||
const std::vector<emumba::market_data::trade_record const *> &trades,
|
||||
__attribute__((unused)) const void *ptr) {
|
||||
LOG(md, Diag, "EmMDListener::on_trades n_trades:{}", trades.size());
|
||||
@@ -436,7 +438,6 @@ void EmMDListener::_add_future(const emumba::market_data::security &sec) {
|
||||
bts_assert(search_result.exists_now); // added now
|
||||
bts_assert(
|
||||
extract_security_type(sec) == api::SecurityType::SECURITYTYPE_FUTURE);
|
||||
// to check with Emumba, what are these id's ?
|
||||
LOG(md, Info,
|
||||
"EmMDListener::_add_future group:{} symbol: {} desc: {} id: {} exp: "
|
||||
"{}",
|
||||
@@ -459,8 +460,35 @@ void EmMDListener::_add_future(const emumba::market_data::security &sec) {
|
||||
_add_security(fsec);
|
||||
}
|
||||
|
||||
void EmMDListener::_add_option(const emumba::market_data::security &) {
|
||||
// TODO
|
||||
void EmMDListener::_add_option(const emumba::market_data::security &sec) {
|
||||
const std::string &desc = extract_security_desc(sec);
|
||||
auto search_result = _find_by_desc(sec.sec_common.symbol, desc, true);
|
||||
if (search_result.existed_before) {
|
||||
return;
|
||||
}
|
||||
bts_assert(search_result.exists_now);
|
||||
bts_assert(
|
||||
extract_security_type(sec) == api::SecurityType::SECURITYTYPE_OPTION);
|
||||
const auto &option = std::get<emumba::market_data::option>(sec.sec);
|
||||
auto option_exp = option.expiration_ts.get_timestamp();
|
||||
LOG(md, Info,
|
||||
"EmMDListener::_add_option group:{} symbol: {} desc: {} id: {} exp: "
|
||||
"{} strike: {} callput: {} ",
|
||||
sec.sec_common.security_group, sec.sec_common.symbol, desc,
|
||||
search_result.key, option_exp, option.strike.to_double(),
|
||||
static_cast<int>(option.op_type));
|
||||
FixedOptionSecurity osec;
|
||||
_copy_security_common(sec, search_result.key, osec);
|
||||
uint32_t year, month, day;
|
||||
get_date_from_epoch_secs(option_exp, year, month, day);
|
||||
LOG(md, Info, "EmMDListener::_add_option yy:{} mm:{} dd:{}", year, month,
|
||||
day);
|
||||
osec.expiration_year = year;
|
||||
osec.expiration_month = month;
|
||||
osec.expiration_day = day;
|
||||
osec.strike = option.strike.to_double();
|
||||
osec.call_put = convert_call_put(option.op_type);
|
||||
_add_security(osec);
|
||||
}
|
||||
|
||||
void EmMDListener::_add_spot(const emumba::market_data::security &) {
|
||||
@@ -530,26 +558,35 @@ EmumbaSecurityData *EmMDListener::_find_security(
|
||||
}
|
||||
|
||||
void EmMDListener::_subsribe() {
|
||||
if (me->handler != nullptr) {
|
||||
// check for already subb;ed (in cons) securities
|
||||
std::unordered_map<std::string, std::list<std::string>> sub_map = {};
|
||||
for (auto &kv : me->sec_map) {
|
||||
const std::string &desc = kv.first;
|
||||
SecuritySubStatus &s = kv.second;
|
||||
if (!s.subsribed) {
|
||||
// check if its part of the initial list
|
||||
s.subsribed = true;
|
||||
auto &sym_list = sub_map[s.symbol];
|
||||
sym_list.push_back(desc);
|
||||
}
|
||||
if (me->handler == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::unordered_map<std::string, std::list<std::string>> sub_map = {};
|
||||
auto add_to_submap = [&](const auto &desc) {
|
||||
const auto &it = me->sec_map.find(desc);
|
||||
bts_assert(it != me->sec_map.end());
|
||||
const auto &sec_sub = it->second;
|
||||
if (sec_sub.subsribed) {
|
||||
return;
|
||||
}
|
||||
for (const auto &kv : sub_map) {
|
||||
for (const auto &d : kv.second) {
|
||||
LOG(md, Info, "EmMDListener::_subsribe security: {}.{}", kv.first,
|
||||
d);
|
||||
}
|
||||
me->handler->reconfigure_instrument_list(kv.first, kv.second);
|
||||
me->index.has_security(sec_sub.locked_key);
|
||||
const auto &val = me->index.get_security(sec_sub.locked_key);
|
||||
const auto &handle = val->handle;
|
||||
const auto &sec = handle.security();
|
||||
// TODO
|
||||
if (sec.type == api::SECURITYTYPE_FUTURE && desc == "BTC-PERPETUAL") {
|
||||
auto &sym_list = sub_map[sec_sub.symbol];
|
||||
sym_list.push_back(desc);
|
||||
LOG(md, Info, "EmMDListener::_subsribe subsribing to sec: {}", desc);
|
||||
}
|
||||
};
|
||||
// check for already subbed (in cons) securities
|
||||
for (auto &kv : me->sec_map) {
|
||||
const std::string &desc = kv.first;
|
||||
add_to_submap(desc);
|
||||
}
|
||||
for (const auto &kv : sub_map) {
|
||||
me->handler->reconfigure_instrument_list(kv.first, kv.second);
|
||||
}
|
||||
}
|
||||
/* #endregion */
|
||||
|
||||
Reference in new issue
Block a user