Ccapi
A header-only C++ library for interacting with crypto exchanges. Bindings for Python, Java, C#, Go, and Javascript are provided.
Install / Use
/learn @crypto-chassis/CcapiREADME
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
Table of Contents generated with DocToc
- ccapi
- Branches
- Build
- Constants
- Examples
- Documentations
- Simple Market Data
- Advanced Market Data
- Complex request parameters
- Specify subscription market depth
- Specify correlation id
- Multiple exchanges and/or instruments
- Receive subscription events at periodic intervals
- Receive subscription events at periodic intervals including when the market depth snapshot hasn't changed
- Receive subscription market depth updates
- Receive subscription trade events
- Receive subscription calculated-candlestick events at periodic intervals
- Receive subscription exchange-provided-candlestick events at periodic intervals
- Send generic public requests
- Make generic public subscriptions
- Send generic private requests
- Simple Execution Management
- Advanced Execution Management
- FIX API
- More Advanced Topics
- Performance Tuning
- Known Issues and Workarounds
ccapi
- 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).
- Bindings for other languages such as Python, Java, C#, Go, and Javascript are provided.
- Code closely follows Bloomberg's API: https://www.bloomberg.com/professional/support/api-library/.
- It is ultra fast thanks to very careful optimizations.
- Supported exchanges:
- 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.
- 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.
- FIX: binance, coinbase, gemini.
- Join us on Discord https://discord.gg/b5EKcp9s8T and Medium https://cryptochassis.medium.com.
- For any questions, email hello@cryptochassis.com.
- We’re experts in market data collection, high-speed trading system, infrastructure optimization, and proprietary market making. Hire us as engineers, liquidity providers, traders, or asset managers.
Branches
- The
developbranch may contain experimental features. - The
masterbranch represents the most recent stable release.
Build
C++
- This library is header-only.
- 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 asCCAPI_ENABLE_EXCHANGE_BYBIT, etc. These macros can be found at the top ofinclude/ccapi_cpp/ccapi_session.h.
- Define service enablement macro such as
- 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).
- If you use FIX API, also need hffix https://github.com/jamesdbrock/hffix/archive/refs/tags/v1.4.1.tar.gz (notice that its include directory is hffix/include).
- Include directory for this library:
- include.
- Link libraries:
- OpenSSL: libssl.
- OpenSSL: libcrypto.
- If you need market data for huobi/huobi-usdt-swap/huobi-coin-swap or execution management for huobi-usdt-swap/huobi-coin-swap/bitmart, also link ZLIB.
- On Windows, also link ws2_32.
- Compiler flags:
-pthreadfor GCC and MinGW.
- Tested platforms:
- macOS: Clang.
- Linux: GCC.
- Windows: MinGW.
- Troubleshoot:
- Try to remove all build artifacts and start from scratch (e.g. for cmake remove all the contents inside your build directory).
- "Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_INCLUDE_DIR)". Try
cmake -DOPENSSL_ROOT_DIR=.... On macOS, you might be missing headers for OpenSSL,brew install opensslandcmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl. On Ubuntu,sudo apt-get install libssl-dev. On Windows,vcpkg install openssl:x64-windowsandcmake -DOPENSSL_ROOT_DIR=C:/vcpkg/installed/x64-windows-static. - "Fatal error: can't write <a> bytes to section .text of <b>: 'File too big'". Try to add compiler flag
-Wa,-mbig-obj. See https://github.com/assimp/assimp/issues/2067. - "string table overflow at offset <a>". Try to add optimization flag
-O1or-O2. See https://stackoverflow.com/questions/14125007/gcc-string-table-overflow-error-during-compilation. - On Windows, if you still encounter resource related issues, try to add optimization flag
-O3 -DNDEBUG.
non-C++
- Require SWIG and CMake.
- SWIG: On macOS,
brew install SWIG. On Linux,sudo apt-get install -y swig. - CMake: https://cmake.org/download/.
- SWIG: On macOS,
- Run the following commands.
mkdir binding/build
cd binding/build
rm -rf * (if rebuild from scratch)
cmake -DBUILD_PYTHON=ON -DBUILD_VERSION=1.0.0 .. (Use -DBUILD_JAVA=ON if the target language is Java, -DBUILD_CSHARP=ON if the target language is C#, -DBUILD_GO=ON if the target language is Go, -DBUILD_JAVASCRIPT=ON if the target language is Javascript)
cmake --build .
- The packaged build artifacts are located in the
binding/build/<language>/packaging/<BUILD_VERSION>directory. SWIG generated raw files and build artifacts are located in thebinding/build/<language>/ccapi_binding_<language>directory. - Python: If a virtual environment (managed by
venvorconda) is active (i.e. theactivatescript has been evaluated), the package will be installed into the virtual environment rather than globally. - C#: The shared library is built using the .NET framework.
- Troubleshoot:
- "Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_INCLUDE
