algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
broker_verbs.hpp
1#pragma once
2
3#include "./broker_caps.hpp"
4#include "./broker_session.hpp"
5#include "./broker_traits.hpp"
6
7#include <boost/asio/use_future.hpp>
8
9#include <optional>
10#include <vector>
11
12namespace algotradelib {
13
31namespace conformance {
32
39 template <typename T>
40 void operator()(T) const {}
41};
42
46 MoveOnlyCallback() = default;
54 MoveOnlyCallback(const MoveOnlyCallback&) = delete;
56
61 template <typename T>
62 void operator()(T) {}
63};
64
70 return InstrumentId{Country::KR, Venue::COMBINED, "000000"};
71}
72
80template <typename Client, typename Token>
82 using Caps = BrokerCaps<Client>;
83 session.async_quote(probe_instrument(), Token{});
84 session.async_holdings(Token{});
85 session.async_bars(BarQuery{}, Token{});
86 session.async_place(OrderRequest{}, Token{});
87 session.async_replace(ref, AmendInstruction{}, Token{});
88 session.async_cancel(ref, AmendInstruction{}, Token{});
89 session.async_order_history(OrderHistoryQuery{}, Token{});
90 if constexpr (Caps::has_buying_power) {
91 session.async_buying_power(Currency{}, Token{});
92 }
93 if constexpr (Caps::sellable_source == SellableSource::INQUIRY) {
94 session.async_sellable_quantity(probe_instrument(), Token{});
95 }
96 if constexpr (Caps::has_commission_schedule) {
97 session.async_commissions(Token{});
98 }
99 if constexpr (Caps::has_working_orders) {
100 session.async_working_orders(Token{});
101 }
102 if constexpr (Caps::has_reference_data) {
103 session.async_instrument(probe_instrument(), Token{});
104 }
105 if constexpr (Caps::has_calendar) {
106 session.async_calendar(Country::KR, std::nullopt, Token{});
107 }
108 if constexpr (Caps::has_price_limits) {
109 session.async_price_limits(probe_instrument(), Token{});
110 }
111 if constexpr (Caps::has_trade_prints) {
112 session.async_trades(probe_instrument(), 1, Token{});
113 }
114 if constexpr (Caps::has_batch_prices) {
115 session.async_prices(std::vector<InstrumentId>{probe_instrument()}, Token{});
116 }
117 if constexpr (Caps::has_depth) {
118 session.async_depth(probe_instrument(), Token{});
119 }
120 if constexpr (Caps::has_order_by_id) {
121 session.async_order(ref, Token{});
122 }
123 if constexpr (Caps::has_account_discovery) {
124 async_accounts(session.client(), Token{});
125 }
126}
127
134template <typename Client>
136 using Caps = BrokerCaps<Client>;
137 static_cast<void>(session.quote(probe_instrument()));
138 static_cast<void>(session.holdings());
139 static_cast<void>(session.bars(BarQuery{}));
140 static_cast<void>(session.place(OrderRequest{}));
141 static_cast<void>(session.replace(ref, AmendInstruction{}));
142 static_cast<void>(session.cancel(ref, AmendInstruction{}));
143 static_cast<void>(session.order_history(OrderHistoryQuery{}));
144 if constexpr (Caps::has_buying_power) {
145 static_cast<void>(session.buying_power(Currency{}));
146 }
147 if constexpr (Caps::sellable_source == SellableSource::INQUIRY) {
148 static_cast<void>(session.sellable_quantity(probe_instrument()));
149 }
150 if constexpr (Caps::has_commission_schedule) {
151 static_cast<void>(session.commissions());
152 }
153 if constexpr (Caps::has_working_orders) {
154 static_cast<void>(session.working_orders());
155 }
156 if constexpr (Caps::has_reference_data) {
157 static_cast<void>(session.instrument(probe_instrument()));
158 }
159 if constexpr (Caps::has_calendar) {
160 static_cast<void>(session.calendar(Country::KR));
161 }
162 if constexpr (Caps::has_price_limits) {
163 static_cast<void>(session.price_limits(probe_instrument()));
164 }
165 if constexpr (Caps::has_trade_prints) {
166 static_cast<void>(session.trades(probe_instrument(), 1));
167 }
168 if constexpr (Caps::has_batch_prices) {
169 static_cast<void>(session.prices(std::vector<InstrumentId>{probe_instrument()}));
170 }
171 if constexpr (Caps::has_depth) {
172 static_cast<void>(session.depth(probe_instrument()));
173 }
174 if constexpr (Caps::has_order_by_id) {
175 static_cast<void>(session.order(ref));
176 }
177 if constexpr (Caps::has_account_discovery) {
178 static_cast<void>(session.accounts());
179 static_cast<void>(list_accounts(session.client()));
180 }
181}
182
188template <typename Client>
189constexpr bool claimed_verbs_compile() {
190 if constexpr (BrokerTraits<Client>::blocking) {
191 static_cast<void>(&call_claimed_blocking_verbs<Client>);
192 } else {
196 }
197 return true;
198}
199
200} // namespace conformance
201
211#define ATL_ASSERT_BROKER(Client) \
212 static_assert( \
213 ::algotradelib::conformance::claimed_verbs_compile<Client>() && \
214 ::algotradelib::answers_every_capability<Client>(), \
215 "every port verb this client's capabilities claim must compile, and every capability " \
216 "must be answered" \
217 )
218
219} // namespace algotradelib
A blocking broker client bound to one account, with the same broker operations as BrokerSession,...
Result< OrderPage > order_history(const OrderHistoryQuery &query)
Returns order history: placed orders and their executions.
Result< Placed > place(OrderRequest order)
Places a new order.
Result< WorkingSet > working_orders()
Returns the orders still open to modification or cancellation; requires Caps::has_working_orders.
Result< OrderSnapshot > order(const Ref &ref)
Returns one order by its reference; requires Caps::has_order_by_id.
Result< BarSeries > bars(BarQuery query)
Returns bars for an instrument, oldest first, paging until count_ bars are read.
Result< QuoteSnapshot > quote(InstrumentId instrument)
Returns the current quote for an instrument.
Result< Placed > replace(const Ref &ref, const AmendInstruction &instruction)
Modifies a working order.
Result< PriceLimits > price_limits(InstrumentId instrument)
Returns an instrument's price limits for today; requires Caps::has_price_limits.
Result< std::vector< TradePrint > > trades(InstrumentId instrument, int count)
Returns recent trades for an instrument, newest first; requires Caps::has_trade_prints.
Result< BuyingPower > buying_power(Currency currency)
Returns what the account may spend in a currency; requires Caps::has_buying_power.
Result< Placed > cancel(const Ref &ref, const AmendInstruction &instruction)
Cancels a working order, in full or in part.
Result< HoldingsSnapshot > holdings()
Returns the account's holdings.
Result< Decimal64 > sellable_quantity(InstrumentId instrument)
Returns how much of an instrument the account may sell; only where Caps::sellable_source is INQUIRY.
Client & client() noexcept
Returns the broker client, for broker-specific operations the session does not offer.
OrderRef< BrokerTag > Ref
The order reference type this session issues and accepts.
Result< DepthSnapshot > depth(InstrumentId instrument)
Returns an instrument's order book, best levels first; requires Caps::has_depth.
Result< TradingCalendar > calendar(Country country, std::optional< Date > from=std::nullopt)
Returns the trading calendar; requires Caps::has_calendar.
Result< CommissionSchedule > commissions()
Returns the account's commission rates; requires Caps::has_commission_schedule.
Result< std::vector< QuoteSnapshot > > prices(std::vector< InstrumentId > instruments)
Returns quotes for several instruments in one request; requires Caps::has_batch_prices.
Result< Instrument > instrument(InstrumentId subject)
Returns an instrument's reference data; requires Caps::has_reference_data.
Result< std::vector< AccountInfo< Client > > > accounts()
Lists the broker's accounts; requires Caps::has_account_discovery.
An asynchronous broker client bound to one account, with broker-neutral operations.
auto async_quote(InstrumentId instrument, CompletionToken &&token)
Requests the current quote for an instrument.
auto async_order_history(OrderHistoryQuery query, CompletionToken &&token)
Requests order history: placed orders and their executions.
OrderRef< BrokerTag > Ref
The order reference type this session issues and accepts.
auto async_place(OrderRequest order, CompletionToken &&token)
Places a new order.
auto async_bars(BarQuery query, CompletionToken &&token)
Requests bars for an instrument, paging until count_ bars are read.
auto async_sellable_quantity(InstrumentId instrument, CompletionToken &&token)
Requests how much of an instrument the account may sell.
auto async_buying_power(Currency currency, CompletionToken &&token)
Requests what the account may spend in a currency.
auto async_price_limits(InstrumentId instrument, CompletionToken &&token)
Requests an instrument's price limits for today.
Client & client() noexcept
Returns the broker client, for broker-specific operations the session does not offer.
auto async_replace(Ref ref, AmendInstruction instruction, CompletionToken &&token)
Modifies a working order.
auto async_commissions(CompletionToken &&token)
Requests the account's commission rates.
auto async_instrument(InstrumentId instrument, CompletionToken &&token)
Requests an instrument's reference data.
auto async_holdings(CompletionToken &&token)
Requests the account's holdings.
auto async_working_orders(CompletionToken &&token)
Requests the orders still open to modification or cancellation.
auto async_trades(InstrumentId instrument, int count, CompletionToken &&token)
Requests recent trades for an instrument, newest first.
auto async_order(Ref ref, CompletionToken &&token)
Requests one order by its reference.
auto async_prices(std::vector< InstrumentId > instruments, CompletionToken &&token)
Requests quotes for several instruments in one request.
auto async_cancel(Ref ref, AmendInstruction instruction, CompletionToken &&token)
Cancels a working order, in full or in part.
auto async_calendar(Country country, std::optional< Date > from, CompletionToken &&token)
Requests the trading calendar.
auto async_depth(InstrumentId instrument, CompletionToken &&token)
Requests an instrument's order book, best levels first.
A three-letter currency code, such as KRW or USD (ISO 4217 style).
Definition types.hpp:374
The compile-time check behind ATL_ASSERT_BROKER(Client).
constexpr bool claimed_verbs_compile()
Compiles the operation checks for a client.
void call_claimed_blocking_verbs(BlockingSession< Client > &session, const typename BlockingSession< Client >::Ref &ref)
Calls every operation a blocking session's capabilities claim; compiled, never run.
void call_claimed_async_verbs(BrokerSession< Client > &session, const typename BrokerSession< Client >::Ref &ref)
Calls every operation an asynchronous session's capabilities claim; compiled, never run.
InstrumentId probe_instrument()
Returns the placeholder instrument the checks call operations with.
The library: broker-neutral types (core), and the modules below.
auto async_accounts(Client &client, CompletionToken &&token)
Lists a broker's accounts, before a session exists; requires BrokerCaps<Client>::has_account_discover...
Result< std::vector< AccountInfo< Client > > > list_accounts(Client &client)
Lists a broker's accounts with a blocking client, before a session exists; requires BrokerCaps<Client...
@ INQUIRY
From a per-instrument inquiry, made only where the snapshot has no figure.
Definition types.hpp:1366
A modification or cancellation of a working order.
Definition types.hpp:2532
What bars to fetch.
What one broker client implements, as compile-time constants.
Describes one broker client to the library: its types, capabilities, call thunks and normalizers.
Identifies an instrument: its country, venue and symbol.
Definition types.hpp:85
The filter for an order-history inquiry.
Definition types.hpp:2617
An order to place, in broker-neutral form.
Definition types.hpp:2216
void operator()(T)
Accepts and discards any completion argument.
MoveOnlyCallback(MoveOnlyCallback &&)=default
Move constructor (the callback has no state).
MoveOnlyCallback()=default
Constructs the callback.
MoveOnlyCallback & operator=(MoveOnlyCallback &&)=default
Move assignment.
A completion handler with no associated executor (a plain callback).
void operator()(T) const
Accepts and discards any completion argument.