Change: Rename taifex files
This commit is contained in:
1 parent
a8f4ec07c8
commit
7d9d176fa2
7 files changed
+317
-26
No files matched your search
@@ -5,13 +5,23 @@ import "lib/api/domain/SecurityCriteria.proto";
|
||||
package bts.api.md;
|
||||
|
||||
option csharp_namespace = "bts.api.md";
|
||||
|
||||
message TaifexConnectionDetails{
|
||||
string live_data_ip = 30;
|
||||
string reference_data_ip = 31;
|
||||
string refresh_data_ip = 32;
|
||||
string live_data_port = 40;
|
||||
string reference_data_port = 41;
|
||||
string refresh_data_port = 42;
|
||||
string interface_ip = 50;
|
||||
}
|
||||
|
||||
message TaifexMarketDataConfig {
|
||||
uint32 unique_check_value = 1;
|
||||
bool read_from_file = 20;
|
||||
string ref_data_file_name = 21;
|
||||
string realtime_data_file_name = 22;
|
||||
TaifexConnectionDetails regular_hours_connection_details = 30;
|
||||
TaifexConnectionDetails after_hours_connection_details = 31;
|
||||
bts.api.domain.SecurityCriteria security_criteria = 3;
|
||||
|
||||
}
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <emumba-deribit-connector/deribit_utils.h>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
@@ -117,10 +118,6 @@ struct MarketDataGateway::PImpl {
|
||||
std::vector<std::unique_ptr<MDReplayData>> replays = {};
|
||||
// we create these and pass them to the cc md sources
|
||||
std::vector<std::shared_ptr<VenueListenerData>> venue_listeners = {};
|
||||
|
||||
void start_glbx();
|
||||
void start_cboe();
|
||||
void start_taifex();
|
||||
};
|
||||
|
||||
MarketDataGateway::MarketDataGateway()
|
||||
@@ -142,9 +139,9 @@ void MarketDataGateway::run() {
|
||||
bts_assert(me_->md_config.emumba_deribit().size() == 1);
|
||||
_start_emumba_deribit(me_->md_config.emumba_deribit().at(0));
|
||||
}
|
||||
me_->start_glbx();
|
||||
me_->start_taifex();
|
||||
me_->start_cboe();
|
||||
start_glbx(me_->md_config);
|
||||
start_taifex(me_->md_config);
|
||||
start_cboe(me_->md_config);
|
||||
_start_replays(me_->md_config);
|
||||
while (true) {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
@@ -247,16 +244,16 @@ void MarketDataGateway::unsubscribe(MarketDataListenerID id) {
|
||||
}
|
||||
/// glbx //////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void MarketDataGateway::PImpl::start_glbx(){
|
||||
for (const auto &glbx : md_config.glbx()) {
|
||||
void MarketDataGateway::start_glbx(const bts::api::md::MarketDataConfig &cfg){
|
||||
for (const auto &glbx : cfg.glbx()) {
|
||||
if(glbx.use_databento()){
|
||||
auto p = venue_listeners.emplace_back(
|
||||
auto p = me_->venue_listeners.emplace_back(
|
||||
std::make_shared<VenueListenerData>(bts::api::VENUE_GLBX));
|
||||
std::string tid_name = "glbx";
|
||||
bts::threading::make_thread(tid_name, [&]() {
|
||||
api::md::glbx::GlbxMarketDatahandler::run(
|
||||
p->listener,
|
||||
sec_id_store,
|
||||
me_->sec_id_store,
|
||||
glbx);
|
||||
}).detach();
|
||||
}
|
||||
@@ -375,29 +372,31 @@ void MarketDataGateway::_start_replays(
|
||||
os::get_thread_id(), os::get_thread_name());
|
||||
}
|
||||
|
||||
void MarketDataGateway::PImpl::start_taifex() {
|
||||
void MarketDataGateway::start_taifex(const bts::api::md::MarketDataConfig &cfg) {
|
||||
// taifex
|
||||
for (const auto &taifex : md_config.taifex()) {
|
||||
auto p = venue_listeners.emplace_back(
|
||||
int counter = 0;
|
||||
for (const auto &taifex : cfg.taifex()) {
|
||||
counter++;
|
||||
auto p = me_->venue_listeners.emplace_back(
|
||||
std::make_shared<VenueListenerData>(bts::api::VENUE_TAIFEX));
|
||||
std::string tid_name = "taifex";
|
||||
std::string tid_name = "taifex" +std::to_string(counter);
|
||||
bts::threading::make_thread(tid_name, [&]() {
|
||||
bts::md::taifex::TaifexDatahandler::run(
|
||||
taifex.read_from_file(), p->listener, sec_id_store);
|
||||
taifex, p->listener, me_->sec_id_store);
|
||||
}).detach();
|
||||
|
||||
}
|
||||
}
|
||||
void MarketDataGateway::PImpl::start_cboe(){
|
||||
void MarketDataGateway::start_cboe(const bts::api::md::MarketDataConfig &cfg){
|
||||
// cboe
|
||||
for (const api::md::CboeMarketDataConfig &cboe : md_config.cboe()) {
|
||||
auto p = venue_listeners.emplace_back(
|
||||
for (const api::md::CboeMarketDataConfig &cboe : cfg.cboe()) {
|
||||
auto p = me_->venue_listeners.emplace_back(
|
||||
std::make_shared<VenueListenerData>(bts::api::VENUE_CBOE));
|
||||
std::string tid_name = "CBOE";
|
||||
bts::threading::make_thread(tid_name, [&]() {
|
||||
api::md::cboe::CboeMarketDatahandler::run(
|
||||
p->listener,
|
||||
sec_id_store,
|
||||
me_->sec_id_store,
|
||||
cboe);
|
||||
}).detach();
|
||||
|
||||
|
||||
@@ -36,6 +36,9 @@ class MarketDataGateway {
|
||||
static void _start_onix_glbx(
|
||||
bts::api::md::GlbxMarketDataConfig cfg);
|
||||
void _start_replays(const bts::api::md::MarketDataConfig &cfg);
|
||||
void start_glbx(const bts::api::md::MarketDataConfig &cfg);
|
||||
void start_cboe(const bts::api::md::MarketDataConfig &cfg);
|
||||
void start_taifex(const bts::api::md::MarketDataConfig &cfg);
|
||||
};
|
||||
|
||||
} // namespace bts::md
|
||||
+68
-4
@@ -1,4 +1,4 @@
|
||||
#include "TaifexDataHandler.h"
|
||||
#include "TaifexDataGateway.h"
|
||||
#include "TaifexMessages.h"
|
||||
#include "TaifexSecurityDetailsMapper.h"
|
||||
#include "lib/api/domain/Venue.pb.h"
|
||||
@@ -16,8 +16,8 @@
|
||||
#include "lib/utils/bts_assert.h"
|
||||
namespace bts::md::taifex {
|
||||
|
||||
const size_t FOOTER_SIZE = 3;
|
||||
const size_t HEADER_SIZE = 19;
|
||||
constexpr size_t FOOTER_SIZE = 3;
|
||||
constexpr size_t HEADER_SIZE = 19;
|
||||
|
||||
void handleParsedMessage(
|
||||
const std::vector<unsigned char> &buffer,
|
||||
@@ -342,9 +342,70 @@ bool readBinaryFile(
|
||||
}
|
||||
return true;
|
||||
}
|
||||
enum LIVE_DATA_STATES{
|
||||
START =0,
|
||||
WAITING_FOR_REFRESH_DATA,
|
||||
REFRESH_DATA_DONE,
|
||||
WAITING_TO_SYNC_LIVE,
|
||||
LIVE_RUNNING
|
||||
};
|
||||
void runLive(){
|
||||
LIVE_DATA_STATES state = START;
|
||||
while(true){
|
||||
switch (state) {
|
||||
|
||||
case START:
|
||||
//reset all variables,
|
||||
//variables:
|
||||
//TaifexSecurityDetailsMapper
|
||||
//close all sockets
|
||||
//reset counter increment
|
||||
//buffer for live_data
|
||||
//last_seq_num = -1
|
||||
|
||||
|
||||
state = WAITING_FOR_REFRESH_DATA;
|
||||
break;
|
||||
case WAITING_FOR_REFRESH_DATA:
|
||||
//start reference data
|
||||
//get live data first message and get seq number
|
||||
//start refresh data
|
||||
//busy loop
|
||||
//while 1
|
||||
//add to live buffer
|
||||
//check if refresh done
|
||||
state = REFRESH_DATA_DONE;
|
||||
break;
|
||||
case REFRESH_DATA_DONE:
|
||||
//stop reference data
|
||||
//apply all refresh data
|
||||
//set last_seq_num = seq_num of last refresh message
|
||||
state = WAITING_TO_SYNC_LIVE;
|
||||
break;
|
||||
case WAITING_TO_SYNC_LIVE:
|
||||
//while 1
|
||||
//process buffer:
|
||||
// if seq_num > last_seq_num + 1
|
||||
state = START;
|
||||
break;
|
||||
// if seq_num <= last_seq_num
|
||||
// skip message
|
||||
// state = LIVE_RUNNING;
|
||||
// break
|
||||
case LIVE_RUNNING:
|
||||
// if seq_num != last_seq_num + 1
|
||||
state = START;
|
||||
break;
|
||||
//else
|
||||
//process live
|
||||
default:
|
||||
bts_assert(false);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
//const std::string &filename,
|
||||
void bts::md::taifex::TaifexDatahandler::run(
|
||||
void bts::md::taifex::TaifexDataGateway::run(
|
||||
const api::md::TaifexMarketDataConfig &config,
|
||||
std::shared_ptr<IMarketDataListener> listner,
|
||||
std::shared_ptr<persistence::IDGenerator> sec_id_store) {
|
||||
@@ -365,6 +426,9 @@ void bts::md::taifex::TaifexDatahandler::run(
|
||||
sleep_for(10s);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// runlive(config,listner,sec_id_store,sec_details,regular_hours_connection_details,after_hours_connection_details);
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace bts::md::taifex
|
||||
+1
-1
@@ -13,7 +13,7 @@ class IMarketDataListener;
|
||||
|
||||
namespace bts::md::taifex {
|
||||
// const std::string &filename,
|
||||
class TaifexDatahandler {
|
||||
class TaifexDataGateway {
|
||||
public:
|
||||
static void run(
|
||||
const api::md::TaifexMarketDataConfig &config,
|
||||
@@ -278,6 +278,171 @@ class TaifexMessages {
|
||||
return os;
|
||||
}
|
||||
};
|
||||
struct I084Data {
|
||||
std::string message_type;
|
||||
unsigned long last_seq;
|
||||
unsigned int no_entries;
|
||||
std::string prod_id;
|
||||
unsigned long last_prod_msg_seq;
|
||||
int no_md_entries;
|
||||
char md_entry_type;
|
||||
enum Sign { POSITIVE = 0, NEGATIVE = 1 };
|
||||
Sign sign;
|
||||
double md_entry_px;
|
||||
size_t md_entry_size;
|
||||
size_t md_price_level;
|
||||
std::string last_match_time;
|
||||
Sign last_match_sign;
|
||||
long last_match_price;
|
||||
double last_match_qty;
|
||||
std::string match_total_qty;
|
||||
std::string match_buy_cnt;
|
||||
std::string match_sell_cnt;
|
||||
std::string first_match_time;
|
||||
long first_match_price;
|
||||
Sign first_match_sign;
|
||||
double first_match_qty;
|
||||
Sign day_high_price_sign;
|
||||
unsigned long day_high_price;
|
||||
Sign day_low_price_sign;
|
||||
unsigned long day_low_price;
|
||||
long buy_order;
|
||||
long buy_qty;
|
||||
long sell_order;
|
||||
long sell_qty;
|
||||
|
||||
const size_t MESSAGE_TYPE_SIZE = 1;
|
||||
const size_t LAST_SEQ_SIZE = 5;
|
||||
const size_t NO_ENTRIES_SIZE = 1;
|
||||
const size_t PROD_ID_SIZE = 20;
|
||||
const size_t LAST_PROD_MSG_SEQ_SIZE = 5;
|
||||
const size_t NO_MD_ENTRIES_SIZE = 1;
|
||||
const size_t MD_ENTRY_TYPE_SIZE = 1;
|
||||
const size_t MD_ENTRY_PX_SIZE = 5;
|
||||
const size_t MD_ENTRY_SIZE_SIZE = 4;
|
||||
const size_t MD_PRICE_LEVEL_SIZE = 1;
|
||||
// Overload the << operator for convenient output
|
||||
friend std::ostream &operator<<(std::ostream &os, const I084Data &data) {
|
||||
os << "The Message Type is: " << data.message_type << "\n";
|
||||
return os;
|
||||
}
|
||||
|
||||
I084Data(
|
||||
const std::vector<unsigned char> &buffer, const size_t &offset = 0) {
|
||||
// const size_t LAST_MATCH_TIME_SIZE = 6;
|
||||
// const size_t LAST_MATCH_SIGN_SIZE = 1;
|
||||
// const size_t LAST_MATCH_PRICE_SIZE = 5;
|
||||
// const size_t LAST_MATCH_QTY_SIZE = 4;
|
||||
// const size_t MATCH_TOTAL_QTY_SIZE = 4;
|
||||
// const size_t MATCH_BUY_CNT_SIZE = 4;
|
||||
// const size_t MATCH_SELL_CNT_SIZE = 4;
|
||||
// const size_t FIRST_MATCH_TIME_SIZE = 6;
|
||||
// const size_t FIRST_MATCH_PRICE_SIZE = 5;
|
||||
// const size_t FIRST_MATCH_SIGN_SIZE = 1;
|
||||
// const size_t FIRST_MATCH_QTY_SIZE = 4;
|
||||
// const size_t DAY_HIGH_PRICE_SIGN_SIZE = 1;
|
||||
// const size_t DAY_HIGH_PRICE_SIZE = 5;
|
||||
// const size_t DAY_LOW_PRICE_SIGN_SIZE = 1;
|
||||
// const size_t DAY_LOW_PRICE_SIZE = 5;
|
||||
// const size_t BUY_ORDER_SIZE = 4;
|
||||
// const size_t BUY_QTY_SIZE = 4;
|
||||
// const size_t SELL_ORDER_SIZE = 4;
|
||||
// const size_t SELL_QTY_SIZE = 4;
|
||||
|
||||
// const size_t MD_ENTRY_SIZE = MD_ENTRY_PX_SIZE + MD_ENTRY_SIZE_SIZE +
|
||||
// MD_ENTRY_TYPE_SIZE;
|
||||
// const size_t MD_ENTRY_SIZE = PROD_ID_SIZE + LAST_PROD_MSG_SEQ_SIZE +
|
||||
// NO_MD_ENTRIES_SIZE;
|
||||
|
||||
auto current_position = buffer.begin() + offset;
|
||||
|
||||
// Message Type
|
||||
message_type.assign(
|
||||
current_position, current_position + MESSAGE_TYPE_SIZE);
|
||||
current_position += MESSAGE_TYPE_SIZE;
|
||||
// message_type = buffer[offset];
|
||||
|
||||
switch (message_type[0]) {
|
||||
case 'A': {
|
||||
std::string seq_number_str =
|
||||
TaifexUtils::decodePackBCD(&(*current_position), LAST_SEQ_SIZE);
|
||||
last_seq = std::stoul(seq_number_str);
|
||||
current_position += LAST_SEQ_SIZE;
|
||||
break;
|
||||
}
|
||||
case 'O': {
|
||||
no_entries = static_cast<unsigned int>(*current_position);
|
||||
current_position += NO_ENTRIES_SIZE;
|
||||
/*-----------repeated No of Entries Times-----------*/
|
||||
for (unsigned int i = 0; i < no_entries; ++i) {
|
||||
// Prod ID
|
||||
prod_id.assign(
|
||||
current_position, current_position + PROD_ID_SIZE);
|
||||
current_position += PROD_ID_SIZE;
|
||||
|
||||
// Last Product Message Sequence
|
||||
std::string last_prod_msg_seq_str = TaifexUtils::decodePackBCD(
|
||||
&(*current_position), LAST_PROD_MSG_SEQ_SIZE);
|
||||
last_prod_msg_seq = std::stoul(last_prod_msg_seq_str);
|
||||
current_position += LAST_PROD_MSG_SEQ_SIZE;
|
||||
|
||||
// Number of Market Data Entries (PACK BCD)
|
||||
std::string no_md_entries_str = TaifexUtils::decodePackBCD(
|
||||
&(*current_position), NO_MD_ENTRIES_SIZE);
|
||||
no_md_entries = std::stoul(no_md_entries_str);
|
||||
current_position += NO_MD_ENTRIES_SIZE;
|
||||
|
||||
if (no_md_entries == 0) {
|
||||
|
||||
} else {
|
||||
for (int j = 0; j < no_md_entries; ++j) {
|
||||
|
||||
md_entry_type = *current_position;
|
||||
current_position += MD_ENTRY_TYPE_SIZE;
|
||||
|
||||
sign = static_cast<Sign>(
|
||||
*current_position - '0'); // Convert ASCII to integer
|
||||
current_position += 1;
|
||||
|
||||
std::string md_entry_px_str = TaifexUtils::decodePackBCD(
|
||||
&(*current_position), MD_ENTRY_PX_SIZE);
|
||||
md_entry_px = stod(md_entry_px_str);
|
||||
current_position += MD_ENTRY_PX_SIZE;
|
||||
|
||||
std::string md_entry_size_str = TaifexUtils::decodePackBCD(
|
||||
&(*current_position), MD_ENTRY_SIZE_SIZE);
|
||||
md_entry_size = std::stoul(md_entry_size_str);
|
||||
current_position += MD_ENTRY_SIZE_SIZE;
|
||||
|
||||
std::string md_price_level_str =
|
||||
TaifexUtils::decodePackBCD(
|
||||
&(*current_position), MD_PRICE_LEVEL_SIZE);
|
||||
md_price_level = std::stoul(md_price_level_str);
|
||||
current_position += MD_PRICE_LEVEL_SIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'S': {
|
||||
break;
|
||||
}
|
||||
case 'P': {
|
||||
break;
|
||||
}
|
||||
case 'Z': {
|
||||
std::string seq_number_str =
|
||||
TaifexUtils::decodePackBCD(&(*current_position), LAST_SEQ_SIZE);
|
||||
last_seq = std::stoul(seq_number_str);
|
||||
current_position += LAST_SEQ_SIZE;
|
||||
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
};
|
||||
struct I024Data {
|
||||
struct trade {
|
||||
enum Sign { POSITIVE = 0, NEGATIVE = 1 };
|
||||
|
||||
@@ -1,15 +1,65 @@
|
||||
#include "lib/logging/logging.h"
|
||||
#include <boost/date_time/posix_time/ptime.hpp>
|
||||
#include <boost/date_time/posix_time/time_parsers.hpp>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
#include <netinet/in.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace bts::md::taifex {
|
||||
class TaifexUtils {
|
||||
public:
|
||||
// Reusable function to create and join a multicast group
|
||||
static int create_multicast_socket(
|
||||
const std::string &multicast_ip,
|
||||
const int port,
|
||||
const std::string &interface_ip) {
|
||||
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (sock < 0) {
|
||||
std::string s = strerror(errno);
|
||||
LOG(md, Error, "Error creating socket: {}", s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int reuse = 1;
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) <
|
||||
0) {
|
||||
std::string s = strerror(errno);
|
||||
LOG(md, Error, "Error setting SO_REUSEADDR: {}", s);
|
||||
close(sock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sockaddr_in addr{};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
addr.sin_port = htons(port);
|
||||
|
||||
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
std::string s = strerror(errno);
|
||||
LOG(md, Error, "Error binding socket: {}", s);
|
||||
close(sock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ip_mreq mreq{};
|
||||
mreq.imr_multiaddr.s_addr = inet_addr(multicast_ip.c_str());
|
||||
mreq.imr_interface.s_addr = inet_addr(interface_ip.c_str());
|
||||
if (setsockopt(
|
||||
sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&mreq,
|
||||
sizeof(mreq)) < 0) {
|
||||
std::string s = strerror(errno);
|
||||
LOG(md, Error, "Error joining multicast group: {}", s);
|
||||
close(sock);
|
||||
return -1;
|
||||
}
|
||||
LOG(md, Info, "Joined multicast group on IP: {}, Port: {}", multicast_ip,
|
||||
port);
|
||||
return sock;
|
||||
}
|
||||
static void printBuffer(
|
||||
const std::vector<unsigned char> &buffer,
|
||||
size_t offset = 0,
|
||||
|
||||
Reference in new issue
Block a user