The binance depth stream must be bootstrapped with a depth snapshot, which is retrieved via an HTTP GET request
47 lines
1.3 KiB
C++
47 lines
1.3 KiB
C++
#include "HTTPHeaders.h"
|
|
#include "lib/utils/StringSplitter.h"
|
|
#include <fmt/format.h>
|
|
#include <range/v3/view.hpp>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
namespace bts::io::http {
|
|
|
|
HTTPHeaders::HTTPHeaders(const std::string &str) {
|
|
auto item_strs = utils::StringSplitter::split(str, "\n");
|
|
auto items = ranges::transform_view(
|
|
item_strs,
|
|
[](const std::string &item_str) -> std::pair<std::string, std::string> {
|
|
auto kv = utils::StringSplitter::split(item_str, ":");
|
|
if (kv.empty()) {
|
|
return std::make_pair("", "");
|
|
}
|
|
if (kv.size() == 1) {
|
|
return std::make_pair(kv[0], std::string(""));
|
|
}
|
|
return std::make_pair(kv[0], kv[1]);
|
|
});
|
|
for (auto p : items) {
|
|
try_emplace(p.first, p.second);
|
|
}
|
|
}
|
|
|
|
std::string HTTPHeaders::to_string() const {
|
|
std::string rv;
|
|
auto query_param_strs = ranges::transform_view(
|
|
*this, [](const auto &qp) { return qp.first + ": " + qp.second; });
|
|
rv.append(fmt::format(
|
|
"{}",
|
|
fmt::join(query_param_strs.begin(), query_param_strs.end(), "\n")));
|
|
return rv;
|
|
}
|
|
|
|
std::ostream &operator<<(
|
|
std::ostream &out, const HTTPHeaders &headers) noexcept {
|
|
out << headers.to_string();
|
|
return out;
|
|
}
|
|
|
|
} // namespace bts::io::http
|