Skip to content

Commit

Permalink
Merge pull request #243 from crypto-chassis/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
cryptochassis committed Dec 30, 2021
2 parents f8b2db8 + d8fdec3 commit 7094194
Show file tree
Hide file tree
Showing 13 changed files with 953 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
* Code closely follows Bloomberg's API: https://www.bloomberg.com/professional/support/api-library/.
* It is ultra fast thanks to very careful optimizations: move semantics, regex optimization, locality of reference, lock contention minimization, etc.
* Supported exchanges:
* Market data: coinbase, gemini, kraken, kraken-futures, bitstamp, bitfinex, bitmex, binance-us, binance, binance-usds-futures, binance-coin-futures, huobi, huobi-usdt-swap, huobi-coin-swap, okex, erisx, kucoin, kucoin-futures, ftx, ftx-us, deribit, gateio, gateio-perpetual-futures.
* Execution Management: coinbase, gemini, kraken, kraken-futures, bitfinex, bitmex, binance-us, binance, binance-usds-futures, binance-coin-futures, huobi, huobi-usdt-swap, huobi-coin-swap, okex, erisx, kucoin, ftx, ftx-us, deribit, gateio, gateio-perpetual-futures.
* Market data: coinbase, gemini, kraken, kraken-futures, bitstamp, bitfinex, bitmex, binance-us, binance, binance-usds-futures, binance-coin-futures, huobi, huobi-usdt-swap, huobi-coin-swap, okex, erisx, kucoin, kucoin-futures, ftx, ftx-us, deribit, gateio, gateio-perpetual-futures, cryptocom.
* Execution Management: coinbase, gemini, kraken, kraken-futures, bitfinex, bitmex, binance-us, binance, binance-usds-futures, binance-coin-futures, huobi, huobi-usdt-swap, huobi-coin-swap, okex, erisx, kucoin, ftx, ftx-us, deribit, gateio, gateio-perpetual-futures, cryptocom.
* FIX: coinbase, gemini, ftx, ftx-us.
* A spot market making application is provided as an end-to-end solution for liquidity providers.
* A single order execution application is provided as an end-to-end solution for executing large orders.
Expand Down
6 changes: 6 additions & 0 deletions app/credential.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ GEMINI_API_SECRET=''
KRAKEN_API_KEY=''
KRAKEN_API_SECRET=''

BITFINEX_API_KEY=''
BITFINEX_API_SECRET=''

BINANCE_API_KEY=''
BINANCE_API_SECRET=''

Expand All @@ -34,3 +37,6 @@ FTX_US_API_SUBACCOUNT=''

GATEIO_API_KEY=''
GATEIO_API_SECRET=''

