diff --git a/include/binapi/api.hpp b/include/binapi/api.hpp index 5285538..ab51534 100644 --- a/include/binapi/api.hpp +++ b/include/binapi/api.hpp @@ -113,6 +113,14 @@ struct api { result prices(prices_cb cb = {}); + using common_str_cb = std::function; + result + common_str( + std::string str_url, + std::initializer_list>> map = {}, + common_str_cb cb = {} + ); + // https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md#current-average-price using avg_price_cb = std::function; result diff --git a/include/binapi/types.hpp b/include/binapi/types.hpp index d504e69..4acf952 100644 --- a/include/binapi/types.hpp +++ b/include/binapi/types.hpp @@ -82,6 +82,21 @@ struct prices_t { const price_t& get_by_symbol(const char *sym) const; }; +struct common_strs_t { + struct common_str_t { + std::string symbol; //useless now + std::string str_return; + + static common_str_t construct(const flatjson::fjson& json); + friend std::ostream& operator<<(std::ostream& os, const common_str_t& f); + }; + + std::map tickers; + + static common_strs_t construct(const flatjson::fjson& json); + friend std::ostream& operator<<(std::ostream& os, const common_strs_t& f); +}; + // https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#24hr-ticker-price-change-statistics struct _24hrs_tickers_t { struct _24hrs_ticker_t { diff --git a/src/api.cpp b/src/api.cpp index f790ff2..7446cbb 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -351,6 +351,7 @@ struct api::impl { return res; } else { + //std::cout << typeid(R).name() << std::endl; res.v = R::construct(json); } } @@ -720,6 +721,16 @@ api::result api::prices(prices_cb cb) { /*************************************************************************************************/ +api::result api::common_str( + std::string str_url, + std::initializer_list>> map, + common_str_cb cb) +{ + return pimpl->post(false, str_url.c_str(), boost::beast::http::verb::get, map, std::move(cb)); +} + +/*************************************************************************************************/ + api::result api::avg_price(const char *symbol, avg_price_cb cb) { const impl::init_list_type map = { {"symbol", symbol} diff --git a/src/types.cpp b/src/types.cpp index 2bec94a..c0a1050 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -16,6 +16,7 @@ #include #include +#include //#include // TODO: comment out @@ -191,6 +192,50 @@ const prices_t::price_t& prices_t::get_by_symbol(const char *sym) const { /*************************************************************************************************/ +common_strs_t::common_str_t +common_strs_t::common_str_t::construct(const flatjson::fjson& json) { + if (!json.is_valid()) { //pure json, differnt with others + std::cout << "common_strs_t::common_str_t::construct error, not valid" << std::endl; + } + + common_strs_t::common_str_t res{}; + + res.symbol = (json.is_object() && json.contains("symbol")) ? json["symbol"].to_string() : ""; + //res.symbol = ""; + res.str_return = json.dump(); + + return res; +} + +std::ostream& operator<<(std::ostream& os, const common_strs_t::common_str_t& f) { + os + << "{" + << "\"symbol\":\"" << f.symbol << "\"," + << "\"str_return\":" << f.str_return + << "}"; + + return os; +} + +common_strs_t common_strs_t::construct(const flatjson::fjson& json) { + if (!json.is_valid()) { //pure json, differnt with others + std::cout << "common_strs_t::construct error, not valid" <