Skip to content

Commit

Permalink
Merge pull request #400 from crypto-chassis/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
cryptochassis committed Jul 2, 2023
2 parents 9a42067 + b67e9e9 commit 5693d89
Show file tree
Hide file tree
Showing 159 changed files with 847 additions and 503 deletions.
87 changes: 75 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,33 +309,31 @@ jobs:
# execute_process(COMMAND ccache -z)
execute_process(
COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/cmake --build test/build -j 2
COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/cmake --build example/build -j 2
RESULT_VARIABLE result
)
if (NOT result EQUAL 0)
message(FATAL_ERROR "Bad exit status")
endif()
execute_process(
COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/cmake --build example/build -j 2
COMMAND rm -rf example/build
RESULT_VARIABLE result
)
if (NOT result EQUAL 0)
message(FATAL_ERROR "Bad exit status")
endif()
if ("${{ runner.os }}" STREQUAL "macOS" OR "${{ runner.os }}" STREQUAL "Linux")
execute_process(
COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/cmake --build binding/build -j 2
RESULT_VARIABLE result
)
if (NOT result EQUAL 0)
message(FATAL_ERROR "Bad exit status")
endif()
execute_process(
COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/cmake --build performance/build -j 2
RESULT_VARIABLE result
)
if (NOT result EQUAL 0)
message(FATAL_ERROR "Bad exit status")
endif()
execute_process(
COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/cmake --build performance/build -j 2
COMMAND rm -rf performance/build
RESULT_VARIABLE result
)
if (NOT result EQUAL 0)
Expand All @@ -350,6 +348,22 @@ jobs:
message(FATAL_ERROR "Bad exit status")
endif()
execute_process(
COMMAND rm -rf app/build
RESULT_VARIABLE result
)
if (NOT result EQUAL 0)
message(FATAL_ERROR "Bad exit status")
endif()
execute_process(
COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/cmake --build test/build -j 2
RESULT_VARIABLE result
)
if (NOT result EQUAL 0)
message(FATAL_ERROR "Bad exit status")
endif()
# execute_process(COMMAND ccache -s)
- name: Test
Expand All @@ -364,6 +378,47 @@ jobs:
message(FATAL_ERROR "Bad exit status")
endif()
execute_process(
COMMAND rm -rf test/build
RESULT_VARIABLE result
)
if (NOT result EQUAL 0)
message(FATAL_ERROR "Bad exit status")
endif()
- name: Build Python
shell: cmake -P {0}
run: |
set(ENV{NINJA_STATUS} "[%f/%t %o/sec] ")
if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x")
file(STRINGS environment_script_output.txt output_lines)
foreach(line IN LISTS output_lines)
if (line MATCHES "^([a-zA-Z0-9_-]+)=(.*)$")
set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}")
endif()
endforeach()
endif()
set(path_separator ":")
if ("${{ runner.os }}" STREQUAL "Windows")
set(path_separator ";")
endif()
set(ENV{PATH} "$ENV{GITHUB_WORKSPACE}${path_separator}$ENV{PATH}")
if ("${{ runner.os }}" STREQUAL "macOS" OR "${{ runner.os }}" STREQUAL "Linux")
execute_process(
COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/cmake --build binding/build -j 2
RESULT_VARIABLE result
)
if (NOT result EQUAL 0)
message(FATAL_ERROR "Bad exit status")
endif()
endif()
- name: Test Python
shell: cmake -P {0}
run: |
if ("${{ runner.os }}" STREQUAL "macOS" OR "${{ runner.os }}" STREQUAL "Linux")
execute_process(
COMMAND ctest -VV
Expand All @@ -375,7 +430,7 @@ jobs:
endif()
endif()
- name: Install
- name: Install Python
shell: cmake -P {0}
run: |
if ("${{ runner.os }}" STREQUAL "macOS" OR "${{ runner.os }}" STREQUAL "Linux")
Expand All @@ -388,3 +443,11 @@ jobs:
message(FATAL_ERROR "Bad exit status")
endif()
endif()
execute_process(
COMMAND rm -rf binding/build
RESULT_VARIABLE result
)
if (NOT result EQUAL 0)
message(FATAL_ERROR "Bad exit status")
endif()
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Notification to Maintainers and Developers: we are aiming at an effort to transition our websocket related code from using websocketpp to boost beast websocket. In release v5.43.x, everything remains fully backward compatible. The codebase introduced a macro `CCAPI_USE_BOOST_BEAST_WEBSOCKET` to faciliate the future transition. If you have any questions, feel free to contact us at any time. Thank you.
Breaking changes in v6: Greetings, Ladies and Gentlemen, we've introduced some simplifications and breaking changes to our build process. Compared to v5, it should be much easier. If you have any questions, feel free to ping us on Discord https://discord.gg/b5EKcp9s8T. Thank you.

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
Expand Down Expand Up @@ -76,15 +76,15 @@ Notification to Maintainers and Developers: we are aiming at an effort to transi
### C++
* This library is header-only.
* Example CMake: example/CMakeLists.txt.
* Require C++14 (prefer C++17) and OpenSSL.
* 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_COINBASE`, etc. These macros can be found at the top of [`include/ccapi_cpp/ccapi_session.h`](include/ccapi_cpp/ccapi_session.h).
* Include directories:
* Dependencies:
* boost https://boostorg.jfrog.io/artifactory/main/release/1.80.0/source/boost_1_80_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.3.0.tar.gz (notice that its include directory is hffix/include).
* Include directory for this library:
* include.
* dependency/websocketpp.
* dependency/boost.
* dependency/rapidjson/include.
* If you need FIX API, also include dependency/hffix/include.
* Link libraries:
* OpenSSL: libssl.
* OpenSSL: libcrypto.
Expand All @@ -107,13 +107,12 @@ Notification to Maintainers and Developers: we are aiming at an effort to transi
* Require Python 3, SWIG, and CMake.
* SWIG: On macOS, `brew install SWIG`. On Linux, `sudo apt-get install -y swig`. On Windows, http://www.swig.org/Doc4.0/Windows.html#Windows.
* CMake: https://cmake.org/download/.
* Copy file [`binding/user_specified_cmake_include.cmake.example`](binding/user_specified_cmake_include.cmake.example) to any location and rename to `user_specified_cmake_include.cmake`. Take note of its full path `<path-to-user_specified_cmake_include>`. Uncomment the lines corresponding to the desired service enablement compile definitions 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_COINBASE`, etc. 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 uncomment the lines corresponding to finding and linking ZLIB.
* Run the following commands.
```
mkdir binding/build
cd binding/build
rm -rf * (if rebuild from scratch)
cmake -DCMAKE_PROJECT_INCLUDE=<path-to-user_specified_cmake_include> -DBUILD_VERSION=<any-string-you-like> -DBUILD_PYTHON=ON -DINSTALL_PYTHON=ON ..
cmake -DBUILD_PYTHON=ON -DINSTALL_PYTHON=ON .. (optional: -DBUILD_VERSION=<anything>)
cmake --build .
cmake --install .
```
Expand Down Expand Up @@ -939,13 +938,12 @@ session.serviceByServiceNameExchangeMap[CCAPI_EXECUTION_MANAGEMENT][CCAPI_EXCHAN
* The code uses a simplified version of Avellaneda & Stoikov’s inventory strategy: https://www.math.nyu.edu/~avellane/HighFrequencyTrading.pdf. See the [parameter configuration file `app/src/spot_market_making/config.env.example`](app/src/spot_market_making/config.env.example) for more details. And read more at https://medium.com/open-crypto-market-data-initiative/simplified-avellaneda-stoikov-market-making-608b9d437403.
* Require CMake.
* CMake: https://cmake.org/download/.
* Copy file [`app/user_specified_cmake_include.cmake.example`](app/user_specified_cmake_include.cmake.example) to any location and rename to `user_specified_cmake_include.cmake`. Take note of its full path `<path-to-user_specified_cmake_include>`. Uncomment the lines corresponding to the desired exchange enablement macros such as `CCAPI_ENABLE_EXCHANGE_COINBASE`, etc.
* Run the following commands.
```
mkdir app/build
cd app/build
rm -rf * (if rebuild from scratch)
cmake -DCMAKE_PROJECT_INCLUDE=<path-to-user_specified_cmake_include> ..
cmake ..
cmake --build . --target spot_market_making
```
* The executable is `app/build/src/spot_market_making/spot_market_making`. Run it after setting relevant environment variables shown in [`app/src/spot_market_making/config.env.example`](app/src/spot_market_making/config.env.example). For example, we can copy file `config.env.example` to `config.env`, edit it, and `export $(grep -v '^#' config.env | xargs)`. To enable and configure advanced parameters, set additional environment variables shown in [`app/src/spot_market_making/config_advanced.env.example`](app/src/spot_market_making/config_advanced.env.example).
Expand All @@ -957,13 +955,12 @@ cmake --build . --target spot_market_making
* The supported strategies are listed in [`app/src/single_order_execution/config.env.example`](app/src/single_order_execution/config.env.example).
* Require CMake.
* CMake: https://cmake.org/download/.
* Copy file [`app/user_specified_cmake_include.cmake.example`](app/user_specified_cmake_include.cmake.example) to any location and rename to `user_specified_cmake_include.cmake`. Take note of its full path `<path-to-user_specified_cmake_include>`. Uncomment the lines corresponding to the desired exchange enablement macros such as `CCAPI_ENABLE_EXCHANGE_COINBASE`, etc.
* Run the following commands.
```
mkdir app/build
cd app/build
rm -rf * (if rebuild from scratch)
cmake -DCMAKE_PROJECT_INCLUDE=<path-to-user_specified_cmake_include> ..
cmake ..
cmake --build . --target single_order_execution
```
* The executable is `app/build/src/single_order_execution/single_order_execution`. Run it after setting relevant environment variables shown in [`app/src/single_order_execution/config.env.example`](app/src/single_order_execution/config.env.example). For example, we can copy file `config.env.example` to `config.env`, edit it, and `export $(grep -v '^#' config.env | xargs)`. To enable and configure advanced parameters, set additional environment variables shown in [`app/src/single_order_execution/config_advanced.env.example`](app/src/single_order_execution/config_advanced.env.example).
Expand Down
87 changes: 85 additions & 2 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,40 @@ endif()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
get_filename_component(CCAPI_PROJECT_DIR ../ ABSOLUTE)
message(STATUS "CCAPI_PROJECT_DIR: ${CCAPI_PROJECT_DIR}")
if(USE_BOOST_BEAST_WEBSOCKET)
if(NOT CCAPI_LEGACY_USE_WEBSOCKETPP)
message(STATUS "use boost beast websocket")
add_compile_definitions(CCAPI_USE_BOOST_BEAST_WEBSOCKET)
if(NOT BOOST_INCLUDE_DIR)
include(ExternalProject)
ExternalProject_Add(boost
URL https://boostorg.jfrog.io/artifactory/main/release/1.80.0/source/boost_1_80_0.tar.gz
SOURCE_DIR "${CMAKE_BINARY_DIR}/boost"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
set(BOOST_INCLUDE_DIR "${CMAKE_BINARY_DIR}/boost")
else()
add_library(boost INTERFACE)
endif()
if(NOT RAPIDJSON_INCLUDE_DIR)
include(ExternalProject)
ExternalProject_Add(rapidjson
URL https://github.com/Tencent/rapidjson/archive/refs/tags/v1.1.0.tar.gz
SOURCE_DIR "${CMAKE_BINARY_DIR}/rapidjson"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
set(RAPIDJSON_INCLUDE_DIR "${CMAKE_BINARY_DIR}/rapidjson/include")
else()
add_library(rapidjson INTERFACE)
endif()
include_directories(${CCAPI_PROJECT_DIR}/include ${BOOST_INCLUDE_DIR} ${RAPIDJSON_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
else()
message(STATUS "use websocketpp")
add_compile_definitions(CCAPI_LEGACY_USE_WEBSOCKETPP)
set(RAPIDJSON_INCLUDE_DIR ${CCAPI_PROJECT_DIR}/dependency/rapidjson/include)
set(WEBSOCKETPP_INCLUDE_DIR ${CCAPI_PROJECT_DIR}/dependency/websocketpp)
set(BOOST_INCLUDE_DIR ${CCAPI_PROJECT_DIR}/dependency/boost)
Expand All @@ -38,5 +66,60 @@ if (WIN32)
endif()
link_libraries(OpenSSL::Crypto OpenSSL::SSL ${ADDITIONAL_LINK_LIBRARIES})
add_compile_options(-Wno-deprecated -Wno-nonnull -Wno-deprecated-declarations)

# If you encountered segmentation fault at run-time, comment out the following line.
if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

add_compile_definitions(CCAPI_ENABLE_EXCHANGE_COINBASE)
#
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_GEMINI)
#
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_KRAKEN)
#
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BITSTAMP)
#
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BITFINEX)
#
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BINANCE_US)
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BINANCE)
#
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX)
#
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_KUCOIN)
#
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_GATEIO)
#
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_CRYPTOCOM)
#
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BYBIT)
#
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_ASCENDEX)
#
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BITGET)
#
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_BITMART)
#
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_MEXC)
#
find_package(ZLIB REQUIRED)
link_libraries(ZLIB::ZLIB)

