algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
client_stores.hpp
1#pragma once
2
3#include "./calendar_cache.hpp"
4#include "./http_client.hpp"
5#include "./token_store.hpp"
6
7#include <memory>
8#include <type_traits>
9#include <utility>
10
11namespace algotradelib {
12namespace network {
13
17 std::shared_ptr<TokenStore> tokens_;
19 std::shared_ptr<CalendarCache> calendars_;
20};
21
40template <typename Client, typename Config>
41std::shared_ptr<Client> make_client(
42 ssl::context& context, Config config, HttpClientOptions options, const ClientStores& stores
43) {
44 constexpr bool takes4 =
45 std::is_constructible_v<Client, ssl::context&, Config, HttpClientOptions, std::shared_ptr<TokenStore>>;
46 constexpr bool takes5 = std::is_constructible_v<
47 Client, ssl::context&, Config, HttpClientOptions, std::shared_ptr<TokenStore>, std::shared_ptr<CalendarCache>
48 >;
49 static_assert(
50 takes4 || takes5,
51 "Client is not constructible from (ssl::context&, Config, HttpClientOptions, shared_ptr<TokenStore>[, "
52 "shared_ptr<CalendarCache>]): check that Config is BrokerTraits<Client>::Config, or construct it by hand"
53 );
54 if constexpr (takes5) {
55 return std::make_shared<Client>(context, std::move(config), std::move(options), stores.tokens_, stores.calendars_);
56 } else if constexpr (takes4) {
57 return std::make_shared<Client>(context, std::move(config), std::move(options), stores.tokens_);
58 }
59}
60
61} // namespace network
62} // namespace algotradelib
HTTP and WebSocket transport, OAuth tokens, and request pacing.
std::shared_ptr< Client > make_client(ssl::context &context, Config config, HttpClientOptions options, const ClientStores &stores)
Constructs a blocking client with the run's stores; sends nothing.
The library: broker-neutral types (core), and the modules below.
What the clients of a run share, across processes too; each takes those its constructor accepts.
std::shared_ptr< CalendarCache > calendars_
Where clients share a trading calendar, or null; only KIS's client takes one, to save requests.
std::shared_ptr< TokenStore > tokens_
Where clients share access tokens, or null for each to keep its own (Toss needs it shared).
Deadlines, size limits and pacing for an HTTP client.