GithubHelp home page GithubHelp logo

dgrr / binance-futures-sdk Goto Github PK

View Code? Open in Web Editor NEW
17.0 3.0 5.0 174 KB

C++ Binance Futures SDK.

License: MIT License

CMake 4.41% C++ 95.15% Dockerfile 0.35% Shell 0.10%
boost websocket asio binance-futures-sdk beast async simdjson websocket-stream

binance-futures-sdk's Introduction

Binance Futures C++ SDK

Binance Futures C++ SDK, unlike other C++ SDKs, works on top of Boost.Beast. No cURL, no weird WebSocket libraries. Only Boost (and simdjson).

Contents

Features

  • Request queuing.

    By default, Boost.ASIO doesn't support sending multiple requests at the same time. This library queues the request internally so you don't need to queue the request in your code.

  • SIMD boosted.

    The library uses simdjson as json parser. Also, it does contain many other SIMD improvements like string to int conversion and decimal to hexadecimal conversion (the latter reuses the string buffer).

HTTP API client

The client works only in ASYNC mode. That means that all your requests will be queued internally and executed sequentially. After every execution, the library will call your callback returning the response.

The client establishes a connection when you call the method connect. The connection won't close unless you either destroy the object, call close or the server closes the connection. The connection is getting opened and closed around every 15 seconds. This is due to some HTTP servers closes the connection if they don't get any request in a given amount of time. By keeping the connection alive we avoid any performance issues on creating a connection for every HTTP request.

If the connection closed unexpectedly or you just want to reset the connection, just call connect again.

WebSocket

The WebSocket stream works only in ASYNC mode too unless for connecting. All the messages sent are not queued, so you'll need to schedule the messages by your own.

If you get disconnected you can re-stablish the connection by calling connect again. Remember, a websocket connection is only valid for 24h, so every 24h you'll need to reconnect.

The WebSocket stream was built on usability with other services in mind. For example, if you want to receive messages from Binance Futures and send the info to an external service via WebSocket, you can by reusing the io_context.

Keep in mind that stream was built to run in a single-thread environment, we do not know yet the consequences of running the stream in a multi-thread context. (with Boost.ASIO/Boost.Beast should be easy to do it).

Handling OS signals

Handling OS signals is up to you. With Boost.ASIO you can handle signals easily.

Build examples

Usual building:

git clone https://github.com/dgrr/binance-futures-sdk
cd binance-futures-sdk
git submodule update --init
mkdir build
cd build
cmake -DBINANCE_DISABLE_THREADING:BOOL=ON -DBINANCE_USE_STRING_VIEW:BOOL=ON -DBINANCE_BUILD_EXAMPLES:BOOL=ON ..
cmake --build . --target all

Building with Docker:

git clone https://github.com/dgrr/binance-futures-sdk
cd binance-futures-sdk
git submodule update --init
./build.sh

binance-futures-sdk's People

Contributors

dgrr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

binance-futures-sdk's Issues

can websocket stream be used for receiving cash data?

I read the websocket API docs between cash and futures, it seems no differences except host IP and port. When I changed the IP and port, the program connects well, but it fails at throwing 'stream truncated' error when trying to subscribe.

compile error in example of websocket

OS: MacOS Catalina

Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

> cmake --build . --target all                                                                                             build -> master ?
Scanning dependencies of target boost_url
[  5%] Building CXX object contrib/boost.url/CMakeFiles/boost_url.dir/src/src.cpp.o
[ 11%] Linking CXX static library libboost_url.a
[ 11%] Built target boost_url
Scanning dependencies of target boost_json
[ 16%] Building CXX object contrib/boost.json/CMakeFiles/boost_json.dir/src/src.cpp.o
[ 22%] Linking CXX static library libboost_json.a
[ 22%] Built target boost_json
Scanning dependencies of target simdjson
[ 27%] Building CXX object contrib/simdjson/src/CMakeFiles/simdjson.dir/simdjson.cpp.o
[ 33%] Linking CXX static library libsimdjson.a
[ 33%] Built target simdjson
Scanning dependencies of target binance-websocket-example
[ 38%] Building CXX object examples/websocket/CMakeFiles/binance-websocket-example.dir/main.cc.o
/Users/pauln/binance-futures-sdk/examples/websocket/main.cc:49:22: error: too few arguments to function call,
      single argument 'cb' was not specified
    ws_->async_close();
    ~~~~~~~~~~~~~~~~ ^
/Users/pauln/binance-futures-sdk/examples/websocket/../../include/binance/websocket/stream.hpp:207:1: note:
      'async_close' declared here
void stream::async_close(std::function<void(boost::system::error_code)> cb)
^
1 error generated.
make[2]: *** [examples/websocket/CMakeFiles/binance-websocket-example.dir/main.cc.o] Error 1
make[1]: *** [examples/websocket/CMakeFiles/binance-websocket-example.dir/all] Error 2
make: *** [all] Error 2

State of project.

Hi,

I've been examining the code, is this project considered to be stable enough for a project to use the existing code base?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.