ccapi: Upgrade to v5.31.2
This commit is contained in:
1 parent
b91431e518
commit
7a3fae62c3
32 files changed
+203
-17
No files matched your search
@@ -15,6 +15,10 @@
|
||||
#include "ccapi_cpp/ccapi_macro.h"
|
||||
#include "ccapi_cpp/service/ccapi_service.h"
|
||||
namespace ccapi {
|
||||
/**
|
||||
* The ExecutionManagementService class inherits from the Service class and provides implemenations more specific to execution management such as order
|
||||
* submission, order cancellation, etc..
|
||||
*/
|
||||
class ExecutionManagementService : public Service {
|
||||
public:
|
||||
enum class JsonDataType {
|
||||
|
||||
@@ -357,6 +357,7 @@ class ExecutionManagementServiceFtxBase : public ExecutionManagementService {
|
||||
message.setElementList(elementList);
|
||||
messageList.emplace_back(std::move(message));
|
||||
} else if (channel == "orders" && fieldSet.find(CCAPI_EM_ORDER_UPDATE) != fieldSet.end()) {
|
||||
message.setTime(timeReceived);
|
||||
message.setType(Message::Type::EXECUTION_MANAGEMENT_EVENTS_ORDER_UPDATE);
|
||||
const std::map<std::string, std::pair<std::string, JsonDataType> >& extractionFieldNameMap = {
|
||||
{CCAPI_EM_ORDER_ID, std::make_pair("id", JsonDataType::STRING)},
|
||||
|
||||
@@ -79,7 +79,10 @@ class ExecutionManagementServiceHuobiBase : public ExecutionManagementService {
|
||||
}
|
||||
} else {
|
||||
if (key == "type") {
|
||||
value = (value == CCAPI_EM_ORDER_SIDE_BUY || value == "buy-limit") ? "buy-limit" : "sell-limit";
|
||||
if (value == CCAPI_EM_ORDER_SIDE_BUY)
|
||||
value = "buy-limit";
|
||||
else if (value == CCAPI_EM_ORDER_SIDE_SELL)
|
||||
value = "sell-limit";
|
||||
}
|
||||
}
|
||||
document.AddMember(rj::Value(key.c_str(), allocator).Move(), rj::Value(value.c_str(), allocator).Move(), allocator);
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_H_
|
||||
#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_H_
|
||||
#ifdef CCAPI_ENABLE_SERVICE_FIX
|
||||
#ifndef CCAPI_FIX_READ_BUFFER_SIZE
|
||||
#define CCAPI_FIX_READ_BUFFER_SIZE 1 << 20
|
||||
#endif
|
||||
#ifndef CCAPI_FIX_WRITE_BUFFER_SIZE
|
||||
#define CCAPI_FIX_WRITE_BUFFER_SIZE 1 << 20
|
||||
#endif
|
||||
#include "ccapi_cpp/service/ccapi_service.h"
|
||||
#include "hffix.hpp"
|
||||
namespace hff = hffix;
|
||||
namespace ccapi {
|
||||
template <class T>
|
||||
/**
|
||||
* Defines a service which provides access to exchange API and normalizes them. This is a base class that implements generic functionalities for dealing with
|
||||
* exchange FIX APIs. The Session object is responsible for routing requests and subscriptions to the desired concrete service.
|
||||
*/
|
||||
class FixService : public Service {
|
||||
public:
|
||||
FixService(std::function<void(Event&, Queue<Event>*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs,
|
||||
@@ -374,7 +384,7 @@ class FixService : public Service {
|
||||
auto& connectionId = fixConnectionPtr->id;
|
||||
auto& writeMessageBuffer = this->writeMessageBufferByConnectionIdMap[connectionId];
|
||||
auto& writeMessageBufferWrittenLength = this->writeMessageBufferWrittenLengthByConnectionIdMap[connectionId];
|
||||
size_t n = 0;
|
||||
size_t n = writeMessageBufferWrittenLength;
|
||||
for (const auto& param : paramList) {
|
||||
auto commonParam = this->createCommonParam(connectionId, nowFixTimeStr);
|
||||
hff::message_writer messageWriter(writeMessageBuffer.data() + n, writeMessageBuffer.data() + writeMessageBuffer.size());
|
||||
@@ -395,11 +405,13 @@ class FixService : public Service {
|
||||
n += messageWriter.message_end() - messageWriter.message_begin();
|
||||
}
|
||||
CCAPI_LOGGER_DEBUG("about to send " + printableString(writeMessageBuffer.data(), n));
|
||||
CCAPI_LOGGER_TRACE("writeMessageBufferWrittenLength = " + toString(writeMessageBufferWrittenLength));
|
||||
if (writeMessageBufferWrittenLength == 0) {
|
||||
CCAPI_LOGGER_TRACE("about to start write");
|
||||
this->startWrite_3(fixConnectionPtr, writeMessageBuffer.data(), n);
|
||||
}
|
||||
writeMessageBufferWrittenLength += n;
|
||||
writeMessageBufferWrittenLength = n;
|
||||
CCAPI_LOGGER_TRACE("writeMessageBufferWrittenLength = " + toString(writeMessageBufferWrittenLength));
|
||||
}
|
||||
void onPongByMethod(PingPongMethod method, std::shared_ptr<FixConnection<T>> fixConnectionPtr, const TimePoint& timeReceived) {
|
||||
CCAPI_LOGGER_FUNCTION_ENTER;
|
||||
@@ -517,9 +529,9 @@ class FixService : public Service {
|
||||
return {};
|
||||
}
|
||||
const size_t readMessageChunkSize = CCAPI_HFFIX_READ_MESSAGE_CHUNK_SIZE;
|
||||
std::map<std::string, std::array<char, 1 << 20>> readMessageBufferByConnectionIdMap;
|
||||
std::map<std::string, std::array<char, CCAPI_FIX_READ_BUFFER_SIZE>> readMessageBufferByConnectionIdMap;
|
||||
std::map<std::string, size_t> readMessageBufferReadLengthByConnectionIdMap;
|
||||
std::map<std::string, std::array<char, 1 << 20>> writeMessageBufferByConnectionIdMap;
|
||||
std::map<std::string, std::array<char, CCAPI_FIX_WRITE_BUFFER_SIZE>> writeMessageBufferByConnectionIdMap;
|
||||
std::map<std::string, size_t> writeMessageBufferWrittenLengthByConnectionIdMap;
|
||||
std::map<std::string, std::shared_ptr<FixConnection<T>>> fixConnectionPtrByIdMap;
|
||||
std::map<std::string, int> sequenceSentByConnectionIdMap;
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
#include "ccapi_cpp/ccapi_util_private.h"
|
||||
#include "ccapi_cpp/service/ccapi_service.h"
|
||||
namespace ccapi {
|
||||
/**
|
||||
* The MarketDataService class inherits from the Service class and provides implemenations more specific to market data such as order book, trades, etc..
|
||||
*/
|
||||
class MarketDataService : public Service {
|
||||
public:
|
||||
MarketDataService(std::function<void(Event&, Queue<Event>*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs,
|
||||
|
||||
@@ -24,7 +24,12 @@ class MarketDataServiceFtxBase : public MarketDataService {
|
||||
const std::map<std::string, std::string> optionMap) override {
|
||||
auto marketDepthRequested = std::stoi(optionMap.at(CCAPI_MARKET_DEPTH_MAX));
|
||||
if (field == CCAPI_MARKET_DEPTH) {
|
||||
this->marketDepthSubscribedToExchangeByConnectionIdChannelIdSymbolIdMap[wsConnection.id][channelId][symbolId] = 100;
|
||||
if (marketDepthRequested == 1) {
|
||||
channelId = CCAPI_WEBSOCKET_FTX_BASE_CHANNEL_TICKER;
|
||||
this->shouldAlignSnapshot = false;
|
||||
} else {
|
||||
this->marketDepthSubscribedToExchangeByConnectionIdChannelIdSymbolIdMap[wsConnection.id][channelId][symbolId] = 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
void pingOnApplicationLevel(wspp::connection_hdl hdl, ErrorCode& ec) override { this->send(hdl, R"({"op":"ping"})", wspp::frame::opcode::text, ec); }
|
||||
@@ -33,14 +38,15 @@ class MarketDataServiceFtxBase : public MarketDataService {
|
||||
for (const auto& subscriptionListByChannelIdSymbolId : this->subscriptionListByConnectionIdChannelIdSymbolIdMap.at(wsConnection.id)) {
|
||||
auto channelId = subscriptionListByChannelIdSymbolId.first;
|
||||
rj::Value channel(rj::kObjectType);
|
||||
rj::Value symbolIds(rj::kArrayType);
|
||||
for (const auto& subscriptionListBySymbolId : subscriptionListByChannelIdSymbolId.second) {
|
||||
rj::Document document;
|
||||
document.SetObject();
|
||||
rj::Document::AllocatorType& allocator = document.GetAllocator();
|
||||
document.AddMember("op", rj::Value("subscribe").Move(), allocator);
|
||||
std::string symbolId = subscriptionListBySymbolId.first;
|
||||
symbolIds.PushBack(rj::Value(symbolId.c_str(), allocator).Move(), allocator);
|
||||
if (channelId == CCAPI_WEBSOCKET_FTX_BASE_CHANNEL_TICKER) {
|
||||
this->l2UpdateIsReplaceByConnectionIdChannelIdSymbolIdMap[wsConnection.id][channelId][symbolId] = true;
|
||||
}
|
||||
std::string exchangeSubscriptionId = channelId + "|" + symbolId;
|
||||
std::string market = symbolId;
|
||||
std::string channelIdString = channelId;
|
||||
@@ -89,7 +95,33 @@ class MarketDataServiceFtxBase : public MarketDataService {
|
||||
auto symbolId = std::string(document["market"].GetString());
|
||||
auto channel = std::string(document["channel"].GetString());
|
||||
auto exchangeSubscriptionId = channel + "|" + symbolId;
|
||||
if (channel == CCAPI_WEBSOCKET_FTX_BASE_CHANNEL_ORDERBOOKS) {
|
||||
if (channel == CCAPI_WEBSOCKET_FTX_BASE_CHANNEL_TICKER) {
|
||||
MarketDataMessage marketDataMessage;
|
||||
marketDataMessage.type = MarketDataMessage::Type::MARKET_DATA_EVENTS_MARKET_DEPTH;
|
||||
marketDataMessage.exchangeSubscriptionId = exchangeSubscriptionId;
|
||||
auto timePair = UtilTime::divide(data["time"].GetString());
|
||||
auto tp = TimePoint(std::chrono::duration<int64_t>(timePair.first));
|
||||
tp += std::chrono::nanoseconds(timePair.second);
|
||||
marketDataMessage.tp = tp;
|
||||
if (this->processedInitialSnapshotByConnectionIdChannelIdSymbolIdMap[wsConnection.id][channel][symbolId]) {
|
||||
marketDataMessage.recapType = MarketDataMessage::RecapType::NONE;
|
||||
} else {
|
||||
marketDataMessage.recapType = MarketDataMessage::RecapType::SOLICITED;
|
||||
}
|
||||
{
|
||||
MarketDataMessage::TypeForDataPoint dataPoint;
|
||||
dataPoint.insert({MarketDataMessage::DataFieldType::PRICE, UtilString::normalizeDecimalString(data["bid"].GetString())});
|
||||
dataPoint.insert({MarketDataMessage::DataFieldType::SIZE, UtilString::normalizeDecimalString(data["bidSize"].GetString())});
|
||||
marketDataMessage.data[MarketDataMessage::DataType::BID].emplace_back(std::move(dataPoint));
|
||||
}
|
||||
{
|
||||
MarketDataMessage::TypeForDataPoint dataPoint;
|
||||
dataPoint.insert({MarketDataMessage::DataFieldType::PRICE, UtilString::normalizeDecimalString(data["ask"].GetString())});
|
||||
dataPoint.insert({MarketDataMessage::DataFieldType::SIZE, UtilString::normalizeDecimalString(data["askSize"].GetString())});
|
||||
marketDataMessage.data[MarketDataMessage::DataType::ASK].emplace_back(std::move(dataPoint));
|
||||
}
|
||||
marketDataMessageList.emplace_back(std::move(marketDataMessage));
|
||||
} else if (channel == CCAPI_WEBSOCKET_FTX_BASE_CHANNEL_ORDERBOOKS) {
|
||||
MarketDataMessage marketDataMessage;
|
||||
marketDataMessage.type = MarketDataMessage::Type::MARKET_DATA_EVENTS_MARKET_DEPTH;
|
||||
marketDataMessage.exchangeSubscriptionId = exchangeSubscriptionId;
|
||||
|
||||
@@ -60,6 +60,10 @@ using tcp = boost::asio::ip::tcp;
|
||||
namespace wspp = websocketpp;
|
||||
namespace rj = rapidjson;
|
||||
namespace ccapi {
|
||||
/**
|
||||
* Defines a service which provides access to exchange API and normalizes them. This is a base class that implements generic functionalities for dealing with
|
||||
* exchange REST and Websocket APIs. The Session object is responsible for routing requests and subscriptions to the desired concrete service.
|
||||
*/
|
||||
class Service : public std::enable_shared_from_this<Service> {
|
||||
public:
|
||||
typedef wspp::lib::shared_ptr<ServiceContext> ServiceContextPtr;
|
||||
@@ -361,6 +365,9 @@ class Service : public std::enable_shared_from_this<Service> {
|
||||
}
|
||||
CCAPI_LOGGER_TRACE("connected");
|
||||
beast::ssl_stream<beast::tcp_stream>& stream = *httpConnectionPtr->streamPtr;
|
||||
// #ifdef CCAPI_DISABLE_NAGLE_ALGORITHM
|
||||
beast::get_lowest_layer(stream).socket().set_option(tcp::no_delay(true));
|
||||
// #endif
|
||||
CCAPI_LOGGER_TRACE("before async_handshake");
|
||||
stream.async_handshake(ssl::stream_base::client,
|
||||
beast::bind_front_handler(&Service::onHandshake, shared_from_this(), httpConnectionPtr, req, errorHandler, responseHandler));
|
||||
@@ -467,6 +474,9 @@ class Service : public std::enable_shared_from_this<Service> {
|
||||
}
|
||||
CCAPI_LOGGER_TRACE("connected");
|
||||
beast::ssl_stream<beast::tcp_stream>& stream = *httpConnectionPtr->streamPtr;
|
||||
// #ifdef CCAPI_DISABLE_NAGLE_ALGORITHM
|
||||
beast::get_lowest_layer(stream).socket().set_option(tcp::no_delay(true));
|
||||
// #endif
|
||||
CCAPI_LOGGER_TRACE("before async_handshake");
|
||||
stream.async_handshake(ssl::stream_base::client,
|
||||
beast::bind_front_handler(&Service::onHandshake_2, shared_from_this(), httpConnectionPtr, request, req, retry, eventQueuePtr));
|
||||
|
||||
@@ -7,18 +7,23 @@
|
||||
#include "websocketpp/config/boost_config.hpp"
|
||||
namespace wspp = websocketpp;
|
||||
namespace ccapi {
|
||||
|
||||
/**
|
||||
* Defines the service that the service depends on.
|
||||
*/
|
||||
class ServiceContext CCAPI_FINAL {
|
||||
public:
|
||||
typedef wspp::lib::asio::io_service IoContext;
|
||||
typedef wspp::lib::shared_ptr<wspp::lib::asio::io_service> IoContextPtr;
|
||||
struct CustomClientConfig : public wspp::config::asio_tls_client {
|
||||
#ifdef WEBSOCKETPP_ENABLE_SINGLE_THREADING
|
||||
#ifdef CCAPI_USE_SINGLE_THREAD
|
||||
typedef wspp::config::asio_tls_client base;
|
||||
static bool const enable_multithreading = false;
|
||||
struct transport_config : public base::transport_config {
|
||||
static bool const enable_multithreading = false;
|
||||
};
|
||||
#endif
|
||||
#ifdef CCAPI_WEBSOCKET_READ_BUFFER_SIZE
|
||||
static const size_t connection_read_buffer_size = CCAPI_WEBSOCKET_READ_BUFFER_SIZE;
|
||||
#endif
|
||||
static const wspp::log::level alog_level = wspp::log::alevel::none;
|
||||
static const wspp::log::level elog_level = wspp::log::elevel::none;
|
||||
|
||||
Reference in new issue
Block a user