#include using namespace binance::endpoint; using namespace binance::websocket::client; using namespace binance::extra; #include #include #include #include using namespace std; const char* api_key = getenv("BINANCE_API_KEY"); const char* api_secret = getenv("BINANCE_API_SECRET"); auto pre_check() { if (!(api_key && api_secret)) throw runtime_error("Please setup binance APIKEY and APISECRET!"); } int main(int argc, char** argv) { pre_check(); auto endpoint = make_shared(api_key, api_secret); endpoint->all_book_tickers() >>= print_results; endpoint->all_prices() >>= print_results; function get_last_price = [](const auto &ts) { return ts.last_price; }; (endpoint->ticker_24hr("LTCBTC") ^ get_last_price) >>= print_result; endpoint->ticker_24hr("LTCBTC") >>= print_result; (endpoint->candlestick_bars("LTCBTC", "5m") >>= head_m) >>= print_result; (endpoint->agg_trades("LTCBTC") >>= head_m) >>= print_result; function>(OrderBook)> get_bids = [](const auto &ob) { return Maybe>(ob.bids); }; ((endpoint->order_book("LTCBTC", 5) >>= get_bids) >>= head_m) >>= print_result; endpoint->ping() >>= print_result; endpoint->time() >>= print_result; endpoint->buy_limit("ETHBTC", 1.0, 0.069) >>= print_result; endpoint->buy_market("ETHBTC", 1.0) >>= print_result; endpoint->order_status("ETHBTC", 13151) >>= print_result; endpoint->open_orders("ETHBTC") >>= print_results; endpoint->all_orders("ETHBTC") >>= print_results; endpoint->cancel_order("ETHBTC", 13151) >>= print_result; function get_buyer_commission = [](const auto &a) { return a.buyer_commission; }; endpoint->my_account() >>= print_result; (endpoint->my_account() ^ get_buyer_commission) >>= print_result; endpoint->my_trades("LTCBTC") >>= print_results; endpoint->withdraw("ETH", "Ox333", 3.3) >>= print_result; endpoint->withdraw_history("NEO") >>= print_result; endpoint->deposit_history("NEO") >>= print_result; endpoint->depth_websocket("ethbtc", [](json data) { DepthEvent de = data; print_result(de); }); endpoint->kline_websocket("ethbtc", "1m", [](json data) { CandleStickEvent cse = data; print_result(cse); }); endpoint->trades_websocket("ethbtc", [](json data) { AggTradeEvent ate = data; print_result(ate); }); auto jr = endpoint->start_user_data_stream(); if (jr.isJust()) { auto listen_key = jr.fromJust(); endpoint->user_data_websockets(listen_key, [](json data) { cout << data.dump(2) << endl; }); } }