The binance depth stream must be bootstrapped with a depth snapshot, which is retrieved via an HTTP GET request
82 lines
2.0 KiB
C++
82 lines
2.0 KiB
C++
#pragma once
|
|
#include <cstddef>
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace bts::utils {
|
|
|
|
class StringSplitter {
|
|
public:
|
|
template <class Range>
|
|
static std::vector<std::string> split(
|
|
Range range, const std::string &delimiter);
|
|
|
|
template <class Iterator>
|
|
static std::vector<std::string> split(
|
|
Iterator first, Iterator last, const std::string &delimiter);
|
|
|
|
template <class Iterator>
|
|
static void split(
|
|
Iterator first,
|
|
Iterator last,
|
|
const std::string &delimiter,
|
|
std::vector<std::string> &parts);
|
|
};
|
|
|
|
//////////////////////////////////////////////////
|
|
// Definition
|
|
//////////////////////////////////////////////////
|
|
|
|
template <class Range>
|
|
std::vector<std::string> StringSplitter::split(
|
|
Range range, const std::string &delimiter) {
|
|
std::vector<std::string> parts;
|
|
split(range.begin(), range.end(), delimiter, parts);
|
|
return parts;
|
|
}
|
|
|
|
template <class Iterator>
|
|
std::vector<std::string> StringSplitter::split(
|
|
Iterator first, Iterator last, const std::string &delimiter) {
|
|
std::vector<std::string> parts;
|
|
split(first, last, delimiter, parts);
|
|
return parts;
|
|
}
|
|
|
|
template <class Iterator>
|
|
void StringSplitter::split(
|
|
Iterator first,
|
|
Iterator last,
|
|
const std::string &delimiter,
|
|
std::vector<std::string> &parts) {
|
|
|
|
auto cursor = first;
|
|
auto curr_end = first;
|
|
auto curr_start = first;
|
|
|
|
auto find_delim = [&cursor, &delimiter, &last]() {
|
|
for (auto it = cursor; it != last; it++) {
|
|
if (*it == delimiter[0]) {
|
|
if (std::equal(
|
|
it + 1, it + delimiter.size(), delimiter.begin() + 1,
|
|
delimiter.end())) {
|
|
return it;
|
|
}
|
|
}
|
|
}
|
|
return last;
|
|
};
|
|
|
|
while ((curr_end = find_delim()) != last) {
|
|
parts.push_back(std::string(curr_start, curr_end));
|
|
curr_start = curr_end + delimiter.size();
|
|
cursor = curr_end + delimiter.size();
|
|
}
|
|
if (cursor != last) {
|
|
parts.push_back(std::string(cursor, last));
|
|
}
|
|
}
|
|
|
|
} // namespace bts::utils
|