• Stars
    star
    261
  • Rank 156,630 (Top 4 %)
  • Language
    C++
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Binance API C++ implementation

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

WebSocket API

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

More Repositories

1

mingw-builds-binaries

MinGW-W64 compiler binaries
2,554
star
2

yas

Yet Another Serialization
C++
731
star
3

mingw-builds

Scripts for building the 32 and 64-bit MinGW-W64 compilers for Windows
Shell
290
star
4

flatjson

The extremely fast zero allocation and zero copying JSON parser
C++
28
star
5

csprot

C++14 compile time literal-string encoder, which decodes a strings at run-time
C++
8
star
6

yal

Yet Another Logger
C++
8
star
7

aescrypt

AES crypt/decrypt using OpenSSL
C++
6
star
8

named-args

C++11 tiny implementation of the concept of named function arguments with zero runtime overhead
C++
6
star
9

enum-gen

'enum's and 'enum class'es metainfo preprocessor generator
C++
5
star
10

std-signals

C++11 managed signals and slots callback implementation
C++
4
star
11

nanolog

C++20 Nano logging library with std::format
C++
4
star
12

cmdargs

C++17 library to work with command-line args and config files
C++
4
star
13

sha1

sha1 summ calculator
C++
3
star
14

contract

Library to support contract programming in C++11
C++
3
star
15

blockchain

Blockchain for fun :)
C++
3
star
16

config-ctor

C++ preprocessor type constuctor for processing structured (JSON) configuration files
C++
3
star
17

mingw-env

The development environment based on the MinGW-W64 project
Shell
2
star
18

fqueue

Persistent file queue of buffers
C++
2
star
19

static_if

C++14 static_if() alternative implementation from D language
C++
1
star
20

switch

switch()-like statement whose cases can be strings and integrals
C++
1
star
21

passgen

Password generator uses common passphrase and URL of the site
Shell
1
star
22

nixman.github.io

letters
HTML
1
star
23

transparent-proxy

Transparent proxy using boost.asio
C++
1
star
24

singleapplication

C++ single-application guard
C++
1
star
25

throw

C++ exceptions helpers
C++
1
star
26

impl-container

Container of implementations with getter by key and verifying the uniqueness of stored implementations
C++
1
star
27

torrent-creator

torrent files creator using libtorrent-rasterbar
C++
1
star
28

any

extended 'any' implementation for C++11
C++
1
star
29

lazy-init

Lazy initialization of objects
C++
1
star
30

dtf

Very fast date-time string maker
C++
1
star