GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - niXman/binapi: Binance API C++ implementation

BranchesTags
Open more actions menu

Latest commit

 

History

102 Commits
102 Commits

Folders and files

NameName
Last commit message
Last commit date
examples
examples
 
 
include/binapi
include/binapi
 
 
src
src
 
 
CMakeLists.txt
CMakeLists.txt
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
accinfo.json
accinfo.json
 
 
exinfo.json
exinfo.json
 
 
main.cpp
main.cpp
 
 

Repository files navigation

binapi

Binance API implemented in C++ for both synchronous and asynchronous way.

Donate

BTC: 3BJKvx6LyKB2J5KgRBqst415KKmwQE5eQX

Motivation

This implementation has been developed as a consequence of the lack of suitable alternatives as part of my multiuser trading platform project.

REST API

  • Test connectivity -> api::ping()
  • Check server time -> api::time()
  • Exchange information -> api::exchange_info()
  • Account information -> api::account_info()
  • Order book -> api::depth()
  • Recent trades list -> api::trades()
  • Aggregate trades list -> api::agg_trades()
  • 24hr ticker price change statistics -> api::_24hrs_ticker()
  • Symbol price ticker -> api::price()
  • New order -> api::new_order()
  • Query order -> api::order_info()
  • Test new order -> api::new_test_order()
  • Cancel order -> api::cancel_order()
  • Current open orders -> api::open_orders()
  • All orders -> api::all_orders()
  • Account trade list -> api::my_trades()
  • Start user data stream -> api::start_user_data_stream()
  • Keepalive user data stream -> api::ping_user_data_stream()
  • Close user data stream -> api::close_user_data_stream()

WebSocket API

  • Partial Book Depth Streams -> websockets::part_depth()
  • Diff. Depth Stream -> websockets::diff_depth()
  • Kline/Candlestick Streams -> websockets::klines()
  • Trade Streams -> websockets::trade()
  • Aggregate Trade Streams -> websockets::agg_trade()
  • Individual Symbol Mini Ticker Stream -> websockets::mini_ticker()
  • All Market Mini Tickers Stream -> websockets::mini_tickers()
  • Individual Symbol Ticker Streams -> websockets::market()
  • All Market Tickers Stream -> websockets::markets()
  • Individual Symbol Book Ticker Streams -> websockets::book()
  • All Book Tickers Stream -> websockets::books()
  • User Data Streams -> websockets::userdata()

Implementation details

The project is written using C++14 and boost (at least version 1.70). boost.beast is used to interact with the network.

Synchronous example

#include "binapi/api.hpp"

#include <boost/asio/io_context.hpp>

#include <iostream>

int main() {
    const std::string pk = "...";
    const std::string sk = "...";

    boost::asio::io_context ioctx;
    binapi::rest::api api(
        ioctx
        ,"api.binance.com"
        ,"443"
        ,pk
        ,sk
        ,10000 // recvWindow
    );

    auto account = api.account_info();
    if ( !account ) {
        std::cerr << "account info error: " << account.errmsg << std::endl;
        return EXIT_FAILURE;
    }

    std::cout << "account info: " << account.v << std::endl << std::endl;

    return EXIT_SUCCESS;
}

Asynchronous example

#include "binapi/api.hpp"

#include <boost/asio/io_context.hpp>

#include <iostream>

int main() {
    const std::string pk = "...";
    const std::string sk = "...";

    boost::asio::io_context ioctx;
    binapi::rest::api api(
        ioctx
        ,"api.binance.com"
        ,"443"
        ,pk
        ,sk
        ,10000 // recvWindow
    );

    api.account_info([](const char *fl, int ec, std::string errmsg, binapi::rest::account_info_t res) {
        if ( ec ) {
            std::cerr << "account info error: fl=" << fl << ", ec=" << ec << ", emsg=" << errmsg << std::endl;
            return false;
        }

        std::cout << "account info: " << res << std::endl;

        return true;
    });

    ioctx.run();

    return EXIT_SUCCESS;
}

WebSocket example

#include <binapi/api.hpp>
#include <binapi/websocket.hpp>

#include <boost/asio/io_context.hpp>

#include <iostream>

int main() {
    boost::asio::io_context ioctx;

    binapi::ws::websockets ws{
         ioctx
        ,"stream.binance.com"
        ,"9443"
    };

    ws.part_depth("BTCUSDT",
        [](const char *fl, int ec, std::string emsg, auto depths) {
            if ( ec ) {
                std::cerr << "subscribe depth error: fl=" << fl << ", ec=" << ec << ", emsg=" << emsg << std::endl;

                return false;
            }

            std::cout << "depths: " << depths << std::endl;

            return true;
        }
    );

    ws.trade("BTCUSDT",
        [](const char *fl, int ec, std::string emsg, auto trades) {
            if ( ec ) {
                std::cerr << "subscribe trades error: fl=" << fl << ", ec=" << ec << ", emsg=" << emsg << std::endl;

                return false;
            }

            std::cout << "trades: " << trades << std::endl;

            return true;
        }
    );

    ioctx.run();

    return EXIT_SUCCESS;
}

Tools (will write later...)

  • filters
  • report generators

About

Binance API C++ implementation

Topics

binancebinance-apicpluspluscplusplus-14

Resources

Readme
Apache-2.0 license
Activity

Stars

326 stars

Watchers

17 watching

Forks

110 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.