algotradelib
0.0.0.9000
C++ header-only library for algorithmic trading
Toggle main menu visibility
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
11
namespace
algotradelib
{
12
namespace
network
{
13
15
struct
ClientStores
{
17
std::shared_ptr<TokenStore>
tokens_
;
19
std::shared_ptr<CalendarCache>
calendars_
;
20
};
21
40
template
<
typename
Client,
typename
Config>
41
std::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
algotradelib::network
HTTP and WebSocket transport, OAuth tokens, and request pacing.
Definition
calendar_cache.hpp:10
algotradelib::network::make_client
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.
Definition
client_stores.hpp:41
algotradelib
The library: broker-neutral types (core), and the modules below.
Definition
conversion.hpp:13
algotradelib::network::ClientStores
What the clients of a run share, across processes too; each takes those its constructor accepts.
Definition
client_stores.hpp:15
algotradelib::network::ClientStores::calendars_
std::shared_ptr< CalendarCache > calendars_
Where clients share a trading calendar, or null; only KIS's client takes one, to save requests.
Definition
client_stores.hpp:19
algotradelib::network::ClientStores::tokens_
std::shared_ptr< TokenStore > tokens_
Where clients share access tokens, or null for each to keep its own (Toss needs it shared).
Definition
client_stores.hpp:17
algotradelib::network::HttpClientOptions
Deadlines, size limits and pacing for an HTTP client.
Definition
http_client.hpp:77
algotradelib
src
network
client_stores.hpp
Generated by
1.18.0