change: changes to make taifex work

This commit is contained in:
Mohammad Arham committed 2024-08-27 07:45:59 -04:00
1 parent cf189ecf81
commit a19e8a7315
2 files changed
+118 -13

No files matched your search

@@ -16,6 +16,7 @@
#include "lib/persistence/IDGenerator.h"
#include "lib/utils/bts_assert.h"
#include "lib/utils/bts_fatal.h"
#include "lib/utils/helper_macros.h"
#include "lib/utils/thread_manager.h"
#include "server/sparkd/md/MarketDataListenerID.h"
#include "server/sparkd/md/MarketDataRegistration.h"
@@ -25,6 +26,7 @@
#include "server/sparkd/md/binance/BinanceSubscription.h"
#include "server/sparkd/md/binance_us/BinanceUsSubscription.h"
#include "server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesSubscription.h"
#include "server/sparkd/md/cboe/CboeMarketDataHandler.h"
#include "server/sparkd/md/coinbase/CoinbaseSubscription.h"
#include "server/sparkd/md/deribit/DeribitSubscription.h"
#include "server/sparkd/md/emumba/EmumbaDeribitData.h"
@@ -36,7 +38,9 @@
#include <bits/stdint-uintn.h>
#include <boost/filesystem.hpp>
#include <cassert>
#include <ccapi_cpp/ccapi_event_dispatcher.h>
#include <emumba-deribit-connector/deribit_utils.h>
#include <memory>
#include <optional>
#include <unordered_map>
@@ -279,6 +283,71 @@ void MarketDataGateway::_start_onix_glbx(
bts::md::run_onixs();
}
static void run_cboe(
bts::api::md::CboeMarketDataConfig cfg,
persistence::IDGenerator *sec_id_store) {
LOG(md, Info, "MarketDataGateway::run_cboe t_id:{} t_name",
os::get_thread_id(), os::get_thread_name());
bts::md::GeneralSecurityIndex sec_index;
bts::md::MDProducer md_producer;
std::shared_ptr<GeneralMarketDataListener> listener =
std::make_shared<bts::md::GeneralMarketDataListener>(
sec_index, md_producer, bts::api::VENUE_CBOE);
UNUSED(cfg);
UNUSED(sec_id_store);
assert(false);
// bts::md::cboe::CboeMarketDatahandler::run(cfg.read_from_file(), listener,sec_id_store);
// Timers
// auto &disp = utils::Dispatcher::current();
// utils::DispatcherTimer heartbeat_timer(disp, 250, [&]() {
// for (auto &p : platforms)
// p->send_heartbeats();
// });
// heartbeat_timer.start();
// disp.run();
}
void MarketDataGateway::_start_cboe(
bts::api::md::CboeMarketDataConfig cfg) {
LOG(md, Error,
"MarketDataGateway::_start_cboe starting t_id:{} t_name:{}. "
"cfg:\n{}",
os::get_thread_id(), os::get_thread_name(), cfg.DebugString());
threading::make_thread("Cboe", [&]() { bts::md::run_cboe(cfg, &me_->sec_id_store);; }).detach();
}
static void run_taifex(
bts::api::md::TaifexMarketDataConfig cfg,
persistence::IDGenerator *sec_id_store) {
LOG(md, Info, "MarketDataGateway::run_taifex t_id:{} t_name",
os::get_thread_id(), os::get_thread_name());
bts::md::GeneralSecurityIndex sec_index;
bts::md::MDProducer md_producer;
std::shared_ptr<GeneralMarketDataListener> listener =
std::make_shared<bts::md::GeneralMarketDataListener>(
sec_index, md_producer, bts::api::VENUE_TAIFEX);
bts::md::taifex::TaifexDatahandler::run(cfg.read_from_file(), listener,sec_id_store);
// Timers
// auto &disp = utils::Dispatcher::current();
// utils::DispatcherTimer heartbeat_timer(disp, 250, [&]() {
// for (auto &p : platforms)
// p->send_heartbeats();
// });
// heartbeat_timer.start();
// disp.run();
}
void MarketDataGateway::_start_taifex(
bts::api::md::TaifexMarketDataConfig cfg) {
LOG(md, Error,
"MarketDataGateway::_start_taifex starting t_id:{} t_name:{}. "
"cfg:\n{}",
os::get_thread_id(), os::get_thread_name(), cfg.DebugString());
threading::make_thread("Taifex", [&]() { bts::md::run_taifex(cfg, &me_->sec_id_store);; }).detach();
LOG(md, Info, "MarketDataGateway::_start_taifez ending t_id:{} t_name:{}",
os::get_thread_id(), os::get_thread_name());
}
// deribit ////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -3,9 +3,13 @@
#include "lib/config/config.h"
#include "lib/domain/Price.h"
#include "lib/domain/Security.h"
<<<<<<< Updated upstream
#include "lib/md/IMarketDataListener.h"
#include "lib/persistence/IDGenerator.h"
=======
#include "lib/logging/logging.h"
>>>>>>> Stashed changes
#include <emumba-deribit-connector/deribit_utils.h>
#include <algorithm>
#include <bit>
@@ -1030,7 +1034,7 @@ bool readBinaryFile(const std::string &file_name,
size_t counter = 0;
size_t hits = 0;
const size_t hits_limit = 5;
const size_t limit = 1000000;
const size_t limit = 10000;
std::unordered_set<std::string> names;
@@ -1061,17 +1065,29 @@ bool readBinaryFile(const std::string &file_name,
// std::cout << "we are looking for this!" << std::endl;
auto i010_message = I010Data(buffer, position + HEADER_SIZE,
Header.Body_Length + FOOTER_SIZE);
const auto remove_spaces= [](const std::string &name){
std::string removed = "";
const char space = ' ';
for (auto c:name){
if(c!=space){
removed+=c;
}
}
return removed;
};
const auto id = remove_spaces(i010_message.prod_id);
const auto symbol = id.substr(0,2);
bts::domain::SecurityID sec_id{
sec_id_store->get_or_add(api::domain::VENUE_TAIFEX, i010_message.prod_id)};
sec_id_store->get_or_add(api::domain::VENUE_TAIFEX, id)};
std::vector<bts::domain::Security> complete_security_list;
bts::domain::Security &sec = complete_security_list.emplace_back();
sec.security_common.venue = bts::api::domain::VENUE_TAIFEX;
sec.security_common.id = sec_id;
sec.security_common.exchange_sec_id = i010_message.prod_id; // Need to fix this
sec.security_common.desc = i010_message.prod_id;
sec.security_common.symbol = i010_message.prod_id;
sec.security_common.asset = i010_message.prod_id;
sec.security_common.group = i010_message.prod_id;
sec.security_common.exchange_sec_id = id; // Need to fix this
sec.security_common.desc = id;
sec.security_common.symbol = symbol;
sec.security_common.asset = id;
sec.security_common.group = id;
sec.security_common.min_price_increment = 0.1;
sec.security_common.min_quantity = 1;
sec.security_common.min_quantity_increment = 0.1;
@@ -1081,11 +1097,16 @@ bool readBinaryFile(const std::string &file_name,
case I010Data::ProductInfo::ProductType::FUTURES: {
auto &t = sec.security.emplace<domain::FutureSecurity>();
//assuming time stamp
std::tm tm = {};
std::istringstream iss(i010_message.end_date);
iss >> std::get_time(&tm, "%Y%m%d");
std::time_t time = std::mktime(&tm);
t.expiration = bts::core::TimeStamp(static_cast<uint64_t>(time));
// std::tm tm = {};
// std::istringstream iss(i010_message.end_date);
// iss >> std::get_time(&tm, "%Y%m%d");
// std::time_t time = std::mktime(&tm);
LOG(md, Error, "DATE {}",i010_message.end_date);
std::cout<<"hello world "<< i010_message.end_date<<std::endl;
auto toISODate = [](const std::string& date) {
return date.substr(0, 4) + "-" + date.substr(4, 2) + "-" + date.substr(6, 2);
};
t.expiration = bts::core::TimeStamp::from_iso_string(toISODate(i010_message.end_date));
// t.future().set_expiration_year(std::stoi(i010_message.end_date.substr(0, 4)));
// t.future().set_expiration_month(std::stoi(i010_message.end_date.substr(4, 2)));
// t.future().set_expiration_day(std::stoi(i010_message.end_date.substr(6, 2)));
@@ -1111,7 +1132,7 @@ bool readBinaryFile(const std::string &file_name,
const_security_list.push_back(&security);
}
listener->on_securities(const_security_list);
hits++;
// hits++;
break;
//std::cout << i010_message << std::endl;
@@ -1194,6 +1215,7 @@ bool readBinaryFile(const std::string &file_name,
//const std::string &filename,
void bts::md::taifex::TaifexDatahandler::run(
<<<<<<< Updated upstream
bool use_file,
std::shared_ptr<IMarketDataListener> listner,
std::shared_ptr<persistence::IDGenerator> sec_id_store) {
@@ -1207,3 +1229,17 @@ void bts::md::taifex::TaifexDatahandler::run(
}
}//namespace bts::md::taifex
=======
const bool &use_file,
std::shared_ptr<GeneralMarketDataListener> listner,
persistence::IDGenerator *sec_id_store) {
std::string file_name = "/reference_data_20240806_1";
if(use_file){
std::string base_path = config::get<bts::config::SystemConfig>().data_path();
readBinaryFile(base_path+file_name, listner, sec_id_store);
while(1);
}
// bts_assert_msg(false, "inside run taifex");
}
}//namespace bts::md::taifex
>>>>>>> Stashed changes