diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 72ded1bb0..56fff5d5c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,6 +14,10 @@ on: - '**/README.md' - '**.example' +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + env: CMAKE_VERSION: 3.17.5 NINJA_VERSION: 1.9.0 @@ -53,7 +57,7 @@ jobs: # } steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - name: Download Ninja and CMake id: cmake_and_ninja diff --git a/README.md b/README.md index 69891b921..e86f9e046 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ * Example CMake: example/CMakeLists.txt. * Require C++17 and OpenSSL. * Macros in the compiler command line: - * Define service enablement macro such as `CCAPI_ENABLE_SERVICE_MARKET_DATA`, `CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT`, `CCAPI_ENABLE_SERVICE_FIX`, etc. and exchange enablement macros such as `CCAPI_ENABLE_EXCHANGE_OKX`, etc. These macros can be found at the top of [`include/ccapi_cpp/ccapi_session.h`](include/ccapi_cpp/ccapi_session.h). + * Define service enablement macro such as `CCAPI_ENABLE_SERVICE_MARKET_DATA`, `CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT`, `CCAPI_ENABLE_SERVICE_FIX`, etc. and exchange enablement macros such as `CCAPI_ENABLE_EXCHANGE_BYBIT`, etc. These macros can be found at the top of [`include/ccapi_cpp/ccapi_session.h`](include/ccapi_cpp/ccapi_session.h). * Dependencies: * boost https://archives.boost.io/release/1.87.0/source/boost_1_87_0.tar.gz (notice that its include directory is boost). * rapidjson https://github.com/Tencent/rapidjson/archive/refs/tags/v1.1.0.tar.gz (notice that its include directory is rapidjson/include). @@ -212,7 +212,7 @@ For a specific exchange and instrument, get recents trades. **Code 1:** -[C++](example/src/market_data_simple_request/main.cpp) / [Python](binding/python/example/market_data_simple_request/main.py) / [Java](binding/java/example/market_data_simple_request/Main.java) / [C#](binding/csharp/example/market_data_simple_request/MainProgram.cs) / [Go](binding/go/example/market_data_simple_request/main.go) / [Javascript](binding/javascript/example/market_data_simple_request/index.js) +[C++](example/market_data_simple_request/main.cpp) / [Python](binding/python/example/market_data_simple_request/main.py) / [Java](binding/java/example/market_data_simple_request/Main.java) / [C#](binding/csharp/example/market_data_simple_request/MainProgram.cs) / [Go](binding/go/example/market_data_simple_request/main.go) / [Javascript](binding/javascript/example/market_data_simple_request/index.js) ``` #include "ccapi_cpp/ccapi_session.h" @@ -240,7 +240,7 @@ int main(int argc, char** argv) { SessionConfigs sessionConfigs; MyEventHandler eventHandler; Session session(sessionOptions, sessionConfigs, &eventHandler); - Request request(Request::Operation::GET_RECENT_TRADES, "okx", "BTC-USDT"); + Request request(Request::Operation::GET_RECENT_TRADES, "bybit", "BTCUSDT"); request.appendParam({ {"LIMIT", "1"}, }); @@ -281,7 +281,7 @@ Received an event: Bye ``` * Request operation types: `GET_SERVER_TIME`, `GET_INSTRUMENT`, `GET_INSTRUMENTS`, `GET_BBOS`, `GET_RECENT_TRADES`, `GET_HISTORICAL_TRADES`, `GET_RECENT_CANDLESTICKS`, `GET_HISTORICAL_CANDLESTICKS`, `GET_RECENT_AGG_TRADES`, `GET_HISTORICAL_AGG_TRADES`(only applicable to binance family: https://binance-docs.github.io/apidocs/spot/en/#compressed-aggregate-trades-list), ``. -* Request parameter names: `LIMIT`, `INSTRUMENT_TYPE`, `CANDLESTICK_INTERVAL_SECONDS`, `START_TIME_SECONDS`, `END_TIME_SECONDS`, `START_TRADE_ID`, `END_TRADE_ID`, `START_AGG_TRADE_ID`, `END_AGG_TRADE_ID`. Instead of these convenient names you can also choose to use arbitrary parameter names and they will be passed to the exchange's native API. See [this example](example/src/market_data_advanced_request/main.cpp). +* Request parameter names: `LIMIT`, `INSTRUMENT_TYPE`, `CANDLESTICK_INTERVAL_SECONDS`, `START_TIME_SECONDS`, `END_TIME_SECONDS`, `START_TRADE_ID`, `END_TRADE_ID`, `START_AGG_TRADE_ID`, `END_AGG_TRADE_ID`. Instead of these convenient names you can also choose to use arbitrary parameter names and they will be passed to the exchange's native API. See [this example](example/market_data_advanced_request/main.cpp). * Message's `time` represents the exchange's reported timestamp. Its `timeReceived` represents the library's receiving timestamp. `time` can be retrieved by `getTime` method and `timeReceived` can be retrieved by `getTimeReceived` method. (For non-C++, please use `getTimeUnix` and `getTimeReceivedUnix` methods or `getTimeISO` and `getTimeReceivedISO` methods). **Objective 2:** @@ -290,7 +290,7 @@ For a specific exchange and instrument, whenever the best bid's or ask's price o **Code 2:** -[C++](example/src/market_data_simple_subscription/main.cpp) / [Python](binding/python/example/market_data_simple_subscription/main.py) / [Java](binding/java/example/market_data_simple_subscription/Main.java) / [C#](binding/csharp/example/market_data_simple_subscription/MainProgram.cs) / [Go](binding/go/example/market_data_simple_subscription/main.go) / [Javascript](binding/javascript/example/market_data_simple_subscription/index.js) +[C++](example/market_data_simple_subscription/main.cpp) / [Python](binding/python/example/market_data_simple_subscription/main.py) / [Java](binding/java/example/market_data_simple_subscription/Main.java) / [C#](binding/csharp/example/market_data_simple_subscription/MainProgram.cs) / [Go](binding/go/example/market_data_simple_subscription/main.go) / [Javascript](binding/javascript/example/market_data_simple_subscription/index.js) ``` #include "ccapi_cpp/ccapi_session.h" @@ -331,7 +331,7 @@ int main(int argc, char** argv) { SessionConfigs sessionConfigs; MyEventHandler eventHandler; Session session(sessionOptions, sessionConfigs, &eventHandler); - Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH"); + Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH"); session.subscribe(subscription); std::this_thread::sleep_for(std::chrono::seconds(10)); session.stop(); @@ -354,13 +354,12 @@ Best bid and ask at 2020-07-27T23:56:51.935993000Z are: ### Advanced Market Data #### Complex request parameters -Please follow the exchange's API documentations: e.g. https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-trades-history. +Please follow the exchange's API documentations: e.g. https://bybit-exchange.github.io/docs/v5/market/instrument. ``` -Request request(Request::Operation::GET_HISTORICAL_TRADES, "okx", "BTC-USDT"); +Request request(Request::Operation::GET_INSTRUMENTS, "bybit"); request.appendParam({ - {"before", "1"}, - {"after", "3"}, - {"limit", "1"}, + {"category", "linear"}, + {"limit", "1000"}, }); ``` @@ -368,18 +367,18 @@ request.appendParam({ Instantiate `Subscription` with option `MARKET_DEPTH_MAX` set to be the desired market depth (e.g. you want to receive market depth snapshot whenever the top 10 bid's or ask's price or size changes). ``` -Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH", "MARKET_DEPTH_MAX=10"); +Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH", "MARKET_DEPTH_MAX=10"); ``` #### Specify correlation id Instantiate `Request` with the desired correlationId. The `correlationId` should be unique. ``` -Request request(Request::Operation::GET_RECENT_TRADES, "okx", "BTC-USDT", "cool correlation id"); +Request request(Request::Operation::GET_RECENT_TRADES, "bybit", "BTCUSDT", "cool correlation id"); ``` Instantiate `Subscription` with the desired correlationId. ``` -Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH", "", "cool correlation id"); +Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH", "", "cool correlation id"); ``` This is used to match a particular request or subscription with its returned data. Within each `Message` there is a `correlationIdList` to identify the request or subscription that requested the data. @@ -387,7 +386,7 @@ This is used to match a particular request or subscription with its returned dat Send a `std::vector`. ``` -Request request_1(Request::Operation::GET_RECENT_TRADES, "okx", "BTC-USDT", "cool correlation id for BTC"); +Request request_1(Request::Operation::GET_RECENT_TRADES, "bybit", "BTCUSDT", "cool correlation id for BTC"); request_1.appendParam(...); Request request_2(Request::Operation::GET_RECENT_TRADES, "binance", "ETH-USDT", "cool correlation id for ETH"); request_2.appendParam(...); @@ -396,8 +395,8 @@ session.sendRequest(requests); ``` Subscribe a `std::vector`. ``` -Subscription subscription_1("okx", "BTC-USDT", "MARKET_DEPTH", "", "cool correlation id for okx BTC-USDT"); -Subscription subscription_2("binance", "ETH-USDT", "MARKET_DEPTH", "", "cool correlation id for binance ETH-USDT"); +Subscription subscription_1("bybit", "BTCUSDT", "MARKET_DEPTH", "", "cool correlation id for bybit BTCUSDT"); +Subscription subscription_2("binance", "ETHUSDT", "MARKET_DEPTH", "", "cool correlation id for binance ETHUSDT"); std::vector subscriptions = {subscription_1, subscription_2}; session.subscribe(subscriptions); ``` @@ -406,49 +405,49 @@ session.subscribe(subscriptions); Instantiate `Subscription` with option `CONFLATE_INTERVAL_MILLISECONDS` set to be the desired interval. ``` -Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH", "CONFLATE_INTERVAL_MILLISECONDS=1000"); +Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH", "CONFLATE_INTERVAL_MILLISECONDS=1000"); ``` #### Receive subscription events at periodic intervals including when the market depth snapshot hasn't changed Instantiate `Subscription` with option `CONFLATE_INTERVAL_MILLISECONDS` set to be the desired interval and `CONFLATE_GRACE_PERIOD_MILLISECONDS` to be the grace period for late events. ``` -Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH", "CONFLATE_INTERVAL_MILLISECONDS=1000&CONFLATE_GRACE_PERIOD_MILLISECONDS=0"); +Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH", "CONFLATE_INTERVAL_MILLISECONDS=1000&CONFLATE_GRACE_PERIOD_MILLISECONDS=0"); ``` #### Receive subscription market depth updates Instantiate `Subscription` with option `MARKET_DEPTH_RETURN_UPDATE` set to 1. This will return the order book updates instead of snapshots. ``` -Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH", "MARKET_DEPTH_RETURN_UPDATE=1&MARKET_DEPTH_MAX=2"); +Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH", "MARKET_DEPTH_RETURN_UPDATE=1&MARKET_DEPTH_MAX=2"); ``` #### Receive subscription trade events Instantiate `Subscription` with field `TRADE`. ``` -Subscription subscription("okx", "BTC-USDT", "TRADE"); +Subscription subscription("bybit", "BTCUSDT", "TRADE"); ``` #### Receive subscription calculated-candlestick events at periodic intervals Instantiate `Subscription` with field `TRADE` and option `CONFLATE_INTERVAL_MILLISECONDS` set to be the desired interval and `CONFLATE_GRACE_PERIOD_MILLISECONDS` to be your network latency. ``` -Subscription subscription("okx", "BTC-USDT", "TRADE", "CONFLATE_INTERVAL_MILLISECONDS=5000&CONFLATE_GRACE_PERIOD_MILLISECONDS=0"); +Subscription subscription("bybit", "BTCUSDT", "TRADE", "CONFLATE_INTERVAL_MILLISECONDS=5000&CONFLATE_GRACE_PERIOD_MILLISECONDS=0"); ``` #### Receive subscription exchange-provided-candlestick events at periodic intervals Instantiate `Subscription` with field `CANDLESTICK` and option `CANDLESTICK_INTERVAL_SECONDS` set to be the desired interval. ``` -Subscription subscription("okx", "BTC-USDT", "CANDLESTICK", "CANDLESTICK_INTERVAL_SECONDS=60"); +Subscription subscription("bybit", "BTCUSDT", "CANDLESTICK", "CANDLESTICK_INTERVAL_SECONDS=60"); ``` #### Send generic public requests Instantiate `Request` with operation `GENERIC_PUBLIC_REQUEST`. Provide request parameters `HTTP_METHOD`, `HTTP_PATH`, and optionally `HTTP_QUERY_STRING` (query string parameter values should be url-encoded), `HTTP_BODY`. ``` -Request request(Request::Operation::GENERIC_PUBLIC_REQUEST, "okx", "", "Check Server Time"); +Request request(Request::Operation::GENERIC_PUBLIC_REQUEST, "bybit", "", "Check Server Time"); request.appendParam({ {"HTTP_METHOD", "GET"}, {"HTTP_PATH", "/api/v5/public/time"}, @@ -459,14 +458,14 @@ request.appendParam({ Instantiate `Subscription` with empty instrument, field `GENERIC_PUBLIC_SUBSCRIPTION` and options set to be the desired websocket payload. ``` -Subscription subscription("okx", "", "GENERIC_PUBLIC_SUBSCRIPTION", R"({"type":"subscribe","channels":[{"name":"status"}]})"); +Subscription subscription("bybit", "", "GENERIC_PUBLIC_SUBSCRIPTION", R"({"type":"subscribe","channels":[{"name":"status"}]})"); ``` #### Send generic private requests Instantiate `Request` with operation `GENERIC_PRIVATE_REQUEST`. Provide request parameters `HTTP_METHOD`, `HTTP_PATH`, and optionally `HTTP_QUERY_STRING` (query string parameter values should be url-encoded), `HTTP_BODY`. ``` -Request request(Request::Operation::GENERIC_PRIVATE_REQUEST, "okx", "", "close all positions"); +Request request(Request::Operation::GENERIC_PRIVATE_REQUEST, "bybit", "", "close all positions"); request.appendParam({ {"HTTP_METHOD", "POST"}, {"HTTP_PATH", "/api/v5/trade/close-position"}, @@ -485,7 +484,7 @@ For a specific exchange and instrument, submit a simple limit order. **Code 1:** -[C++](example/src/execution_management_simple_request/main.cpp) / [Python](binding/python/example/execution_management_simple_request/main.py) / [Java](binding/java/example/execution_management_simple_request/Main.java) / [C#](binding/csharp/example/execution_management_simple_request/MainProgram.cs) / [Go](binding/go/example/execution_management_simple_request/main.go) / [Javascript](binding/javascript/example/execution_management_simple_request/index.js) +[C++](example/execution_management_simple_request/main.cpp) / [Python](binding/python/example/execution_management_simple_request/main.py) / [Java](binding/java/example/execution_management_simple_request/Main.java) / [C#](binding/csharp/example/execution_management_simple_request/MainProgram.cs) / [Go](binding/go/example/execution_management_simple_request/main.go) / [Javascript](binding/javascript/example/execution_management_simple_request/index.js) ``` #include "ccapi_cpp/ccapi_session.h" @@ -511,24 +510,21 @@ using ::ccapi::toString; using ::ccapi::UtilSystem; int main(int argc, char** argv) { - if (UtilSystem::getEnvAsString("OKX_API_KEY").empty()) { - std::cerr << "Please set environment variable OKX_API_KEY" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_KEY").empty()) { + std::cerr << "Please set environment variable BYBIT_API_KEY" << std::endl; return EXIT_FAILURE; } - if (UtilSystem::getEnvAsString("OKX_API_SECRET").empty()) { - std::cerr << "Please set environment variable OKX_API_SECRET" << std::endl; - return EXIT_FAILURE; - } - if (UtilSystem::getEnvAsString("OKX_API_PASSPHRASE").empty()) { - std::cerr << "Please set environment variable OKX_API_PASSPHRASE" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_SECRET").empty()) { + std::cerr << "Please set environment variable BYBIT_API_SECRET" << std::endl; return EXIT_FAILURE; } + SessionOptions sessionOptions; SessionConfigs sessionConfigs; MyEventHandler eventHandler; Session session(sessionOptions, sessionConfigs, &eventHandler); - Request request(Request::Operation::CREATE_ORDER, "okx", "BTC-USDT"); + Request request(Request::Operation::CREATE_ORDER, "bybit", "BTCUSDT"); request.appendParam({ {"SIDE", "BUY"}, {"QUANTITY", "0.0005"}, @@ -576,7 +572,7 @@ Received an event: Bye ``` * Request operation types: `CREATE_ORDER`, `CANCEL_ORDER`, `GET_ORDER`, `GET_OPEN_ORDERS`, `CANCEL_OPEN_ORDERS`, `GET_ACCOUNTS`, `GET_ACCOUNT_BALANCES`, `GET_ACCOUNT_POSITIONS`. -* Request parameter names: `SIDE`, `QUANTITY`, `LIMIT_PRICE`, `ACCOUNT_ID`, `ACCOUNT_TYPE`, `ORDER_ID`, `CLIENT_ORDER_ID`, `PARTY_ID`, `ORDER_TYPE`, `LEVERAGE`. Instead of these convenient names you can also choose to use arbitrary parameter names and they will be passed to the exchange's native API. See [this example](example/src/execution_management_advanced_request/main.cpp). +* Request parameter names: `SIDE`, `QUANTITY`, `LIMIT_PRICE`, `ACCOUNT_ID`, `ACCOUNT_TYPE`, `ORDER_ID`, `CLIENT_ORDER_ID`, `PARTY_ID`, `ORDER_TYPE`, `LEVERAGE`. Instead of these convenient names you can also choose to use arbitrary parameter names and they will be passed to the exchange's native API. See [this example](example/execution_management_advanced_request/main.cpp). **Objective 2:** @@ -584,7 +580,7 @@ For a specific exchange and instrument, receive order updates. **Code 2:** -[C++](example/src/execution_management_simple_subscription/main.cpp) / [Python](binding/python/example/execution_management_simple_subscription/main.py) / [Java](binding/java/example/execution_management_simple_subscription/Main.java) / [C#](binding/csharp/example/execution_management_simple_subscription/MainProgram.cs) / [Go](binding/go/example/execution_management_simple_subscription/main.go) / [Javascript](binding/javascript/example/execution_management_simple_subscription/index.js) +[C++](example/execution_management_simple_subscription/main.cpp) / [Python](binding/python/example/execution_management_simple_subscription/main.py) / [Java](binding/java/example/execution_management_simple_subscription/Main.java) / [C#](binding/csharp/example/execution_management_simple_subscription/MainProgram.cs) / [Go](binding/go/example/execution_management_simple_subscription/main.go) / [Javascript](binding/javascript/example/execution_management_simple_subscription/index.js) ``` #include "ccapi_cpp/ccapi_session.h" @@ -599,7 +595,7 @@ class MyEventHandler : public EventHandler { std::cout << "Received an event of type SUBSCRIPTION_STATUS:\n" + event.toPrettyString(2, 2) << std::endl; auto message = event.getMessageList().at(0); if (message.getType() == Message::Type::SUBSCRIPTION_STARTED) { - Request request(Request::Operation::CREATE_ORDER, "okx", "BTC-USDT"); + Request request(Request::Operation::CREATE_ORDER, "bybit", "BTCUSDT"); request.appendParam({ {"SIDE", "BUY"}, {"LIMIT_PRICE", "20000"}, @@ -625,23 +621,20 @@ using ::ccapi::Subscription; using ::ccapi::UtilSystem; int main(int argc, char** argv) { - if (UtilSystem::getEnvAsString("OKX_API_KEY").empty()) { - std::cerr << "Please set environment variable OKX_API_KEY" << std::endl; - return EXIT_FAILURE; - } - if (UtilSystem::getEnvAsString("OKX_API_SECRET").empty()) { - std::cerr << "Please set environment variable OKX_API_SECRET" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_KEY").empty()) { + std::cerr << "Please set environment variable BYBIT_API_KEY" << std::endl; return EXIT_FAILURE; } - if (UtilSystem::getEnvAsString("OKX_API_PASSPHRASE").empty()) { - std::cerr << "Please set environment variable OKX_API_PASSPHRASE" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_SECRET").empty()) { + std::cerr << "Please set environment variable BYBIT_API_SECRET" << std::endl; return EXIT_FAILURE; } + SessionOptions sessionOptions; SessionConfigs sessionConfigs; MyEventHandler eventHandler; Session session(sessionOptions, sessionConfigs, &eventHandler); - Subscription subscription("okx", "BTC-USDT", "ORDER_UPDATE"); + Subscription subscription("bybit", "BTCUSDT", "ORDER_UPDATE"); session.subscribe(subscription); std::this_thread::sleep_for(std::chrono::seconds(10)); session.stop(); @@ -705,11 +698,11 @@ Bye Instantiate `Request` with the desired `correlationId`. The `correlationId` should be unique. ``` -Request request(Request::Operation::CREATE_ORDER, "okx", "BTC-USDT", "cool correlation id"); +Request request(Request::Operation::CREATE_ORDER, "bybit", "BTCUSDT", "cool correlation id"); ``` Instantiate `Subscription` with the desired `correlationId`. ``` -Subscription subscription("okx", "BTC-USDT", "ORDER_UPDATE", "", "cool correlation id"); +Subscription subscription("bybit", "BTCUSDT", "ORDER_UPDATE", "", "cool correlation id"); ``` This is used to match a particular request or subscription with its returned data. Within each `Message` there is a `correlationIdList` to identify the request or subscription that requested the data. @@ -717,23 +710,23 @@ This is used to match a particular request or subscription with its returned dat Send a `std::vector`. ``` -Request request_1(Request::Operation::CREATE_ORDER, "okx", "BTC-USDT", "cool correlation id for BTC"); +Request request_1(Request::Operation::CREATE_ORDER, "bybit", "BTCUSDT", "cool correlation id for BTC"); request_1.appendParam(...); -Request request_2(Request::Operation::CREATE_ORDER, "okx", "ETH-USDT", "cool correlation id for ETH"); +Request request_2(Request::Operation::CREATE_ORDER, "bybit", "ETH-USDT", "cool correlation id for ETH"); request_2.appendParam(...); std::vector requests = {request_1, request_2}; session.sendRequest(requests); ``` Subscribe one `Subscription` per exchange with a comma separated string of instruments. ``` -Subscription subscription("okx", "BTC-USDT,ETH-USDT", "ORDER_UPDATE"); +Subscription subscription("bybit", "BTC-USDT,ETH-USDT", "ORDER_UPDATE"); ``` #### Multiple subscription fields Subscribe one `Subscription` with a comma separated string of fields. ``` -Subscription subscription("okx", "BTC-USDT", "ORDER_UPDATE,PRIVATE_TRADE"); +Subscription subscription("bybit", "BTCUSDT", "ORDER_UPDATE,PRIVATE_TRADE"); ``` #### Make Session::sendRequest blocking @@ -752,31 +745,30 @@ There are 3 ways to provide API credentials (listed with increasing priority). * Provide credentials to `SessionConfigs`. ``` sessionConfigs.setCredential({ - {"OKX_API_KEY", ...}, - {"OKX_API_SECRET", ...} + {"BYBIT_API_KEY", ...}, + {"BYBIT_API_SECRET", ...} }); ``` * Provide credentials to `Request` or `Subscription`. ``` -Request request(Request::Operation::CREATE_ORDER, "okx", "BTC-USDT", "", { - {"OKX_API_KEY", ...}, - {"OKX_API_SECRET", ...} +Request request(Request::Operation::CREATE_ORDER, "bybit", "BTCUSDT", "", { + {"BYBIT_API_KEY", ...}, + {"BYBIT_API_SECRET", ...} }); ``` ``` -Subscription subscription("okx", "BTC-USDT", "ORDER_UPDATE", "", "", { - {"OKX_API_KEY", ...}, - {"OKX_API_SECRET", ...} +Subscription subscription("bybit", "BTCUSDT", "ORDER_UPDATE", "", "", { + {"BYBIT_API_KEY", ...}, + {"BYBIT_API_SECRET", ...} }); ``` #### Complex request parameters -Please follow the exchange's API documentations: e.g. https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order. +Please follow the exchange's API documentations: e.g. https://bybit-exchange.github.io/docs/v5/order/create-order. ``` -Request request(Request::Operation::CREATE_ORDER, "okx", "BTC-USDT"); +Request request(Request::Operation::CREATE_ORDER, "bybit", "BTCUSDT"); request.appendParam({ - {"tdMode", "cross"}, - {"ccy", "USDT"}, + {"isLeverage", "1"}, }); ``` @@ -784,10 +776,10 @@ request.appendParam({ For okx, cryptocom: ``` std::string websocketOrderEntrySubscriptionCorrelationId("any"); -Subscription subscription("okx", "", "ORDER_UPDATE", "", websocketOrderEntrySubscriptionCorrelationId); +Subscription subscription("bybit", "", "ORDER_UPDATE", "", websocketOrderEntrySubscriptionCorrelationId); session.subscribe(subscription); ... -Request request(Request::Operation::CREATE_ORDER, "okx", "BTC-USDT"); +Request request(Request::Operation::CREATE_ORDER, "bybit", "BTCUSDT"); request.appendParam({ {"SIDE", "BUY"}, {"LIMIT_PRICE", "20000"}, @@ -828,7 +820,7 @@ For a specific exchange and instrument, submit a simple limit order. **Code:** -[C++](example/src/fix_simple/main.cpp) / [Python](binding/python/example/fix_simple/main.py) / [Java](binding/java/example/fix_simple/Main.java) / [C#](binding/csharp/example/fix_simple/MainProgram.cs) / [Go](binding/go/example/fix_simple/main.go) / [Javascript](binding/javascript/example/fix_simple/index.js) +[C++](example/fix_simple/main.cpp) / [Python](binding/python/example/fix_simple/main.py) / [Java](binding/java/example/fix_simple/Main.java) / [C#](binding/csharp/example/fix_simple/MainProgram.cs) / [Go](binding/go/example/fix_simple/main.go) / [Javascript](binding/javascript/example/fix_simple/index.js) ``` #include "ccapi_cpp/ccapi_session.h" @@ -1002,12 +994,12 @@ Bye In general there are 2 ways to handle events. * When a `Session` is instantiated with an `eventHandler` argument, it will handle events in immediate mode. The `processEvent` method in the `eventHandler` will be invoked immediately when an `Event` is available, and the invocation will run on the thread where `boost::asio::io_context` runs. When a `Session` is instantiated with an `eventHandler` and an `eventDispatcher` argument, it will also handle events in immediate mode. The `processEvent` method in the `eventHandler` will also be invoked immediately when an `Event` is available, but the invocation will run in the thread(s) provided by the `eventDispatcher` therefore not blocking the thread where `boost::asio::io_context` runs. `EventHandler`s and/or `EventDispatcher`s can be shared among different sessions. Otherwise, different sessions are independent from each other. -An example can be found [here](example/src/market_data_advanced_subscription/main.cpp). +An example can be found [here](example/market_data_advanced_subscription/main.cpp). * When a `Session` is instantiated without an `eventHandler` argument, it will handle events in batching mode. The events will be batched into an internal `Queue` and can be retrieved by ``` std::vector eventList = session.getEventQueue().purge(); ``` -An example can be found [here](example/src/market_data_advanced_subscription/main.cpp). +An example can be found [here](example/market_data_advanced_subscription/main.cpp). #### Thread safety * The following methods are implemented to be thread-safe: `Session::sendRequest`, `Session::subscribe`, `Session::sendRequestByFix`, `Session::setTimer`, all public methods in `Queue`. @@ -1015,7 +1007,7 @@ An example can be found [here](example/src/market_data_advanced_subscription/mai #### Enable library logging -[C++](example/src/enable_library_logging/main.cpp) / [Python](binding/python/example/enable_library_logging/main.py) / [Java](binding/java/example/enable_library_logging/Main.java) / [C#](binding/csharp/example/enable_library_logging/MainProgram.cs) / [Go](binding/go/example/enable_library_logging/main.go) +[C++](example/enable_library_logging/main.cpp) / [Python](binding/python/example/enable_library_logging/main.py) / [Java](binding/java/example/enable_library_logging/Main.java) / [C#](binding/csharp/example/enable_library_logging/MainProgram.cs) / [Go](binding/go/example/enable_library_logging/main.go) Extend a subclass, e.g. `MyLogger`, from class `Logger` and override method `logMessage`. Assign a `MyLogger` pointer to `Logger::logger`. Add one of the following macros in the compiler command line: `CCAPI_ENABLE_LOG_TRACE`, `CCAPI_ENABLE_LOG_DEBUG`, `CCAPI_ENABLE_LOG_INFO`, `CCAPI_ENABLE_LOG_WARN`, `CCAPI_ENABLE_LOG_ERROR`, `CCAPI_ENABLE_LOG_FATAL`. Enable logging if you'd like to inspect raw responses/messages from the exchange for troubleshooting purposes. ``` @@ -1041,7 +1033,7 @@ Logger* Logger::logger = &myLogger; #### Set timer -[C++](example/src/set_timer/main.cpp) +[C++](example/set_timer/main.cpp) To perform an asynchronous wait, use the utility method `setTimer` in class `Session`. The handlers are invoked in the same threads as the `processEvent` method in the `EventHandler` class. The `id` of the timer should be unique. `delayMilliseconds` can be 0. ``` @@ -1055,7 +1047,7 @@ sessionPtr->setTimer( #### Heartbeat -[C++](example/src/heartbeat/main.cpp) +[C++](example/heartbeat/main.cpp) To receive heartbeat events, instantiate a `Subscription` object with field `HEARTBEAT` and subscribe it. ``` @@ -1065,7 +1057,7 @@ session.subscribe(subscription); #### Use multiple sessions -[C++](example/src/use_multiple_sessions/main.cpp) +[C++](example/use_multiple_sessions/main.cpp) Multiple `session` instances, each with their own `SessionOptions` and `SessionConfigs`, can share a common `EventHandler`. If no `EventDispatcher` is provided, thread safety must be maintained by using a shared `ServiceContext`. ``` @@ -1074,16 +1066,16 @@ session.subscribe(subscription); ``` #### Override exchange urls -You can override exchange urls at compile time by using macros. See section "exchange REST urls", "exchange WS urls", and "exchange FIX urls" in [`include/ccapi_cpp/ccapi_macro.h`](include/ccapi_cpp/ccapi_macro.h). You can also override exchange urls at runtime. See [this example](example/src/override_exchange_url_at_runtime/main.cpp). These can be useful if you need to connect to test accounts (e.g. https://www.okx.com/docs-v5/en/#overview-demo-trading-services). +You can override exchange urls at compile time by using macros. See section "exchange REST urls", "exchange WS urls", and "exchange FIX urls" in [`include/ccapi_cpp/ccapi_macro.h`](include/ccapi_cpp/ccapi_macro.h). You can also override exchange urls at runtime. See [this example](example/override_exchange_url_at_runtime/main.cpp). These can be useful if you need to connect to test accounts (e.g. https://testnet.bybit.com/). #### Connect to a proxy Instantiate `Subscription` with the desired `proxyUrl`. ``` -Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH", "", "", {}, "172.30.0.146:9000"); +Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH", "", "", {}, "172.30.0.146:9000"); ``` #### Reduce build time -The Pimpl (Pointer to Implementation) idiom in C++ can significantly reduce build time. This reduction is achieved by minimizing compilation dependencies and isolating implementation details. See [this example](example/src/reduce_build_time). +The Pimpl (Pointer to Implementation) idiom in C++ can significantly reduce build time. This reduction is achieved by minimizing compilation dependencies and isolating implementation details. See [this example](example/reduce_build_time). ## Performance Tuning * Turn on compiler optimization flags (e.g. `cmake -DCMAKE_BUILD_TYPE=Release ...`). diff --git a/binding/go/CMakeLists.txt b/binding/go/CMakeLists.txt index b580648e0..93a0ce831 100644 --- a/binding/go/CMakeLists.txt +++ b/binding/go/CMakeLists.txt @@ -121,6 +121,7 @@ foreach(ZLIB_LIBRARY IN LISTS ZLIB_LIBRARIES) get_filename_component(ZLIB_LIBRARY_DIR ${ZLIB_LIBRARY} DIRECTORY) list(APPEND CGO_LDFLAGS_LIST -L${ZLIB_LIBRARY_DIR} -lz) endforeach() +list(REMOVE_DUPLICATES CGO_LDFLAGS_LIST) list(JOIN CGO_LDFLAGS_LIST " " CGO_LDFLAGS) message(STATUS "CGO_LDFLAGS: ${CGO_LDFLAGS}") file(APPEND ${COMPILER_OPTIONS_FILE_PATH} diff --git a/binding/go/example/execution_management_simple_request/main.go b/binding/go/example/execution_management_simple_request/main.go index 149d30e89..5814db69e 100644 --- a/binding/go/example/execution_management_simple_request/main.go +++ b/binding/go/example/execution_management_simple_request/main.go @@ -12,7 +12,7 @@ type MyEventHandler struct { } func (*MyEventHandler) ProcessEvent(event ccapi.Event, session ccapi.Session) { - fmt.Printf("Received an event:\n%s\n", event.ToStringPretty(2, 2)) + fmt.Printf("Received an event:\n%s\n", event.ToPrettyString(2, 2)) } func main() { diff --git a/binding/go/example/execution_management_simple_subscription/main.go b/binding/go/example/execution_management_simple_subscription/main.go index dddc2cc47..6f6b79b6a 100644 --- a/binding/go/example/execution_management_simple_subscription/main.go +++ b/binding/go/example/execution_management_simple_subscription/main.go @@ -13,7 +13,7 @@ type MyEventHandler struct { func (*MyEventHandler) ProcessEvent(event ccapi.Event, session ccapi.Session) { if event.GetType() == ccapi.EventType_SUBSCRIPTION_STATUS { - fmt.Printf("Received an event of type SUBSCRIPTION_STATUS:\n%s\n", event.ToStringPretty(2, 2)) + fmt.Printf("Received an event of type SUBSCRIPTION_STATUS:\n%s\n", event.ToPrettyString(2, 2)) message := event.GetMessageList().Get(0) if message.GetType() == ccapi.MessageType_SUBSCRIPTION_STARTED { request := ccapi.NewRequest(ccapi.RequestOperation_CREATE_ORDER, "okx", "BTC-USDT") @@ -27,7 +27,7 @@ func (*MyEventHandler) ProcessEvent(event ccapi.Event, session ccapi.Session) { session.SendRequest(request) } } else if event.GetType() == ccapi.EventType_SUBSCRIPTION_DATA { - fmt.Printf("Received an event of type SUBSCRIPTION_DATA:\n%s\n", event.ToStringPretty(2, 2)) + fmt.Printf("Received an event of type SUBSCRIPTION_DATA:\n%s\n", event.ToPrettyString(2, 2)) } } diff --git a/binding/go/example/fix_simple/main.go b/binding/go/example/fix_simple/main.go index 96571d76f..36bc3cbd4 100644 --- a/binding/go/example/fix_simple/main.go +++ b/binding/go/example/fix_simple/main.go @@ -13,7 +13,7 @@ type MyEventHandler struct { func (*MyEventHandler) ProcessEvent(event ccapi.Event, session ccapi.Session) { if event.GetType() == ccapi.EventType_AUTHORIZATION_STATUS { - fmt.Printf("Received an event of type AUTHORIZATION_STATUS:\n%s\n", event.ToStringPretty(2, 2)) + fmt.Printf("Received an event of type AUTHORIZATION_STATUS:\n%s\n", event.ToPrettyString(2, 2)) message := event.GetMessageList().Get(0) if message.GetType() == ccapi.MessageType_AUTHORIZATION_SUCCESS { request := ccapi.NewRequest(ccapi.RequestOperation_FIX, "coinbase", "", "same correlation id for subscription and request") @@ -44,7 +44,7 @@ func (*MyEventHandler) ProcessEvent(event ccapi.Event, session ccapi.Session) { session.SendRequestByFix(request) } } else if event.GetType() == ccapi.EventType_FIX { - fmt.Printf("Received an event of type FIX:\n%s\n", event.ToStringPretty(2, 2)) + fmt.Printf("Received an event of type FIX:\n%s\n", event.ToPrettyString(2, 2)) } } diff --git a/binding/go/example/market_data_simple_request/main.go b/binding/go/example/market_data_simple_request/main.go index 29b70d0de..a65b8efcf 100644 --- a/binding/go/example/market_data_simple_request/main.go +++ b/binding/go/example/market_data_simple_request/main.go @@ -11,7 +11,7 @@ type MyEventHandler struct { } func (*MyEventHandler) ProcessEvent(event ccapi.Event, session ccapi.Session) { - fmt.Printf("Received an event:\n%s\n", event.ToStringPretty(2, 2)) + fmt.Printf("Received an event:\n%s\n", event.ToPrettyString(2, 2)) } func main() { diff --git a/binding/go/example/market_data_simple_subscription/main.go b/binding/go/example/market_data_simple_subscription/main.go index c9d154782..16e0d1745 100644 --- a/binding/go/example/market_data_simple_subscription/main.go +++ b/binding/go/example/market_data_simple_subscription/main.go @@ -12,7 +12,7 @@ type MyEventHandler struct { func (*MyEventHandler) ProcessEvent(event ccapi.Event, session ccapi.Session) { if event.GetType() == ccapi.EventType_SUBSCRIPTION_STATUS { - fmt.Printf("Received an event of type SUBSCRIPTION_STATUS:\n%s\n", event.ToStringPretty(2, 2)) + fmt.Printf("Received an event of type SUBSCRIPTION_STATUS:\n%s\n", event.ToPrettyString(2, 2)) } else if event.GetType() == ccapi.EventType_SUBSCRIPTION_DATA { messageList := event.GetMessageList() for i := 0; i < int(messageList.Size()); i++ { diff --git a/binding/go/go.mod.in b/binding/go/go.mod.in index d0379da69..f95899395 100644 --- a/binding/go/go.mod.in +++ b/binding/go/go.mod.in @@ -1 +1,3 @@ module cryptochassis.com + +go 1.17 diff --git a/binding/go/go.mod.in_2 b/binding/go/go.mod.in_2 index b49f2dfb0..7dbca1bce 100644 --- a/binding/go/go.mod.in_2 +++ b/binding/go/go.mod.in_2 @@ -1,5 +1,7 @@ module main +go 1.17 + require ( cryptochassis.com/ccapi v1.0.0 ) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index c4649b5b0..51f7552f3 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -68,23 +68,23 @@ if(WIN32) endif() link_libraries(OpenSSL::Crypto OpenSSL::SSL ${ADDITIONAL_LINK_LIBRARIES}) add_compile_options(-Wno-deprecated -Wno-nonnull -Wno-deprecated-declarations) -add_subdirectory(src/market_data_simple_request) -add_subdirectory(src/market_data_simple_subscription) -add_subdirectory(src/market_data_advanced_request) -add_subdirectory(src/market_data_advanced_subscription) -add_subdirectory(src/generic_public_request) -add_subdirectory(src/generic_private_request) -add_subdirectory(src/execution_management_simple_request) -add_subdirectory(src/execution_management_simple_subscription) -add_subdirectory(src/execution_management_advanced_request) -add_subdirectory(src/execution_management_advanced_subscription) -add_subdirectory(src/fix_simple) -add_subdirectory(src/fix_advanced) -add_subdirectory(src/enable_library_logging) -add_subdirectory(src/set_timer) -add_subdirectory(src/heartbeat) -add_subdirectory(src/override_exchange_url_at_runtime) -add_subdirectory(src/test_order_latency) -add_subdirectory(src/test_cpu_usage) -add_subdirectory(src/use_multiple_sessions) -add_subdirectory(src/reduce_build_time) +add_subdirectory(market_data_simple_request) +add_subdirectory(market_data_simple_subscription) +add_subdirectory(market_data_advanced_request) +add_subdirectory(market_data_advanced_subscription) +add_subdirectory(generic_public_request) +add_subdirectory(generic_private_request) +add_subdirectory(execution_management_simple_request) +add_subdirectory(execution_management_simple_subscription) +add_subdirectory(execution_management_advanced_request) +add_subdirectory(execution_management_advanced_subscription) +add_subdirectory(fix_simple) +add_subdirectory(fix_advanced) +add_subdirectory(enable_library_logging) +add_subdirectory(set_timer) +add_subdirectory(heartbeat) +add_subdirectory(override_exchange_url_at_runtime) +add_subdirectory(test_order_latency) +add_subdirectory(test_cpu_usage) +add_subdirectory(use_multiple_sessions) +add_subdirectory(reduce_build_time) diff --git a/example/src/enable_library_logging/CMakeLists.txt b/example/enable_library_logging/CMakeLists.txt similarity index 81% rename from example/src/enable_library_logging/CMakeLists.txt rename to example/enable_library_logging/CMakeLists.txt index 6129de925..d0696545f 100644 --- a/example/src/enable_library_logging/CMakeLists.txt +++ b/example/enable_library_logging/CMakeLists.txt @@ -2,6 +2,6 @@ set(NAME enable_library_logging) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_LOG_TRACE) add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/enable_library_logging/main.cpp b/example/enable_library_logging/main.cpp similarity index 93% rename from example/src/enable_library_logging/main.cpp rename to example/enable_library_logging/main.cpp index 123520aa9..d69936424 100644 --- a/example/src/enable_library_logging/main.cpp +++ b/example/enable_library_logging/main.cpp @@ -24,7 +24,7 @@ using ::ccapi::Subscription; int main(int argc, char** argv) { Session session; - Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH"); + Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH"); session.subscribe(subscription); std::this_thread::sleep_for(std::chrono::seconds(10)); session.stop(); diff --git a/example/src/execution_management_advanced_request/CMakeLists.txt b/example/execution_management_advanced_request/CMakeLists.txt similarity index 79% rename from example/src/execution_management_advanced_request/CMakeLists.txt rename to example/execution_management_advanced_request/CMakeLists.txt index f9025f8dc..acca9d96e 100644 --- a/example/src/execution_management_advanced_request/CMakeLists.txt +++ b/example/execution_management_advanced_request/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME execution_management_advanced_request) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/execution_management_advanced_request/main.cpp b/example/execution_management_advanced_request/main.cpp similarity index 65% rename from example/src/execution_management_advanced_request/main.cpp rename to example/execution_management_advanced_request/main.cpp index f189f0092..106ec99ac 100644 --- a/example/src/execution_management_advanced_request/main.cpp +++ b/example/execution_management_advanced_request/main.cpp @@ -19,23 +19,20 @@ using ::ccapi::SessionOptions; using ::ccapi::UtilSystem; int main(int argc, char** argv) { - if (UtilSystem::getEnvAsString("OKX_API_KEY").empty()) { - std::cerr << "Please set environment variable OKX_API_KEY" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_KEY").empty()) { + std::cerr << "Please set environment variable BYBIT_API_KEY" << std::endl; return EXIT_FAILURE; } - if (UtilSystem::getEnvAsString("OKX_API_SECRET").empty()) { - std::cerr << "Please set environment variable OKX_API_SECRET" << std::endl; - return EXIT_FAILURE; - } - if (UtilSystem::getEnvAsString("OKX_API_PASSPHRASE").empty()) { - std::cerr << "Please set environment variable OKX_API_PASSPHRASE" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_SECRET").empty()) { + std::cerr << "Please set environment variable BYBIT_API_SECRET" << std::endl; return EXIT_FAILURE; } + SessionOptions sessionOptions; SessionConfigs sessionConfigs; MyEventHandler eventHandler; Session session(sessionOptions, sessionConfigs, &eventHandler); - Request request(Request::Operation::CREATE_ORDER, "okx", "BTC-USDT"); + Request request(Request::Operation::CREATE_ORDER, "bybit", "BTCUSDT"); request.appendParam({ {"tdMode", "cross"}, {"ccy", "USDT"}, diff --git a/example/src/execution_management_advanced_subscription/CMakeLists.txt b/example/execution_management_advanced_subscription/CMakeLists.txt similarity index 80% rename from example/src/execution_management_advanced_subscription/CMakeLists.txt rename to example/execution_management_advanced_subscription/CMakeLists.txt index 8dde0f470..ce5c1051e 100644 --- a/example/src/execution_management_advanced_subscription/CMakeLists.txt +++ b/example/execution_management_advanced_subscription/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME execution_management_advanced_subscription) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/execution_management_advanced_subscription/main.cpp b/example/execution_management_advanced_subscription/main.cpp similarity index 73% rename from example/src/execution_management_advanced_subscription/main.cpp rename to example/execution_management_advanced_subscription/main.cpp index d51f2cacc..456ac7aa4 100644 --- a/example/src/execution_management_advanced_subscription/main.cpp +++ b/example/execution_management_advanced_subscription/main.cpp @@ -13,7 +13,7 @@ class MyEventHandler : public EventHandler { std::cout << "Received an event:\n" + event.toPrettyString(2, 2) << std::endl; if (!willSendRequest) { sessionPtr->setTimer("id", 1000, nullptr, [this, sessionPtr]() { - Request request(Request::Operation::CREATE_ORDER, "okx", "BTC-USDT"); + Request request(Request::Operation::CREATE_ORDER, "bybit", "BTCUSDT"); request.appendParam({ {"SIDE", "BUY"}, {"LIMIT_PRICE", "20000"}, @@ -43,25 +43,24 @@ using ::ccapi::Subscription; using ::ccapi::UtilSystem; int main(int argc, char** argv) { - if (UtilSystem::getEnvAsString("OKX_API_KEY").empty()) { - std::cerr << "Please set environment variable OKX_API_KEY" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_KEY").empty()) { + std::cerr << "Please set environment variable BYBIT_API_KEY" << std::endl; return EXIT_FAILURE; } - if (UtilSystem::getEnvAsString("OKX_API_SECRET").empty()) { - std::cerr << "Please set environment variable OKX_API_SECRET" << std::endl; - return EXIT_FAILURE; - } - if (UtilSystem::getEnvAsString("OKX_API_PASSPHRASE").empty()) { - std::cerr << "Please set environment variable OKX_API_PASSPHRASE" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_SECRET").empty()) { + std::cerr << "Please set environment variable BYBIT_API_SECRET" << std::endl; return EXIT_FAILURE; } + SessionOptions sessionOptions; SessionConfigs sessionConfigs; std::string websocketOrderEntrySubscriptionCorrelationId("any"); MyEventHandler eventHandler(websocketOrderEntrySubscriptionCorrelationId); Session session(sessionOptions, sessionConfigs, &eventHandler); - Subscription subscription("okx", "", "ORDER_UPDATE", "", websocketOrderEntrySubscriptionCorrelationId); - session.subscribe(subscription); + Subscription subscription_1("bybit", "", "ORDER_UPDATE"); + Subscription subscription_2("bybit", "", "WEBSOCKET_ORDER_ENTRY", "", websocketOrderEntrySubscriptionCorrelationId); + std::vector subscriptions = {subscription_1, subscription_2}; + session.subscribe(subscriptions); std::this_thread::sleep_for(std::chrono::seconds(10)); session.stop(); std::cout << "Bye" << std::endl; diff --git a/example/src/execution_management_simple_request/CMakeLists.txt b/example/execution_management_simple_request/CMakeLists.txt similarity index 79% rename from example/src/execution_management_simple_request/CMakeLists.txt rename to example/execution_management_simple_request/CMakeLists.txt index 256156105..3771a3609 100644 --- a/example/src/execution_management_simple_request/CMakeLists.txt +++ b/example/execution_management_simple_request/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME execution_management_simple_request) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/execution_management_simple_request/main.cpp b/example/execution_management_simple_request/main.cpp similarity index 79% rename from example/src/execution_management_simple_request/main.cpp rename to example/execution_management_simple_request/main.cpp index a28516944..0bc0dc385 100644 --- a/example/src/execution_management_simple_request/main.cpp +++ b/example/execution_management_simple_request/main.cpp @@ -20,18 +20,15 @@ using ::ccapi::toString; using ::ccapi::UtilSystem; int main(int argc, char** argv) { - if (UtilSystem::getEnvAsString("OKX_API_KEY").empty()) { - std::cerr << "Please set environment variable OKX_API_KEY" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_KEY").empty()) { + std::cerr << "Please set environment variable BYBIT_API_KEY" << std::endl; return EXIT_FAILURE; } - if (UtilSystem::getEnvAsString("OKX_API_SECRET").empty()) { - std::cerr << "Please set environment variable OKX_API_SECRET" << std::endl; - return EXIT_FAILURE; - } - if (UtilSystem::getEnvAsString("OKX_API_PASSPHRASE").empty()) { - std::cerr << "Please set environment variable OKX_API_PASSPHRASE" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_SECRET").empty()) { + std::cerr << "Please set environment variable BYBIT_API_SECRET" << std::endl; return EXIT_FAILURE; } + std::vector modeList = { "create_order", "cancel_order", "get_order", "get_open_orders", "cancel_open_orders", "get_account_balances", }; @@ -52,7 +49,7 @@ int main(int argc, char** argv) { session.stop(); return EXIT_FAILURE; } - Request request(Request::Operation::CREATE_ORDER, "okx", argv[2]); + Request request(Request::Operation::CREATE_ORDER, "bybit", argv[2]); request.appendParam({ {"SIDE", strcmp(argv[3], "buy") == 0 ? "BUY" : "SELL"}, {"QUANTITY", argv[4]}, @@ -67,7 +64,7 @@ int main(int argc, char** argv) { session.stop(); return EXIT_FAILURE; } - Request request(Request::Operation::CANCEL_ORDER, "okx", argv[2]); + Request request(Request::Operation::CANCEL_ORDER, "bybit", argv[2]); request.appendParam({ {"ORDER_ID", argv[3]}, }); @@ -80,7 +77,7 @@ int main(int argc, char** argv) { session.stop(); return EXIT_FAILURE; } - Request request(Request::Operation::GET_ORDER, "okx", argv[2]); + Request request(Request::Operation::GET_ORDER, "bybit", argv[2]); request.appendParam({ {"ORDER_ID", argv[3]}, }); @@ -93,7 +90,7 @@ int main(int argc, char** argv) { session.stop(); return EXIT_FAILURE; } - Request request(Request::Operation::GET_OPEN_ORDERS, "okx", argv[2]); + Request request(Request::Operation::GET_OPEN_ORDERS, "bybit", argv[2]); session.sendRequest(request); } else if (mode == "cancel_open_orders") { if (argc != 3) { @@ -103,10 +100,10 @@ int main(int argc, char** argv) { session.stop(); return EXIT_FAILURE; } - Request request(Request::Operation::CANCEL_OPEN_ORDERS, "okx", argv[2]); + Request request(Request::Operation::CANCEL_OPEN_ORDERS, "bybit", argv[2]); session.sendRequest(request); } else if (mode == "get_account_balances") { - Request request(Request::Operation::GET_ACCOUNT_BALANCES, "okx"); + Request request(Request::Operation::GET_ACCOUNT_BALANCES, "bybit"); session.sendRequest(request); } std::this_thread::sleep_for(std::chrono::seconds(10)); diff --git a/example/src/execution_management_simple_subscription/CMakeLists.txt b/example/execution_management_simple_subscription/CMakeLists.txt similarity index 79% rename from example/src/execution_management_simple_subscription/CMakeLists.txt rename to example/execution_management_simple_subscription/CMakeLists.txt index 598c08836..c7b271339 100644 --- a/example/src/execution_management_simple_subscription/CMakeLists.txt +++ b/example/execution_management_simple_subscription/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME execution_management_simple_subscription) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/execution_management_simple_subscription/main.cpp b/example/execution_management_simple_subscription/main.cpp similarity index 71% rename from example/src/execution_management_simple_subscription/main.cpp rename to example/execution_management_simple_subscription/main.cpp index e6b285d53..52a4878d4 100644 --- a/example/src/execution_management_simple_subscription/main.cpp +++ b/example/execution_management_simple_subscription/main.cpp @@ -10,7 +10,7 @@ class MyEventHandler : public EventHandler { std::cout << "Received an event:\n" + event.toPrettyString(2, 2) << std::endl; if (!willSendRequest) { sessionPtr->setTimer("id", 1000, nullptr, [this, sessionPtr]() { - Request request(Request::Operation::CREATE_ORDER, "okx", "BTC-USDT"); + Request request(Request::Operation::CREATE_ORDER, "bybit", "BTCUSDT"); request.appendParam({ {"SIDE", "BUY"}, {"LIMIT_PRICE", "20000"}, @@ -39,23 +39,20 @@ using ::ccapi::Subscription; using ::ccapi::UtilSystem; int main(int argc, char** argv) { - if (UtilSystem::getEnvAsString("OKX_API_KEY").empty()) { - std::cerr << "Please set environment variable OKX_API_KEY" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_KEY").empty()) { + std::cerr << "Please set environment variable BYBIT_API_KEY" << std::endl; return EXIT_FAILURE; } - if (UtilSystem::getEnvAsString("OKX_API_SECRET").empty()) { - std::cerr << "Please set environment variable OKX_API_SECRET" << std::endl; - return EXIT_FAILURE; - } - if (UtilSystem::getEnvAsString("OKX_API_PASSPHRASE").empty()) { - std::cerr << "Please set environment variable OKX_API_PASSPHRASE" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_SECRET").empty()) { + std::cerr << "Please set environment variable BYBIT_API_SECRET" << std::endl; return EXIT_FAILURE; } + SessionOptions sessionOptions; SessionConfigs sessionConfigs; MyEventHandler eventHandler; Session session(sessionOptions, sessionConfigs, &eventHandler); - Subscription subscription("okx", "BTC-USDT", "ORDER_UPDATE"); + Subscription subscription("bybit", "BTCUSDT", "ORDER_UPDATE"); session.subscribe(subscription); std::this_thread::sleep_for(std::chrono::seconds(10)); session.stop(); diff --git a/example/src/fix_advanced/CMakeLists.txt b/example/fix_advanced/CMakeLists.txt similarity index 100% rename from example/src/fix_advanced/CMakeLists.txt rename to example/fix_advanced/CMakeLists.txt diff --git a/example/src/fix_advanced/main.cpp b/example/fix_advanced/main.cpp similarity index 100% rename from example/src/fix_advanced/main.cpp rename to example/fix_advanced/main.cpp diff --git a/example/src/fix_simple/CMakeLists.txt b/example/fix_simple/CMakeLists.txt similarity index 100% rename from example/src/fix_simple/CMakeLists.txt rename to example/fix_simple/CMakeLists.txt diff --git a/example/src/fix_simple/main.cpp b/example/fix_simple/main.cpp similarity index 100% rename from example/src/fix_simple/main.cpp rename to example/fix_simple/main.cpp diff --git a/example/src/generic_private_request/CMakeLists.txt b/example/generic_private_request/CMakeLists.txt similarity index 78% rename from example/src/generic_private_request/CMakeLists.txt rename to example/generic_private_request/CMakeLists.txt index 01e075ee6..a49554fe4 100644 --- a/example/src/generic_private_request/CMakeLists.txt +++ b/example/generic_private_request/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME generic_private_request) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/generic_private_request/main.cpp b/example/generic_private_request/main.cpp similarity index 72% rename from example/src/generic_private_request/main.cpp rename to example/generic_private_request/main.cpp index 87e600faf..45705e4db 100644 --- a/example/src/generic_private_request/main.cpp +++ b/example/generic_private_request/main.cpp @@ -21,23 +21,20 @@ using ::ccapi::UtilSystem; using ::ccapi::UtilTime; int main(int argc, char** argv) { - if (UtilSystem::getEnvAsString("OKX_API_KEY").empty()) { - std::cerr << "Please set environment variable OKX_API_KEY" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_KEY").empty()) { + std::cerr << "Please set environment variable BYBIT_API_KEY" << std::endl; return EXIT_FAILURE; } - if (UtilSystem::getEnvAsString("OKX_API_SECRET").empty()) { - std::cerr << "Please set environment variable OKX_API_SECRET" << std::endl; - return EXIT_FAILURE; - } - if (UtilSystem::getEnvAsString("OKX_API_PASSPHRASE").empty()) { - std::cerr << "Please set environment variable OKX_API_PASSPHRASE" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_SECRET").empty()) { + std::cerr << "Please set environment variable BYBIT_API_SECRET" << std::endl; return EXIT_FAILURE; } + SessionOptions sessionOptions; SessionConfigs sessionConfigs; MyEventHandler eventHandler; Session session(sessionOptions, sessionConfigs, &eventHandler); - Request request(Request::Operation::GENERIC_PRIVATE_REQUEST, "okx", "", "close all positions"); + Request request(Request::Operation::GENERIC_PRIVATE_REQUEST, "bybit", "", "close all positions"); request.appendParam({ {"HTTP_METHOD", "POST"}, {"HTTP_PATH", "/api/v5/trade/close-position"}, diff --git a/example/src/generic_public_request/CMakeLists.txt b/example/generic_public_request/CMakeLists.txt similarity index 77% rename from example/src/generic_public_request/CMakeLists.txt rename to example/generic_public_request/CMakeLists.txt index 8e8183d13..494cbe517 100644 --- a/example/src/generic_public_request/CMakeLists.txt +++ b/example/generic_public_request/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME generic_public_request) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/generic_public_request/main.cpp b/example/generic_public_request/main.cpp similarity index 91% rename from example/src/generic_public_request/main.cpp rename to example/generic_public_request/main.cpp index 73403c90c..77abe303e 100644 --- a/example/src/generic_public_request/main.cpp +++ b/example/generic_public_request/main.cpp @@ -23,7 +23,7 @@ int main(int argc, char** argv) { SessionConfigs sessionConfigs; MyEventHandler eventHandler; Session session(sessionOptions, sessionConfigs, &eventHandler); - Request request(Request::Operation::GENERIC_PUBLIC_REQUEST, "okx", "", "Check Server Time"); + Request request(Request::Operation::GENERIC_PUBLIC_REQUEST, "bybit", "", "Check Server Time"); request.appendParam({ {"HTTP_METHOD", "GET"}, {"HTTP_PATH", "/api/v5/public/time"}, diff --git a/example/src/heartbeat/CMakeLists.txt b/example/heartbeat/CMakeLists.txt similarity index 76% rename from example/src/heartbeat/CMakeLists.txt rename to example/heartbeat/CMakeLists.txt index 6ec5784be..90959da56 100644 --- a/example/src/heartbeat/CMakeLists.txt +++ b/example/heartbeat/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME heartbeat) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/heartbeat/main.cpp b/example/heartbeat/main.cpp similarity index 100% rename from example/src/heartbeat/main.cpp rename to example/heartbeat/main.cpp diff --git a/example/src/market_data_advanced_request/CMakeLists.txt b/example/market_data_advanced_request/CMakeLists.txt similarity index 78% rename from example/src/market_data_advanced_request/CMakeLists.txt rename to example/market_data_advanced_request/CMakeLists.txt index 3636c49bc..5b16003b6 100644 --- a/example/src/market_data_advanced_request/CMakeLists.txt +++ b/example/market_data_advanced_request/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME market_data_advanced_request) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/market_data_advanced_request/main.cpp b/example/market_data_advanced_request/main.cpp similarity index 85% rename from example/src/market_data_advanced_request/main.cpp rename to example/market_data_advanced_request/main.cpp index 77462ce43..450d7dc57 100644 --- a/example/src/market_data_advanced_request/main.cpp +++ b/example/market_data_advanced_request/main.cpp @@ -22,11 +22,10 @@ int main(int argc, char** argv) { SessionConfigs sessionConfigs; MyEventHandler eventHandler; Session session(sessionOptions, sessionConfigs, &eventHandler); - Request request(Request::Operation::GET_HISTORICAL_TRADES, "okx", "BTC-USDT"); + Request request(Request::Operation::GET_INSTRUMENTS, "bybit"); request.appendParam({ - {"before", "1"}, - {"after", "3"}, - {"limit", "1"}, + {"category", "linear"}, + {"limit", "1000"}, }); session.sendRequest(request); std::this_thread::sleep_for(std::chrono::seconds(10)); diff --git a/example/src/market_data_advanced_subscription/CMakeLists.txt b/example/market_data_advanced_subscription/CMakeLists.txt similarity index 78% rename from example/src/market_data_advanced_subscription/CMakeLists.txt rename to example/market_data_advanced_subscription/CMakeLists.txt index 527e25c01..ef4f47b67 100644 --- a/example/src/market_data_advanced_subscription/CMakeLists.txt +++ b/example/market_data_advanced_subscription/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME market_data_advanced_subscription) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/market_data_advanced_subscription/main.cpp b/example/market_data_advanced_subscription/main.cpp similarity index 93% rename from example/src/market_data_advanced_subscription/main.cpp rename to example/market_data_advanced_subscription/main.cpp index f86ecc92b..981c4e291 100644 --- a/example/src/market_data_advanced_subscription/main.cpp +++ b/example/market_data_advanced_subscription/main.cpp @@ -36,7 +36,7 @@ int main(int argc, char** argv) { MyEventHandler eventHandler; EventDispatcher eventDispatcher(2); Session session(sessionOptions, sessionConfigs, &eventHandler, &eventDispatcher); - Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH"); + Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH"); session.subscribe(subscription); std::this_thread::sleep_for(std::chrono::seconds(10)); session.stop(); @@ -45,7 +45,7 @@ int main(int argc, char** argv) { SessionOptions sessionOptions; SessionConfigs sessionConfigs; Session session(sessionOptions, sessionConfigs); - Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH"); + Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH"); session.subscribe(subscription); std::this_thread::sleep_for(std::chrono::seconds(10)); std::vector eventList = session.getEventQueue().purge(); diff --git a/example/src/market_data_simple_request/CMakeLists.txt b/example/market_data_simple_request/CMakeLists.txt similarity index 77% rename from example/src/market_data_simple_request/CMakeLists.txt rename to example/market_data_simple_request/CMakeLists.txt index c8e400594..2143c2dca 100644 --- a/example/src/market_data_simple_request/CMakeLists.txt +++ b/example/market_data_simple_request/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME market_data_simple_request) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/market_data_simple_request/main.cpp b/example/market_data_simple_request/main.cpp similarity index 92% rename from example/src/market_data_simple_request/main.cpp rename to example/market_data_simple_request/main.cpp index 564b34321..076e69b28 100644 --- a/example/src/market_data_simple_request/main.cpp +++ b/example/market_data_simple_request/main.cpp @@ -22,7 +22,7 @@ int main(int argc, char** argv) { SessionConfigs sessionConfigs; MyEventHandler eventHandler; Session session(sessionOptions, sessionConfigs, &eventHandler); - Request request(Request::Operation::GET_RECENT_TRADES, "okx", "BTC-USDT"); + Request request(Request::Operation::GET_RECENT_TRADES, "bybit", "BTCUSDT"); request.appendParam({ {"LIMIT", "1"}, }); diff --git a/example/src/market_data_simple_subscription/CMakeLists.txt b/example/market_data_simple_subscription/CMakeLists.txt similarity index 78% rename from example/src/market_data_simple_subscription/CMakeLists.txt rename to example/market_data_simple_subscription/CMakeLists.txt index c72cc7503..e08ea973d 100644 --- a/example/src/market_data_simple_subscription/CMakeLists.txt +++ b/example/market_data_simple_subscription/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME market_data_simple_subscription) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/market_data_simple_subscription/main.cpp b/example/market_data_simple_subscription/main.cpp similarity index 96% rename from example/src/market_data_simple_subscription/main.cpp rename to example/market_data_simple_subscription/main.cpp index ca9eff167..2a2e1c7d2 100644 --- a/example/src/market_data_simple_subscription/main.cpp +++ b/example/market_data_simple_subscription/main.cpp @@ -37,7 +37,7 @@ int main(int argc, char** argv) { SessionConfigs sessionConfigs; MyEventHandler eventHandler; Session session(sessionOptions, sessionConfigs, &eventHandler); - Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH"); + Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH"); session.subscribe(subscription); std::this_thread::sleep_for(std::chrono::seconds(10)); session.stop(); diff --git a/example/src/override_exchange_url_at_runtime/CMakeLists.txt b/example/override_exchange_url_at_runtime/CMakeLists.txt similarity index 78% rename from example/src/override_exchange_url_at_runtime/CMakeLists.txt rename to example/override_exchange_url_at_runtime/CMakeLists.txt index 68cfc8d13..aef5f0d72 100644 --- a/example/src/override_exchange_url_at_runtime/CMakeLists.txt +++ b/example/override_exchange_url_at_runtime/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME override_exchange_url_at_runtime) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/override_exchange_url_at_runtime/main.cpp b/example/override_exchange_url_at_runtime/main.cpp similarity index 93% rename from example/src/override_exchange_url_at_runtime/main.cpp rename to example/override_exchange_url_at_runtime/main.cpp index 8a2f119c1..9942ed2ac 100644 --- a/example/src/override_exchange_url_at_runtime/main.cpp +++ b/example/override_exchange_url_at_runtime/main.cpp @@ -35,11 +35,11 @@ int main(int argc, char** argv) { SessionOptions sessionOptions; SessionConfigs sessionConfigs; std::map urlWebsocketBase = sessionConfigs.getUrlWebsocketBase(); - urlWebsocketBase["okx"] = "wss://wsaws.okx.com:8443"; + urlWebsocketBase["bybit"] = "wss://wsaws.bybit.com:8443"; sessionConfigs.setUrlWebsocketBase(urlWebsocketBase); MyEventHandler eventHandler; Session session(sessionOptions, sessionConfigs, &eventHandler); - Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH"); + Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH"); session.subscribe(subscription); std::this_thread::sleep_for(std::chrono::seconds(10)); session.stop(); diff --git a/example/src/reduce_build_time/CMakeLists.txt b/example/reduce_build_time/CMakeLists.txt similarity index 78% rename from example/src/reduce_build_time/CMakeLists.txt rename to example/reduce_build_time/CMakeLists.txt index 0f6ad54bb..679aa2015 100644 --- a/example/src/reduce_build_time/CMakeLists.txt +++ b/example/reduce_build_time/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME reduce_build_time) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp my_session.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/reduce_build_time/main.cpp b/example/reduce_build_time/main.cpp similarity index 94% rename from example/src/reduce_build_time/main.cpp rename to example/reduce_build_time/main.cpp index 81a1537b6..f44cc5f21 100644 --- a/example/src/reduce_build_time/main.cpp +++ b/example/reduce_build_time/main.cpp @@ -29,7 +29,7 @@ int main(int argc, char** argv) { MyEventHandler eventHandler; MySession mySession(sessionOptions, sessionConfigs, &eventHandler); eventHandler.setMySessionPtr(&mySession); - Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH"); + Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH"); mySession.subscribe(subscription); std::this_thread::sleep_for(std::chrono::seconds(10)); mySession.stop(); diff --git a/example/src/reduce_build_time/my_session.cpp b/example/reduce_build_time/my_session.cpp similarity index 100% rename from example/src/reduce_build_time/my_session.cpp rename to example/reduce_build_time/my_session.cpp diff --git a/example/src/reduce_build_time/my_session.h b/example/reduce_build_time/my_session.h similarity index 100% rename from example/src/reduce_build_time/my_session.h rename to example/reduce_build_time/my_session.h diff --git a/example/src/set_timer/CMakeLists.txt b/example/set_timer/CMakeLists.txt similarity index 76% rename from example/src/set_timer/CMakeLists.txt rename to example/set_timer/CMakeLists.txt index 1d6386739..757ac1835 100644 --- a/example/src/set_timer/CMakeLists.txt +++ b/example/set_timer/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME set_timer) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/set_timer/main.cpp b/example/set_timer/main.cpp similarity index 95% rename from example/src/set_timer/main.cpp rename to example/set_timer/main.cpp index 0d5fcb03b..17a9aacf1 100644 --- a/example/src/set_timer/main.cpp +++ b/example/set_timer/main.cpp @@ -33,7 +33,7 @@ int main(int argc, char** argv) { SessionConfigs sessionConfigs; MyEventHandler eventHandler; Session session(sessionOptions, sessionConfigs, &eventHandler); - Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH"); + Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH"); session.subscribe(subscription); std::this_thread::sleep_for(std::chrono::seconds(10)); session.stop(); diff --git a/example/src/test_cpu_usage/CMakeLists.txt b/example/test_cpu_usage/CMakeLists.txt similarity index 76% rename from example/src/test_cpu_usage/CMakeLists.txt rename to example/test_cpu_usage/CMakeLists.txt index 0453cd25b..4ab3a16da 100644 --- a/example/src/test_cpu_usage/CMakeLists.txt +++ b/example/test_cpu_usage/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME test_cpu_usage) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/test_cpu_usage/main.cpp b/example/test_cpu_usage/main.cpp similarity index 99% rename from example/src/test_cpu_usage/main.cpp rename to example/test_cpu_usage/main.cpp index 64bb1a8dc..07857d055 100644 --- a/example/src/test_cpu_usage/main.cpp +++ b/example/test_cpu_usage/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char** argv) { SessionConfigs sessionConfigs; MyEventHandler eventHandler(subscriptionDataEventPrintCount); Session session(sessionOptions, sessionConfigs, &eventHandler); - std::string exchange = "okx"; + std::string exchange = "bybit"; if (instruments.empty()) { Request request(Request::Operation::GET_TICKERS, exchange); diff --git a/example/src/test_order_latency/CMakeLists.txt b/example/test_order_latency/CMakeLists.txt similarity index 78% rename from example/src/test_order_latency/CMakeLists.txt rename to example/test_order_latency/CMakeLists.txt index 6034f01ef..61cd16e36 100644 --- a/example/src/test_order_latency/CMakeLists.txt +++ b/example/test_order_latency/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME test_order_latency) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/test_order_latency/main.cpp b/example/test_order_latency/main.cpp similarity index 86% rename from example/src/test_order_latency/main.cpp rename to example/test_order_latency/main.cpp index a8aae7a46..c5866c7cc 100644 --- a/example/src/test_order_latency/main.cpp +++ b/example/test_order_latency/main.cpp @@ -24,7 +24,7 @@ class MyEventHandler : public EventHandler { if (event.getType() == Event::Type::SUBSCRIPTION_STATUS) { const auto& message = event.getMessageList().at(0); if (message.getType() == Message::Type::SUBSCRIPTION_STARTED) { - Request request(Request::Operation::GET_OPEN_ORDERS, "okx", this->symbol); + Request request(Request::Operation::GET_OPEN_ORDERS, "bybit", this->symbol); sessionPtr->sendRequest(request); } } else if (event.getType() == Event::Type::RESPONSE) { @@ -37,7 +37,7 @@ class MyEventHandler : public EventHandler { std::cout << std::string("Timer error handler is triggered at ") + UtilTime::getISOTimestamp(UtilTime::now()) << std::endl; }, [this, sessionPtr]() { - Request request(Request::Operation::CREATE_ORDER, "okx", this->symbol); + Request request(Request::Operation::CREATE_ORDER, "bybit", this->symbol); const auto& clientOrderId = UtilString::generateRandomString(this->clientOrderIdLength); request.appendParam({ {"SIDE", UtilString::toUpper(this->side)}, @@ -65,7 +65,7 @@ class MyEventHandler : public EventHandler { if (status == "live") { this->orderCreateLatencies.push_back(now - this->orderCreateTimes.at(clientOrderId)); this->orderCreateTimes.erase(clientOrderId); - Request request(Request::Operation::CANCEL_ORDER, "okx", this->symbol); + Request request(Request::Operation::CANCEL_ORDER, "bybit", this->symbol); if (this->cancelByClientOrderId) { request.appendParam({ {"CLIENT_ORDER_ID", clientOrderId}, @@ -124,18 +124,15 @@ using ::ccapi::Subscription; using ::ccapi::UtilSystem; int main(int argc, char** argv) { - if (UtilSystem::getEnvAsString("OKX_API_KEY").empty()) { - std::cerr << "Please set environment variable OKX_API_KEY" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_KEY").empty()) { + std::cerr << "Please set environment variable BYBIT_API_KEY" << std::endl; return EXIT_FAILURE; } - if (UtilSystem::getEnvAsString("OKX_API_SECRET").empty()) { - std::cerr << "Please set environment variable OKX_API_SECRET" << std::endl; - return EXIT_FAILURE; - } - if (UtilSystem::getEnvAsString("OKX_API_PASSPHRASE").empty()) { - std::cerr << "Please set environment variable OKX_API_PASSPHRASE" << std::endl; + if (UtilSystem::getEnvAsString("BYBIT_API_SECRET").empty()) { + std::cerr << "Please set environment variable BYBIT_API_SECRET" << std::endl; return EXIT_FAILURE; } + const auto& symbol = UtilSystem::getEnvAsString("SYMBOL"); const auto& side = UtilSystem::getEnvAsString("SIDE"); const auto& quantity = UtilSystem::getEnvAsString("QUANTITY"); @@ -147,16 +144,16 @@ int main(int argc, char** argv) { SessionOptions sessionOptions; SessionConfigs sessionConfigs; - const auto& okx_rest_fast_url = ccapi::UtilSystem::getEnvAsString("OKX_REST_FAST_URL"); - const auto& okx_websocket_fast_url = ccapi::UtilSystem::getEnvAsString("OKX_WEBSOCKET_FAST_URL"); + const auto& bybit_rest_fast_url = ccapi::UtilSystem::getEnvAsString("BYBIT_REST_FAST_URL"); + const auto& bybit_websocket_fast_url = ccapi::UtilSystem::getEnvAsString("BYBIT_WEBSOCKET_FAST_URL"); auto url_rest_base = sessionConfigs.getUrlRestBase(); - if (!okx_rest_fast_url.empty()) { - url_rest_base.at("okx") = okx_rest_fast_url; + if (!bybit_rest_fast_url.empty()) { + url_rest_base.at("bybit") = bybit_rest_fast_url; } sessionConfigs.setUrlRestBase(url_rest_base); std::map url_websocket_base = sessionConfigs.getUrlWebsocketBase(); - if (!okx_websocket_fast_url.empty()) { - url_websocket_base.at("okx") = okx_websocket_fast_url; + if (!bybit_websocket_fast_url.empty()) { + url_websocket_base.at("bybit") = bybit_websocket_fast_url; } sessionConfigs.setUrlWebsocketBase(url_websocket_base); @@ -164,7 +161,7 @@ int main(int argc, char** argv) { MyEventHandler eventHandler(symbol, side, quantity, price, clientOrderIdLength, cancelByClientOrderId, numOrders, byWebsocket, websocketOrderEntrySubscriptionCorrelationId); Session session(sessionOptions, sessionConfigs, &eventHandler); - Subscription subscription("okx", symbol, "ORDER_UPDATE", "", websocketOrderEntrySubscriptionCorrelationId); + Subscription subscription("bybit", symbol, "ORDER_UPDATE", "", websocketOrderEntrySubscriptionCorrelationId); session.subscribe(subscription); while (!eventHandler.done) { std::this_thread::sleep_for(std::chrono::seconds(1)); diff --git a/example/src/use_multiple_sessions/CMakeLists.txt b/example/use_multiple_sessions/CMakeLists.txt similarity index 77% rename from example/src/use_multiple_sessions/CMakeLists.txt rename to example/use_multiple_sessions/CMakeLists.txt index 47ccce6fc..daaa90718 100644 --- a/example/src/use_multiple_sessions/CMakeLists.txt +++ b/example/use_multiple_sessions/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME use_multiple_sessions) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) +add_compile_definitions(CCAPI_ENABLE_EXCHANG_BYBIT) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/use_multiple_sessions/main.cpp b/example/use_multiple_sessions/main.cpp similarity index 96% rename from example/src/use_multiple_sessions/main.cpp rename to example/use_multiple_sessions/main.cpp index a63c6c542..c1f621742 100644 --- a/example/src/use_multiple_sessions/main.cpp +++ b/example/use_multiple_sessions/main.cpp @@ -41,7 +41,7 @@ int main(int argc, char** argv) { {&session_1, "1"}, {&session_2, "2"}, }); - Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH"); + Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH"); session_1.subscribe(subscription); session_2.subscribe(subscription); diff --git a/include/ccapi_cpp/ccapi_element.h b/include/ccapi_cpp/ccapi_element.h index 9fb90c6c0..7f74c4b02 100644 --- a/include/ccapi_cpp/ccapi_element.h +++ b/include/ccapi_cpp/ccapi_element.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_ELEMENT_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_ELEMENT_H_ +#pragma once + #include #include @@ -125,4 +125,3 @@ class Element { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_ELEMENT_H_ diff --git a/include/ccapi_cpp/ccapi_event.h b/include/ccapi_cpp/ccapi_event.h index 745093e67..0bd6edeb3 100644 --- a/include/ccapi_cpp/ccapi_event.h +++ b/include/ccapi_cpp/ccapi_event.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_EVENT_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_EVENT_H_ +#pragma once + #include #include "ccapi_cpp/ccapi_logger.h" @@ -115,4 +115,3 @@ class Event { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_EVENT_H_ diff --git a/include/ccapi_cpp/ccapi_event_dispatcher.h b/include/ccapi_cpp/ccapi_event_dispatcher.h index 5d21395b3..de4635ffc 100644 --- a/include/ccapi_cpp/ccapi_event_dispatcher.h +++ b/include/ccapi_cpp/ccapi_event_dispatcher.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_EVENT_DISPATCHER_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_EVENT_DISPATCHER_H_ +#pragma once + #include #include @@ -104,4 +104,3 @@ class EventDispatcher { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_EVENT_DISPATCHER_H_ diff --git a/include/ccapi_cpp/ccapi_event_handler.h b/include/ccapi_cpp/ccapi_event_handler.h index 0abacc1a3..f1af77b72 100644 --- a/include/ccapi_cpp/ccapi_event_handler.h +++ b/include/ccapi_cpp/ccapi_event_handler.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_EVENT_HANDLER_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_EVENT_HANDLER_H_ +#pragma once + #include "ccapi_cpp/ccapi_event.h" namespace ccapi { @@ -27,4 +27,3 @@ class EventHandler { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_EVENT_HANDLER_H_ diff --git a/include/ccapi_cpp/ccapi_fix_connection.h b/include/ccapi_cpp/ccapi_fix_connection.h index ca6e7e03f..e3726ed5e 100644 --- a/include/ccapi_cpp/ccapi_fix_connection.h +++ b/include/ccapi_cpp/ccapi_fix_connection.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_FIX_CONNECTION_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_FIX_CONNECTION_H_ +#pragma once + #include #include @@ -125,4 +125,3 @@ class FixConnection { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_FIX_CONNECTION_H_ diff --git a/include/ccapi_cpp/ccapi_hmac.h b/include/ccapi_cpp/ccapi_hmac.h index edd1544e9..038258571 100644 --- a/include/ccapi_cpp/ccapi_hmac.h +++ b/include/ccapi_cpp/ccapi_hmac.h @@ -1,5 +1,4 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_HMAC_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_HMAC_H_ +#pragma once #include #include @@ -70,4 +69,3 @@ class Hmac { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_HMAC_H_ diff --git a/include/ccapi_cpp/ccapi_http_connection.h b/include/ccapi_cpp/ccapi_http_connection.h index ffc395f13..af836a2ce 100644 --- a/include/ccapi_cpp/ccapi_http_connection.h +++ b/include/ccapi_cpp/ccapi_http_connection.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_HTTP_CONNECTION_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_HTTP_CONNECTION_H_ +#pragma once + #include #include "ccapi_cpp/ccapi_logger.h" @@ -37,4 +37,3 @@ class HttpConnection { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_HTTP_CONNECTION_H_ diff --git a/include/ccapi_cpp/ccapi_http_retry.h b/include/ccapi_cpp/ccapi_http_retry.h index 92d9d84f8..40d446aec 100644 --- a/include/ccapi_cpp/ccapi_http_retry.h +++ b/include/ccapi_cpp/ccapi_http_retry.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_HTTP_RETRY_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_HTTP_RETRY_H_ +#pragma once + #include #include @@ -28,4 +28,3 @@ class HttpRetry { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_HTTP_RETRY_H_ diff --git a/include/ccapi_cpp/ccapi_inflate_stream.h b/include/ccapi_cpp/ccapi_inflate_stream.h index 80d646eb6..ae967b4d5 100644 --- a/include/ccapi_cpp/ccapi_inflate_stream.h +++ b/include/ccapi_cpp/ccapi_inflate_stream.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_INFLATE_STREAM_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_INFLATE_STREAM_H_ +#pragma once + #ifndef CCAPI_DECOMPRESS_BUFFER_SIZE #define CCAPI_DECOMPRESS_BUFFER_SIZE (1 << 20) #endif @@ -100,4 +100,3 @@ class InflateStream { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_INFLATE_STREAM_H_ diff --git a/include/ccapi_cpp/ccapi_jwt.h b/include/ccapi_cpp/ccapi_jwt.h index e45c5e392..b673563f7 100644 --- a/include/ccapi_cpp/ccapi_jwt.h +++ b/include/ccapi_cpp/ccapi_jwt.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_JWT_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_JWT_H_ +#pragma once + #include "ccapi_cpp/ccapi_hmac.h" #include "ccapi_cpp/ccapi_logger.h" #include "ccapi_cpp/ccapi_macro.h" @@ -30,4 +30,3 @@ class Jwt { } }; } // namespace ccapi -#endif // INCLUDE_CCAPI_CPP_CCAPI_JWT_H_ diff --git a/include/ccapi_cpp/ccapi_logger.h b/include/ccapi_cpp/ccapi_logger.h index afe7ac965..ede6d308a 100644 --- a/include/ccapi_cpp/ccapi_logger.h +++ b/include/ccapi_cpp/ccapi_logger.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_LOGGER_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_LOGGER_H_ +#pragma once + #ifdef _WIN32 #define CCAPI_LOGGER_FILE_SEPARATOR '\\' #else @@ -168,4 +168,3 @@ class Logger { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_LOGGER_H_ diff --git a/include/ccapi_cpp/ccapi_macro.h b/include/ccapi_cpp/ccapi_macro.h index 610cb737b..d50df7ced 100644 --- a/include/ccapi_cpp/ccapi_macro.h +++ b/include/ccapi_cpp/ccapi_macro.h @@ -1,5 +1,4 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_MACRO_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_MACRO_H_ +#pragma once #ifndef CCAPI_PRINT_DOUBLE_PRECISION_DEFAULT #define CCAPI_PRINT_DOUBLE_PRECISION_DEFAULT 10 @@ -418,6 +417,7 @@ #define CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_PARTIAL_BOOK_DEPTH "depth" #define CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_AGG_TRADE "aggTrade" #define CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_KLINE "kline" +#define CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_DIFF_DEPTH "depth" #define CCAPI_WEBSOCKET_HUOBI_CHANNEL_TRADE_DETAIL "market.$symbol.trade.detail" #define CCAPI_WEBSOCKET_HUOBI_CHANNEL_TRADE_DETAIL_REGEX "market\\.(.+)\\.trade\\.detail" #define CCAPI_WEBSOCKET_HUOBI_CHANNEL_MARKET_BBO "market.$symbol.bbo" @@ -1737,6 +1737,3 @@ #ifndef CCAPI_EM_CLIENT_ORDER_ID_SEQUENCE_NUMBER_PAD_TO_LENGTH #define CCAPI_EM_CLIENT_ORDER_ID_SEQUENCE_NUMBER_PAD_TO_LENGTH 3 #endif - -#endif -// INCLUDE_CCAPI_CPP_CCAPI_MACRO_H_ diff --git a/include/ccapi_cpp/ccapi_market_data_message.h b/include/ccapi_cpp/ccapi_market_data_message.h index 4760c020b..0c396c14f 100644 --- a/include/ccapi_cpp/ccapi_market_data_message.h +++ b/include/ccapi_cpp/ccapi_market_data_message.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_MARKET_DATA_MESSAGE_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_MARKET_DATA_MESSAGE_H_ +#pragma once + #include "ccapi_cpp/ccapi_logger.h" #include "ccapi_cpp/ccapi_util_private.h" @@ -176,43 +176,56 @@ class MarketDataMessage { return output; } - static std::string dataToString(const TypeForData& data) { + template + static std::string dataToString(const DataMap& data) { std::string output1 = "{"; auto size1 = data.size(); auto i1 = 0; + for (const auto& elem1 : data) { output1 += dataTypeToString(elem1.first); output1 += "="; + std::string output2 = "[ "; auto size2 = elem1.second.size(); auto i2 = 0; + for (const auto& elem2 : elem1.second) { std::string output3 = "{"; auto size3 = elem2.size(); auto i3 = 0; + for (const auto& elem3 : elem2) { output3 += dataFieldTypeToString(elem3.first); output3 += "="; + + // Works for std::string, std::string_view, or any type output3 += ccapi::toString(elem3.second); + if (i3 < size3 - 1) { output3 += ", "; } ++i3; } + output3 += "}"; output2 += output3; + if (i2 < size2 - 1) { output2 += ", "; } ++i2; } + output2 += " ]"; output1 += output2; + if (i1 < size1 - 1) { output1 += ", "; } ++i1; } + output1 += "}"; return output1; } @@ -243,7 +256,7 @@ class MarketDataMessage { std::string toString() const { std::string output = "MarketDataMessage [type = " + typeToString(type) + ", recapType = " + recapTypeToString(recapType) + ", tp = " + ccapi::toString(tp) + - ", exchangeSubscriptionId = " + exchangeSubscriptionId + ", data = " + dataToString(data) + "]"; + ", exchangeSubscriptionId = " + exchangeSubscriptionId + ", data = " + dataToString(data) + "]"; return output; } @@ -255,4 +268,3 @@ class MarketDataMessage { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_MARKET_DATA_MESSAGE_H_ diff --git a/include/ccapi_cpp/ccapi_message.h b/include/ccapi_cpp/ccapi_message.h index 8fe1a0580..8826c74a4 100644 --- a/include/ccapi_cpp/ccapi_message.h +++ b/include/ccapi_cpp/ccapi_message.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_MESSAGE_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_MESSAGE_H_ +#pragma once + #include #include @@ -315,4 +315,3 @@ class Message { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_MESSAGE_H_ diff --git a/include/ccapi_cpp/ccapi_queue.h b/include/ccapi_cpp/ccapi_queue.h index 31f5fc2b6..d73ae3e4c 100644 --- a/include/ccapi_cpp/ccapi_queue.h +++ b/include/ccapi_cpp/ccapi_queue.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_QUEUE_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_QUEUE_H_ +#pragma once + #include #include @@ -87,4 +87,3 @@ class Queue { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_QUEUE_H_ diff --git a/include/ccapi_cpp/ccapi_request.h b/include/ccapi_cpp/ccapi_request.h index 5e23b9796..0c3c22248 100644 --- a/include/ccapi_cpp/ccapi_request.h +++ b/include/ccapi_cpp/ccapi_request.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_REQUEST_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_REQUEST_H_ +#pragma once + #include #include #include @@ -318,4 +318,3 @@ class Request { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_REQUEST_H_ diff --git a/include/ccapi_cpp/ccapi_session.h b/include/ccapi_cpp/ccapi_session.h index 46a304ec5..bef7e9f83 100644 --- a/include/ccapi_cpp/ccapi_session.h +++ b/include/ccapi_cpp/ccapi_session.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_SESSION_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_SESSION_H_ +#pragma once + #include "ccapi_cpp/ccapi_macro.h" // start: enable exchanges for market data @@ -790,7 +790,7 @@ class Session { virtual void onEvent(Event& event, Queue* eventQueue) { CCAPI_LOGGER_FUNCTION_ENTER; - CCAPI_LOGGER_TRACE("event = " + toString(event)); + CCAPI_LOGGER_DEBUG("event = " + toString(event)); if (eventQueue) { eventQueue->pushBack(std::move(event)); } else { @@ -1038,4 +1038,3 @@ class Session { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_SESSION_H_ diff --git a/include/ccapi_cpp/ccapi_session_configs.h b/include/ccapi_cpp/ccapi_session_configs.h index 737d5675c..4123bde8b 100644 --- a/include/ccapi_cpp/ccapi_session_configs.h +++ b/include/ccapi_cpp/ccapi_session_configs.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_SESSION_CONFIGS_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_SESSION_CONFIGS_H_ +#pragma once + #include #include #include @@ -440,4 +440,3 @@ class SessionConfigs { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_SESSION_CONFIGS_H_ diff --git a/include/ccapi_cpp/ccapi_session_options.h b/include/ccapi_cpp/ccapi_session_options.h index ffec80108..601eaad86 100644 --- a/include/ccapi_cpp/ccapi_session_options.h +++ b/include/ccapi_cpp/ccapi_session_options.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_SESSION_OPTIONS_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_SESSION_OPTIONS_H_ +#pragma once + #include #include @@ -64,4 +64,3 @@ class SessionOptions { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_SESSION_OPTIONS_H_ diff --git a/include/ccapi_cpp/ccapi_subscription.h b/include/ccapi_cpp/ccapi_subscription.h index 5eb8fff01..e07f49694 100644 --- a/include/ccapi_cpp/ccapi_subscription.h +++ b/include/ccapi_cpp/ccapi_subscription.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_SUBSCRIPTION_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_SUBSCRIPTION_H_ +#pragma once + #include #include @@ -193,4 +193,3 @@ class Subscription { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_SUBSCRIPTION_H_ diff --git a/include/ccapi_cpp/ccapi_url.h b/include/ccapi_cpp/ccapi_url.h index a39fdaddf..8b8ac5a11 100644 --- a/include/ccapi_cpp/ccapi_url.h +++ b/include/ccapi_cpp/ccapi_url.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_URL_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_URL_H_ +#pragma once + #include #include @@ -120,4 +120,3 @@ class Url { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_URL_H_ diff --git a/include/ccapi_cpp/ccapi_util.h b/include/ccapi_cpp/ccapi_util.h index 3d0652c6e..7797ac120 100644 --- a/include/ccapi_cpp/ccapi_util.h +++ b/include/ccapi_cpp/ccapi_util.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_UTIL_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_UTIL_H_ +#pragma once + #include #include @@ -8,4 +8,3 @@ namespace ccapi { typedef std::chrono::time_point TimePoint; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_UTIL_H_ diff --git a/include/ccapi_cpp/ccapi_util_private.h b/include/ccapi_cpp/ccapi_util_private.h index 655a1d912..3e673b64d 100644 --- a/include/ccapi_cpp/ccapi_util_private.h +++ b/include/ccapi_cpp/ccapi_util_private.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_UTIL_PRIVATE_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_UTIL_PRIVATE_H_ +#pragma once + #ifdef _WIN32 #define timegm _mkgmtime #endif @@ -1877,4 +1877,3 @@ V mapGetWithDefault(const C& m, const K& key, const V defaultValu } } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_CCAPI_UTIL_PRIVATE_H_ diff --git a/include/ccapi_cpp/ccapi_ws_connection.h b/include/ccapi_cpp/ccapi_ws_connection.h index fdc28ca88..931ea09e9 100644 --- a/include/ccapi_cpp/ccapi_ws_connection.h +++ b/include/ccapi_cpp/ccapi_ws_connection.h @@ -1,5 +1,4 @@ -#ifndef INCLUDE_CCAPI_CPP_CCAPI_WS_CONNECTION_H_ -#define INCLUDE_CCAPI_CPP_CCAPI_WS_CONNECTION_H_ +#pragma once #include #include @@ -164,5 +163,3 @@ class WsConnection { }; } /* namespace ccapi */ - -#endif // INCLUDE_CCAPI_CPP_CCAPI_WS_CONNECTION_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service.h b/include/ccapi_cpp/service/ccapi_execution_management_service.h index 962012962..8e4358e3f 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #include @@ -373,4 +373,3 @@ class ExecutionManagementService : public Service { } /* namespace ccapi */ #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h b/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h index 5768cfe8a..4b6836134 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_ASCENDEX_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_ASCENDEX_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_ASCENDEX #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -520,4 +520,3 @@ class ExecutionManagementServiceAscendex : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_ASCENDEX_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h index 4d5603d3b..e19717dbb 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_BINANCE #ifndef CCAPI_BINANCE_CREATE_ORDER_PATH @@ -53,4 +53,3 @@ class ExecutionManagementServiceBinance : public ExecutionManagementServiceBinan } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_base.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_base.h index b56e81f53..c5b0370ed 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_base.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #if defined(CCAPI_ENABLE_EXCHANGE_BINANCE_US) || defined(CCAPI_ENABLE_EXCHANGE_BINANCE) || defined(CCAPI_ENABLE_EXCHANGE_BINANCE_USDS_FUTURES) || \ defined(CCAPI_ENABLE_EXCHANGE_BINANCE_COIN_FUTURES) @@ -873,4 +873,3 @@ class ExecutionManagementServiceBinanceBase : public ExecutionManagementService } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h index 237f0aaf4..9a9756757 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_COIN_FUTURES_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_COIN_FUTURES_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_BINANCE_COIN_FUTURES #include "ccapi_cpp/service/ccapi_execution_management_service_binance_derivatives_base.h" @@ -43,4 +43,3 @@ class ExecutionManagementServiceBinanceCoinFutures : public ExecutionManagementS } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_COIN_FUTURES_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_derivatives_base.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_derivatives_base.h index cf641ff62..a9141976e 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_derivatives_base.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_derivatives_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_DERIVATIVES_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_DERIVATIVES_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #if defined(CCAPI_ENABLE_EXCHANGE_BINANCE_USDS_FUTURES) || defined(CCAPI_ENABLE_EXCHANGE_BINANCE_COIN_FUTURES) #include "ccapi_cpp/service/ccapi_execution_management_service_binance_base.h" @@ -72,4 +72,3 @@ class ExecutionManagementServiceBinanceDerivativesBase : public ExecutionManagem } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_DERIVATIVES_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h index e3558727b..d4f7697fe 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_US_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_US_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_BINANCE_US #include "ccapi_cpp/service/ccapi_execution_management_service_binance_base.h" @@ -34,4 +34,3 @@ class ExecutionManagementServiceBinanceUs : public ExecutionManagementServiceBin } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_US_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h index 93bf5eae3..5fe30255a 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_USDS_FUTURES_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_USDS_FUTURES_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_BINANCE_USDS_FUTURES #include "ccapi_cpp/service/ccapi_execution_management_service_binance_derivatives_base.h" @@ -43,4 +43,3 @@ class ExecutionManagementServiceBinanceUsdsFutures : public ExecutionManagementS } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_USDS_FUTURES_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h index d73b2d1ab..476579802 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITFINEX_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITFINEX_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_BITFINEX #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -480,4 +480,3 @@ class ExecutionManagementServiceBitfinex : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITFINEX_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h index 67d9743d2..f24e64f2b 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITGET_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITGET_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_BITGET #include "ccapi_cpp/service/ccapi_execution_management_service_bitget_base.h" @@ -436,4 +436,3 @@ class ExecutionManagementServiceBitget : public ExecutionManagementServiceBitget } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITGET_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_base.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_base.h index 5a8df34da..0cca0050c 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_base.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITGET_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITGET_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #if defined(CCAPI_ENABLE_EXCHANGE_BITGET) || defined(CCAPI_ENABLE_EXCHANGE_BITGET_FUTURES) #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -83,4 +83,3 @@ class ExecutionManagementServiceBitgetBase : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITGET_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h index f5dbced38..10d8436aa 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITGET_FUTURES_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITGET_FUTURES_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_BITGET_FUTURES #include "ccapi_cpp/service/ccapi_execution_management_service_bitget_base.h" @@ -523,4 +523,3 @@ class ExecutionManagementServiceBitgetFutures : public ExecutionManagementServic } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITGET_FUTURES_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h index 69fd645e8..26764ba10 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITMART_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITMART_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_BITMART #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -462,4 +462,3 @@ class ExecutionManagementServiceBitmart : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITMART_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h index 2a7452a85..2f22c9b70 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITMEX_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITMEX_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_BITMEX #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -471,4 +471,3 @@ class ExecutionManagementServiceBitmex : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITMEX_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h index a30a17268..ec0f164c3 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITSTAMP_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITSTAMP_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_BITSTAMP #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -20,12 +20,12 @@ class ExecutionManagementServiceBitstamp : public ExecutionManagementService { this->apiSecretName = CCAPI_BITSTAMP_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); std::string prefix = "/api/v2"; - this->createOrderTarget = prefix + "/{buy_or_sell}/{order_type}/{currency_pair}/"; + this->createOrderTarget = prefix + "/{buy_or_sell}/{order_type}/{market_symbol}/"; this->cancelOrderTarget = prefix + "/cancel_order/"; this->getOrderTarget = prefix + "/order_status/"; - this->getOpenOrdersTarget = prefix + "/open_orders/{currency_pair}/"; - this->cancelOpenOrdersTarget = prefix + "/cancel_all_orders/{currency_pair}/"; - this->getAccountBalancesTarget = prefix + "/balance/{currency_pair}/"; + this->getOpenOrdersTarget = prefix + "/open_orders/"; + this->cancelOpenOrdersTarget = prefix + "/cancel_all_orders/{market_symbol}/"; + this->getAccountBalancesTarget = prefix + "/account_balances/"; this->getWebSocketsTokenTarget = prefix + "/websockets_token/"; } @@ -138,7 +138,7 @@ class ExecutionManagementServiceBitstamp : public ExecutionManagementService { std::string target = this->createOrderTarget; UtilString::replaceFirstOccurrence(target, "{buy_or_sell}", orderSide); UtilString::replaceFirstOccurrence(target, "{order_type}", orderType); - UtilString::replaceFirstOccurrence(target, "{currency_pair}", symbolId); + UtilString::replaceFirstOccurrence(target, "{market_symbol}", symbolId); UtilString::replaceFirstOccurrence(target, "//", "/"); req.target(target); std::string body; @@ -168,7 +168,10 @@ class ExecutionManagementServiceBitstamp : public ExecutionManagementService { req.method(http::verb::post); const std::map param = request.getFirstParamWithDefault(); std::string target = this->getOpenOrdersTarget; - UtilString::replaceFirstOccurrence(target, "{currency_pair}", symbolId.empty() ? "all" : symbolId); + if (!symbolId.empty()) { + target += symbolId; + target += "/"; + } req.target(target); this->signRequest(req, "", credential); } break; @@ -176,18 +179,14 @@ class ExecutionManagementServiceBitstamp : public ExecutionManagementService { req.method(http::verb::post); const std::map param = request.getFirstParamWithDefault(); std::string target = this->cancelOpenOrdersTarget; - UtilString::replaceFirstOccurrence(target, "{currency_pair}", symbolId); + UtilString::replaceFirstOccurrence(target, "{market_symbol}", symbolId); UtilString::replaceFirstOccurrence(target, "//", "/"); req.target(target); this->signRequest(req, "", credential); } break; case Request::Operation::GET_ACCOUNT_BALANCES: { req.method(http::verb::post); - const std::map param = request.getFirstParamWithDefault(); - std::string target = this->getAccountBalancesTarget; - UtilString::replaceFirstOccurrence(target, "{currency_pair}", symbolId); - UtilString::replaceFirstOccurrence(target, "//", "/"); - req.target(target); + req.target(this->getAccountBalancesTarget); this->signRequest(req, "", credential); } break; default: @@ -214,9 +213,8 @@ class ExecutionManagementServiceBitstamp : public ExecutionManagementService { {CCAPI_EM_CLIENT_ORDER_ID, std::make_pair("client_order_id", JsonDataType::INTEGER)}, {CCAPI_EM_ORDER_QUANTITY, std::make_pair("amount", JsonDataType::STRING)}, {CCAPI_EM_ORDER_LIMIT_PRICE, std::make_pair("price", JsonDataType::STRING)}, - {CCAPI_EM_ORDER_REMAINING_QUANTITY, std::make_pair("amount_remaining", JsonDataType::STRING)}, {CCAPI_EM_ORDER_STATUS, std::make_pair("status", JsonDataType::STRING)}, - {CCAPI_EM_ORDER_INSTRUMENT, std::make_pair("currency_pair", JsonDataType::STRING)}, + {CCAPI_EM_ORDER_INSTRUMENT, std::make_pair("market", JsonDataType::STRING)}, }; if (operation == Request::Operation::CANCEL_OPEN_ORDERS) { for (const auto& x : document["canceled"].GetArray()) { @@ -243,24 +241,11 @@ class ExecutionManagementServiceBitstamp : public ExecutionManagementService { const rj::Document& document) override { switch (request.getOperation()) { case Request::Operation::GET_ACCOUNT_BALANCES: { - std::map> balances; - for (auto itr = document.MemberBegin(); itr != document.MemberEnd(); ++itr) { - const auto& splitted = UtilString::split(itr->name.GetString(), '_'); - if (splitted.size() >= 2) { - const auto& type = splitted.at(1); - if (type == "available") { - balances[splitted.at(0)][CCAPI_EM_QUANTITY_AVAILABLE_FOR_TRADING] = itr->value.GetString(); - } else if (type == "balance") { - balances[splitted.at(0)][CCAPI_EM_QUANTITY_TOTAL] = itr->value.GetString(); - } - } - } - for (const auto& kv1 : balances) { + for (const auto& x : document.GetArray()) { Element element; - element.insert(CCAPI_EM_ASSET, UtilString::toUpper(kv1.first)); - for (const auto& kv2 : kv1.second) { - element.insert(kv2.first, kv2.second); - } + element.insert(CCAPI_EM_ASSET, x["currency"].GetString()); + element.insert(CCAPI_EM_QUANTITY_TOTAL, x["total"].GetString()); + element.insert(CCAPI_EM_QUANTITY_AVAILABLE_FOR_TRADING, x["available"].GetString()); elementList.emplace_back(std::move(element)); } } break; @@ -456,4 +441,3 @@ class ExecutionManagementServiceBitstamp : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BITSTAMP_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h index 8baeb0ed9..c6d3385dd 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BYBIT_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BYBIT_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_BYBIT #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -653,4 +653,3 @@ class ExecutionManagementServiceBybit : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BYBIT_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h b/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h index 576605062..7fdebbb8c 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_COINBASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_COINBASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_COINBASE #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -402,4 +402,3 @@ class ExecutionManagementServiceCoinbase : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_COINBASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h b/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h index 7202ec593..79b70e172 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_CRYPTOCOM_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_CRYPTOCOM_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_CRYPTOCOM #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -583,4 +583,3 @@ class ExecutionManagementServiceCryptocom : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_CRYPTOCOM_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h b/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h index 5d11fa03a..d47b639a0 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_DERIBIT_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_DERIBIT_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_DERIBIT #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -535,4 +535,3 @@ class ExecutionManagementServiceDeribit : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_DERIBIT_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_erisx.h b/include/ccapi_cpp/service/ccapi_execution_management_service_erisx.h index 406a81597..1581648a1 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_erisx.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_erisx.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_ERISX_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_ERISX_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_ERISX #include "ccapi_cpp/ccapi_jwt.h" @@ -239,4 +239,3 @@ class ExecutionManagementServiceErisx : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_ERISX_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h index e69074b14..3af65c5a4 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_FTX_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_FTX_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_FTX #include "ccapi_cpp/service/ccapi_execution_management_service_ftx_base.h" @@ -79,4 +79,3 @@ class ExecutionManagementServiceFtx : public ExecutionManagementServiceFtxBase { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_FTX_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_base.h b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_base.h index e0f881a0b..b8e472b3e 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_base.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_FTX_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_FTX_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #if defined(CCAPI_ENABLE_EXCHANGE_FTX) || defined(CCAPI_ENABLE_EXCHANGE_FTX_US) #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -441,4 +441,3 @@ class ExecutionManagementServiceFtxBase : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_FTX_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h index 60adb1011..0a852e558 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_FTX_US_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_FTX_US_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_FTX_US #include "ccapi_cpp/service/ccapi_execution_management_service_ftx_base.h" @@ -41,4 +41,3 @@ class ExecutionManagementServiceFtxUs : public ExecutionManagementServiceFtxBase } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_FTX_US_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h index b5dd4b68a..be2fb34b8 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_GATEIO_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_GATEIO_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_GATEIO #include "ccapi_cpp/service/ccapi_execution_management_service_gateio_base.h" @@ -38,4 +38,3 @@ class ExecutionManagementServiceGateio : public ExecutionManagementServiceGateio } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_GATEIO_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_base.h b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_base.h index 20b66f522..c5f33e630 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_base.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_GATEIO_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_GATEIO_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #if defined(CCAPI_ENABLE_EXCHANGE_GATEIO) || defined(CCAPI_ENABLE_EXCHANGE_GATEIO_PERPETUAL_FUTURES) #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -465,4 +465,3 @@ class ExecutionManagementServiceGateioBase : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_GATEIO_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h index bb1291522..6aaf0db4d 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_GATEIO_PERPETUAL_FUTURES_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_GATEIO_PERPETUAL_FUTURES_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_GATEIO_PERPETUAL_FUTURES #include "ccapi_cpp/service/ccapi_execution_management_service_gateio_base.h" @@ -117,4 +117,3 @@ class ExecutionManagementServiceGateioPerpetualFutures : public ExecutionManagem } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_GATEIO_PERPETUAL_FUTURES_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h b/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h index 1913ce2db..2399d55b5 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_GEMINI_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_GEMINI_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_GEMINI #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -421,4 +421,3 @@ class ExecutionManagementServiceGemini : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_GEMINI_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h index 0af963f1e..960d1fc4f 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_HUOBI_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_HUOBI_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_HUOBI #include "ccapi_cpp/service/ccapi_execution_management_service_huobi_base.h" @@ -438,4 +438,3 @@ class ExecutionManagementServiceHuobi : public ExecutionManagementServiceHuobiBa } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_HUOBI_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_base.h b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_base.h index 86f289b22..d3e3f1e09 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_base.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_HUOBI_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_HUOBI_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #if defined(CCAPI_ENABLE_EXCHANGE_HUOBI) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP) #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -137,4 +137,3 @@ class ExecutionManagementServiceHuobiBase : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_HUOBI_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h index 7f8f1d96b..a35def54a 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_HUOBI_COIN_SWAP_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_HUOBI_COIN_SWAP_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP #include "ccapi_cpp/service/ccapi_execution_management_service_huobi_derivatives_base.h" @@ -35,4 +35,3 @@ class ExecutionManagementServiceHuobiCoinSwap : public ExecutionManagementServic } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_HUOBI_COIN_SWAP_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_derivatives_base.h b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_derivatives_base.h index 60e39d6a9..46ddb310e 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_derivatives_base.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_derivatives_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_HUOBI_DERIVATIVES_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_HUOBI_DERIVATIVES_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #if defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP) #include "ccapi_cpp/ccapi_util_private.h" @@ -421,4 +421,3 @@ class ExecutionManagementServiceHuobiDerivativesBase : public ExecutionManagemen } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_HUOBI_DERIVATIVES_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h index 3245911e5..437bbfd16 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_HUOBI_USDT_SWAP_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_HUOBI_USDT_SWAP_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP #include "ccapi_cpp/service/ccapi_execution_management_service_huobi_derivatives_base.h" @@ -35,4 +35,3 @@ class ExecutionManagementServiceHuobiUsdtSwap : public ExecutionManagementServic } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_HUOBI_USDT_SWAP_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h index ba89e56f6..6ed6bfb9d 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_KRAKEN_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_KRAKEN_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_KRAKEN #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -478,4 +478,3 @@ class ExecutionManagementServiceKraken : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_KRAKEN_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h index 5497bf053..4c80c9be5 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_KRAKEN_FUTURES_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_KRAKEN_FUTURES_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_KRAKEN_FUTURES #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -436,4 +436,3 @@ class ExecutionManagementServiceKrakenFutures : public ExecutionManagementServic } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_KRAKEN_FUTURES_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h index 8d437c9a7..308e27238 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_KUCOIN_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_KUCOIN_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_KUCOIN #include "ccapi_cpp/service/ccapi_execution_management_service_kucoin_base.h" @@ -66,4 +66,3 @@ class ExecutionManagementServiceKucoin : public ExecutionManagementServiceKucoin } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_KUCOIN_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_base.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_base.h index e605b3682..db1085edd 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_base.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_KUCOIN_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_KUCOIN_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #if defined(CCAPI_ENABLE_EXCHANGE_KUCOIN) || defined(CCAPI_ENABLE_EXCHANGE_KUCOIN_FUTURES) #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -495,4 +495,3 @@ class ExecutionManagementServiceKucoinBase : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_KUCOIN_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h index 7d13be86c..c97c032c0 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_KUCOIN_FUTURES_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_KUCOIN_FUTURES_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_KUCOIN_FUTURES #include "ccapi_cpp/service/ccapi_execution_management_service_kucoin_base.h" @@ -67,4 +67,3 @@ class ExecutionManagementServiceKucoinFutures : public ExecutionManagementServic } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_KUCOIN_FUTURES_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h index 0882070b5..2ef7a8e96 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_MEXC_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_MEXC_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_MEXC #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -449,4 +449,3 @@ class ExecutionManagementServiceMexc : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_MEXC_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h index 7aa548bbe..4cbe92f0c 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_MEXC_FUTURES_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_MEXC_FUTURES_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_MEXC_FUTURES #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -546,4 +546,3 @@ this->send(wsConnectionPtr, sendString, ec); } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_MEXC_FUTURES_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h b/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h index 0b9e50d36..36787b3ec 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_OKX_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_OKX_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT #ifdef CCAPI_ENABLE_EXCHANGE_OKX #include "ccapi_cpp/service/ccapi_execution_management_service.h" @@ -670,4 +670,3 @@ class ExecutionManagementServiceOkx : public ExecutionManagementService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_OKX_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_whitebit.h b/include/ccapi_cpp/service/ccapi_execution_management_service_whitebit.h index e69de29bb..6f70f09be 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_whitebit.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_whitebit.h @@ -0,0 +1 @@ +#pragma once diff --git a/include/ccapi_cpp/service/ccapi_fix_service.h b/include/ccapi_cpp/service/ccapi_fix_service.h index 70f40af52..f63b37734 100644 --- a/include/ccapi_cpp/service/ccapi_fix_service.h +++ b/include/ccapi_cpp/service/ccapi_fix_service.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_FIX #ifndef CCAPI_FIX_READ_BUFFER_SIZE #define CCAPI_FIX_READ_BUFFER_SIZE (1 << 20) @@ -170,7 +170,7 @@ class FixService : public Service { if constexpr (std::is_same_v>) { if (!SSL_set_tlsext_host_name(streamPtr->native_handle(), fixConnectionPtr->host.c_str())) { beast::error_code ec{static_cast(::ERR_get_error()), net::error::get_ssl_category()}; - CCAPI_LOGGER_DEBUG("error SSL_set_tlsext_host_name: " + ec.message()); + CCAPI_LOGGER_DEBUG("error SSL_set_tlsext_host_name for host " + fixConnectionPtr->host + ": " + ec.message()); this->onError(Event::Type::FIX_STATUS, Message::Type::FIX_FAILURE, ec, "set SNI Hostname", {fixConnectionPtr->subscription.getCorrelationId()}); return; } @@ -698,4 +698,3 @@ class FixService : public Service { } /* namespace ccapi */ #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_H_ diff --git a/include/ccapi_cpp/service/ccapi_fix_service_binance.h b/include/ccapi_cpp/service/ccapi_fix_service_binance.h index ff145e39a..d6611a7a4 100644 --- a/include/ccapi_cpp/service/ccapi_fix_service_binance.h +++ b/include/ccapi_cpp/service/ccapi_fix_service_binance.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_BINANCE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_BINANCE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_FIX #ifdef CCAPI_ENABLE_EXCHANGE_BINANCE #include "ccapi_cpp/ccapi_hmac.h" @@ -88,4 +88,3 @@ class FixServiceBinance : public FixService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_BINANCE_H_ diff --git a/include/ccapi_cpp/service/ccapi_fix_service_coinbase.h b/include/ccapi_cpp/service/ccapi_fix_service_coinbase.h index ab1a8e2ce..63c7917b2 100644 --- a/include/ccapi_cpp/service/ccapi_fix_service_coinbase.h +++ b/include/ccapi_cpp/service/ccapi_fix_service_coinbase.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_COINBASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_COINBASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_FIX #ifdef CCAPI_ENABLE_EXCHANGE_COINBASE #include "ccapi_cpp/ccapi_hmac.h" @@ -70,4 +70,3 @@ class FixServiceCoinbase : public FixService } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_FTX_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_fix_service_ftx_us.h b/include/ccapi_cpp/service/ccapi_fix_service_ftx_us.h index 9d03c9bf9..963b16fce 100644 --- a/include/ccapi_cpp/service/ccapi_fix_service_ftx_us.h +++ b/include/ccapi_cpp/service/ccapi_fix_service_ftx_us.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_FTX_US_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_FTX_US_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_FIX #ifdef CCAPI_ENABLE_EXCHANGE_FTX_US #include "ccapi_cpp/ccapi_hmac.h" @@ -34,4 +34,3 @@ class FixServiceFtxUs : public FixServiceFtxBase { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_FTX_US_H_ diff --git a/include/ccapi_cpp/service/ccapi_fix_service_gemini.h b/include/ccapi_cpp/service/ccapi_fix_service_gemini.h index 31496535a..7c6d2b5d0 100644 --- a/include/ccapi_cpp/service/ccapi_fix_service_gemini.h +++ b/include/ccapi_cpp/service/ccapi_fix_service_gemini.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_GEMINI_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_GEMINI_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_FIX #ifdef CCAPI_ENABLE_EXCHANGE_GEMINI #include "ccapi_cpp/service/ccapi_fix_service.h" @@ -56,4 +56,3 @@ class FixServiceGemini : public FixService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_FIX_SERVICE_GEMINI_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service.h b/include/ccapi_cpp/service/ccapi_market_data_service.h index 33a1afb12..85e8a3117 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #include #include @@ -870,7 +870,7 @@ class MarketDataService : public Service { const TimePoint& tp, const TimePoint& timeReceived, MarketDataMessage::TypeForData& input, const std::string& field, const std::map& optionMap, const std::vector& correlationIdList, std::map& snapshotBid, std::map& snapshotAsk) { - CCAPI_LOGGER_TRACE("input = " + MarketDataMessage::dataToString(input)); + CCAPI_LOGGER_TRACE("input = " + MarketDataMessage::dataToString(input)); if (this->processedInitialSnapshotByConnectionIdChannelIdSymbolIdMap[wsConnectionPtr->id][channelId][symbolId]) { std::vector messageList; CCAPI_LOGGER_TRACE("optionMap = " + toString(optionMap)); @@ -988,7 +988,7 @@ class MarketDataService : public Service { void processTrade(std::shared_ptr wsConnectionPtr, const std::string& channelId, const std::string& symbolId, Event& event, const TimePoint& tp, const TimePoint& timeReceived, MarketDataMessage::TypeForData& input, const std::string& field, const std::map& optionMap, const std::vector& correlationIdList, bool isSolicited) { - CCAPI_LOGGER_TRACE("input = " + MarketDataMessage::dataToString(input)); + CCAPI_LOGGER_TRACE("input = " + MarketDataMessage::dataToString(input)); CCAPI_LOGGER_TRACE("optionMap = " + toString(optionMap)); bool shouldConflate = optionMap.at(CCAPI_CONFLATE_INTERVAL_MILLISECONDS) != CCAPI_CONFLATE_INTERVAL_MILLISECONDS_DEFAULT; CCAPI_LOGGER_TRACE("shouldConflate = " + toString(shouldConflate)); @@ -1459,20 +1459,18 @@ class MarketDataService : public Service { } void buildOrderBookInitialOnFail(std::shared_ptr wsConnectionPtr, const std::string& exchangeSubscriptionId, long delayMilliseconds) { - auto thisDelayMilliseconds = delayMilliseconds * 2; - if (thisDelayMilliseconds > 0) { - TimerPtr timerPtr(new boost::asio::steady_timer(*this->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(thisDelayMilliseconds))); - timerPtr->async_wait([wsConnectionPtr, exchangeSubscriptionId, thisDelayMilliseconds, that = this](ErrorCode const& ec) { - if (ec) { - that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); - } else { - that->buildOrderBookInitial(wsConnectionPtr, exchangeSubscriptionId, thisDelayMilliseconds); - } - }); - this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap[wsConnectionPtr->id][exchangeSubscriptionId] = timerPtr; - } else { - this->buildOrderBookInitial(wsConnectionPtr, exchangeSubscriptionId, thisDelayMilliseconds); - } + CCAPI_LOGGER_ERROR("buildOrderBookInitialOnFail: wsConnectionPtr = " + toString(*wsConnectionPtr) + ", exchangeSubscriptionId = " + exchangeSubscriptionId + + ", delayMilliseconds = " + toString(delayMilliseconds)); + auto thisDelayMilliseconds = delayMilliseconds > 0 ? delayMilliseconds * 2 : 1000; + TimerPtr timerPtr(new boost::asio::steady_timer(*this->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(thisDelayMilliseconds))); + timerPtr->async_wait([wsConnectionPtr, exchangeSubscriptionId, thisDelayMilliseconds, that = this](ErrorCode const& ec) { + if (ec) { + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); + } else { + that->buildOrderBookInitial(wsConnectionPtr, exchangeSubscriptionId, thisDelayMilliseconds); + } + }); + this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap[wsConnectionPtr->id][exchangeSubscriptionId] = timerPtr; } void buildOrderBookInitial(std::shared_ptr wsConnectionPtr, const std::string& exchangeSubscriptionId, long delayMilliseconds) { @@ -1536,39 +1534,39 @@ class MarketDataService : public Service { } } } - if (that->marketDataMessageDataBufferByConnectionIdExchangeSubscriptionIdVersionIdMap.at(wsConnectionPtr->id).find(exchangeSubscriptionId) != - that->marketDataMessageDataBufferByConnectionIdExchangeSubscriptionIdVersionIdMap.at(wsConnectionPtr->id).end()) { - auto it = that->marketDataMessageDataBufferByConnectionIdExchangeSubscriptionIdVersionIdMap.at(wsConnectionPtr->id) - .at(exchangeSubscriptionId) - .upper_bound(versionId); - while (it != that->marketDataMessageDataBufferByConnectionIdExchangeSubscriptionIdVersionIdMap.at(wsConnectionPtr->id) - .at(exchangeSubscriptionId) - .end()) { - const auto& input = it->second; - for (const auto& x : input) { - const auto& type = x.first; - const auto& detail = x.second; - if (type == MarketDataMessage::DataType::BID) { - for (const auto& y : detail) { - const auto& price = y.at(MarketDataMessage::DataFieldType::PRICE); - const auto& size = y.at(MarketDataMessage::DataFieldType::SIZE); - Decimal decimalPrice(price); - that->updateOrderBook(snapshotBid, decimalPrice, size, that->sessionOptions.enableCheckOrderBookChecksum); - } - } else if (type == MarketDataMessage::DataType::ASK) { - for (const auto& y : detail) { - const auto& price = y.at(MarketDataMessage::DataFieldType::PRICE); - const auto& size = y.at(MarketDataMessage::DataFieldType::SIZE); - Decimal decimalPrice(price); - that->updateOrderBook(snapshotAsk, decimalPrice, size, that->sessionOptions.enableCheckOrderBookChecksum); - } + // if (that->marketDataMessageDataBufferByConnectionIdExchangeSubscriptionIdVersionIdMap.at(wsConnectionPtr->id).find(exchangeSubscriptionId) != + // that->marketDataMessageDataBufferByConnectionIdExchangeSubscriptionIdVersionIdMap.at(wsConnectionPtr->id).end()) { + auto it = that->marketDataMessageDataBufferByConnectionIdExchangeSubscriptionIdVersionIdMap.at(wsConnectionPtr->id) + .at(exchangeSubscriptionId) + .upper_bound(versionId); + while (it != that->marketDataMessageDataBufferByConnectionIdExchangeSubscriptionIdVersionIdMap.at(wsConnectionPtr->id) + .at(exchangeSubscriptionId) + .end()) { + const auto& input = it->second; + for (const auto& x : input) { + const auto& type = x.first; + const auto& detail = x.second; + if (type == MarketDataMessage::DataType::BID) { + for (const auto& y : detail) { + const auto& price = y.at(MarketDataMessage::DataFieldType::PRICE); + const auto& size = y.at(MarketDataMessage::DataFieldType::SIZE); + Decimal decimalPrice(price); + that->updateOrderBook(snapshotBid, decimalPrice, size, that->sessionOptions.enableCheckOrderBookChecksum); + } + } else if (type == MarketDataMessage::DataType::ASK) { + for (const auto& y : detail) { + const auto& price = y.at(MarketDataMessage::DataFieldType::PRICE); + const auto& size = y.at(MarketDataMessage::DataFieldType::SIZE); + Decimal decimalPrice(price); + that->updateOrderBook(snapshotAsk, decimalPrice, size, that->sessionOptions.enableCheckOrderBookChecksum); } } - that->orderbookVersionIdByConnectionIdExchangeSubscriptionIdMap[wsConnectionPtr->id][exchangeSubscriptionId] = it->first; - it++; } - that->marketDataMessageDataBufferByConnectionIdExchangeSubscriptionIdVersionIdMap.at(wsConnectionPtr->id).erase(exchangeSubscriptionId); + that->orderbookVersionIdByConnectionIdExchangeSubscriptionIdMap[wsConnectionPtr->id][exchangeSubscriptionId] = it->first; + it++; } + that->marketDataMessageDataBufferByConnectionIdExchangeSubscriptionIdVersionIdMap.at(wsConnectionPtr->id).erase(exchangeSubscriptionId); + // } Event event; event.setType(Event::Type::SUBSCRIPTION_DATA); std::vector elementList; @@ -1737,4 +1735,3 @@ class MarketDataService : public Service { } /* namespace ccapi */ #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h b/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h index 31a47d4bb..b70e109f2 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_ASCENDEX_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_ASCENDEX_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_ASCENDEX #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -330,4 +330,3 @@ class MarketDataServiceAscendex : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_ASCENDEX_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance.h index 2f6904d66..44726a05d 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_BINANCE #include "ccapi_cpp/service/ccapi_market_data_service_binance_base.h" @@ -37,4 +37,3 @@ class MarketDataServiceBinance : public MarketDataServiceBinanceBase { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_base.h index 2dcb5a454..4c9c55442 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #if defined(CCAPI_ENABLE_EXCHANGE_BINANCE_US) || defined(CCAPI_ENABLE_EXCHANGE_BINANCE) || defined(CCAPI_ENABLE_EXCHANGE_BINANCE_USDS_FUTURES) || \ defined(CCAPI_ENABLE_EXCHANGE_BINANCE_COIN_FUTURES) @@ -22,7 +22,6 @@ class MarketDataServiceBinanceBase : public MarketDataService { #endif void onOpen(std::shared_ptr wsConnectionPtr) override { - CCAPI_LOGGER_FUNCTION_ENTER; Service::onOpen(wsConnectionPtr); this->startSubscribe(wsConnectionPtr); } @@ -35,15 +34,22 @@ class MarketDataServiceBinanceBase : public MarketDataService { if (marketDepthRequested == 1) { channelId = CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_BOOK_TICKER; } else { - int marketDepthSubscribedToExchange = 1; - marketDepthSubscribedToExchange = this->calculateMarketDepthAllowedByExchange(marketDepthRequested, std::vector({5, 10, 20})); std::string updateSpeed; if (conflateIntervalMilliseconds < 1000) { updateSpeed = "100ms"; } - channelId += std::string("?") + CCAPI_MARKET_DEPTH_SUBSCRIBED_TO_EXCHANGE + "=" + std::to_string(marketDepthSubscribedToExchange); - if (!updateSpeed.empty()) { - channelId += "&UPDATE_SPEED=" + updateSpeed; + int marketDepthSubscribedToExchange = 1; + marketDepthSubscribedToExchange = this->calculateMarketDepthAllowedByExchange(marketDepthRequested, std::vector({5, 10, 20, 5000})); + if (marketDepthSubscribedToExchange > 20) { + channelId = CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_DIFF_DEPTH; + if (!updateSpeed.empty()) { + channelId += "?UPDATE_SPEED=" + updateSpeed; + } + } else { + channelId += std::string("?") + CCAPI_MARKET_DEPTH_SUBSCRIBED_TO_EXCHANGE + "=" + std::to_string(marketDepthSubscribedToExchange); + if (!updateSpeed.empty()) { + channelId += "&UPDATE_SPEED=" + updateSpeed; + } } this->marketDepthSubscribedToExchangeByConnectionIdChannelIdSymbolIdMap[wsConnectionPtr->id][channelId][symbolId] = marketDepthSubscribedToExchange; } @@ -70,16 +76,27 @@ class MarketDataServiceBinanceBase : public MarketDataService { if (channelId.rfind(CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_BOOK_TICKER, 0) == 0) { this->l2UpdateIsReplaceByConnectionIdChannelIdSymbolIdMap[wsConnectionPtr->id][channelId][symbolId] = true; exchangeSubscriptionId += CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_BOOK_TICKER; - } else if (channelId.rfind(CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_PARTIAL_BOOK_DEPTH, 0) == 0) { - this->l2UpdateIsReplaceByConnectionIdChannelIdSymbolIdMap[wsConnectionPtr->id][channelId][symbolId] = true; - int marketDepthSubscribedToExchange = - this->marketDepthSubscribedToExchangeByConnectionIdChannelIdSymbolIdMap.at(wsConnectionPtr->id).at(channelId).at(symbolId); - exchangeSubscriptionId += std::string(CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_PARTIAL_BOOK_DEPTH) + std::to_string(marketDepthSubscribedToExchange); - auto splitted = UtilString::split(channelId, "?"); - if (splitted.size() == 2) { - auto mapped = Url::convertQueryStringToMap(splitted.at(1)); - if (mapped.find("UPDATE_SPEED") != mapped.end()) { - exchangeSubscriptionId += "@" + mapped.at("UPDATE_SPEED"); + } else if (channelId.rfind("depth", 0) == 0) { + if (channelId.find("MARKET_DEPTH_SUBSCRIBED_TO_EXCHANGE=") != std::string::npos) { + this->l2UpdateIsReplaceByConnectionIdChannelIdSymbolIdMap[wsConnectionPtr->id][channelId][symbolId] = true; + int marketDepthSubscribedToExchange = + this->marketDepthSubscribedToExchangeByConnectionIdChannelIdSymbolIdMap.at(wsConnectionPtr->id).at(channelId).at(symbolId); + exchangeSubscriptionId += std::string(CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_PARTIAL_BOOK_DEPTH) + std::to_string(marketDepthSubscribedToExchange); + const auto& splitted = UtilString::split(channelId, "?"); + if (splitted.size() == 2) { + const auto& mapped = Url::convertQueryStringToMap(splitted.at(1)); + if (mapped.find("UPDATE_SPEED") != mapped.end()) { + exchangeSubscriptionId += "@" + mapped.at("UPDATE_SPEED"); + } + } + } else { + exchangeSubscriptionId += std::string(CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_DIFF_DEPTH); + const auto& splitted = UtilString::split(channelId, "?"); + if (splitted.size() == 2) { + const auto& mapped = Url::convertQueryStringToMap(splitted.at(1)); + if (mapped.find("UPDATE_SPEED") != mapped.end()) { + exchangeSubscriptionId += "@" + mapped.at("UPDATE_SPEED"); + } } } } else { @@ -105,6 +122,44 @@ class MarketDataServiceBinanceBase : public MarketDataService { return sendStringList; } + bool isDiffBookDepthStream(const std::string& channelId) { + const std::string search_term = "depth"; + size_t pos = channelId.find(search_term); + if (pos == std::string::npos) { + return false; + } + if (channelId.find("MARKET_DEPTH_SUBSCRIBED_TO_EXCHANGE=") != std::string::npos) { + return false; + } + return true; + } + + void createFetchOrderBookInitialReq(http::request& req, const std::string& symbolId, const TimePoint& now, + const std::map& credential) override { + req.set(http::field::host, this->hostRest); + req.method(http::verb::get); + req.target(this->getMarketDepthTarget + "?symbol=" + Url::urlEncode(symbolId) + "&limit=5000"); + } + + void extractOrderBookInitialVersionId(int64_t& versionId, const rj::Document& document) override { + versionId = std::stoll(document["lastUpdateId"].GetString()); + } + + void extractOrderBookInitialData(MarketDataMessage::TypeForData& input, const rj::Document& document) override { + for (const auto& x : document["bids"].GetArray()) { + MarketDataMessage::TypeForDataPoint dataPoint; + dataPoint.emplace(MarketDataMessage::DataFieldType::PRICE, UtilString::normalizeDecimalStringView(x[0].GetString())); + dataPoint.emplace(MarketDataMessage::DataFieldType::SIZE, UtilString::normalizeDecimalStringView(x[1].GetString())); + input[MarketDataMessage::DataType::BID].emplace_back(std::move(dataPoint)); + } + for (const auto& x : document["asks"].GetArray()) { + MarketDataMessage::TypeForDataPoint dataPoint; + dataPoint.emplace(MarketDataMessage::DataFieldType::PRICE, UtilString::normalizeDecimalStringView(x[0].GetString())); + dataPoint.emplace(MarketDataMessage::DataFieldType::SIZE, UtilString::normalizeDecimalStringView(x[1].GetString())); + input[MarketDataMessage::DataType::ASK].emplace_back(std::move(dataPoint)); + } + } + void processTextMessage(std::shared_ptr wsConnectionPtr, boost::beast::string_view textMessageView, const TimePoint& timeReceived, Event& event, std::vector& marketDataMessageList) override { this->jsonDocumentAllocator.Clear(); @@ -173,39 +228,70 @@ class MarketDataServiceBinanceBase : public MarketDataService { marketDataMessage.data[MarketDataMessage::DataType::ASK].emplace_back(std::move(dataPoint)); } marketDataMessageList.emplace_back(std::move(marketDataMessage)); - } else if (channelId.rfind(CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_PARTIAL_BOOK_DEPTH, 0) == 0) { - marketDataMessage.type = MarketDataMessage::Type::MARKET_DATA_EVENTS_MARKET_DEPTH; - marketDataMessage.recapType = this->processedInitialSnapshotByConnectionIdChannelIdSymbolIdMap[wsConnectionPtr->id][channelId][symbolId] - ? MarketDataMessage::RecapType::NONE - : MarketDataMessage::RecapType::SOLICITED; - marketDataMessage.tp = this->isDerivatives ? TimePoint(std::chrono::milliseconds(std::stoll(data["T"].GetString()))) : timeReceived; - marketDataMessage.exchangeSubscriptionId = exchangeSubscriptionId; - const char* bidsName = this->isDerivatives ? "b" : "bids"; - int bidIndex = 0; - int maxMarketDepth = std::stoi(optionMap.at(CCAPI_MARKET_DEPTH_MAX)); - for (const auto& x : data[bidsName].GetArray()) { - if (bidIndex >= maxMarketDepth) { - break; + } else if (channelId.rfind("depth", 0) == 0) { + if (this->isDiffBookDepthStream(channelId)) { + MarketDataMessage marketDataMessage; + marketDataMessage.type = MarketDataMessage::Type::MARKET_DATA_EVENTS_MARKET_DEPTH; + marketDataMessage.exchangeSubscriptionId = exchangeSubscriptionId; + marketDataMessage.tp = this->isDerivatives ? TimePoint(std::chrono::milliseconds(std::stoll(data["T"].GetString()))) : timeReceived; + marketDataMessage.recapType = MarketDataMessage::RecapType::NONE; + const auto& itAsks = data.FindMember("a"); + if (itAsks != data.MemberEnd()) { + const rj::Value& asks = itAsks->value; + for (auto& x : asks.GetArray()) { + MarketDataMessage::TypeForDataPoint dataPoint; + dataPoint.emplace(MarketDataMessage::DataFieldType::PRICE, UtilString::normalizeDecimalStringView(x[0].GetString())); + dataPoint.emplace(MarketDataMessage::DataFieldType::SIZE, UtilString::normalizeDecimalStringView(x[1].GetString())); + marketDataMessage.data[MarketDataMessage::DataType::ASK].emplace_back(std::move(dataPoint)); + } } - MarketDataMessage::TypeForDataPoint dataPoint; - dataPoint.emplace(MarketDataMessage::DataFieldType::PRICE, UtilString::normalizeDecimalStringView(x[0].GetString())); - dataPoint.emplace(MarketDataMessage::DataFieldType::SIZE, UtilString::normalizeDecimalStringView(x[1].GetString())); - marketDataMessage.data[MarketDataMessage::DataType::BID].emplace_back(std::move(dataPoint)); - ++bidIndex; - } - const char* asksName = this->isDerivatives ? "a" : "asks"; - int askIndex = 0; - for (const auto& x : data[asksName].GetArray()) { - if (askIndex >= maxMarketDepth) { - break; + const auto& itBids = data.FindMember("b"); + if (itBids != data.MemberEnd()) { + const rj::Value& bids = itBids->value; + for (auto& x : bids.GetArray()) { + MarketDataMessage::TypeForDataPoint dataPoint; + dataPoint.emplace(MarketDataMessage::DataFieldType::PRICE, UtilString::normalizeDecimalStringView(x[0].GetString())); + dataPoint.emplace(MarketDataMessage::DataFieldType::SIZE, UtilString::normalizeDecimalStringView(x[1].GetString())); + marketDataMessage.data[MarketDataMessage::DataType::BID].emplace_back(std::move(dataPoint)); + } } - MarketDataMessage::TypeForDataPoint dataPoint; - dataPoint.emplace(MarketDataMessage::DataFieldType::PRICE, UtilString::normalizeDecimalStringView(x[0].GetString())); - dataPoint.emplace(MarketDataMessage::DataFieldType::SIZE, UtilString::normalizeDecimalStringView(x[1].GetString())); - marketDataMessage.data[MarketDataMessage::DataType::ASK].emplace_back(std::move(dataPoint)); - ++askIndex; + int64_t versionId = std::stoll(data["u"].GetString()); + this->processOrderBookWithVersionId(versionId, wsConnectionPtr, channelId, symbolId, exchangeSubscriptionId, optionMap, marketDataMessageList, + marketDataMessage); + } else { + marketDataMessage.type = MarketDataMessage::Type::MARKET_DATA_EVENTS_MARKET_DEPTH; + marketDataMessage.recapType = this->processedInitialSnapshotByConnectionIdChannelIdSymbolIdMap[wsConnectionPtr->id][channelId][symbolId] + ? MarketDataMessage::RecapType::NONE + : MarketDataMessage::RecapType::SOLICITED; + marketDataMessage.tp = this->isDerivatives ? TimePoint(std::chrono::milliseconds(std::stoll(data["T"].GetString()))) : timeReceived; + marketDataMessage.exchangeSubscriptionId = exchangeSubscriptionId; + const char* bidsName = this->isDerivatives ? "b" : "bids"; + int bidIndex = 0; + int maxMarketDepth = std::stoi(optionMap.at(CCAPI_MARKET_DEPTH_MAX)); + for (const auto& x : data[bidsName].GetArray()) { + if (bidIndex >= maxMarketDepth) { + break; + } + MarketDataMessage::TypeForDataPoint dataPoint; + dataPoint.emplace(MarketDataMessage::DataFieldType::PRICE, UtilString::normalizeDecimalStringView(x[0].GetString())); + dataPoint.emplace(MarketDataMessage::DataFieldType::SIZE, UtilString::normalizeDecimalStringView(x[1].GetString())); + marketDataMessage.data[MarketDataMessage::DataType::BID].emplace_back(std::move(dataPoint)); + ++bidIndex; + } + const char* asksName = this->isDerivatives ? "a" : "asks"; + int askIndex = 0; + for (const auto& x : data[asksName].GetArray()) { + if (askIndex >= maxMarketDepth) { + break; + } + MarketDataMessage::TypeForDataPoint dataPoint; + dataPoint.emplace(MarketDataMessage::DataFieldType::PRICE, UtilString::normalizeDecimalStringView(x[0].GetString())); + dataPoint.emplace(MarketDataMessage::DataFieldType::SIZE, UtilString::normalizeDecimalStringView(x[1].GetString())); + marketDataMessage.data[MarketDataMessage::DataType::ASK].emplace_back(std::move(dataPoint)); + ++askIndex; + } + marketDataMessageList.emplace_back(std::move(marketDataMessage)); } - marketDataMessageList.emplace_back(std::move(marketDataMessage)); } else if (channelId == CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_TRADE) { MarketDataMessage marketDataMessage; marketDataMessage.type = MarketDataMessage::Type::MARKET_DATA_EVENTS_TRADE; @@ -457,7 +543,9 @@ class MarketDataServiceBinanceBase : public MarketDataService { case Request::Operation::GET_MARKET_DEPTH: { MarketDataMessage marketDataMessage; marketDataMessage.type = MarketDataMessage::Type::MARKET_DATA_EVENTS_MARKET_DEPTH; - marketDataMessage.tp = UtilTime::makeTimePointFromMilliseconds(std::stoll(document["T"].GetString())); + if (this->isDerivatives) { + marketDataMessage.tp = UtilTime::makeTimePointFromMilliseconds(std::stoll(document["T"].GetString())); + } for (const auto& x : document["bids"].GetArray()) { MarketDataMessage::TypeForDataPoint dataPoint; dataPoint.emplace(MarketDataMessage::DataFieldType::PRICE, x[0].GetString()); @@ -540,4 +628,3 @@ class MarketDataServiceBinanceBase : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h index b5543e8bc..a17f6f888 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_COIN_FUTURES_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_COIN_FUTURES_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_BINANCE_COIN_FUTURES #include "ccapi_cpp/service/ccapi_market_data_service_binance_derivatives_base.h" @@ -37,4 +37,3 @@ class MarketDataServiceBinanceCoinFutures : public MarketDataServiceBinanceDeriv } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_COIN_FUTURES_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance_derivatives_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_derivatives_base.h index a46aaa993..c3f1717d7 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_derivatives_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_derivatives_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_DERIVATIVES_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_DERIVATIVES_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #if defined(CCAPI_ENABLE_EXCHANGE_BINANCE_USDS_FUTURES) || defined(CCAPI_ENABLE_EXCHANGE_BINANCE_COIN_FUTURES) #include "ccapi_cpp/service/ccapi_market_data_service_binance_base.h" @@ -25,7 +25,7 @@ class MarketDataServiceBinanceDerivativesBase : public MarketDataServiceBinanceB auto conflateIntervalMilliseconds = std::stoi(optionMap.at(CCAPI_CONFLATE_INTERVAL_MILLISECONDS)); if (field == CCAPI_MARKET_DEPTH) { int marketDepthSubscribedToExchange = 1; - marketDepthSubscribedToExchange = this->calculateMarketDepthAllowedByExchange(marketDepthRequested, std::vector({1, 5, 10, 20})); + marketDepthSubscribedToExchange = this->calculateMarketDepthAllowedByExchange(marketDepthRequested, std::vector({1, 5, 10, 20, 1000})); if (marketDepthSubscribedToExchange == 1) { channelId = CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_BOOK_TICKER; } else { @@ -35,9 +35,16 @@ class MarketDataServiceBinanceDerivativesBase : public MarketDataServiceBinanceB } else if (conflateIntervalMilliseconds >= 500) { updateSpeed = "500ms"; } - channelId += std::string("?") + CCAPI_MARKET_DEPTH_SUBSCRIBED_TO_EXCHANGE + "=" + std::to_string(marketDepthSubscribedToExchange); - if (!updateSpeed.empty()) { - channelId += "&UPDATE_SPEED=" + updateSpeed; + if (marketDepthSubscribedToExchange > 20) { + channelId = CCAPI_WEBSOCKET_BINANCE_BASE_CHANNEL_DIFF_DEPTH; + if (!updateSpeed.empty()) { + channelId += "?UPDATE_SPEED=" + updateSpeed; + } + } else { + channelId += std::string("?") + CCAPI_MARKET_DEPTH_SUBSCRIBED_TO_EXCHANGE + "=" + std::to_string(marketDepthSubscribedToExchange); + if (!updateSpeed.empty()) { + channelId += "&UPDATE_SPEED=" + updateSpeed; + } } this->marketDepthSubscribedToExchangeByConnectionIdChannelIdSymbolIdMap[wsConnectionPtr->id][channelId][symbolId] = marketDepthSubscribedToExchange; } @@ -145,9 +152,15 @@ class MarketDataServiceBinanceDerivativesBase : public MarketDataServiceBinanceB MarketDataServiceBinanceBase::convertTextMessageToMarketDataMessage(request, textMessageView, timeReceived, event, marketDataMessageList); } } + + void createFetchOrderBookInitialReq(http::request& req, const std::string& symbolId, const TimePoint& now, + const std::map& credential) override { + req.set(http::field::host, this->hostRest); + req.method(http::verb::get); + req.target(this->getMarketDepthTarget + "?symbol=" + Url::urlEncode(symbolId) + "&limit=1000"); + } }; } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_DERIVATIVES_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h index 75d6240cb..027cbe8b9 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_US_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_US_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_BINANCE_US #include "ccapi_cpp/service/ccapi_market_data_service_binance_base.h" @@ -37,4 +37,3 @@ class MarketDataServiceBinanceUs : public MarketDataServiceBinanceBase { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_US_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h index 1d85c61ff..a7941c33f 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_USDS_FUTURES_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_USDS_FUTURES_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_BINANCE_USDS_FUTURES #include "ccapi_cpp/service/ccapi_market_data_service_binance_derivatives_base.h" @@ -37,4 +37,3 @@ class MarketDataServiceBinanceUsdsFutures : public MarketDataServiceBinanceDeriv } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BINANCE_USDS_FUTURES_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h index 2a0d0cbc8..707687d22 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITFINEX_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITFINEX_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_BITFINEX #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -246,7 +246,7 @@ class MarketDataServiceBitfinex : public MarketDataService { } else { MarketDataMessage::TypeForDataPoint dataPoint; dataPoint.emplace(MarketDataMessage::DataFieldType::PRICE, UtilString::normalizeDecimalStringView(x[0].GetString())); - std::string_view count = std::string(x[1].GetString()); + std::string_view count = x[1].GetString(); std::string_view amount = UtilString::normalizeDecimalStringView(x[2].GetString()); if (count != "0") { if (amount.at(0) == '-') { @@ -587,4 +587,3 @@ class MarketDataServiceBitfinex : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITFINEX_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h index 0e61a8a50..9ad5094fd 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITGET_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITGET_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_BITGET #include "ccapi_cpp/service/ccapi_market_data_service_bitget_base.h" @@ -32,4 +32,3 @@ class MarketDataServiceBitget : public MarketDataServiceBitgetBase { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITGET_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitget_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitget_base.h index 6e3ad9b16..6392be1a4 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitget_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitget_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITGET_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITGET_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #if defined(CCAPI_ENABLE_EXCHANGE_BITGET) || defined(CCAPI_ENABLE_EXCHANGE_BITGET_FUTURES) #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -523,4 +523,3 @@ class MarketDataServiceBitgetBase : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITGET_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h index e7e4dbba4..b11f21553 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITGET_FUTURES_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITGET_FUTURES_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_BITGET_FUTURES #include "ccapi_cpp/service/ccapi_market_data_service_bitget_base.h" @@ -33,4 +33,3 @@ class MarketDataServiceBitgetFutures : public MarketDataServiceBitgetBase { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITGET_FUTURES_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h index bbf976315..3bd0df76d 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITMART_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITMART_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_BITMART #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -330,4 +330,3 @@ class MarketDataServiceBitmart : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITMART_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h index 8da92187b..3aecf2025 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITMEX_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITMEX_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_BITMEX #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -340,4 +340,3 @@ class MarketDataServiceBitmex : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITMEX_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h index c46db55a0..9f667270b 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITSTAMP_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITSTAMP_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_BITSTAMP #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -17,9 +17,10 @@ class MarketDataServiceBitstamp : public MarketDataService { this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); // this->setHostWsFromUrlWs(this->baseUrlWs); - this->getRecentTradesTarget = "/api/v2/transactions/{currency_pair}/"; // must have trailing slash - this->getInstrumentTarget = "/api/v2/trading-pairs-info/"; - this->getInstrumentsTarget = "/api/v2/trading-pairs-info/"; + this->getRecentTradesTarget = "/api/v2/transactions/{market_symbol}/"; // must have trailing slash + this->getMarketDepthTarget = "/api/v2/order_book/{market_symbol}/"; + this->getInstrumentTarget = "/api/v2/markets/"; + this->getInstrumentsTarget = "/api/v2/markets/"; } virtual ~MarketDataServiceBitstamp() {} @@ -168,7 +169,18 @@ class MarketDataServiceBitstamp : public MarketDataService { req.method(http::verb::get); auto target = this->getRecentTradesTarget; this->substituteParam(target, { - {"{currency_pair}", symbolId}, + {"{market_symbol}", symbolId}, + }); + std::string queryString; + const std::map param = request.getFirstParamWithDefault(); + this->appendParam(queryString, param, {}); + req.target(target + "?" + queryString); + } break; + case Request::Operation::GET_MARKET_DEPTH: { + req.method(http::verb::get); + auto target = this->getMarketDepthTarget; + this->substituteParam(target, { + {"{market_symbol}", symbolId}, }); std::string queryString; const std::map param = request.getFirstParamWithDefault(); @@ -191,13 +203,9 @@ class MarketDataServiceBitstamp : public MarketDataService { } void extractInstrumentInfo(Element& element, const rj::Value& x) { - element.insert(CCAPI_INSTRUMENT, x["url_symbol"].GetString()); - std::string name = x["name"].GetString(); - auto splitted = UtilString::split(name, "/"); - auto baseAsset = splitted.at(0); - auto quoteAsset = splitted.at(1); - element.insert(CCAPI_BASE_ASSET, baseAsset); - element.insert(CCAPI_QUOTE_ASSET, quoteAsset); + element.insert(CCAPI_INSTRUMENT, x["market_symbol"].GetString()); + element.insert(CCAPI_BASE_ASSET, x["base_currency"].GetString()); + element.insert(CCAPI_QUOTE_ASSET, x["counter_currency"].GetString()); int counterDecimals = std::stoi(x["counter_decimals"].GetString()); if (counterDecimals > 0) { element.insert(CCAPI_ORDER_PRICE_INCREMENT, "0." + std::string(counterDecimals - 1, '0') + "1"); @@ -210,13 +218,22 @@ class MarketDataServiceBitstamp : public MarketDataService { } else { element.insert(CCAPI_ORDER_QUANTITY_INCREMENT, "1"); } - auto splittedMinimumOrder = UtilString::split(x["minimum_order"].GetString(), ' '); - if (splittedMinimumOrder.size() == 2) { - if (splittedMinimumOrder.at(1) == quoteAsset) { - element.insert(CCAPI_ORDER_QUOTE_QUANTITY_MIN, splittedMinimumOrder.at(0)); - } else if (splittedMinimumOrder.at(1) == baseAsset) { - element.insert(CCAPI_ORDER_QUANTITY_MIN, splittedMinimumOrder.at(0)); - } + if (x.HasMember("minimum_order_amount")) { + element.insert(CCAPI_ORDER_QUANTITY_MIN, x["minimum_order_amount"].GetString()); + } else { + element.insert(CCAPI_ORDER_QUANTITY_MIN, element.getValue(CCAPI_ORDER_QUANTITY_INCREMENT)); + } + if (x.HasMember("minimum_order_value")) { + element.insert(CCAPI_ORDER_QUOTE_QUANTITY_MIN, x["minimum_order_value"].GetString()); + } + if (x.HasMember("maximum_order_amount")) { + element.insert(CCAPI_ORDER_QUANTITY_MAX, x["maximum_order_amount"].GetString()); + } + if (x.HasMember("maximum_order_value")) { + element.insert(CCAPI_ORDER_QUOTE_QUANTITY_MAX, x["maximum_order_value"].GetString()); + } + if (x.HasMember("contract_size")) { + element.insert(CCAPI_CONTRACT_SIZE, x["contract_size"].GetString()); } } @@ -240,6 +257,26 @@ class MarketDataServiceBitstamp : public MarketDataService { marketDataMessageList.emplace_back(std::move(marketDataMessage)); } } break; + case Request::Operation::GET_MARKET_DEPTH: { + MarketDataMessage marketDataMessage; + marketDataMessage.type = MarketDataMessage::Type::MARKET_DATA_EVENTS_MARKET_DEPTH; + std::string microtimestamp = document["microtimestamp"].GetString(); + microtimestamp.insert(microtimestamp.size() - 6, "."); + marketDataMessage.tp = UtilTime::makeTimePoint(UtilTime::divide(microtimestamp)); + for (const auto& x : document["bids"].GetArray()) { + MarketDataMessage::TypeForDataPoint dataPoint; + dataPoint.emplace(MarketDataMessage::DataFieldType::PRICE, x[0].GetString()); + dataPoint.emplace(MarketDataMessage::DataFieldType::SIZE, x[1].GetString()); + marketDataMessage.data[MarketDataMessage::DataType::BID].emplace_back(std::move(dataPoint)); + } + for (const auto& x : document["asks"].GetArray()) { + MarketDataMessage::TypeForDataPoint dataPoint; + dataPoint.emplace(MarketDataMessage::DataFieldType::PRICE, x[0].GetString()); + dataPoint.emplace(MarketDataMessage::DataFieldType::SIZE, x[1].GetString()); + marketDataMessage.data[MarketDataMessage::DataType::ASK].emplace_back(std::move(dataPoint)); + } + marketDataMessageList.emplace_back(std::move(marketDataMessage)); + } break; case Request::Operation::GET_INSTRUMENT: { Message message; message.setTimeReceived(timeReceived); @@ -278,4 +315,3 @@ class MarketDataServiceBitstamp : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BITSTAMP_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h b/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h index 2b8950fc6..b6919fac0 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BYBIT_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BYBIT_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_BYBIT #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -483,4 +483,3 @@ class MarketDataServiceBybit : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_BYBIT_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h b/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h index d7b452054..1273ccd8a 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_COINBASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_COINBASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_COINBASE #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -342,4 +342,3 @@ class MarketDataServiceCoinbase : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_COINBASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h b/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h index b4745d138..b66d8374b 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_CRYPTOCOM_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_CRYPTOCOM_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_CRYPTOCOM #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -353,4 +353,3 @@ class MarketDataServiceCryptocom : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_CRYPTOCOM_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h b/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h index afa8ed01e..6001f9cc3 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_DERIBIT_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_DERIBIT_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_DERIBIT #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -482,4 +482,3 @@ class MarketDataServiceDeribit : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_DERIBIT_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_erisx.h b/include/ccapi_cpp/service/ccapi_market_data_service_erisx.h index c3bba0730..284e9a26d 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_erisx.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_erisx.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_ERISX_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_ERISX_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_ERISX #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -178,4 +178,3 @@ class MarketDataServiceErisx : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_ERISX_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h b/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h index d5441bd2f..27c0eedf4 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_FTX_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_FTX_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_FTX #include "ccapi_cpp/service/ccapi_market_data_service_ftx_base.h" @@ -35,4 +35,3 @@ class MarketDataServiceFtx : public MarketDataServiceFtxBase { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_FTX_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_ftx_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_ftx_base.h index 3528a6e1a..c0b7ed040 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ftx_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ftx_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_FTX_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_FTX_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #if defined(CCAPI_ENABLE_EXCHANGE_FTX) || defined(CCAPI_ENABLE_EXCHANGE_FTX_US) #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -380,4 +380,3 @@ class MarketDataServiceFtxBase : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_FTX_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h b/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h index 617f8bea0..fa22319f4 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_FTX_US_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_FTX_US_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_FTX_US #include "ccapi_cpp/service/ccapi_market_data_service_ftx_base.h" @@ -35,4 +35,3 @@ class MarketDataServiceFtxUs : public MarketDataServiceFtxBase { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_FTX_US_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h b/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h index dce6a969c..1d7c852b0 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_GATEIO_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_GATEIO_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_GATEIO #include "ccapi_cpp/service/ccapi_market_data_service_gateio_base.h" @@ -180,4 +180,3 @@ class MarketDataServiceGateio : public MarketDataServiceGateioBase { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_GATEIO_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_gateio_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_gateio_base.h index f40939152..e2368025a 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gateio_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gateio_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_GATEIO_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_GATEIO_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #if defined(CCAPI_ENABLE_EXCHANGE_GATEIO) || defined(CCAPI_ENABLE_EXCHANGE_GATEIO_PERPETUAL_FUTURES) #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -381,4 +381,3 @@ class MarketDataServiceGateioBase : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_GATEIO_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h index d02d680b2..8b6b7ad04 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_GATEIO_PERPETUAL_FUTURES_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_GATEIO_PERPETUAL_FUTURES_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_GATEIO_PERPETUAL_FUTURES #include "ccapi_cpp/service/ccapi_market_data_service_gateio_base.h" @@ -221,4 +221,3 @@ class MarketDataServiceGateioPerpetualFutures : public MarketDataServiceGateioBa } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_GATEIO_PERPETUAL_FUTURES_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h b/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h index 6c2b54229..dff1f8657 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_GEMINI_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_GEMINI_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_GEMINI #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -319,4 +319,3 @@ class MarketDataServiceGemini : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_GEMINI_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h index 385f4bc3e..99e7f0f12 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_HUOBI_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_HUOBI_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_HUOBI #include "ccapi_cpp/service/ccapi_market_data_service_huobi_base.h" @@ -117,4 +117,3 @@ class MarketDataServiceHuobi : public MarketDataServiceHuobiBase { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_HUOBI_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_base.h index 329ba2011..03c3eefa4 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_HUOBI_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_HUOBI_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #if defined(CCAPI_ENABLE_EXCHANGE_HUOBI) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP) #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -396,4 +396,3 @@ class MarketDataServiceHuobiBase : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_HUOBI_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h index 325908a9b..fe8ff4613 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_HUOBI_COIN_SWAP_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_HUOBI_COIN_SWAP_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP #include "ccapi_cpp/service/ccapi_market_data_service_huobi_derivatives_base.h" @@ -27,4 +27,3 @@ class MarketDataServiceHuobiCoinSwap : public MarketDataServiceHuobiDerivativesB } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_HUOBI_COIN_SWAP_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_derivatives_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_derivatives_base.h index fe4694d31..d04264ef1 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_derivatives_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_derivatives_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_HUOBI_DERIVATIVES_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_HUOBI_DERIVATIVES_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #if defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP) #include "ccapi_cpp/service/ccapi_market_data_service_huobi_base.h" @@ -108,4 +108,3 @@ class MarketDataServiceHuobiDerivativesBase : public MarketDataServiceHuobiBase } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_HUOBI_DERIVATIVES_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h index 55a222b6c..b083518af 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_HUOBI_USDT_SWAP_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_HUOBI_USDT_SWAP_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP #include "ccapi_cpp/service/ccapi_market_data_service_huobi_derivatives_base.h" @@ -27,4 +27,3 @@ class MarketDataServiceHuobiUsdtSwap : public MarketDataServiceHuobiDerivativesB } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_HUOBI_USDT_SWAP_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h b/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h index 3462d395f..0d531eaca 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_KRAKEN_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_KRAKEN_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_KRAKEN #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -416,4 +416,3 @@ class MarketDataServiceKraken : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_KRAKEN_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h index d9ebb2f5e..e8959e2c2 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_KRAKEN_FUTURES_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_KRAKEN_FUTURES_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_KRAKEN_FUTURES #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -290,4 +290,3 @@ class MarketDataServiceKrakenFutures : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_KRAKEN_FUTURES_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h index f591164be..c26da07b9 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_KUCOIN_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_KUCOIN_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #if defined(CCAPI_ENABLE_EXCHANGE_KUCOIN) #include "ccapi_cpp/service/ccapi_market_data_service_kucoin_base.h" @@ -59,4 +59,3 @@ class MarketDataServiceKucoin : public MarketDataServiceKucoinBase { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_KUCOIN_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_base.h index 29a62b11f..52c343c76 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_base.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_KUCOIN_BASE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_KUCOIN_BASE_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #if defined(CCAPI_ENABLE_EXCHANGE_KUCOIN) || defined(CCAPI_ENABLE_EXCHANGE_KUCOIN_FUTURES) #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -657,4 +657,3 @@ class MarketDataServiceKucoinBase : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_KUCOIN_BASE_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h index e99731624..684371c40 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_KUCOIN_FUTURES_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_KUCOIN_FUTURES_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #if defined(CCAPI_ENABLE_EXCHANGE_KUCOIN_FUTURES) #include "ccapi_cpp/service/ccapi_market_data_service_kucoin_base.h" @@ -51,4 +51,3 @@ class MarketDataServiceKucoinFutures : public MarketDataServiceKucoinBase { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_KUCOIN_FUTURES_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h b/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h index 3eb0841fc..852b6330a 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_MEXC_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_MEXC_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_MEXC #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -348,4 +348,3 @@ class MarketDataServiceMexc : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_MEXC_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h index cb5c4c4a1..97208a7f2 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_MEXC_FUTURES_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_MEXC_FUTURES_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_MEXC_FUTURES #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -261,4 +261,3 @@ class MarketDataServiceMexcFutures : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_MEXC_FUTURES_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_okx.h b/include/ccapi_cpp/service/ccapi_market_data_service_okx.h index 828f96958..ccb997391 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_okx.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_okx.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_OKX_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_OKX_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_OKX @@ -601,4 +601,3 @@ class MarketDataServiceOkx : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_OKX_H_ diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h b/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h index e5217be65..df891a519 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_WHITEBIT_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_WHITEBIT_H_ +#pragma once + #ifdef CCAPI_ENABLE_SERVICE_MARKET_DATA #ifdef CCAPI_ENABLE_EXCHANGE_WHITEBIT #include "ccapi_cpp/service/ccapi_market_data_service.h" @@ -339,4 +339,3 @@ class MarketDataServiceWhitebit : public MarketDataService { } /* namespace ccapi */ #endif #endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_MARKET_DATA_SERVICE_WHITEBIT_H_ diff --git a/include/ccapi_cpp/service/ccapi_service.h b/include/ccapi_cpp/service/ccapi_service.h index 6edbdd76c..877b47377 100644 --- a/include/ccapi_cpp/service/ccapi_service.h +++ b/include/ccapi_cpp/service/ccapi_service.h @@ -1,5 +1,13 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_SERVICE_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_SERVICE_H_ +#pragma once + +#if (defined(CCAPI_ENABLE_SERVICE_MARKET_DATA) && \ + (defined(CCAPI_ENABLE_EXCHANGE_HUOBI) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP))) || \ + (defined(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT) && \ + (defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_BITMART))) +#define CCAPI_REQUIRES_INFLATE_STREAM 1 +#else +#define CCAPI_REQUIRES_INFLATE_STREAM 0 +#endif #ifndef CCAPI_HTTP_RESPONSE_PARSER_BODY_LIMIT #define CCAPI_HTTP_RESPONSE_PARSER_BODY_LIMIT (8 * 1024 * 1024) @@ -27,12 +35,6 @@ #define CCAPI_WEBSOCKET_WRITE_BUFFER_SIZE (1 << 20) #endif -#define CCAPI_REQUIRES_INFLATE_STREAM \ - ((defined(CCAPI_ENABLE_SERVICE_MARKET_DATA) && \ - (defined(CCAPI_ENABLE_EXCHANGE_HUOBI) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP))) || \ - (defined(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT) && \ - (defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_BITMART)))) - #include #include "boost/asio/strand.hpp" @@ -530,7 +532,7 @@ class Service : public std::enable_shared_from_this { // Set SNI hostname (important for TLS handshakes) if (!SSL_set_tlsext_host_name(streamPtr->native_handle(), host.c_str())) { beast::error_code ec{static_cast(::ERR_get_error()), net::error::get_ssl_category()}; - CCAPI_LOGGER_DEBUG("error SSL_set_tlsext_host_name: " + ec.message()); + CCAPI_LOGGER_DEBUG("error SSL_set_tlsext_host_name for host " + host + ": " + ec.message()); throw ec; } @@ -1021,7 +1023,7 @@ class Service : public std::enable_shared_from_this { // Set SNI hostname (only for WSS) if (!SSL_set_tlsext_host_name(streamPtr->next_layer().native_handle(), wsConnectionPtr->host.c_str())) { beast::error_code ec{static_cast(::ERR_get_error()), net::error::get_ssl_category()}; - CCAPI_LOGGER_DEBUG("error SSL_set_tlsext_host_name: " + ec.message()); + CCAPI_LOGGER_DEBUG("error SSL_set_tlsext_host_name for host " + wsConnectionPtr->host + ": " + ec.message()); this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "set SNI Hostname", wsConnectionPtr->correlationIdList); return; } @@ -1674,4 +1676,3 @@ class Service : public std::enable_shared_from_this { }; } /* namespace ccapi */ -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_SERVICE_H_ diff --git a/include/ccapi_cpp/service/ccapi_service_context.h b/include/ccapi_cpp/service/ccapi_service_context.h index e6faa536f..a6fb98e63 100644 --- a/include/ccapi_cpp/service/ccapi_service_context.h +++ b/include/ccapi_cpp/service/ccapi_service_context.h @@ -1,5 +1,4 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_SERVICE_CONTEXT_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_SERVICE_CONTEXT_H_ +#pragma once #include "boost/asio/ssl.hpp" #include "ccapi_cpp/ccapi_logger.h" @@ -94,5 +93,3 @@ class ServiceContext { }; } /* namespace ccapi */ - -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_SERVICE_CONTEXT_H_