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.
91 lines
2.4 KiB
C++
91 lines
2.4 KiB
C++
#pragma once
|
|
#include <type_traits>
|
|
#include <utility>
|
|
|
|
namespace bts::spartan {
|
|
|
|
// Provides a very fast, very small roughly equivalent to
|
|
// std::function. Unlike std::function instances of Delegate do not
|
|
// copy the call back they are bound to.
|
|
template <typename Signature>
|
|
class Delegate;
|
|
|
|
template <typename R, typename... Arg>
|
|
class Delegate<R(Arg...)> {
|
|
|
|
private:
|
|
void *target_obj_;
|
|
R (*invoke_)(void *, Arg...);
|
|
|
|
template <class T>
|
|
struct handler_traits;
|
|
template <class T, class Re>
|
|
struct handler_traits<Re T::*> {
|
|
using HandlerType = T;
|
|
using HandlerReturnType = Re;
|
|
};
|
|
template <auto handler_member, typename Re, typename... Args>
|
|
static R invoke_member_handler(void *handler_obj, Args... arg) {
|
|
using HandlerMethod = decltype(handler_member);
|
|
static_assert(std::is_member_function_pointer<HandlerMethod>::value);
|
|
using HandlerType = typename handler_traits<HandlerMethod>::HandlerType;
|
|
return (((HandlerType *)handler_obj)->*handler_member)(
|
|
std::forward<Arg>(arg)...);
|
|
}
|
|
template <auto handler, typename Re, typename... Args>
|
|
static R invoke_static_handler(void *, Args... arg) {
|
|
return handler(std::forward<Arg>(arg)...);
|
|
}
|
|
|
|
static R null_target(Arg...) {
|
|
if constexpr (std::is_same<void, R>::value)
|
|
return;
|
|
else
|
|
return {};
|
|
}
|
|
|
|
public:
|
|
Delegate() : target_obj_(), invoke_() { bind<&Delegate::null_target>(); }
|
|
|
|
Delegate(Delegate const &d)
|
|
: target_obj_(d.target_obj), invoke_(d.invoke_) {}
|
|
|
|
Delegate &operator=(Delegate const &d) {
|
|
target_obj_ = d.target_obj_;
|
|
invoke_ = d.invoke_;
|
|
return *this;
|
|
}
|
|
|
|
template <class C>
|
|
void bind(C &handler_obj) {
|
|
target_obj_ = &handler_obj;
|
|
bind<&C::operator()>(handler_obj);
|
|
}
|
|
|
|
template <auto handler_member>
|
|
void bind(typename handler_traits<decltype(handler_member)>::HandlerType
|
|
&handler_obj) {
|
|
target_obj_ = &handler_obj;
|
|
invoke_ = invoke_member_handler<handler_member, R, Arg...>;
|
|
}
|
|
|
|
template <auto static_handler>
|
|
void bind() {
|
|
target_obj_ = nullptr;
|
|
invoke_ = invoke_static_handler<static_handler, R, Arg...>;
|
|
}
|
|
|
|
R operator()(Arg... arg) {
|
|
return invoke_(target_obj_, std::forward<Arg>(arg)...);
|
|
}
|
|
};
|
|
|
|
} // namespace bts::spartan
|
|
|
|
namespace bts::core {
|
|
|
|
template <typename Signature>
|
|
using Delegate = bts::spartan::Delegate<Signature>;
|
|
|
|
} // namespace bts::core
|