flashnuke / BinanceExtensionCPP

An extension for the API of Binance (https://www.binance.com/)
GNU General Public License v3.0
14 stars 4 forks source link
algo-trading algotrade algotrading binance binance-api bitcoin crtp crypto cryptocurrencies cryptocurrency hft high-frequency-trading trading

BinanceExtensionCPP

Intro

This library is an extension for the API of Binance. It is designed for writing trading algorithms on Binance.
The design is delibaretly attempting to reduce execution time during runtime, by using methods such as CRTP and the Params object; no virtual classes/methods are used in this library.

Dependencies

  1. JsonCPP (latest version tested: jsoncpp 1.9.3)
  2. CURL (latest version tested: curl 7.72.0)
  3. Boost/Beast websockets (latest version tested: boost-1.73.0)

These 3 must be installed in order to use the library.

Documentation

In order to use this library, you must have all dependencies installed. Only one #include statement is required - #include "include/Binance_Client.h", and all source files are inside the /src directory (You can copy an example from /examples into /src and compile using the compilation lines provided below).
Note that .inl files are included inside the main header.


You must initialize a Client object, which is one of the following: [SpotClient, FuturesClientUSDT, FuturesClientCoin, OpsClient]

Unique methods

Many endpoints are divided by category into different structs inside Client. In order to use them, you must instantiate a struct object first.


They should be initialized from within other Client classes, and by passing the Client object to the constructor.
i.e:

SpotClient::Wallet my_wallet{ my_client_obj }.

Exchange client

In order to initialize a client that is not public, api-key and api-secret must be passed in std::string format to the constructor.

FuturesClientUSDT(api_key, api_secret)


Futures and Options clients may be set in testnet mode by using the method set_testnet_mode(bool). SpotClient has test_new_order() method but no testnet mode endpoints.

REST client

All (except for ones that don't have mandatory parameters) REST request methods take a pointer to a Params object. This object holds the parameters that would be generated to a query string and sent as the request body.
Endpoints that do not require any params, have a default argument which is a nullptr (beware if using threads).
* Signing requests is done after generating the query, and the Params object remains unchanged.

Websocket client

Each time a client object is created, a websocket client is also instantiated. In fact, the websocket client accepts the Client object as an argument.


The websocket client holds a map of all stream connection names and their current status. symbol@stream_name (i.e: btc@aggTrade). This is very crucial to know in order to be able to close a stream by using the close_stream() method.
Not all streams accept the same arguments list, but all of them accept a functor object to use as callback.

Compilation & Optimizations

For Microsoft compilers (Visual Studio) set the following flags for better runtime performance:

If compiling on Linux, make sure you have the following dependencies installed:

If compiling on MacOS, install the dependencies using Homebrew:

Note for compiling on MacOS, if during compilation an error of missing openssl files is encountered, add the following flags to the compilation line: -L/usr/local/opt/openssl/lib -I/usr/local/opt/openssl/include


and use the following command to compile: g++ -std=c++11 src/* -o3 -lssl -lcrypto -lcurl -lpthread -ljsoncpp -o a.out
Make sure your .src file that includes the main() function is inside /src.
If the following error is encountered: fatal error: json/json.h: No such file or directory, you should change #include <json/json.h> to #include <jsoncpp/json/json.h> inside include/Binance_Client.h.

Examples

Release Notes

Latest version release - 2.3

Please see release notes here https://github.com/adanikel/BinanceExtensionCPP/releases/

Latest changelog updates: 2021-27-09 (Binance API Changelogs have been implemented up to this date)

Links