So we can subscribe to depth for "FTX Options" or "FTX BTC Futures", rather than having to list each security explicitly. This commit also unhooks binance from MarketDataGateway. A new paradigm is emerging with the FTX impl, and it'll be easier to redo Binance than try to make the existing impl fit the new mold. Unfortunately, ccapi doesn't provide all the security metadata we need, such as the security type and expiration date/time, so we get the list of FTX securities directly from the exchange.
179 lines
5.0 KiB
C++
179 lines
5.0 KiB
C++
#pragma once
|
|
#include <fmt/format.h>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
namespace bts::core {
|
|
|
|
class StringJoiner {
|
|
public:
|
|
template <class Arg>
|
|
static std::ostream &join(
|
|
const std::string &delimiter, std::ostream &out, Arg arg);
|
|
|
|
template <class Arg>
|
|
static std::string join(const std::string &delimiter, Arg arg);
|
|
|
|
template <class Arg, class... Args>
|
|
static std::ostream &join(
|
|
const std::string &delimiter, std::ostream &out, Arg arg, Args... args);
|
|
|
|
template <class Arg, class... Args>
|
|
static std::string join(const std::string &delimiter, Arg arg, Args... args);
|
|
|
|
template <class Iter>
|
|
static std::ostream &join(
|
|
Iter first, Iter last, const std::string &delimiter, std::ostream &out);
|
|
|
|
template <class Iter>
|
|
static std::string join(Iter first, Iter last, const std::string &delimiter);
|
|
|
|
/**
|
|
* Converts the args to strings (using the standard output operator), then
|
|
* joins the non-empty ones with the specified delimiter.
|
|
*/
|
|
template <class Arg>
|
|
static std::string join_non_empties(const std::string &delimiter, Arg arg);
|
|
|
|
/**
|
|
* Converts the args to strings (using the standard output operator), then
|
|
* joins the non-empty ones with the specified delimiter.
|
|
*/
|
|
template <class Arg, class... Args>
|
|
static std::string join_non_empties(
|
|
const std::string &delimiter, Arg arg, Args... args);
|
|
|
|
/**
|
|
* Converts the args to strings (using the standard output operator), then
|
|
* joins the non-empty ones with the specified delimiter.
|
|
*/
|
|
template <class Arg>
|
|
static std::ostream &join_non_empties(
|
|
const std::string &delimiter, std::ostream &out, Arg arg);
|
|
|
|
/**
|
|
* Converts the args to strings (using the standard output operator), then
|
|
* joins the non-empty ones with the specified delimiter.
|
|
*/
|
|
template <class Arg, class... Args>
|
|
static std::ostream &join_non_empties(
|
|
const std::string &delimiter, std::ostream &out, Arg arg, Args... args);
|
|
|
|
private:
|
|
template <class Arg, class... Args>
|
|
static std::ostream &join_non_empties_(
|
|
const std::string &delimiter, std::ostream &out, Arg arg, Args... args);
|
|
};
|
|
|
|
//////////////////////////////////////////////////
|
|
// Definition
|
|
//////////////////////////////////////////////////
|
|
|
|
template <class Arg>
|
|
std::ostream &StringJoiner::join(
|
|
const std::string & /*delimiter*/, std::ostream &out, Arg arg) {
|
|
// special case for single item (don't use delimiter)
|
|
out << arg;
|
|
return out;
|
|
}
|
|
|
|
template <class Arg>
|
|
std::string StringJoiner::join(const std::string & /*delimiter*/, Arg arg) {
|
|
// special case for single item (don't use delimiter)
|
|
std::stringstream out;
|
|
out << arg;
|
|
return out.str();
|
|
}
|
|
|
|
template <class Arg, class... Args>
|
|
std::ostream &StringJoiner::join(
|
|
const std::string &delimiter, std::ostream &out, Arg arg, Args... args) {
|
|
out << arg << delimiter;
|
|
return join(delimiter, out, args...);
|
|
}
|
|
|
|
template <class Arg, class... Args>
|
|
std::string StringJoiner::join(
|
|
const std::string &delimiter, Arg arg, Args... args) {
|
|
std::stringstream out;
|
|
out << arg << delimiter;
|
|
join<Args...>(delimiter, out, args...);
|
|
return out.str();
|
|
}
|
|
|
|
template <class Iter>
|
|
std::ostream &StringJoiner::join(
|
|
Iter it, Iter last, const std::string &delimiter, std::ostream &out) {
|
|
if (it == last) {
|
|
return out;
|
|
}
|
|
out << *it;
|
|
it++;
|
|
for (; it != last; it++) {
|
|
out << delimiter << *it;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
template <class Iter>
|
|
std::string StringJoiner::join(
|
|
Iter it, Iter last, const std::string &delimiter) {
|
|
std::stringstream out;
|
|
join(it, last, delimiter, out);
|
|
return out.str();
|
|
}
|
|
|
|
template <class Arg>
|
|
std::string StringJoiner::join_non_empties(
|
|
const std::string & /*delimiter*/, Arg arg) {
|
|
std::stringstream ss;
|
|
ss << arg;
|
|
return ss.str();
|
|
}
|
|
|
|
template <class Arg, class... Args>
|
|
std::string StringJoiner::join_non_empties(
|
|
const std::string &delimiter, Arg arg, Args... args) {
|
|
std::stringstream ss;
|
|
std::ostream &out = ss;
|
|
join_non_empties(delimiter, out, arg, args...);
|
|
return ss.str();
|
|
}
|
|
|
|
template <class Arg>
|
|
std::ostream &StringJoiner::join_non_empties(
|
|
const std::string & /*delimiter*/, std::ostream &out, Arg arg) {
|
|
out << arg;
|
|
return out;
|
|
}
|
|
|
|
template <class Arg, class... Args>
|
|
std::ostream &StringJoiner::join_non_empties(
|
|
const std::string &delimiter, std::ostream &out, Arg arg, Args... args) {
|
|
std::stringstream ss;
|
|
ss << arg;
|
|
auto arg_str = ss.str();
|
|
if (arg_str.empty()) {
|
|
return join_non_empties(delimiter, out, args...);
|
|
}
|
|
out << arg;
|
|
return join_non_empties_(delimiter, out, args...);
|
|
}
|
|
|
|
template <class Arg, class... Args>
|
|
std::ostream &StringJoiner::join_non_empties_(
|
|
const std::string &delimiter, std::ostream &out, Arg arg, Args... args) {
|
|
std::stringstream ss;
|
|
ss << arg;
|
|
auto arg_str = ss.str();
|
|
if (arg_str.empty()) {
|
|
return join_non_empties_(delimiter, out, args...);
|
|
}
|
|
out << delimiter << arg_str;
|
|
join(delimiter, out, args...);
|
|
return out;
|
|
}
|
|
|
|
} // namespace bts::core
|