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
@@ -4,7 +4,10 @@
|
||||
|
||||
#include "ccapi_cpp/ccapi_util_private.h"
|
||||
namespace ccapi {
|
||||
// minimalistic just for the purpose of being used as the key of a map
|
||||
/**
|
||||
* This class provides a numeric type for representing an arbitrary precision decimal number. It is minimalistic for the purpose of high performance.
|
||||
* Furthermore, unlike double, it is suitable for being used as the key of a map.
|
||||
*/
|
||||
class Decimal CCAPI_FINAL {
|
||||
public:
|
||||
Decimal() {}
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
|
||||
#include "ccapi_cpp/ccapi_util_private.h"
|
||||
namespace ccapi {
|
||||
/**
|
||||
* Element represents an item in a message. The value(s) in an Element can be queried in a number of ways. Use the getValue() functions to retrieve a single
|
||||
* value. Use the getNameValueMap() function (or getTagValueMap() function for FIX API) to retrieve all the values.
|
||||
*/
|
||||
class Element CCAPI_FINAL {
|
||||
public:
|
||||
explicit Element(bool isFix = false) : isFix(isFix) {}
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
#include "ccapi_cpp/ccapi_logger.h"
|
||||
#include "ccapi_cpp/ccapi_message.h"
|
||||
namespace ccapi {
|
||||
/**
|
||||
** A single event resulting from a subscription or a request. Event objects are created by the API and passed to the application either through a registered
|
||||
*EventHandler or EventQueue. Event objects contain Message objects which can be accessed using the getMessageList() function. The Event object is a handle to an
|
||||
*event. The event is the basic unit of work provided to applications. Each Event object consists of an Type attribute and zero or more Message objects.
|
||||
*/
|
||||
|
||||
class Event CCAPI_FINAL {
|
||||
public:
|
||||
enum class Type {
|
||||
|
||||
@@ -13,6 +13,12 @@
|
||||
#include "ccapi_cpp/ccapi_logger.h"
|
||||
#include "ccapi_cpp/ccapi_util_private.h"
|
||||
namespace ccapi {
|
||||
/**
|
||||
* Dispatches events from one or more Sessions through callbacks. EventDispatcher objects are optionally specified when Session objects are constructed. A
|
||||
* single EventDispatcher can be shared by multiple Session objects. The EventDispatcher provides an event-driven interface, generating callbacks from one or
|
||||
* more internal threads for one or more sessions.
|
||||
*/
|
||||
|
||||
class EventDispatcher CCAPI_FINAL {
|
||||
public:
|
||||
explicit EventDispatcher(const int numDispatcherThreads = 1) : numDispatcherThreads(numDispatcherThreads) {
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
#include "ccapi_cpp/ccapi_event.h"
|
||||
namespace ccapi {
|
||||
class Session;
|
||||
/**
|
||||
* Defines the callback supplied by the application to process Events. Applications which use event driven programming supply instances of their own subclass of
|
||||
* this class to the Session to receive callbacks when an Event is available.
|
||||
*/
|
||||
class EventHandler {
|
||||
public:
|
||||
virtual ~EventHandler() {}
|
||||
|
||||
@@ -8,6 +8,9 @@ namespace beast = boost::beast;
|
||||
namespace ccapi {
|
||||
template <class T>
|
||||
class FixConnection CCAPI_FINAL {
|
||||
/**
|
||||
* This class represents a TCP socket connection for the FIX API.
|
||||
*/
|
||||
public:
|
||||
FixConnection(std::string host, std::string port, Subscription subscription, std::shared_ptr<T> streamPtr)
|
||||
: host(host), port(port), subscription(subscription), streamPtr(streamPtr) {
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
namespace beast = boost::beast;
|
||||
namespace ccapi {
|
||||
class HttpConnection CCAPI_FINAL {
|
||||
/**
|
||||
* This class represents a TCP socket connection for the REST API.
|
||||
*/
|
||||
public:
|
||||
HttpConnection(std::string host, std::string port, std::shared_ptr<beast::ssl_stream<beast::tcp_stream> > streamPtr)
|
||||
: host(host), port(port), streamPtr(streamPtr) {}
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
#define INCLUDE_CCAPI_CPP_CCAPI_HTTP_RETRY_H_
|
||||
#include <string>
|
||||
namespace ccapi {
|
||||
/**
|
||||
* This class is used for retrying http requests for the REST API.
|
||||
*/
|
||||
class HttpRetry CCAPI_FINAL {
|
||||
public:
|
||||
explicit HttpRetry(int numRetry = 0, int numRedirect = 0, std::string redirectUrlStr = "",
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#include "ccapi_cpp/ccapi_macro.h"
|
||||
#include "ccapi_cpp/ccapi_util_private.h"
|
||||
namespace ccapi {
|
||||
/**
|
||||
* This class is used for handling jwt tokens.
|
||||
*/
|
||||
class Jwt CCAPI_FINAL {
|
||||
public:
|
||||
static std::string generate(const Hmac::ShaVersion shaVersion, const std::string& secret, const std::string& payload) {
|
||||
|
||||
@@ -75,6 +75,9 @@
|
||||
#include "ccapi_cpp/ccapi_macro.h"
|
||||
#include "ccapi_cpp/ccapi_util.h"
|
||||
namespace ccapi {
|
||||
/**
|
||||
* This class is used for library logging.
|
||||
*/
|
||||
class Logger {
|
||||
public:
|
||||
std::string LOG_SEVERITY_FATAL = "FATAL";
|
||||
|
||||
@@ -261,6 +261,7 @@
|
||||
#define CCAPI_WEBSOCKET_KUCOIN_FUTURES_CHANNEL_MARKET_LEVEL2DEPTH50 "/contractMarket/level2Depth50"
|
||||
#define CCAPI_WEBSOCKET_FTX_BASE_CHANNEL_TRADES "trades"
|
||||
#define CCAPI_WEBSOCKET_FTX_BASE_CHANNEL_ORDERBOOKS "orderbook"
|
||||
#define CCAPI_WEBSOCKET_FTX_BASE_CHANNEL_TICKER "ticker"
|
||||
#define CCAPI_WEBSOCKET_DERIBIT_CHANNEL_TRADES "trades.{instrument_name}.{interval}"
|
||||
#define CCAPI_WEBSOCKET_DERIBIT_CHANNEL_BOOK "book.{instrument_name}.{group}.{depth}.{interval}"
|
||||
#define CCAPI_WEBSOCKET_DERIBIT_CHANNEL_BOOK_TBT "book.{instrument_name}.{interval}"
|
||||
@@ -474,7 +475,7 @@
|
||||
|
||||
// start: exchange REST urls
|
||||
#ifndef CCAPI_COINBASE_URL_REST_BASE
|
||||
#define CCAPI_COINBASE_URL_REST_BASE "https://api.pro.coinbase.com"
|
||||
#define CCAPI_COINBASE_URL_REST_BASE "https://api.exchange.coinbase.com"
|
||||
#endif
|
||||
#ifndef CCAPI_GEMINI_URL_REST_BASE
|
||||
#define CCAPI_GEMINI_URL_REST_BASE "https://api.gemini.com"
|
||||
@@ -639,7 +640,7 @@
|
||||
|
||||
// start: exchange WS urls
|
||||
#ifndef CCAPI_COINBASE_URL_WS_BASE
|
||||
#define CCAPI_COINBASE_URL_WS_BASE "wss://ws-feed.pro.coinbase.com"
|
||||
#define CCAPI_COINBASE_URL_WS_BASE "wss://ws-feed.exchange.coinbase.com"
|
||||
#endif
|
||||
#ifndef CCAPI_GEMINI_URL_WS_BASE
|
||||
#define CCAPI_GEMINI_URL_WS_BASE "wss://api.gemini.com"
|
||||
@@ -744,7 +745,7 @@
|
||||
|
||||
// start: exchange FIX urls
|
||||
#ifndef CCAPI_COINBASE_URL_FIX_BASE
|
||||
#define CCAPI_COINBASE_URL_FIX_BASE "tcp+ssl://fix.pro.coinbase.com:4198"
|
||||
#define CCAPI_COINBASE_URL_FIX_BASE "tcp+ssl://fix.exchange.coinbase.com:4198"
|
||||
#endif
|
||||
#ifndef CCAPI_GEMINI_URL_FIX_HOST
|
||||
#define CCAPI_GEMINI_URL_FIX_HOST ""
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
// #include "ccapi_message.h"
|
||||
namespace ccapi {
|
||||
class MarketDataMessage CCAPI_FINAL {
|
||||
/**
|
||||
* A handle to a single market data message. Each MarketDataMessage is associated with one 'exchangeSubscriptionId' value. The MarketDataMessage contents are
|
||||
* represented in its 'data' attribute. Each MarketDataMessage object consists of an Type attribute and a RecapType attribute. The exchange timestamp (if any)
|
||||
* associated with the MarketDataMessage object is represented in its 'tp' attribute.
|
||||
*/
|
||||
public:
|
||||
enum class Type {
|
||||
UNKNOWN,
|
||||
|
||||
@@ -6,6 +6,12 @@
|
||||
#include "ccapi_cpp/ccapi_element.h"
|
||||
#include "ccapi_cpp/ccapi_logger.h"
|
||||
namespace ccapi {
|
||||
/**
|
||||
* A handle to a single message. Message objects are obtained from the getMessageList() function of the Event object. Each Message is associated with one or
|
||||
* more correlation id values. The Message contents are represented as Elements and can be accessed via the getElementList() function. Each Message object
|
||||
* consists of an Type attribute and a RecapType attribute. The exchange timestamp (if any) associated with the Messsage object can be retrieved via the
|
||||
* getTime() function. The library timestamp can be retrieved via the getTimeReceived() function.
|
||||
*/
|
||||
class Message CCAPI_FINAL {
|
||||
public:
|
||||
enum class RecapType {
|
||||
|
||||
@@ -7,13 +7,18 @@
|
||||
#include "ccapi_cpp/ccapi_logger.h"
|
||||
namespace ccapi {
|
||||
template <class T>
|
||||
/**
|
||||
* This class represents a generic FIFO queue.
|
||||
*/
|
||||
class Queue {
|
||||
public:
|
||||
std::string EXCEPTION_QUEUE_FULL = "queue is full";
|
||||
std::string EXCEPTION_QUEUE_EMPTY = "queue is empty";
|
||||
explicit Queue(const size_t maxSize = 0) : maxSize(maxSize) {}
|
||||
void pushBack(T&& t) {
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
std::lock_guard<std::mutex> lock(this->m);
|
||||
#endif
|
||||
if (this->maxSize <= 0 || this->queue.size() < this->maxSize) {
|
||||
CCAPI_LOGGER_TRACE("this->queue.size() = " + size_tToString(this->queue.size()));
|
||||
this->queue.push_back(t);
|
||||
@@ -22,7 +27,9 @@ class Queue {
|
||||
}
|
||||
}
|
||||
T popBack() {
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
std::lock_guard<std::mutex> lock(this->m);
|
||||
#endif
|
||||
if (this->queue.empty()) {
|
||||
throw std::runtime_error(EXCEPTION_QUEUE_EMPTY);
|
||||
} else {
|
||||
@@ -32,13 +39,17 @@ class Queue {
|
||||
}
|
||||
}
|
||||
std::vector<T> purge() {
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
std::lock_guard<std::mutex> lock(this->m);
|
||||
#endif
|
||||
std::vector<T> p;
|
||||
std::swap(p, this->queue);
|
||||
return p;
|
||||
}
|
||||
void removeAll(std::vector<T>& c) {
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
std::lock_guard<std::mutex> lock(this->m);
|
||||
#endif
|
||||
if (c.empty()) {
|
||||
c = std::move(this->queue);
|
||||
} else {
|
||||
@@ -48,11 +59,15 @@ class Queue {
|
||||
this->queue.clear();
|
||||
}
|
||||
size_t size() const {
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
std::lock_guard<std::mutex> lock(this->m);
|
||||
#endif
|
||||
return this->queue.size();
|
||||
}
|
||||
bool empty() const {
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
std::lock_guard<std::mutex> lock(this->m);
|
||||
#endif
|
||||
return this->queue.empty();
|
||||
}
|
||||
#ifndef CCAPI_EXPOSE_INTERNAL
|
||||
@@ -60,7 +75,9 @@ class Queue {
|
||||
private:
|
||||
#endif
|
||||
std::vector<T> queue;
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
mutable std::mutex m;
|
||||
#endif
|
||||
size_t maxSize{};
|
||||
};
|
||||
} /* namespace ccapi */
|
||||
|
||||
@@ -8,6 +8,12 @@
|
||||
#include "ccapi_cpp/ccapi_macro.h"
|
||||
#include "ccapi_cpp/ccapi_util_private.h"
|
||||
namespace ccapi {
|
||||
/**
|
||||
* A single request. Request objects are created using Request constructors. They are used with Session::sendRequest() or Session::sendRequestByWebsocket() or
|
||||
* Session::sendRequestByFix(). The Request object contains the parameters for a single request. Once a Request has been created its fields can be further
|
||||
* modified using the convenience functions appendParam() or appendParamFix() or setParamList() or setParamListFix(). A correlation id can be used as the unique
|
||||
* identifier to tag all data associated with this request.
|
||||
*/
|
||||
class Request CCAPI_FINAL {
|
||||
public:
|
||||
static constexpr int operationTypeCustom = 0x100;
|
||||
@@ -130,6 +136,9 @@ class Request CCAPI_FINAL {
|
||||
const std::string& getServiceName() const { return serviceName; }
|
||||
void appendParam(const std::map<std::string, std::string>& param) { this->paramList.push_back(param); }
|
||||
void appendParamFix(const std::vector<std::pair<int, std::string> >& param) { this->paramListFix.push_back(param); }
|
||||
void appendParamListFix(const std::vector<std::vector<std::pair<int, std::string> > >& paramList) {
|
||||
this->paramListFix.insert(std::end(this->paramListFix), std::begin(paramList), std::end(paramList));
|
||||
}
|
||||
void setParamListFix(const std::vector<std::vector<std::pair<int, std::string> > >& paramListFix) { this->paramListFix = paramListFix; }
|
||||
Operation getOperation() const { return operation; }
|
||||
const std::vector<std::map<std::string, std::string> >& getParamList() const { return paramList; }
|
||||
|
||||
@@ -203,6 +203,12 @@
|
||||
#include "ccapi_cpp/service/ccapi_service_context.h"
|
||||
using steady_timer = boost::asio::steady_timer;
|
||||
namespace ccapi {
|
||||
/**
|
||||
* This class provides a consumer session for making requests and subscriptions for services. Sessions manage access to services either by requests and
|
||||
* responses or subscriptions. A Session can dispatch events and replies in either an immediate or batching mode. The mode of a Session is determined when it is
|
||||
* constructed and cannot be changed subsequently. A Session is immediate if an EventHandler object is supplied when it is constructed. All incoming events are
|
||||
* delivered to the EventHandler supplied on construction. A Session is batching if an EventHandler object is not supplied when it is constructed.
|
||||
*/
|
||||
class Session {
|
||||
public:
|
||||
Session(const Session&) = delete;
|
||||
@@ -614,6 +620,18 @@ class Session {
|
||||
} else {
|
||||
if (this->eventHandler) {
|
||||
CCAPI_LOGGER_TRACE("handle event in immediate mode");
|
||||
#ifdef CCAPI_USE_SINGLE_THREAD
|
||||
bool shouldContinue = true;
|
||||
try {
|
||||
shouldContinue = this->eventHandler->processEvent(event, this);
|
||||
} catch (const std::runtime_error& e) {
|
||||
CCAPI_LOGGER_ERROR(e.what());
|
||||
}
|
||||
if (!shouldContinue) {
|
||||
CCAPI_LOGGER_DEBUG("about to pause the event dispatcher");
|
||||
this->eventDispatcher->pause();
|
||||
}
|
||||
#else
|
||||
this->eventDispatcher->dispatch([that = this, event = std::move(event)] {
|
||||
bool shouldContinue = true;
|
||||
try {
|
||||
@@ -626,6 +644,7 @@ class Session {
|
||||
that->eventDispatcher->pause();
|
||||
}
|
||||
});
|
||||
#endif
|
||||
} else {
|
||||
CCAPI_LOGGER_TRACE("handle event in batching mode");
|
||||
this->eventQueue.pushBack(std::move(event));
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
#include "ccapi_cpp/ccapi_macro.h"
|
||||
#include "ccapi_cpp/ccapi_util_private.h"
|
||||
namespace ccapi {
|
||||
/**
|
||||
* This class contains the configs when creating a session. It loads and maintains exchange information. Most of the values shouldn't be changed. To use
|
||||
* non-default configs on a Session, create a SessionConfigs instance and set the required configs and then supply it when creating a Session.
|
||||
*/
|
||||
class SessionConfigs CCAPI_FINAL {
|
||||
public:
|
||||
explicit SessionConfigs(std::map<std::string, std::string> credential = {}) : credential(credential) {
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
#include "ccapi_cpp/ccapi_macro.h"
|
||||
#include "ccapi_cpp/ccapi_util_private.h"
|
||||
namespace ccapi {
|
||||
/**
|
||||
* This class contains the options which the user can specify when creating a session. To use non-default options on a Session, create a SessionOptions instance
|
||||
* and set the required options and then supply it when creating a Session.
|
||||
*/
|
||||
class SessionOptions CCAPI_FINAL {
|
||||
public:
|
||||
std::string toString() const {
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
#include "ccapi_cpp/ccapi_macro.h"
|
||||
#include "ccapi_cpp/ccapi_util_private.h"
|
||||
namespace ccapi {
|
||||
/**
|
||||
* A single subscription. A 'Subscription' is used when calling 'Session::subscribe()' or 'Session::subscribeByFix'. Subscription objects are created using
|
||||
* Subscription constructors. A correlation id can be used as the unique identifier to tag all data associated with this subscription.
|
||||
*/
|
||||
class Subscription CCAPI_FINAL {
|
||||
public:
|
||||
Subscription() {}
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#include "ccapi_cpp/ccapi_macro.h"
|
||||
#include "ccapi_cpp/ccapi_util_private.h"
|
||||
namespace ccapi {
|
||||
/**
|
||||
* This class represents a url.
|
||||
*/
|
||||
class Url CCAPI_FINAL {
|
||||
public:
|
||||
explicit Url(std::string urlStr) {
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
#include "ccapi_cpp/ccapi_util.h"
|
||||
#include "openssl/evp.h"
|
||||
namespace ccapi {
|
||||
/**
|
||||
* Utilities.
|
||||
*/
|
||||
class UtilString CCAPI_FINAL {
|
||||
public:
|
||||
static std::string roundInputBySignificantFigure(double input, int numSignificantFigure, int roundDirection) {
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#include "ccapi_cpp/ccapi_subscription.h"
|
||||
namespace wspp = websocketpp;
|
||||
namespace ccapi {
|
||||
/**
|
||||
* This class represents a TCP socket connection for the websocket API.
|
||||
*/
|
||||
class WsConnection CCAPI_FINAL {
|
||||
public:
|
||||
WsConnection(std::string url, std::string group, std::vector<Subscription> subscriptionList) : url(url), group(group), subscriptionList(subscriptionList) {
|
||||
|
||||
@@ -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