algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
broker_caps.hpp
1#pragma once
2
3#include "./broker_traits.hpp"
4#include "./market_data.hpp"
5#include "./types.hpp"
6
7namespace algotradelib {
8
9namespace caps_detail {
10
16template <typename T>
17constexpr bool terminal_working_state() {
18 if constexpr (T::has_working_orders) {
19 return T::working_orders_state_terminal;
20 } else {
21 return false;
22 }
23}
24
30template <typename T>
31constexpr SellableBasis inquiry_basis() {
32 if constexpr (T::sellable_source == SellableSource::INQUIRY) {
33 return T::sellable_inquiry_basis;
34 } else {
35 return SellableBasis{};
36 }
37}
38
39} // namespace caps_detail
40
55template <typename Client>
56struct BrokerCaps {
59
61 static constexpr bool has_account_discovery = Traits::has_account_discovery;
62
64 static constexpr bool has_client_order_id = Traits::has_client_order_id;
65
70 static constexpr bool has_working_orders = Traits::has_working_orders;
71
73 static constexpr bool has_amendable_quantity = Traits::has_amendable_quantity;
74
82 static constexpr bool working_orders_state_terminal = caps_detail::terminal_working_state<Traits>();
83
91 static constexpr bool has_trigger_price = Traits::has_trigger_price;
92
100 static constexpr bool data_only = Traits::data_only;
101
103 static constexpr bool has_order_by_id = Traits::has_order_by_id;
104
106 static constexpr bool has_partial_cancel = Traits::has_partial_cancel;
107
109 static constexpr bool history_requires_range = Traits::history_requires_range;
110
116 static constexpr bool has_history_cursor = Traits::has_history_cursor;
117
123 static constexpr bool has_history_limit = Traits::has_history_limit;
124
126 static constexpr bool has_history_symbol_filter = Traits::has_history_symbol_filter;
127
129 static constexpr bool has_depth = Traits::has_depth;
130
132 static constexpr bool has_price_limits = Traits::has_price_limits;
133
135 static constexpr bool has_trade_prints = Traits::has_trade_prints;
136
138 static constexpr bool has_batch_prices = Traits::has_batch_prices;
139
141 static constexpr bool has_buying_power = Traits::has_buying_power;
142
149 static constexpr bool has_buying_power_quantity = Traits::has_buying_power_quantity;
150
155 static constexpr SellableSource sellable_source = Traits::sellable_source;
156
163 static constexpr SellableBasis sellable_inquiry_basis = caps_detail::inquiry_basis<Traits>();
164
166 static constexpr bool has_commission_schedule = Traits::has_commission_schedule;
167
169 static constexpr bool has_reference_data = Traits::has_reference_data;
170
176 static constexpr bool has_batch_reference_data = Traits::has_batch_reference_data;
177
179 static constexpr bool has_calendar = Traits::has_calendar;
180
187 static constexpr bool has_calendar_range = Traits::has_calendar_range;
188
193 static constexpr bool has_calendar_sessions = Traits::has_calendar_sessions;
194
204 static constexpr bool supports_interval(BarInterval interval) {
205 return Traits::supports_interval(interval);
206 }
207};
208
215// A constant added to `BrokerCaps` must be added here.
216template <typename Caps>
217constexpr bool reads_every_capability() {
218 constexpr bool read[] = {
219 Caps::has_account_discovery,
220 Caps::has_client_order_id,
221 Caps::has_working_orders,
222 Caps::has_amendable_quantity,
223 Caps::working_orders_state_terminal,
224 Caps::has_trigger_price,
225 Caps::data_only,
226 Caps::has_order_by_id,
227 Caps::has_partial_cancel,
228 Caps::history_requires_range,
229 Caps::has_history_cursor,
230 Caps::has_history_limit,
231 Caps::has_history_symbol_filter,
232 Caps::has_depth,
233 Caps::has_price_limits,
234 Caps::has_trade_prints,
235 Caps::has_batch_prices,
236 Caps::has_buying_power,
237 Caps::has_buying_power_quantity,
238 Caps::sellable_source == SellableSource::INQUIRY,
239 Caps::sellable_inquiry_basis.coverage_ == SellableBasis::Coverage::UNESTABLISHED,
240 Caps::has_commission_schedule,
241 Caps::has_reference_data,
242 Caps::has_batch_reference_data,
243 Caps::has_calendar,
244 Caps::has_calendar_range,
245 Caps::has_calendar_sessions,
246 };
247 static_cast<void>(read);
248 // Named, not called: the predicate need not be usable in a constant expression to be conforming.
249 static_cast<void>(&Caps::supports_interval);
250 return true;
251}
252
258template <typename Client>
262
263} // namespace algotradelib
The library: broker-neutral types (core), and the modules below.
constexpr bool reads_every_capability()
Reads every capability constant of a capability set, so a missing one fails to compile here.
SellableSource
Where the library gets a broker's sellable quantity.
Definition types.hpp:1092
@ INQUIRY
From a per-instrument inquiry, made only where the snapshot has no figure.
Definition types.hpp:1096
constexpr bool answers_every_capability()
Reads every capability of a client's traits (see reads_every_capability).
BarInterval
The period one bar covers.
What one broker client implements, as compile-time constants.
static constexpr bool has_history_limit
Whether an order-history inquiry accepts a row limit (OrderHistoryQuery::limit_).
static constexpr bool has_commission_schedule
Whether the broker publishes the account's commission rates.
static constexpr SellableBasis sellable_inquiry_basis
What a sellable figure from the per-instrument inquiry covers.
static constexpr bool has_batch_prices
Whether the broker quotes several instruments in one request.
static constexpr bool has_amendable_quantity
Whether the broker reports the quantity still amendable on an open order.
static constexpr bool has_history_cursor
Whether an order-history answer can carry a cursor to the next page.
static constexpr bool history_requires_range
Whether an order-history inquiry needs a date range (OrderHistoryQuery::from_).
static constexpr bool has_client_order_id
Whether the broker accepts an idempotency key (OrderRequest::client_order_id_).
static constexpr bool has_price_limits
Whether the broker publishes the day's price limits.
static constexpr bool has_history_symbol_filter
Whether an order-history inquiry can filter by symbol.
static constexpr bool has_account_discovery
Whether the broker lists the selectable accounts.
static constexpr SellableSource sellable_source
Where the library gets the sellable quantity: HOLDINGS costs nothing, INQUIRY one request per instrum...
static constexpr bool has_reference_data
Whether the broker publishes instrument reference data.
static constexpr bool has_calendar
Whether the broker publishes the trading calendar.
static constexpr bool has_trade_prints
Whether the broker publishes recent trades.
static constexpr bool has_partial_cancel
Whether the broker can cancel part of an order.
static constexpr bool has_buying_power
Whether the broker reports buying power.
static constexpr bool has_calendar_range
Whether one calendar request covers a span of dates.
static constexpr bool has_order_by_id
Whether the broker can look up one order by its id.
static constexpr bool supports_interval(BarInterval interval)
Tests whether the broker publishes bars of an interval.
static constexpr bool data_only
Whether the client is a market-data source that takes no orders (built on DataOnlyTraits).
static constexpr bool has_buying_power_quantity
Whether the broker can also say how many shares are affordable.
static constexpr bool has_trigger_price
Whether the adapter sends trigger prices (stop-limit orders).
static constexpr bool working_orders_state_terminal
Whether the working-order listing can show a terminal status (filled, cancelled, ....
static constexpr bool has_batch_reference_data
Whether one reference-data request can cover several instruments.
static constexpr bool has_calendar_sessions
Whether the broker publishes intraday session hours (only Toss); the library does not expose them yet...
static constexpr bool has_depth
Whether the broker publishes the order book (depth).
BrokerTraits< Client > Traits
The traits specialization the constants are read from.
static constexpr bool has_working_orders
Whether the broker lists the orders still open to amendment. A listing shows only what the broker's A...
Describes one broker client to the library: its types, capabilities, call thunks and normalizers.
What a sellable quantity covers, and how RiskGuard must treat resting sells against it.
Definition types.hpp:918
@ UNESTABLISHED
Not established; RiskGuard refuses.
Definition types.hpp:922