Skip to content

Commit 5fbbc0b

Browse files
Merge pull request #523 from crypto-chassis/develop
Release
2 parents 10cc186 + 220874c commit 5fbbc0b

164 files changed

Lines changed: 4012 additions & 2947 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/release.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,11 @@ jobs:
211211
-DBUILD_TEST_UNIT=OFF
212212
-S test
213213
-B test/build
214-
-D CMAKE_BUILD_TYPE=$ENV{CMAKE_BUILD_TYPE}
215-
-G Ninja
216-
-D CMAKE_MAKE_PROGRAM=ninja
217-
# -D CMAKE_C_COMPILER_LAUNCHER=ccache
218-
# -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
214+
-DCMAKE_BUILD_TYPE=$ENV{CMAKE_BUILD_TYPE}
215+
# -G Ninja
216+
# -DCMAKE_MAKE_PROGRAM=ninja
217+
# -DCMAKE_C_COMPILER_LAUNCHER=ccache
218+
# -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
219219
RESULT_VARIABLE result
220220
)
221221
if (NOT result EQUAL 0)
@@ -227,11 +227,11 @@ jobs:
227227
-DCMAKE_OSX_ARCHITECTURES=arm64
228228
-S example
229229
-B example/build
230-
-D CMAKE_BUILD_TYPE=$ENV{CMAKE_BUILD_TYPE}
231-
-G Ninja
232-
-D CMAKE_MAKE_PROGRAM=ninja
233-
# -D CMAKE_C_COMPILER_LAUNCHER=ccache
234-
# -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
230+
-DCMAKE_BUILD_TYPE=$ENV{CMAKE_BUILD_TYPE}
231+
# -G Ninja
232+
# -DCMAKE_MAKE_PROGRAM=ninja
233+
# -DCMAKE_C_COMPILER_LAUNCHER=ccache
234+
# -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
235235
RESULT_VARIABLE result
236236
)
237237
if (NOT result EQUAL 0)
@@ -250,13 +250,13 @@ jobs:
250250
-DBUILD_TEST=ON
251251
-S binding
252252
-B binding/build
253-
-D CMAKE_BUILD_TYPE=$ENV{CMAKE_BUILD_TYPE}
253+
-DCMAKE_BUILD_TYPE=$ENV{CMAKE_BUILD_TYPE}
254254
-D DOTNET_BUILD_CONFIGURATION=$ENV{DOTNET_BUILD_CONFIGURATION}
255255
-D NODE_GYP_BUILD_MODE=$ENV{NODE_GYP_BUILD_MODE}
256-
-G Ninja
257-
-D CMAKE_MAKE_PROGRAM=ninja
258-
# -D CMAKE_C_COMPILER_LAUNCHER=ccache
259-
# -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
256+
# -G Ninja
257+
# -DCMAKE_MAKE_PROGRAM=ninja
258+
# -DCMAKE_C_COMPILER_LAUNCHER=ccache
259+
# -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
260260
RESULT_VARIABLE result
261261
)
262262
if (NOT result EQUAL 0)
@@ -378,11 +378,11 @@ jobs:
378378
-DBUILD_TEST_UNIT=ON
379379
-S test
380380
-B test/build
381-
-D CMAKE_BUILD_TYPE=$ENV{CMAKE_BUILD_TYPE}
382-
-G Ninja
383-
-D CMAKE_MAKE_PROGRAM=ninja
384-
# -D CMAKE_C_COMPILER_LAUNCHER=ccache
385-
# -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
381+
-DCMAKE_BUILD_TYPE=$ENV{CMAKE_BUILD_TYPE}
382+
# -G Ninja
383+
# -DCMAKE_MAKE_PROGRAM=ninja
384+
# -DCMAKE_C_COMPILER_LAUNCHER=ccache
385+
# -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
386386
RESULT_VARIABLE result
387387
)
388388
if (NOT result EQUAL 0)

