Upgrade ccapi to v6.12.0
This commit is contained in:
1 parent
8069cc893f
commit
90492733fd
109 files changed
+4172
-8930
No files matched your search
@@ -79,9 +79,6 @@
|
||||
#ifdef CCAPI_ENABLE_EXCHANGE_BYBIT
|
||||
#include "ccapi_cpp/service/ccapi_market_data_service_bybit.h"
|
||||
#endif
|
||||
#ifdef CCAPI_ENABLE_EXCHANGE_BYBIT_DERIVATIVES
|
||||
#include "ccapi_cpp/service/ccapi_market_data_service_bybit_derivatives.h"
|
||||
#endif
|
||||
#ifdef CCAPI_ENABLE_EXCHANGE_ASCENDEX
|
||||
#include "ccapi_cpp/service/ccapi_market_data_service_ascendex.h"
|
||||
#endif
|
||||
@@ -186,9 +183,6 @@
|
||||
#ifdef CCAPI_ENABLE_EXCHANGE_BYBIT
|
||||
#include "ccapi_cpp/service/ccapi_execution_management_service_bybit.h"
|
||||
#endif
|
||||
#ifdef CCAPI_ENABLE_EXCHANGE_BYBIT_DERIVATIVES
|
||||
#include "ccapi_cpp/service/ccapi_execution_management_service_bybit_derivatives.h"
|
||||
#endif
|
||||
#ifdef CCAPI_ENABLE_EXCHANGE_ASCENDEX
|
||||
#include "ccapi_cpp/service/ccapi_execution_management_service_ascendex.h"
|
||||
#endif
|
||||
@@ -227,9 +221,9 @@
|
||||
#ifdef CCAPI_ENABLE_EXCHANGE_FTX_US
|
||||
#include "ccapi_cpp/service/ccapi_fix_service_ftx_us.h"
|
||||
#endif
|
||||
#ifdef CCAPI_ENABLE_EXCHANGE_DERIBIT
|
||||
#include "ccapi_cpp/service/ccapi_fix_service_deribit.h"
|
||||
#endif
|
||||
// #ifdef CCAPI_ENABLE_EXCHANGE_DERIBIT
|
||||
// #include "ccapi_cpp/service/ccapi_fix_service_deribit.h"
|
||||
// #endif
|
||||
#endif
|
||||
// end: enable exchanges for FIX
|
||||
|
||||
@@ -259,15 +253,27 @@ class Session {
|
||||
Session(const Session&) = delete;
|
||||
Session& operator=(const Session&) = delete;
|
||||
Session(const SessionOptions& sessionOptions = SessionOptions(), const SessionConfigs& sessionConfigs = SessionConfigs(),
|
||||
EventHandler* eventHandler = nullptr, EventDispatcher* eventDispatcher = nullptr)
|
||||
EventHandler* eventHandler = nullptr, EventDispatcher* eventDispatcher = nullptr
|
||||
#ifndef SWIG
|
||||
,
|
||||
ServiceContext* serviceContextPtr = nullptr
|
||||
#endif
|
||||
)
|
||||
: sessionOptions(sessionOptions),
|
||||
sessionConfigs(sessionConfigs),
|
||||
eventHandler(eventHandler),
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
eventDispatcher(eventDispatcher),
|
||||
#endif
|
||||
eventQueue(sessionOptions.maxEventQueueSize),
|
||||
serviceContextPtr(new ServiceContext()) {
|
||||
eventQueue(sessionOptions.maxEventQueueSize)
|
||||
#ifndef SWIG
|
||||
,
|
||||
serviceContextPtr(serviceContextPtr)
|
||||
#endif
|
||||
{
|
||||
if (!this->serviceContextPtr) {
|
||||
this->serviceContextPtr = new ServiceContext();
|
||||
}
|
||||
CCAPI_LOGGER_FUNCTION_ENTER;
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
if (this->eventHandler) {
|
||||
@@ -291,6 +297,7 @@ class Session {
|
||||
delete this->eventDispatcher;
|
||||
}
|
||||
#endif
|
||||
delete this->serviceContextPtr;
|
||||
CCAPI_LOGGER_FUNCTION_EXIT;
|
||||
}
|
||||
virtual void start() {
|
||||
@@ -399,10 +406,6 @@ class Session {
|
||||
this->serviceByServiceNameExchangeMap[CCAPI_MARKET_DATA][CCAPI_EXCHANGE_NAME_BYBIT] =
|
||||
std::make_shared<MarketDataServiceBybit>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
|
||||
#endif
|
||||
#ifdef CCAPI_ENABLE_EXCHANGE_BYBIT_DERIVATIVES
|
||||
this->serviceByServiceNameExchangeMap[CCAPI_MARKET_DATA][CCAPI_EXCHANGE_NAME_BYBIT_DERIVATIVES] =
|
||||
std::make_shared<MarketDataServiceBybitDerivatives>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
|
||||
#endif
|
||||
#ifdef CCAPI_ENABLE_EXCHANGE_ASCENDEX
|
||||
this->serviceByServiceNameExchangeMap[CCAPI_MARKET_DATA][CCAPI_EXCHANGE_NAME_ASCENDEX] =
|
||||
std::make_shared<MarketDataServiceAscendex>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
|
||||
@@ -537,10 +540,6 @@ class Session {
|
||||
this->serviceByServiceNameExchangeMap[CCAPI_EXECUTION_MANAGEMENT][CCAPI_EXCHANGE_NAME_BYBIT] =
|
||||
std::make_shared<ExecutionManagementServiceBybit>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
|
||||
#endif
|
||||
#ifdef CCAPI_ENABLE_EXCHANGE_BYBIT_DERIVATIVES
|
||||
this->serviceByServiceNameExchangeMap[CCAPI_EXECUTION_MANAGEMENT][CCAPI_EXCHANGE_NAME_BYBIT_DERIVATIVES] =
|
||||
std::make_shared<ExecutionManagementServiceBybitDerivatives>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
|
||||
#endif
|
||||
#ifdef CCAPI_ENABLE_EXCHANGE_ASCENDEX
|
||||
this->serviceByServiceNameExchangeMap[CCAPI_EXECUTION_MANAGEMENT][CCAPI_EXCHANGE_NAME_ASCENDEX] =
|
||||
std::make_shared<ExecutionManagementServiceAscendex>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
|
||||
@@ -576,10 +575,10 @@ class Session {
|
||||
this->serviceByServiceNameExchangeMap[CCAPI_FIX][CCAPI_EXCHANGE_NAME_COINBASE] =
|
||||
std::make_shared<FixServiceCoinbase>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
|
||||
#endif
|
||||
#ifdef CCAPI_ENABLE_EXCHANGE_GEMINI
|
||||
this->serviceByServiceNameExchangeMap[CCAPI_FIX][CCAPI_EXCHANGE_NAME_GEMINI] =
|
||||
std::make_shared<FixServiceGemini>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
|
||||
#endif
|
||||
// #ifdef CCAPI_ENABLE_EXCHANGE_GEMINI
|
||||
// this->serviceByServiceNameExchangeMap[CCAPI_FIX][CCAPI_EXCHANGE_NAME_GEMINI] =
|
||||
// std::make_shared<FixServiceGemini>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
|
||||
// #endif
|
||||
#ifdef CCAPI_ENABLE_EXCHANGE_FTX
|
||||
this->serviceByServiceNameExchangeMap[CCAPI_FIX][CCAPI_EXCHANGE_NAME_FTX] =
|
||||
std::make_shared<FixServiceFtx>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
|
||||
@@ -588,10 +587,10 @@ class Session {
|
||||
this->serviceByServiceNameExchangeMap[CCAPI_FIX][CCAPI_EXCHANGE_NAME_FTX_US] =
|
||||
std::make_shared<FixServiceFtxUs>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
|
||||
#endif
|
||||
#ifdef CCAPI_ENABLE_EXCHANGE_DERIBIT
|
||||
this->serviceByServiceNameExchangeMap[CCAPI_FIX][CCAPI_EXCHANGE_NAME_DERIBIT] =
|
||||
std::make_shared<FixServiceDeribit>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
|
||||
#endif
|
||||
// #ifdef CCAPI_ENABLE_EXCHANGE_DERIBIT
|
||||
// this->serviceByServiceNameExchangeMap[CCAPI_FIX][CCAPI_EXCHANGE_NAME_DERIBIT] =
|
||||
// std::make_shared<FixServiceDeribit>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
|
||||
// #endif
|
||||
#endif
|
||||
for (const auto& x : this->serviceByServiceNameExchangeMap) {
|
||||
auto serviceName = x.first;
|
||||
@@ -623,6 +622,34 @@ class Session {
|
||||
}
|
||||
virtual void subscribe(std::vector<Subscription>& subscriptionList) {
|
||||
CCAPI_LOGGER_FUNCTION_ENTER;
|
||||
for (auto& subscription : subscriptionList) {
|
||||
auto exchange = subscription.getExchange();
|
||||
if (exchange == CCAPI_EXCHANGE_NAME_BYBIT) {
|
||||
auto instrumentType = subscription.getInstrumentType();
|
||||
if (instrumentType.empty()) {
|
||||
instrumentType = "spot";
|
||||
}
|
||||
std::vector<std::string> instrumentTypeList = {"spot", "linear", "inverse", "option"};
|
||||
if (std::find(instrumentTypeList.begin(), instrumentTypeList.end(), instrumentType) == instrumentTypeList.end()) {
|
||||
this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE,
|
||||
"unsupported exchange instrument types: " + toString(instrumentType) + ". Allowed values: " + toString(instrumentTypeList) + ".");
|
||||
return;
|
||||
}
|
||||
subscription.setInstrumentType(instrumentType);
|
||||
} else if (exchange == CCAPI_EXCHANGE_NAME_BITGET_FUTURES) {
|
||||
auto instrumentType = subscription.getInstrumentType();
|
||||
if (instrumentType.empty()) {
|
||||
instrumentType = "USDT-FUTURES";
|
||||
}
|
||||
std::vector<std::string> instrumentTypeList = {"USDT-FUTURES", "COIN-FUTURES", "USDC-FUTURES"};
|
||||
if (std::find(instrumentTypeList.begin(), instrumentTypeList.end(), instrumentType) == instrumentTypeList.end()) {
|
||||
this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE,
|
||||
"unsupported exchange instrument types: " + toString(instrumentType) + ". Allowed values: " + toString(instrumentTypeList) + ".");
|
||||
return;
|
||||
}
|
||||
subscription.setInstrumentType(instrumentType);
|
||||
}
|
||||
}
|
||||
std::map<std::string, std::vector<Subscription> > subscriptionListByServiceNameMap;
|
||||
for (const auto& subscription : subscriptionList) {
|
||||
auto serviceName = subscription.getServiceName();
|
||||
@@ -637,19 +664,10 @@ class Session {
|
||||
return;
|
||||
}
|
||||
if (serviceName == CCAPI_MARKET_DATA) {
|
||||
std::set<std::string> correlationIdSet;
|
||||
std::set<std::string> duplicateCorrelationIdSet;
|
||||
std::unordered_set<std::string> unsupportedExchangeFieldSet;
|
||||
std::map<std::string, std::vector<Subscription> > subscriptionListByExchangeMap;
|
||||
auto exchangeFieldMap = this->sessionConfigs.getExchangeFieldMap();
|
||||
CCAPI_LOGGER_DEBUG("exchangeFieldMap = " + toString(exchangeFieldMap));
|
||||
for (const auto& subscription : subscriptionList) {
|
||||
auto correlationId = subscription.getCorrelationId();
|
||||
if (correlationIdSet.find(correlationId) != correlationIdSet.end()) {
|
||||
duplicateCorrelationIdSet.insert(correlationId);
|
||||
} else {
|
||||
correlationIdSet.insert(correlationId);
|
||||
}
|
||||
auto exchange = subscription.getExchange();
|
||||
CCAPI_LOGGER_DEBUG("exchange = " + exchange);
|
||||
auto field = subscription.getField();
|
||||
@@ -661,29 +679,16 @@ class Session {
|
||||
CCAPI_LOGGER_DEBUG("unsupported exchange " + exchange + ", field = " + field);
|
||||
unsupportedExchangeFieldSet.insert(exchange + "|" + field);
|
||||
}
|
||||
subscriptionListByExchangeMap[exchange].push_back(subscription);
|
||||
}
|
||||
if (!duplicateCorrelationIdSet.empty()) {
|
||||
this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE,
|
||||
"duplicated correlation ids: " + toString(duplicateCorrelationIdSet));
|
||||
return;
|
||||
}
|
||||
if (!unsupportedExchangeFieldSet.empty()) {
|
||||
this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE,
|
||||
"unsupported exchange fields: " + toString(unsupportedExchangeFieldSet));
|
||||
return;
|
||||
}
|
||||
std::map<std::string, std::vector<Subscription> > subscriptionListByExchangeMap;
|
||||
for (const auto& subscription : subscriptionList) {
|
||||
auto exchange = subscription.getExchange();
|
||||
if (exchange == CCAPI_EXCHANGE_NAME_BYBIT_DERIVATIVES) {
|
||||
const auto& instrumentType = subscription.getInstrumentType();
|
||||
std::vector<std::string> instrumentTypeList = {"usdt-contract", "usdc-contract", "usdc-options"};
|
||||
if (std::find(instrumentTypeList.begin(), instrumentTypeList.end(), instrumentType) == instrumentTypeList.end()) {
|
||||
this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE,
|
||||
"unsupported exchange instrument types: " + toString(instrumentType) + ". Allowed values: " + toString(instrumentTypeList) + ".");
|
||||
return;
|
||||
}
|
||||
}
|
||||
subscriptionListByExchangeMap[exchange].push_back(subscription);
|
||||
}
|
||||
CCAPI_LOGGER_TRACE("subscriptionListByExchangeMap = " + toString(subscriptionListByExchangeMap));
|
||||
for (auto& subscriptionListByExchange : subscriptionListByExchangeMap) {
|
||||
@@ -821,13 +826,13 @@ class Session {
|
||||
this->sendRequestByWebsocket(x);
|
||||
}
|
||||
}
|
||||
virtual void sendRequest(Request& request, Queue<Event>* eventQueuePtr = nullptr, long delayMilliSeconds = 0) {
|
||||
virtual void sendRequest(Request& request, Queue<Event>* eventQueuePtr = nullptr, long delayMilliseconds = 0) {
|
||||
CCAPI_LOGGER_FUNCTION_ENTER;
|
||||
std::vector<Request> requestList({request});
|
||||
this->sendRequest(requestList, eventQueuePtr, delayMilliSeconds);
|
||||
this->sendRequest(requestList, eventQueuePtr, delayMilliseconds);
|
||||
CCAPI_LOGGER_FUNCTION_EXIT;
|
||||
}
|
||||
virtual void sendRequest(std::vector<Request>& requestList, Queue<Event>* eventQueuePtr = nullptr, long delayMilliSeconds = 0) {
|
||||
virtual void sendRequest(std::vector<Request>& requestList, Queue<Event>* eventQueuePtr = nullptr, long delayMilliseconds = 0) {
|
||||
CCAPI_LOGGER_FUNCTION_ENTER;
|
||||
std::vector<std::shared_ptr<std::future<void> > > futurePtrList;
|
||||
// std::set<std::string> serviceNameExchangeSet;
|
||||
@@ -854,7 +859,7 @@ class Session {
|
||||
// serviceNameExchangeSet.insert(key);
|
||||
// }
|
||||
auto now = UtilTime::now();
|
||||
auto futurePtr = servicePtr->sendRequest(request, !!eventQueuePtr, now, delayMilliSeconds, eventQueuePtr);
|
||||
auto futurePtr = servicePtr->sendRequest(request, !!eventQueuePtr, now, delayMilliseconds, eventQueuePtr);
|
||||
if (eventQueuePtr) {
|
||||
futurePtrList.push_back(futurePtr);
|
||||
}
|
||||
@@ -886,10 +891,24 @@ class Session {
|
||||
this->onEvent(event, eventQueuePtr);
|
||||
}
|
||||
#ifndef SWIG
|
||||
virtual void setTimer(const std::string& id, long delayMilliSeconds, std::function<void(const boost::system::error_code&)> errorHandler,
|
||||
virtual void setImmediate(std::function<void()> successHandler) {
|
||||
boost::asio::post(*this->serviceContextPtr->ioContextPtr, [this, successHandler]() {
|
||||
if (this->eventHandler) {
|
||||
#ifdef CCAPI_USE_SINGLE_THREAD
|
||||
successHandler();
|
||||
#else
|
||||
this->eventDispatcher->dispatch([successHandler] {
|
||||
successHandler();
|
||||
});
|
||||
#endif
|
||||
}
|
||||
});
|
||||
}
|
||||
virtual void setTimer(const std::string& id, long delayMilliseconds, std::function<void(const boost::system::error_code&)> errorHandler,
|
||||
std::function<void()> successHandler) {
|
||||
boost::asio::post(*this->serviceContextPtr->ioContextPtr, [this, id, delayMilliSeconds, errorHandler, successHandler]() {
|
||||
std::shared_ptr<steady_timer> timerPtr(new steady_timer(*this->serviceContextPtr->ioContextPtr, boost::asio::chrono::milliseconds(delayMilliSeconds)));
|
||||
boost::asio::post(*this->serviceContextPtr->ioContextPtr, [this, id, delayMilliseconds, errorHandler, successHandler]() {
|
||||
std::shared_ptr<boost::asio::steady_timer> timerPtr(
|
||||
new boost::asio::steady_timer(*this->serviceContextPtr->ioContextPtr, boost::asio::chrono::milliseconds(delayMilliseconds)));
|
||||
timerPtr->async_wait([this, id, errorHandler, successHandler](const boost::system::error_code& ec) {
|
||||
if (this->eventHandler) {
|
||||
#ifdef CCAPI_USE_SINGLE_THREAD
|
||||
@@ -932,19 +951,30 @@ class Session {
|
||||
}
|
||||
}
|
||||
}
|
||||
void forceCloseWebsocketConnections(const std::string& serviceName = "", const std::string& exchangeName = "") {
|
||||
for (const auto& x : this->serviceByServiceNameExchangeMap) {
|
||||
if (serviceName.empty() || serviceName == x.first) {
|
||||
for (const auto& y : x.second) {
|
||||
if (exchangeName.empty() || exchangeName == y.first) {
|
||||
y.second->forceCloseWebsocketConnections();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifndef CCAPI_EXPOSE_INTERNAL
|
||||
|
||||
private:
|
||||
protected:
|
||||
#endif
|
||||
SessionOptions sessionOptions;
|
||||
SessionConfigs sessionConfigs;
|
||||
EventHandler* eventHandler;
|
||||
EventHandler* eventHandler{nullptr};
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
EventDispatcher* eventDispatcher;
|
||||
EventDispatcher* eventDispatcher{nullptr};
|
||||
bool useInternalEventDispatcher{};
|
||||
#endif
|
||||
std::shared_ptr<ServiceContext> serviceContextPtr;
|
||||
ServiceContext* serviceContextPtr{nullptr};
|
||||
std::map<std::string, std::map<std::string, std::shared_ptr<Service> > > serviceByServiceNameExchangeMap;
|
||||
std::thread t;
|
||||
Queue<Event> eventQueue;
|
||||
|
||||
Reference in new issue
Block a user