can not receive some exchange market data
xtuyaowu opened this issue · 0 comments
1、user_specified_cmake_include.cmake
include_guard(DIRECTORY)
add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA)
add_compile_definitions(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT)
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_HUOBI)
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_KRAKEN)
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BINANCE_US)
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BINANCE)
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BITMEX)
find_package(ZLIB REQUIRED)
link_libraries(ZLIB::ZLIB)
2、CMakeLists.txt
set(NAME aggregate_arbitrage)
project(${NAME})
add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA)
add_compile_definitions(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT)
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_HUOBI)
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_KRAKEN)
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BINANCE_US)
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BINANCE)
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BITMEX)
find_package(ZLIB REQUIRED)
link_libraries(ZLIB::ZLIB)
add_executable(${NAME} main.cpp)
3、main.cpp
#include "ccapi_cpp/ccapi_session.h"
#include
#include <pthread.h>
#include
#include
namespace ccapi {
Logger* Logger::logger = nullptr; // This line is needed.
class MarketDataEventHandler : public EventHandler {
public:
bool processEvent(const Event& event, Session* session) override {
// std::cout << toString(event) + "\n" << std::endl;
if (event.getType() == Event::Type::SUBSCRIPTION_DATA) {
for (const auto& message : event.getMessageList()) {
auto correlationId = message.getCorrelationIdList().at(0);
std::cout << std::string("getTimeReceived: ") + std::to_string(UtilTime::getUnixTimestamp(message.getTimeReceived()))+
" getTime: "+ std::to_string(UtilTime::getUnixTimestamp(message.getTime())) << std::endl;
}
}
return true;
}
};
} /* namespace ccapi */
std::string roundPrice(double price) {
std::stringstream stream;
stream << std::fixed << std::setprecision(2) << price;
return stream.str();
}
using ::ccapi::Event;
using ::ccapi::EventDispatcher;
using ::ccapi::MarketDataEventHandler;
using ::ccapi::Request;
using ::ccapi::Session;
using ::ccapi::SessionConfigs;
using ::ccapi::SessionOptions;
using ::ccapi::Subscription;
using ::ccapi::UtilSystem;
void thread01_market_data_subscribe(void)
{
SessionOptions sessionOptions;
SessionConfigs sessionConfigs;
MarketDataEventHandler eventHandler;
Session session(sessionOptions, sessionConfigs, &eventHandler);
std::vector subscriptionList;
subscriptionList.emplace_back("huobi", "btcusdt", "MARKET_DEPTH", "", "huobi");
subscriptionList.emplace_back("kraken", "BTC/USDT", "MARKET_DEPTH", "", "kraken");
subscriptionList.emplace_back("binance-us", "BTCUSDT", "MARKET_DEPTH", "", "binance-us");
subscriptionList.emplace_back("binance", "BTCUSDT", "MARKET_DEPTH", "", "binance");
subscriptionList.emplace_back("bitmex", "BTCUSD", "MARKET_DEPTH", "", "bitmex");
session.subscribe(subscriptionList);
while (true) {
std::cout << "I'm waiting for arbitrage opportunities" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
}
return EXIT_SUCCESS;
}
int main(int argc, char** argv) {
std::cout << "Created Main thread!" << std::endl;
pthread_t market_data_thread;
pthread_create(&market_data_thread, NULL, &thread01_market_data_subscribe, NULL);
pthread_join(market_data_thread, NULL);
}