# If backtesting, you may want to comment out the following line to improve run-time speed.
add_compile_definitions(CCAPI_APP_ENABLE_LOG_INFO)

# If uncommented, the program will print out more information.
# add_compile_definitions(CCAPI_APP_ENABLE_LOG_DEBUG)

# If you have custom logics and want to reuse part of class EventHandlerBase.
# add_compile_definitions(CCAPI_APP_USE_CUSTOM_EVENT_HANDLER)
# get_filename_component(CUSTOM_EVENT_HANDLER_DIRECTORY ${CUSTOM_EVENT_HANDLER_PATH} DIRECTORY)
# include_directories(${CUSTOM_EVENT_HANDLER_DIRECTORY})

# If you have custom logics and need to repeatedly rebuild for backtesting, you may want to comment out the following line to improve build-time speed. If so, make sure to
# provide additional environment variables BASE_ASSET_OVERRIDE, QUOTE_ASSET_OVERRIDE, ORDER_PRICE_INCREMENT_OVERRIDE, and ORDER_QUANTITY_INCREMENT_OVERRIDE at run time.
# add_compile_definitions(CCAPI_APP_IS_BACKTEST)

add_subdirectory(src/spot_market_making)
add_subdirectory(src/single_order_execution)
3 changes: 3 additions & 0 deletions app/src/single_order_execution/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ project(${NAME})
add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA)
add_compile_definitions(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT)
add_executable(${NAME} main.cpp)
if(NOT CCAPI_LEGACY_USE_WEBSOCKETPP)
add_dependencies(${NAME} boost rapidjson)
endif()
3 changes: 3 additions & 0 deletions app/src/spot_market_making/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ project(${NAME})
add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA)
add_compile_definitions(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT)
add_executable(${NAME} main.cpp)
if(NOT CCAPI_LEGACY_USE_WEBSOCKETPP)
add_dependencies(${NAME} boost rapidjson)
endif()
58 changes: 0 additions & 58 deletions app/user_specified_cmake_include.cmake.example

This file was deleted.

Loading

0 comments on commit 5693d89

Please sign in to comment.