git clone https://github.com/tensaix2j/binacpp
jsoncpp-1.8.3
libcurl-7.56.0
libwebsockets-2.4.0
Depended shared libraries and their headers are included in the repository's lib directory
use -I to include header paths for compiler to look for headers
and -L and -l for linker to link against shared libraries.
libcurl_dir=../lib/libcurl-7.56.0
libcurl_include=${libcurl_dir}/include
libcurl_lib=${libcurl_dir}/lib
jsoncpp_dir=../lib/jsoncpp-1.8.3
jsoncpp_include=${jsoncpp_dir}/include
jsoncpp_src=${jsoncpp_dir}/src
libwebsockets_dir=../lib/libwebsockets-2.4.0
libwebsockets_include=${libwebsockets_dir}/include
libwebsockets_lib=${libwebsockets_dir}/lib
libbinacpp_dir=../lib/libbinacpp
libbinacpp_include=${libbinacpp_dir}/include
libbinacpp_lib=${libbinacpp_dir}/lib
. Then compile like this:
g++ -I$(libcurl_include) -I$(jsoncpp_include) -I$(libwebsockets_include) -I$(libbinacpp_include) \
example.cpp \
-L$(libcurl_lib) \
-L$(libwebsockets_lib) \
-L$(libbinacpp_lib) \
-lcurl -lcrypto -lwebsockets -lbinacpp -o example
And export LD_LIBRARY_PATH and run like this:
libcurl_dir=../lib/libcurl-7.56.0
libcurl_lib=${libcurl_dir}/lib
libwebsockets_dir=../lib/libwebsockets-2.4.0
libwebsockets_lib=${libwebsockets_dir}/lib
libbinacpp_dir=../lib/libbinacpp
libbinacpp_lib=${libbinacpp_dir}/lib
export SSL_CERT_FILE=`pwd`/cacert.pem
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$libcurl_lib:$libwebsockets_lib:$libbinacpp_lib
./example
You can refer to the following Makefile to get a better picture...
https://github.com/tensaix2j/binacpp/blob/master/example/Makefile
cd example
make example
#include "binacpp.h"
#include "binacpp_websocket.h"
#include <json/json.h>
string api_key = API_KEY;
string secret_key = SECRET_KEY;
BinaCPP::init( api_key , secret_key );
Json::Value result;
BinaCPP::get_serverTime( result ) ;
Json::Value result;
BinaCPP::get_allPrices( result );
double bnbeth_price = BinaCPP::get_price( "BNBETH");
Json::Value result;
long recvWindow = 10000;
BinaCPP::get_account( recvWindow , result );
Json::Value result;
BinaCPP::get_allBookTickers( result );
Json::Value result;
BinaCPP::get_bookTicker("bnbeth", result );
Json::Value result;
BinaCPP::get_depth( "ETHBTC", 5, result ) ;
long recvWindow = 10000;
Json::Value result;
BinaCPP::send_order( "BNBETH", "BUY", "LIMIT", "GTC", 20 , 0.00380000, "",0,0, recvWindow, result );
long recvWindow = 10000;
Json::Value result;
BinaCPP::send_order( "BNBETH", "BUY", "MARKET", "GTC", 20 , 0, "",0,0, recvWindow, result );
long recvWindow = 10000;
Json::Value result;
BinaCPP::send_order( "BNBETH", "BUY", "MARKET", "GTC", 1 , 0, "",0,20, recvWindow , result );
long recvWindow = 10000;
Json::Value result;
BinaCPP::get_order( "BNBETH", 12345678, "", recvWindow, result );
long recvWindow = 10000;
Json::Value result;
BinaCPP::cancel_order("BNBETH", 12345678, "","", recvWindow, result);
long recvWindow = 10000;
Json::Value result;
BinaCPP::get_openOrders( "BNBETH", recvWindow, result ) ;
long recvWindow = 10000;
Json::Value result;
BinaCPP::get_allOrders( "BNBETH", 0,0, recvWindow, result )
long recvWindow = 10000;
Json::Value result;
BinaCPP::get_myTrades( "BNBETH", 0,0, recvWindow , result );
Json::Value result;
BinaCPP::get_24hr( "ETHBTC", result ) ;
Json::Value result;
BinaCPP::get_klines( "ETHBTC", "1h", 10 , 0, 0, result );
BinaCPP::start_userDataStream(result );
string ws_path = string("/ws/");
ws_path.append( result["listenKey"].asString() );
BinaCPP_websocket::init();
BinaCPP_websocket::connect_endpoint( ws_aggTrade_OnData ,"/ws/bnbbtc@aggTrade" );
BinaCPP_websocket::connect_endpoint( ws_userStream_OnData , ws_path.c_str() );
BinaCPP_websocket::connect_endpoint( ws_klines_onData ,"/ws/bnbbtc@kline_1m" );
BinaCPP_websocket::connect_endpoint( ws_depth_onData ,"/ws/bnbbtc@depth" );
BinaCPP_websocket::enter_event_loop();