README.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
# Some breaking changes introduced
2-
* The return type of `EventHandler::processEvent` has been changed from `bool` to `void`.
3-
* Please read [Handle events in "immediate" vs. "batching" mode](#handle-events-in-immediate-vs-batching-mode).
1+
# Notice
2+
* New release has about 20% reduction in cpu usage.
43

54
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
65

76
**Table of Contents** *generated with [DocToc](https://github.com/ktechhub/doctoc)*
87

98
<!---toc start-->
109

11-
* [Some breaking changes introduced](#some-breaking-changes-introduced)
10+
* [Notice](#notice)
1211
* [ccapi](#ccapi)
1312
* [Branches](#branches)
1413
* [Build](#build)
@@ -51,7 +50,6 @@
5150
* [Set timer](#set-timer)
5251
* [Performance Tuning](#performance-tuning)
5352
* [Known Issues and Workarounds](#known-issues-and-workarounds)
54-
* [Contributing](#contributing)
5553

5654
<!---toc end-->
5755

@@ -60,14 +58,17 @@
6058

6159

6260

61+
62+
63+
6364
# ccapi
6465
* A header-only C++ library for streaming market data and executing trades directly from cryptocurrency exchanges (i.e. the connections are between your server and the exchange server without anything in-between).
6566
* Bindings for other languages such as Python, Java, C#, Go, and Javascript are provided.
6667
* Code closely follows Bloomberg's API: https://www.bloomberg.com/professional/support/api-library/.
6768
* It is ultra fast thanks to very careful optimizations: move semantics, regex optimization, locality of reference, lock contention minimization, etc.
6869
* Supported exchanges:
69-
* Market Data: ascendex, binance, binance-usds-futures, binance-coin-futures, bitfinex, bitget, bitget-futures, bitmart, bitmex, bitstamp, bybit, coinbase, cryptocom, deribit, erisx (Cboe Digital), gateio, gateio-perpetual-futures, gemini, huobi, huobi-usdt-swap, huobi-coin-swap, kraken, kraken-futures, kucoin, kucoin-futures, mexc, mexc-futures, okx, whitebit.
70-
* Execution Management: ascendex, binance, binance-usds-futures, binance-coin-futures, bitfinex, bitget, bitget-futures, bitmart, bitmex, bitstamp, bybit, coinbase, cryptocom, deribit, erisx (Cboe Digital), gateio, gateio-perpetual-futures, gemini, huobi, huobi-usdt-swap, huobi-coin-swap, kraken, kraken-futures, kucoin, kucoin-futures, mexc, okx.
70+
* Market Data: ascendex, [binance](https://www.marketwebb.net/activity/referral-entry/CPA?ref=CPA_00WFM0HU96), [binance-usds-futures](https://www.marketwebb.net/activity/referral-entry/CPA?ref=CPA_00WFM0HU96), [binance-coin-futures](https://www.marketwebb.net/activity/referral-entry/CPA?ref=CPA_00WFM0HU96), bitfinex, bitget, bitget-futures, bitmart, bitmex, bitstamp, [bybit](https://www.bybit.com/invite?ref=XNYP2K), coinbase, [cryptocom](https://crypto.com/exch/tqj4b8x48w), deribit, erisx (Cboe Digital), [gateio](https://www.gate.com/signup/VLUQXVFWAW?ref_type=103), [gateio-perpetual-futures](https://www.gate.com/signup/VLUQXVFWAW?ref_type=103), gemini, huobi, huobi-usdt-swap, huobi-coin-swap, kraken, kraken-futures, kucoin, kucoin-futures, mexc, mexc-futures, [okx](https://www.okx.com/join/47636709), whitebit.
71+
* Execution Management: ascendex, [binance](https://www.marketwebb.net/activity/referral-entry/CPA?ref=CPA_00WFM0HU96), [binance-usds-futures](https://www.marketwebb.net/activity/referral-entry/CPA?ref=CPA_00WFM0HU96), [binance-coin-futures](https://www.marketwebb.net/activity/referral-entry/CPA?ref=CPA_00WFM0HU96), bitfinex, bitget, bitget-futures, bitmart, bitmex, bitstamp, [bybit](https://www.bybit.com/invite?ref=XNYP2K), coinbase, [cryptocom](https://crypto.com/exch/tqj4b8x48w), deribit, erisx (Cboe Digital), [gateio](https://www.gate.com/signup/VLUQXVFWAW?ref_type=103), [gateio-perpetual-futures](https://www.gate.com/signup/VLUQXVFWAW?ref_type=103), gemini, huobi, huobi-usdt-swap, huobi-coin-swap, kraken, kraken-futures, kucoin, kucoin-futures, mexc, [okx](https://www.okx.com/join/47636709).
7172
* FIX: coinbase, gemini.
7273
* Join us on Discord https://discord.gg/b5EKcp9s8T and Medium https://cryptochassis.medium.com.
7374

@@ -134,6 +135,7 @@ cmake --build .
134135

135136
## Constants
136137
[`include/ccapi_cpp/ccapi_macro.h`](include/ccapi_cpp/ccapi_macro.h)
138+
* For most cryptocurrencies, the default value of `CCAPI_DECIMAL_SCALE` is sufficient. You can override it if you need more.
137139

138140
## Examples
139141
[C++](example)
@@ -224,6 +226,7 @@ For a specific exchange and instrument, get recents trades.
224226
#include "ccapi_cpp/ccapi_session.h"
225227
226228
namespace ccapi {
229+
227230
Logger* Logger::logger = nullptr; // This line is needed.
228231
229232
class MyEventHandler : public EventHandler {
@@ -232,6 +235,7 @@ class MyEventHandler : public EventHandler {
232235
std::cout << "Received an event:\n" + event.toStringPretty(2, 2) << std::endl;
233236
}
234237
};
238+
235239
} /* namespace ccapi */
236240
237241
using ::ccapi::MyEventHandler;
@@ -300,6 +304,7 @@ For a specific exchange and instrument, whenever the best bid's or ask's price o
300304
#include "ccapi_cpp/ccapi_session.h"
301305
302306
namespace ccapi {
307+
303308
Logger* Logger::logger = nullptr; // This line is needed.
304309
305310
class MyEventHandler : public EventHandler {
@@ -311,13 +316,16 @@ class MyEventHandler : public EventHandler {
311316
for (const auto& message : event.getMessageList()) {
312317
std::cout << std::string("Best bid and ask at ") + UtilTime::getISOTimestamp(message.getTime()) + " are:" << std::endl;
313318
for (const auto& element : message.getElementList()) {
314-
const std::map<std::string, std::string>& elementNameValueMap = element.getNameValueMap();
319+
// They key std::string_view is created from a string literal and therefore is safe, because string
320+
// literals have static storage duration, meaning they live for the entire duration of the program.
321+
const std::map<std::string_view, std::string>& elementNameValueMap = element.getNameValueMap();
315322
std::cout << " " + toString(elementNameValueMap) << std::endl;
316323
}
317324
}
318325
}
319326
}
320327
};
328+
321329
} /* namespace ccapi */
322330
323331
using ::ccapi::MyEventHandler;
@@ -491,6 +499,7 @@ For a specific exchange and instrument, submit a simple limit order.
491499
#include "ccapi_cpp/ccapi_session.h"
492500
493501
namespace ccapi {
502+
494503
Logger* Logger::logger = nullptr; // This line is needed.
495504
496505
class MyEventHandler : public EventHandler {
@@ -499,6 +508,7 @@ class MyEventHandler : public EventHandler {
499508
std::cout << "Received an event:\n" + event.toStringPretty(2, 2) << std::endl;
500509
}
501510
};
511+
502512
} /* namespace ccapi */
503513
504514
using ::ccapi::MyEventHandler;
@@ -588,6 +598,7 @@ For a specific exchange and instrument, receive order updates.
588598
#include "ccapi_cpp/ccapi_session.h"
589599
590600
namespace ccapi {
601+
591602
Logger* Logger::logger = nullptr; // This line is needed.
592603
593604
class MyEventHandler : public EventHandler {
@@ -611,6 +622,7 @@ class MyEventHandler : public EventHandler {
611622
}
612623
}
613624
};
625+
614626
} /* namespace ccapi */
615627
616628
using ::ccapi::MyEventHandler;
@@ -832,6 +844,7 @@ For a specific exchange and instrument, submit a simple limit order.
832844
```
833845
#include "ccapi_cpp/ccapi_session.h"
834846
namespace ccapi {
847+
835848
Logger* Logger::logger = nullptr; // This line is needed.
836849
class MyEventHandler : public EventHandler {
837850
public:
@@ -858,6 +871,7 @@ class MyEventHandler : public EventHandler {
858871
}
859872
}
860873
};
874+
861875
} /* namespace ccapi */
862876
using ::ccapi::MyEventHandler;
863877
using ::ccapi::Session;
@@ -963,6 +977,7 @@ An example can be found [here](example/src/market_data_advanced_subscription/mai
963977

964978
#### Thread safety
965979
* The following methods are implemented to be thread-safe: `Session::sendRequest`, `Session::subscribe`, `Session::sendRequestByFix`, `Session::subscribeByFix`, `Session::setTimer`, all public methods in `Queue`.
980+
* If you choose to inject an external `boost::asio::io_context` to `ServiceContext`, the `boost::asio::io_context` has to run on a single thread to ensure thread safety.
966981

967982
#### Enable library logging
968983

@@ -971,6 +986,7 @@ An example can be found [here](example/src/market_data_advanced_subscription/mai
971986
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.
972987
```
973988
namespace ccapi {
989+
974990
class MyLogger final : public Logger {
975991
public:
976992
void logMessage(const std::string& severity, const std::string& threadId, const std::string& timeISO, const std::string& fileName,
@@ -985,6 +1001,7 @@ class MyLogger final : public Logger {
9851001
9861002
MyLogger myLogger;
9871003
Logger* Logger::logger = &myLogger;
1004+
9881005
} /* namespace ccapi */
9891006
```
9901007

@@ -1005,14 +1022,8 @@ sessionPtr->setTimer(
10051022
## Performance Tuning
10061023
* Turn on compiler optimization flags (e.g. `cmake -DCMAKE_BUILD_TYPE=Release ...`).
10071024
* Enable link time optimization (e.g. in CMakeLists.txt `set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)` before a target is created). Note that link time optimization is only applicable to static linking.
1008-
* Shorten constant strings used as key names in the returned `Element` (e.g. in CmakeLists.txt `add_compile_definitions(CCAPI_BEST_BID_N_PRICE="b")`).
10091025
* Only enable the services and exchanges that you need.
10101026
* Handle events in ["batching" mode](#handle-events-in-immediate-vs-batching-mode) if your application (e.g. market data archiver) isn't latency sensitive.
10111027

10121028
## Known Issues and Workarounds
10131029
* Kraken invalid nonce errors. Give the API key a nonce window (https://support.kraken.com/hc/en-us/articles/360001148023-What-is-a-nonce-window-). We use unix timestamp with microsecond resolution as nonce and therefore a nonce window of 500000 translates to a tolerance of 0.5 second.
1014-
1015-
## Contributing
1016-
* (Required) Create a new branch from the `develop` branch and submit a pull request to the `develop` branch.
1017-
* (Optional) C++ code style: https://google.github.io/styleguide/cppguide.html. See file [.clang-format](.clang-format).
1018-
* (Optional) Commit message format: https://conventionalcommits.org.

binding/ccapi_logger.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "ccapi_cpp/ccapi_logger.h"
22

33
namespace ccapi {
4+
45
Logger* Logger::logger = nullptr;
56
}

binding/python/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,15 @@ add_custom_target(
4949
${PACKAGING_DIR_FULL}
5050
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${SWIG_TARGET_NAME}>
5151
${PACKAGING_DIR_FULL}
52-
COMMAND ${Python_EXECUTABLE} -m pip install --upgrade setuptools wheel
53-
COMMAND ${Python_EXECUTABLE} setup.py bdist_wheel
54-
COMMAND ${Python_EXECUTABLE} -m pip install --upgrade .
52+
# ----- modern part -----
53+
# ensure the wheel-building front-end is available
54+
COMMAND ${Python_EXECUTABLE} -m pip install --upgrade build
55+
# build a wheel via PEP 517 backend (uses pyproject.toml if present,
56+
# falls back to setup.py automatically)
57+
COMMAND ${Python_EXECUTABLE} -m build --wheel
58+
# install the freshly-built wheel
59+
COMMAND ${Python_EXECUTABLE} -m pip install --upgrade dist/*.whl
60+
# -----------------------
5561
WORKING_DIRECTORY ${PACKAGING_DIR_FULL})
5662
add_dependencies(${PYTHON_PACKAGING_TARGET_NAME} ${SWIG_TARGET_NAME})
5763

example/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,4 @@ add_subdirectory(src/enable_library_logging)
8484
add_subdirectory(src/utility_set_timer)
8585
add_subdirectory(src/override_exchange_url_at_runtime)
8686
add_subdirectory(src/test_order_latency)
87+
add_subdirectory(src/test_cpu_usage)

example/src/enable_library_logging/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "ccapi_cpp/ccapi_session.h"
22

33
namespace ccapi {
4+
45
class MyLogger final : public Logger {
56
public:
67
void logMessage(const std::string& severity, const std::string& threadId, const std::string& timeISO, const std::string& fileName,
@@ -15,6 +16,7 @@ class MyLogger final : public Logger {
1516

1617
MyLogger myLogger;
1718
Logger* Logger::logger = &myLogger;
19+
1820
} /* namespace ccapi */
1921

2022
using ::ccapi::Session;

example/src/execution_management_advanced_request/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#include "ccapi_cpp/ccapi_session.h"
22

33
namespace ccapi {
4+
45
Logger* Logger::logger = nullptr; // This line is needed.
56

67
class MyEventHandler : public EventHandler {
78
public:
89
void processEvent(const Event& event, Session* sessionPtr) override { std::cout << "Received an event:\n" + event.toStringPretty(2, 2) << std::endl; }
910
};
11+
1012
} /* namespace ccapi */
1113

1214
using ::ccapi::MyEventHandler;

example/src/execution_management_advanced_subscription/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "ccapi_cpp/ccapi_session.h"
22

33
namespace ccapi {
4+
45
Logger* Logger::logger = nullptr; // This line is needed.
56

67
class MyEventHandler : public EventHandler {
@@ -29,6 +30,7 @@ class MyEventHandler : public EventHandler {
2930
std::string websocketOrderEntrySubscriptionCorrelationId;
3031
bool willSendRequest{};
3132
};
33+
3234
} /* namespace ccapi */
3335

3436
using ::ccapi::MyEventHandler;

example/src/execution_management_simple_request/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#include "ccapi_cpp/ccapi_session.h"
22

33
namespace ccapi {
4+
45
Logger* Logger::logger = nullptr; // This line is needed.
56

67
class MyEventHandler : public EventHandler {
78
public:
89
void processEvent(const Event& event, Session* sessionPtr) override { std::cout << "Received an event:\n" + event.toStringPretty(2, 2) << std::endl; }
910
};
11+
1012
} /* namespace ccapi */
1113

1214
using ::ccapi::MyEventHandler;

0 commit comments

Comments
 (0)