Working around Deribit option md bugs
This commit is contained in:
1 parent
8af07756ef
commit
fdc4e59d09
3 files changed
+36
-14
No files matched your search
@@ -76,7 +76,7 @@ AnalyticsServiceServer::AnalyticsServiceServer(
|
||||
for (const auto &kvp : key_vals) {
|
||||
const std::string &key = kvp.first;
|
||||
const std::string &val = kvp.second;
|
||||
LOG(OrderMan, Info, "vs:{} key:{} val:{}", vs_name, key, val);
|
||||
LOG(OrderMan, Diag, "vs:{} key:{} val:{}", vs_name, key, val);
|
||||
VolSurfaceEntry vs_entry;
|
||||
utils::pb::from_string(val, &vs_entry);
|
||||
me->vs_publisher.add_or_update(vs_entry);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "lib/utils/bts_chrono.h"
|
||||
#include "lib/utils/overloaded.h"
|
||||
#include "server/sparkd/cmds/spartan/utils/FileUtils.h"
|
||||
#include "server/sparkd/md/platforms/emumba/EmumbaSecurityIndex.h"
|
||||
#include <array>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <cstdint>
|
||||
@@ -355,6 +356,16 @@ void EmMDListener::on_quote(
|
||||
__attribute__((unused)) const emumba::market_data::quote "e,
|
||||
__attribute__((unused)) const void *ptr) {}
|
||||
|
||||
void _log_book(
|
||||
EmumbaSecurityData *s_data, const emumba::market_data::order_book &book) {
|
||||
if (s_data->handle.security().type == api::SECURITYTYPE_OPTION) {
|
||||
LOG(md, Info, "BookTop sec: {} bid: {}/{} ask: {}/{}",
|
||||
std::string(s_data->handle.security().security_desc()),
|
||||
book.bids.level[0].px.to_double(), book.bids.level[0].direct_qty,
|
||||
book.asks.level[0].px.to_double(), book.asks.level[0].direct_qty);
|
||||
}
|
||||
}
|
||||
|
||||
void EmMDListener::on_book(
|
||||
const emumba::market_data::order_book &book,
|
||||
__attribute__((unused)) const void *ptr) {
|
||||
@@ -364,14 +375,9 @@ 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;
|
||||
_log_book(sec_data, book);
|
||||
copy_books(book.bids, me->bids);
|
||||
copy_books(book.asks, me->asks);
|
||||
sec_data->handle.update_direct(utils::TimeStamp::now(), me->bids, me->asks);
|
||||
@@ -557,12 +563,23 @@ EmumbaSecurityData *EmMDListener::_find_security(
|
||||
return me->index.get_security(search_result.key);
|
||||
}
|
||||
|
||||
template <typename ExpSecurity>
|
||||
bool is_exp(const ExpSecurity &sec, uint32_t yy, uint32_t mm, uint32_t dd) {
|
||||
return sec.expiration_year == yy && sec.expiration_month == mm &&
|
||||
sec.expiration_day == dd;
|
||||
}
|
||||
|
||||
void EmMDListener::_subsribe() {
|
||||
if (me->handler == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::unordered_map<std::string, std::list<std::string>> sub_map = {};
|
||||
auto add_to_submap = [&](const auto &desc) {
|
||||
auto add_instr = [&](const auto &symbol, const auto &desc) {
|
||||
auto &sym_list = sub_map[symbol];
|
||||
sym_list.push_back(desc);
|
||||
LOG(md, Info, "EmMDListener::_subsribe subsribing to sec: {}", desc);
|
||||
};
|
||||
const auto &it = me->sec_map.find(desc);
|
||||
bts_assert(it != me->sec_map.end());
|
||||
const auto &sec_sub = it->second;
|
||||
@@ -572,12 +589,17 @@ void EmMDListener::_subsribe() {
|
||||
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);
|
||||
const FixedSecurity &sec = handle.security();
|
||||
if (sec.type == api::SECURITYTYPE_FUTURE) {
|
||||
if (is_exp((const FixedFutureSecurity &)sec, 2022, 1, 28)) {
|
||||
add_instr(sec_sub.symbol, desc);
|
||||
}
|
||||
} else if (sec.type == api::SECURITYTYPE_OPTION) {
|
||||
const FixedOptionSecurity &osec = (const FixedOptionSecurity &)sec;
|
||||
if (is_exp(osec, 2022, 1, 28) && osec.strike >= 34000 &&
|
||||
osec.strike <= 38000) {
|
||||
add_instr(sec_sub.symbol, desc);
|
||||
}
|
||||
}
|
||||
};
|
||||
// check for already subbed (in cons) securities
|
||||
|
||||
@@ -115,7 +115,7 @@ class HandleIndex {
|
||||
auto id = _consumer->id();
|
||||
_consumer->on_security(
|
||||
[this, id](const SecurityPtr &sec, MDConsumerHandle handle) {
|
||||
LOG(md, Info,
|
||||
LOG(md, Diag,
|
||||
"PositionService::HandleIndex::on_security security:{}",
|
||||
bts::securities::descriptor(*sec));
|
||||
if (_consumer->id() == id) {
|
||||
|
||||
Reference in new issue
Block a user