CRYPTOCOM_API_KEY=''
CRYPTOCOM_API_SECRET=''
17 changes: 8 additions & 9 deletions app/include/app/event_handler_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ class EventHandlerBase : public EventHandler {
auto remainingQuantity = element.getValue(CCAPI_EM_ORDER_REMAINING_QUANTITY);
bool filled = false;
if (!quantity.empty() && !cumulativeFilledQuantity.empty()) {
filled = UtilString::normalizeDecimalString(quantity) == UtilString::normalizeDecimalString(cumulativeFilledQuantity);
filled = Decimal(quantity).toString() == Decimal(cumulativeFilledQuantity).toString();
} else if (!remainingQuantity.empty()) {
filled = UtilString::normalizeDecimalString(remainingQuantity) == "0";
filled = Decimal(remainingQuantity).toString() == "0";
}
if (filled) {
this->numOpenOrders -= 1;
Expand Down Expand Up @@ -525,9 +525,7 @@ class EventHandlerBase : public EventHandler {
const auto& messageTimeReceived = firstMessage.getTimeReceived();
const auto& messageTimeReceivedISO = UtilTime::getISOTimestamp(messageTimeReceived);
if (firstMessage.getType() == Message::Type::RESPONSE_ERROR) {
for (const auto& element : firstMessage.getElementList()) {
APP_LOGGER_ERROR("Received an error: " + element.getValue(CCAPI_ERROR_MESSAGE) + ".");
}
APP_LOGGER_ERROR(event.toStringPretty() + ".");
}
if (std::find(correlationIdList.begin(), correlationIdList.end(), std::string("CREATE_ORDER_") + CCAPI_EM_ORDER_SIDE_BUY) != correlationIdList.end() ||
std::find(correlationIdList.begin(), correlationIdList.end(), std::string("CREATE_ORDER_") + CCAPI_EM_ORDER_SIDE_SELL) != correlationIdList.end() ||
Expand Down Expand Up @@ -581,8 +579,9 @@ class EventHandlerBase : public EventHandler {
this->accountBalanceCsvWriter->flush();
}
if (this->numOpenOrders == 0) {
size_t oldRequestListSize = requestList.size();
this->placeOrders(requestList, messageTimeReceived);
this->numOpenOrders = requestList.size();
this->numOpenOrders = requestList.size() - oldRequestListSize;
}
} else if (std::find(correlationIdList.begin(), correlationIdList.end(), "GET_INSTRUMENT") != correlationIdList.end()) {
const auto& element = firstMessage.getElementList().at(0);
Expand Down Expand Up @@ -691,9 +690,9 @@ class EventHandlerBase : public EventHandler {
if (message.getType() == Message::Type::SESSION_CONNECTION_UP) {
for (const auto& correlationId : message.getCorrelationIdList()) {
if (correlationId == PRIVATE_SUBSCRIPTION_DATA_CORRELATION_ID) {
const auto& messageTime = message.getTime();
const auto& messageTimeISO = UtilTime::getISOTimestamp(messageTime);
this->cancelOpenOrders(requestList, messageTime, messageTimeISO, true);
const auto& messageTimeReceived = message.getTimeReceived();
const auto& messageTimeReceivedISO = UtilTime::getISOTimestamp(messageTimeReceived);
this->cancelOpenOrders(requestList, messageTimeReceived, messageTimeReceivedISO, true);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/user_specified_cmake_include.cmake.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ endif()
#
# add_compile_definitions(CCAPI_ENABLE_EXCHANGE_GATEIO)
#
# add_compile_definitions(CCAPI_ENABLE_EXCHANGE_CRYPTOCOM)
#
# find_package(ZLIB REQUIRED)
# link_libraries(ZLIB::ZLIB)

Expand Down
2 changes: 2 additions & 0 deletions binding/user_specified_cmake_include.cmake.example
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ include_guard(DIRECTORY)
# add_compile_definitions(CCAPI_ENABLE_EXCHANGE_GATEIO)
# add_compile_definitions(CCAPI_ENABLE_EXCHANGE_GATEIO_PERPETUAL_FUTURES)
#
# add_compile_definitions(CCAPI_ENABLE_EXCHANGE_CRYPTOCOM)
#
# add_compile_definitions(CCAPI_ENABLE_LOG_TRACE)
#
# add_compile_definitions(CCAPI_ENABLE_LOG_DEBUG)
Expand Down
17 changes: 17 additions & 0 deletions include/ccapi_cpp/ccapi_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@
#ifndef CCAPI_EXCHANGE_NAME_GATEIO_PERPETUAL_FUTURES
#define CCAPI_EXCHANGE_NAME_GATEIO_PERPETUAL_FUTURES "gateio-perpetual-futures"
#endif
#ifndef CCAPI_EXCHANGE_NAME_CRYPTOCOM
#define CCAPI_EXCHANGE_NAME_CRYPTOCOM "cryptocom"
#endif
// #ifndef CCAPI_EXCHANGE_NAME_BYBIT
// #define CCAPI_EXCHANGE_NAME_BYBIT "bybit"
// #endif
Expand Down Expand Up @@ -265,6 +268,8 @@
#define CCAPI_WEBSOCKET_GATEIO_PERPETUAL_FUTURES_CHANNEL_TRADES "futures.trades"
#define CCAPI_WEBSOCKET_GATEIO_PERPETUAL_FUTURES_CHANNEL_BOOK_TICKER "futures.book_ticker"
#define CCAPI_WEBSOCKET_GATEIO_PERPETUAL_FUTURES_CHANNEL_ORDER_BOOK "futures.order_book"
#define CCAPI_WEBSOCKET_CRYPTOCOM_CHANNEL_TRADE "trade.{instrument_name}"
#define CCAPI_WEBSOCKET_CRYPTOCOM_CHANNEL_BOOK "book.{instrument_name}.{depth}"
// #define CCAPI_WEBSOCKET_BYBIT_CHANNEL_TRADE "trade"
// #define CCAPI_WEBSOCKET_BYBIT_CHANNEL_BOOK_TICKER "bookTicker"
// #define CCAPI_WEBSOCKET_BYBIT_CHANNEL_DEPTH "depth"
Expand Down Expand Up @@ -587,6 +592,9 @@
#ifndef CCAPI_GATEIO_PERPETUAL_FUTURES_URL_REST_BASE
#define CCAPI_GATEIO_PERPETUAL_FUTURES_URL_REST_BASE "https://fx-api.gateio.ws"
#endif
#ifndef CCAPI_CRYPTOCOM_URL_REST_BASE
#define CCAPI_CRYPTOCOM_URL_REST_BASE "https://api.crypto.com"
#endif
// #ifndef CCAPI_BYBIT_URL_REST_BASE
// #define CCAPI_BYBIT_URL_REST_BASE "https://api.bybit.com"
// #endif
Expand Down Expand Up @@ -686,6 +694,9 @@
#ifndef CCAPI_GATEIO_PERPETUAL_FUTURES_URL_WS_BASE
#define CCAPI_GATEIO_PERPETUAL_FUTURES_URL_WS_BASE "wss://fx-ws.gateio.ws"
#endif
#ifndef CCAPI_CRYPTOCOM_URL_WS_BASE
#define CCAPI_CRYPTOCOM_URL_WS_BASE "wss://stream.crypto.com"
#endif
// #ifndef CCAPI_BYBIT_URL_WS_BASE
// #define CCAPI_BYBIT_URL_WS_BASE "https://api.bybit.com"
// #endif
Expand Down Expand Up @@ -884,6 +895,12 @@
#ifndef CCAPI_GATEIO_PERPETUAL_FUTURES_API_SECRET
#define CCAPI_GATEIO_PERPETUAL_FUTURES_API_SECRET "GATEIO_PERPETUAL_FUTURES_API_SECRET"
#endif
#ifndef CCAPI_CRYPTOCOM_API_KEY
#define CCAPI_CRYPTOCOM_API_KEY "CRYPTOCOM_API_KEY"
#endif
#ifndef CCAPI_CRYPTOCOM_API_SECRET
#define CCAPI_CRYPTOCOM_API_SECRET "CRYPTOCOM_API_SECRET"
#endif
// #ifndef CCAPI_BYBIT_API_KEY
// #define CCAPI_BYBIT_API_KEY "BYBIT_API_KEY"
// #endif
Expand Down
14 changes: 14 additions & 0 deletions include/ccapi_cpp/ccapi_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
#ifdef CCAPI_ENABLE_EXCHANGE_GATEIO_PERPETUAL_FUTURES
#include "ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h"
#endif
#ifdef CCAPI_ENABLE_EXCHANGE_CRYPTOCOM
#include "ccapi_cpp/service/ccapi_market_data_service_cryptocom.h"
#endif
#endif
// end: enable exchanges for market data

Expand Down Expand Up @@ -144,6 +147,9 @@
#ifdef CCAPI_ENABLE_EXCHANGE_GATEIO_PERPETUAL_FUTURES
#include "ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h"
#endif
#ifdef CCAPI_ENABLE_EXCHANGE_CRYPTOCOM
#include "ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h"
#endif
#endif
// end: enable exchanges for execution management

Expand Down Expand Up @@ -311,6 +317,10 @@ class Session {
this->serviceByServiceNameExchangeMap[CCAPI_MARKET_DATA][CCAPI_EXCHANGE_NAME_GATEIO_PERPETUAL_FUTURES] =
std::make_shared<MarketDataServiceGateioPerpetualFutures>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
#endif
#ifdef CCAPI_ENABLE_EXCHANGE_CRYPTOCOM
this->serviceByServiceNameExchangeMap[CCAPI_MARKET_DATA][CCAPI_EXCHANGE_NAME_CRYPTOCOM] =
std::make_shared<MarketDataServiceCryptocom>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
#endif
#endif
#ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT
#ifdef CCAPI_ENABLE_EXCHANGE_COINBASE
Expand Down Expand Up @@ -402,6 +412,10 @@ class Session {
this->serviceByServiceNameExchangeMap[CCAPI_EXECUTION_MANAGEMENT][CCAPI_EXCHANGE_NAME_GATEIO_PERPETUAL_FUTURES] =
std::make_shared<ExecutionManagementServiceGateioPerpetualFutures>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
#endif
#ifdef CCAPI_ENABLE_EXCHANGE_CRYPTOCOM
this->serviceByServiceNameExchangeMap[CCAPI_EXECUTION_MANAGEMENT][CCAPI_EXCHANGE_NAME_CRYPTOCOM] =
std::make_shared<ExecutionManagementServiceCryptocom>(this->internalEventHandler, sessionOptions, sessionConfigs, this->serviceContextPtr);
#endif
#endif
#ifdef CCAPI_ENABLE_SERVICE_FIX
#ifdef CCAPI_ENABLE_EXCHANGE_COINBASE
Expand Down
12 changes: 11 additions & 1 deletion include/ccapi_cpp/ccapi_session_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ class SessionConfigs CCAPI_FINAL {
{CCAPI_TRADE, CCAPI_WEBSOCKET_GATEIO_PERPETUAL_FUTURES_CHANNEL_TRADES},
{CCAPI_MARKET_DEPTH, CCAPI_WEBSOCKET_GATEIO_PERPETUAL_FUTURES_CHANNEL_ORDER_BOOK},
};
std::map<std::string, std::string> fieldWebsocketChannelMapCryptocom = {
{CCAPI_TRADE, CCAPI_WEBSOCKET_CRYPTOCOM_CHANNEL_TRADE},
{CCAPI_MARKET_DEPTH, CCAPI_WEBSOCKET_CRYPTOCOM_CHANNEL_BOOK},
};
for (auto const& fieldWebsocketChannel : fieldWebsocketChannelMapCoinbase) {
this->exchangeFieldMap[CCAPI_EXCHANGE_NAME_COINBASE].push_back(fieldWebsocketChannel.first);
}
Expand Down Expand Up @@ -192,6 +196,9 @@ class SessionConfigs CCAPI_FINAL {
for (auto const& fieldWebsocketChannel : fieldWebsocketChannelMapGateioPerpetualFutures) {
this->exchangeFieldMap[CCAPI_EXCHANGE_NAME_GATEIO_PERPETUAL_FUTURES].push_back(fieldWebsocketChannel.first);
}
for (auto const& fieldWebsocketChannel : fieldWebsocketChannelMapCryptocom) {
this->exchangeFieldMap[CCAPI_EXCHANGE_NAME_CRYPTOCOM].push_back(fieldWebsocketChannel.first);
}
for (auto& x : this->exchangeFieldMap) {
x.second.push_back(CCAPI_GENERIC_PUBLIC_SUBSCRIPTION);
}
Expand Down Expand Up @@ -220,6 +227,7 @@ class SessionConfigs CCAPI_FINAL {
{CCAPI_EXCHANGE_NAME_DERIBIT, fieldWebsocketChannelMapDeribit},
{CCAPI_EXCHANGE_NAME_GATEIO, fieldWebsocketChannelMapGateio},
{CCAPI_EXCHANGE_NAME_GATEIO_PERPETUAL_FUTURES, fieldWebsocketChannelMapGateioPerpetualFutures},
{CCAPI_EXCHANGE_NAME_CRYPTOCOM, fieldWebsocketChannelMapCryptocom},
};
this->urlWebsocketBase = {
{CCAPI_EXCHANGE_NAME_COINBASE, CCAPI_COINBASE_URL_WS_BASE},
Expand All @@ -228,7 +236,7 @@ class SessionConfigs CCAPI_FINAL {
{CCAPI_EXCHANGE_NAME_KRAKEN_FUTURES, CCAPI_KRAKEN_FUTURES_URL_WS_BASE},
{CCAPI_EXCHANGE_NAME_BITSTAMP, CCAPI_BITSTAMP_URL_WS_BASE},
// Bitfinex has different urls for public and private APIs. Here it is only a placeholder for subscription grouping purposes.
{CCAPI_EXCHANGE_NAME_BITFINEX, "CCAPI_BITFINEX_URL_WS_BASE"},
{CCAPI_EXCHANGE_NAME_BITFINEX, ""},
{CCAPI_EXCHANGE_NAME_BITMEX, CCAPI_BITMEX_URL_WS_BASE},
{CCAPI_EXCHANGE_NAME_BINANCE_US, CCAPI_BINANCE_US_URL_WS_BASE},
{CCAPI_EXCHANGE_NAME_BINANCE, CCAPI_BINANCE_URL_WS_BASE},
Expand All @@ -248,6 +256,7 @@ class SessionConfigs CCAPI_FINAL {
{CCAPI_EXCHANGE_NAME_DERIBIT, CCAPI_DERIBIT_URL_WS_BASE},
{CCAPI_EXCHANGE_NAME_GATEIO, CCAPI_GATEIO_URL_WS_BASE},
{CCAPI_EXCHANGE_NAME_GATEIO_PERPETUAL_FUTURES, CCAPI_GATEIO_PERPETUAL_FUTURES_URL_WS_BASE},
{CCAPI_EXCHANGE_NAME_CRYPTOCOM, CCAPI_CRYPTOCOM_URL_WS_BASE},
};
this->initialSequenceByExchangeMap = {{CCAPI_EXCHANGE_NAME_GEMINI, 0}, {CCAPI_EXCHANGE_NAME_BITFINEX, 1}};
}
Expand Down Expand Up @@ -277,6 +286,7 @@ class SessionConfigs CCAPI_FINAL {
{CCAPI_EXCHANGE_NAME_DERIBIT, CCAPI_DERIBIT_URL_REST_BASE},
{CCAPI_EXCHANGE_NAME_GATEIO, CCAPI_GATEIO_URL_REST_BASE},
{CCAPI_EXCHANGE_NAME_GATEIO_PERPETUAL_FUTURES, CCAPI_GATEIO_PERPETUAL_FUTURES_URL_REST_BASE},
{CCAPI_EXCHANGE_NAME_CRYPTOCOM, CCAPI_CRYPTOCOM_URL_REST_BASE},
};
}
void initializUrlFixBase() {
Expand Down
Loading

0 comments on commit 7094194

Please sign in to comment.