3#include "./broker_caps.hpp"
4#include "./broker_traits.hpp"
5#include "./calendar.hpp"
6#include "./instrument.hpp"
8#include "../network/rate_limit.hpp"
10#include <boost/asio/associated_executor.hpp>
11#include <boost/asio/async_result.hpp>
12#include <boost/asio/bind_executor.hpp>
13#include <boost/asio/post.hpp>
14#include <boost/asio/system_executor.hpp>
27namespace net = boost::asio;
29namespace port_detail {
32template <
typename Client,
typename Items>
33Result<std::vector<AccountInfo<Client>>> to_account_info(Result<Items> raw) {
34 using Traits = BrokerTraits<Client>;
35 using Accounts = std::vector<AccountInfo<Client>>;
40 listed.reserve(raw.value().size());
41 for (
const auto& item : raw.value()) {
42 AccountInfo<Client> info;
43 info.display_number_ = Traits::display_of(item);
44 info.type_ = Traits::type_of(item);
45 info.selector_ = Traits::selector_of(item);
46 listed.push_back(std::move(info));
63template <
typename Client>
64std::optional<BrokerError> trigger_refusal(
const std::optional<Decimal64>& trigger) {
73 error.reached_broker_ =
false;
74 error.broker_code_ =
"unsupported_trigger_price";
76 "this broker does not declare that it transmits a trigger price, so an order carrying one "
77 "would be sent without it; place the order without a trigger or through a broker whose "
78 "BrokerCaps::has_trigger_price is true";
90template <
typename Client>
91std::optional<BrokerError> prepare_place(
const OrderRequest& order) {
92 if (
auto refused = trigger_refusal<Client>(order.trigger_price_)) {
95 return BrokerTraits<Client>::validate_place(order);
107template <
typename Client>
108Result<typename BrokerTraits<Client>::Amendment> prepare_replace(
109 const OrderRef<
typename BrokerTraits<Client>::BrokerTag>& ref,
const AmendInstruction& instruction
111 using Amendment =
typename BrokerTraits<Client>::Amendment;
115 return BrokerTraits<Client>::to_replacement(ref, instruction);
134template <
typename Client>
165 !Traits::blocking,
"BrokerSession requires an asynchronous client; use BlockingSession for a blocking facade"
177 throw std::invalid_argument(
"broker session requires a client");
239 return Traits::rate_limit_stats(*client_);
256 template <
typename CompletionToken>
258 return translate<QuoteSnapshot>(
259 std::forward<CompletionToken>(token),
260 [
client = client_, instrument = std::move(instrument)](
auto&& sink)
mutable {
261 Traits::quote(*
client, std::move(instrument), std::forward<
decltype(sink)>(sink));
277 template <
typename CompletionToken>
279 return translate<HoldingsSnapshot>(
280 std::forward<CompletionToken>(token),
281 [
client = client_,
account = account_](
auto&& sink)
mutable {
282 Traits::holdings(*
client,
account, std::forward<
decltype(sink)>(sink));
303 template <
typename CompletionToken>
306 return translate<BuyingPower>(
307 std::forward<CompletionToken>(token),
308 [
client = client_,
account = account_, currency](
auto&& sink)
mutable {
309 Traits::buying_power(*
client,
account, currency, std::forward<
decltype(sink)>(sink));
317 port_detail::dependent_false<Client>,
318 "this broker does not answer what the account may spend; gate the call with "
319 "BrokerCaps<Client>::has_buying_power"
336 template <
typename CompletionToken>
339 return translate<Decimal64>(
340 std::forward<CompletionToken>(token),
341 [
client = client_,
account = account_, instrument = std::move(instrument)](
auto&& sink)
mutable {
342 Traits::sellable_quantity(*
client,
account, std::move(instrument), std::forward<
decltype(sink)>(sink));
350 port_detail::dependent_false<Client>,
351 "this broker has no separate sellable-quantity inquiry; read "
352 "HoldingPosition::sellable_quantity_ from the holdings snapshot, and gate on "
353 "BrokerCaps<Client>::sellable_source"
369 template <
typename CompletionToken>
372 return translate<CommissionSchedule>(
373 std::forward<CompletionToken>(token),
374 [
client = client_,
account = account_](
auto&& sink)
mutable {
375 Traits::commissions(*
client,
account, std::forward<
decltype(sink)>(sink));
383 port_detail::dependent_false<Client>,
384 "this broker publishes no commission schedule; gate the call with "
385 "BrokerCaps<Client>::has_commission_schedule"
407 template <
typename CompletionToken>
409 if (
auto refused = port_detail::prepare_place<Client>(order)) {
410 return complete_error<Placed>(std::forward<CompletionToken>(token), std::move(*refused));
412 return translate<Placed>(
413 std::forward<CompletionToken>(token),
414 [
client = client_,
account = account_, order = std::move(order)](
auto&& sink)
mutable {
415 Traits::place_order(*
client,
account, std::move(order), std::forward<
decltype(sink)>(sink));
418 return Traits::normalize_place(std::move(raw));
439 template <
typename CompletionToken>
441 auto amendment = port_detail::prepare_replace<Client>(ref, instruction);
443 return complete_error<Placed>(std::forward<CompletionToken>(token), std::move(amendment.error()));
445 return translate<Placed>(
446 std::forward<CompletionToken>(token),
447 [
client = client_,
account = account_, value = std::move(amendment.value())](
auto&& sink)
mutable {
448 Traits::replace_order(*client, account, std::move(value), std::forward<decltype(sink)>(sink));
451 return Traits::normalize_place(std::move(raw));
476 template <
typename CompletionToken>
478 auto amendment = Traits::to_cancellation(ref, instruction);
480 return complete_error<Placed>(std::forward<CompletionToken>(token), std::move(amendment.error()));
482 return translate<Placed>(
483 std::forward<CompletionToken>(token),
484 [
client = client_,
account = account_, value = std::move(amendment.value())](
auto&& sink)
mutable {
485 Traits::cancel_order(*client, account, std::move(value), std::forward<decltype(sink)>(sink));
488 return Traits::normalize_place(std::move(raw));
504 template <
typename CompletionToken>
507 return translate<WorkingSet>(
508 std::forward<CompletionToken>(token),
509 [
client = client_,
account = account_](
auto&& sink)
mutable {
510 Traits::working_orders(*
client,
account, std::forward<
decltype(sink)>(sink));
513 return Traits::normalize_working_orders(std::move(raw));
518 port_detail::dependent_false<Client>,
519 "this broker does not publish its amendable orders; gate the call with "
520 "BrokerCaps<Client>::has_working_orders"
535 template <
typename CompletionToken>
537 auto converted = Traits::to_history_query(account_, query);
539 return complete_error<OrderPage>(std::forward<CompletionToken>(token), std::move(converted.error()));
541 return translate<OrderPage>(
542 std::forward<CompletionToken>(token),
543 [
client = client_,
account = account_, value = std::move(converted.value())](
auto&& sink)
mutable {
544 Traits::order_history(*client, account, std::move(value), std::forward<decltype(sink)>(sink));
564 template <
typename CompletionToken>
566 if (
auto invalid = Traits::validate_bars(query)) {
567 return complete_error<BarSeries>(std::forward<CompletionToken>(token), std::move(*invalid));
569 return translate<BarSeries>(
570 std::forward<CompletionToken>(token),
571 [
client = client_, query = std::move(query)](
auto&& sink)
mutable {
572 Traits::bars(*
client, std::move(query), std::forward<
decltype(sink)>(sink));
592 template <
typename CompletionToken>
595 return translate<Instrument>(
596 std::forward<CompletionToken>(token),
597 [
client = client_, instrument = std::move(instrument)](
auto&& sink)
mutable {
598 Traits::instrument(*
client, std::move(instrument), std::forward<
decltype(sink)>(sink));
606 port_detail::dependent_false<Client>,
607 "this broker does not publish instrument reference data; gate the call with "
608 "BrokerCaps<Client>::has_reference_data"
626 template <
typename CompletionToken>
629 if (
auto invalid = Traits::validate_calendar(country, from)) {
630 return complete_error<TradingCalendar>(std::forward<CompletionToken>(token), std::move(*invalid));
632 return translate<TradingCalendar>(
633 std::forward<CompletionToken>(token),
634 [
client = client_, country, from](
auto&& sink)
mutable {
635 Traits::calendar(*
client, country, from, std::forward<
decltype(sink)>(sink));
643 port_detail::dependent_false<Client>,
644 "this broker does not publish a trading calendar; gate the call with "
645 "BrokerCaps<Client>::has_calendar"
661 template <
typename CompletionToken>
664 return translate<PriceLimits>(
665 std::forward<CompletionToken>(token),
666 [
client = client_, instrument = std::move(instrument)](
auto&& sink)
mutable {
667 Traits::price_limits(*
client, std::move(instrument), std::forward<
decltype(sink)>(sink));
675 port_detail::dependent_false<Client>,
676 "this broker does not publish price limits; gate the call with "
677 "BrokerCaps<Client>::has_price_limits"
694 template <
typename CompletionToken>
697 return translate<std::vector<TradePrint>>(
698 std::forward<CompletionToken>(token),
699 [
client = client_, instrument = std::move(instrument), count](
auto&& sink)
mutable {
700 Traits::trades(*
client, std::move(instrument), count, std::forward<
decltype(sink)>(sink));
708 port_detail::dependent_false<Client>,
709 "this broker does not publish recent executions; gate the call with "
710 "BrokerCaps<Client>::has_trade_prints"
726 template <
typename CompletionToken>
727 auto async_prices(std::vector<InstrumentId> instruments, CompletionToken&& token) {
729 return translate<std::vector<QuoteSnapshot>>(
730 std::forward<CompletionToken>(token),
731 [
client = client_, instruments = std::move(instruments)](
auto&& sink)
mutable {
732 Traits::prices(*
client, std::move(instruments), std::forward<
decltype(sink)>(sink));
740 port_detail::dependent_false<Client>,
741 "this broker quotes one instrument per request; gate the call with "
742 "BrokerCaps<Client>::has_batch_prices and call async_quote per instrument"
758 template <
typename CompletionToken>
761 return translate<DepthSnapshot>(
762 std::forward<CompletionToken>(token),
763 [
client = client_, instrument = std::move(instrument)](
auto&& sink)
mutable {
764 Traits::depth(*
client, std::move(instrument), std::forward<
decltype(sink)>(sink));
772 port_detail::dependent_false<Client>,
773 "this broker does not publish an order book; gate the call with "
774 "BrokerCaps<Client>::has_depth"
790 template <
typename CompletionToken>
793 return translate<OrderSnapshot>(
794 std::forward<CompletionToken>(token),
796 Traits::order_by_id(*client, account, std::move(id), std::forward<decltype(sink)>(sink));
804 port_detail::dependent_false<Client>,
805 "this broker does not retrieve one order by identifier; gate the call with "
806 "BrokerCaps<Client>::has_order_by_id and read the order from "
807 "async_working_orders or async_order_history instead"
814 template <
typename Out,
typename Token,
typename Call,
typename Normalize>
815 static auto translate(Token&& token, Call call, Normalize normalize) {
816 return net::async_initiate<Token, void(
Result<Out>)>(
817 [call = std::move(call), normalize = std::move(normalize)](
auto&& handler)
mutable {
818 auto executor = net::get_associated_executor(handler);
822 [handler = std::forward<
decltype(handler)>(handler), normalize = std::move(normalize)](
auto raw)
mutable {
823 std::move(handler)(normalize(std::move(raw)));
834 template <
typename Out,
typename Token>
835 static auto complete_error(Token&& token, BrokerError error) {
836 return net::async_initiate<Token, void(Result<Out>)>(
837 [error = std::move(error)](
auto&& handler)
mutable {
838 auto executor = net::get_associated_executor(handler, net::system_executor());
839 net::post(executor, [handler = std::forward<
decltype(handler)>(handler), error = std::move(error)]()
mutable {
847 std::shared_ptr<Client> client_;
859template <
typename Client>
891 "BlockingSession requires a blocking client facade; use BrokerSession for an "
892 "asynchronous client"
904 throw std::invalid_argument(
"broker session requires a client");
950 return Traits::rate_limit_stats(*client_);
959 return Traits::quote(*client_, std::move(
instrument));
967 return Traits::holdings(*client_, account_);
977 return Traits::buying_power(*client_, account_, currency);
980 port_detail::dependent_false<Client>,
981 "this broker does not answer what the account may spend; gate the call with "
982 "BrokerCaps<Client>::has_buying_power"
994 return Traits::sellable_quantity(*client_, account_, std::move(
instrument));
997 port_detail::dependent_false<Client>,
998 "this broker has no separate sellable-quantity inquiry; read "
999 "HoldingPosition::sellable_quantity_ from the holdings snapshot, and gate on "
1000 "BrokerCaps<Client>::sellable_source"
1011 return Traits::commissions(*client_, account_);
1014 port_detail::dependent_false<Client>,
1015 "this broker publishes no commission schedule; gate the call with "
1016 "BrokerCaps<Client>::has_commission_schedule"
1028 return Traits::instrument(*client_, std::move(subject));
1031 port_detail::dependent_false<Client>,
1032 "this broker does not publish instrument reference data; gate the call with "
1033 "BrokerCaps<Client>::has_reference_data"
1046 if (
auto invalid = Traits::validate_calendar(country, from)) {
1049 return Traits::calendar(*client_, country, from);
1052 port_detail::dependent_false<Client>,
1053 "this broker does not publish a trading calendar; gate the call with "
1054 "BrokerCaps<Client>::has_calendar"
1066 return Traits::price_limits(*client_, std::move(
instrument));
1069 port_detail::dependent_false<Client>,
1070 "this broker does not publish price limits; gate the call with "
1071 "BrokerCaps<Client>::has_price_limits"
1084 return Traits::trades(*client_, std::move(
instrument), count);
1087 port_detail::dependent_false<Client>,
1088 "this broker does not publish recent executions; gate the call with "
1089 "BrokerCaps<Client>::has_trade_prints"
1101 return Traits::prices(*client_, std::move(instruments));
1104 port_detail::dependent_false<Client>,
1105 "this broker quotes one instrument per request; gate the call with "
1106 "BrokerCaps<Client>::has_batch_prices and call quote per instrument"
1118 return Traits::depth(*client_, std::move(
instrument));
1121 port_detail::dependent_false<Client>,
1122 "this broker does not publish an order book; gate the call with "
1123 "BrokerCaps<Client>::has_depth"
1134 if (
auto invalid = Traits::validate_bars(query)) {
1137 return Traits::bars(*client_, std::move(query));
1152 if (
auto refused = port_detail::prepare_place<Client>(
order)) {
1155 return Traits::normalize_place(Traits::place_order(*client_, account_, std::move(
order)));
1171 auto amendment = port_detail::prepare_replace<Client>(ref, instruction);
1175 return Traits::normalize_place(Traits::replace_order(*client_, account_, std::move(amendment.value())));
1192 auto amendment = Traits::to_cancellation(ref, instruction);
1196 return Traits::normalize_place(Traits::cancel_order(*client_, account_, std::move(amendment.value())));
1205 return Traits::normalize_working_orders(Traits::working_orders(*client_, account_));
1208 port_detail::dependent_false<Client>,
1209 "this broker does not publish its amendable orders; gate the call with "
1210 "BrokerCaps<Client>::has_working_orders"
1221 auto converted = Traits::to_history_query(account_, query);
1225 return Traits::order_history(*client_, account_, std::move(converted.value()));
1235 return Traits::order_by_id(*client_, account_, ref.
primary_);
1238 port_detail::dependent_false<Client>,
1239 "this broker does not retrieve one order by identifier; gate the call with "
1240 "BrokerCaps<Client>::has_order_by_id and read the order from working_orders or "
1241 "order_history instead"
1252 return port_detail::to_account_info<Client>(Traits::accounts(*client_));
1255 port_detail::dependent_false<Client>,
1256 "this broker does not publish selectable accounts; its account selector comes from "
1257 "configuration, so gate the call with BrokerCaps<Client>::has_account_discovery"
1263 std::shared_ptr<Client> client_;
1277template <
typename Client,
typename CompletionToken>
1281 using Accounts = std::vector<AccountInfo<Client>>;
1283 [&client](
auto&& handler)
mutable {
1284 auto executor = net::get_associated_executor(handler);
1286 client, net::bind_executor(executor, [handler = std::forward<
decltype(handler)>(handler)](
auto raw)
mutable {
1287 std::move(handler)(port_detail::to_account_info<Client>(std::move(raw)));
1295 port_detail::dependent_false<Client>,
1296 "this broker does not publish selectable accounts; its account selector comes from "
1297 "configuration, so gate the call with BrokerCaps<Client>::has_account_discovery"
1310template <
typename Client>
1316 port_detail::dependent_false<Client>,
1317 "this broker does not publish selectable accounts; its account selector comes from "
1318 "configuration, so gate the call with BrokerCaps<Client>::has_account_discovery"
1323namespace port_detail {
1326inline std::string account_characters(std::string_view number) {
1328 for (
const char c : number) {
1329 if (c !=
'-' && c !=
' ' && c !=
'.' && c !=
'/') {
1337inline BrokerError account_refusal(
const char* code, std::string message,
bool reached_broker) {
1340 error.reached_broker_ = reached_broker;
1341 error.broker_code_ = code;
1342 error.message_ = std::move(message);
1347template <
typename Client>
1348Result<AccountInfo<Client>> pick_account(
1349 std::vector<AccountInfo<Client>> candidates, std::string_view number,
bool reached_broker
1351 using Picked = Result<AccountInfo<Client>>;
1352 if (!number.empty()) {
1353 const auto wanted = account_characters(number);
1354 const auto unwanted = [&wanted](
const AccountInfo<Client>& candidate) {
1355 return wanted.empty() || account_characters(candidate.display_number_) != wanted;
1357 candidates.erase(std::remove_if(candidates.begin(), candidates.end(), unwanted), candidates.end());
1358 if (candidates.empty()) {
1359 return Picked(account_refusal(
"account_not_found",
"no account has that number", reached_broker));
1362 if (candidates.size() > 1) {
1363 auto message = std::to_string(candidates.size()) +
" accounts; choose one by its number:";
1364 for (
const auto& candidate : candidates) {
1365 const auto shown = account_characters(candidate.display_number_);
1366 message +=
" ..." + shown.substr(shown.size() > 4 ? shown.size() - 4 : 0);
1367 message += candidate.type_.empty() ? std::string(
";") :
" (" + candidate.type_ +
");";
1370 return Picked(account_refusal(
"several_accounts", std::move(message), reached_broker));
1372 if (account_characters(candidates.front().display_number_).empty()) {
1373 return Picked(account_refusal(
"account_without_number",
"the account has no number", reached_broker));
1375 return Picked(std::move(candidates.front()));
1398template <
typename Client>
1402 using Resolved = Result<AccountInfo<Client>>;
1403 if constexpr (!BrokerTraits<Client>::blocking) {
1404 static_assert(port_detail::dependent_false<Client>,
"resolve_account requires a blocking client");
1406 static_assert(port_detail::dependent_false<Client>,
"resolve_account: a data-only client acts for no account");
1410 port_detail::account_refusal(
1411 "account_configured",
"this broker lists its accounts, so a configured one is refused: choose by number",
1418 return Resolved(std::move(listed.error()));
1420 if (listed.value().empty()) {
1421 return Resolved(port_detail::account_refusal(
"no_accounts",
"the broker lists no account",
true));
1423 return port_detail::pick_account<Client>(std::move(listed.value()), number,
true);
1425 static_cast<void>(client);
1427 return Resolved(port_detail::account_refusal(
"account_missing",
"no account is configured",
false));
1430 std::vector<AccountInfo<Client>> candidates;
1431 candidates.push_back(
1434 return port_detail::pick_account<Client>(std::move(candidates), number,
false);
WorkingOrder< BrokerTag > Working
One working order of this broker.
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.
typename Traits::Config Config
The broker's configuration type.
typename Traits::Account Account
The broker's account selector type.
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.
BrokerCaps< Client > Caps
The client's capabilities.
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.
const Client & client() const noexcept
Returns the broker client.
Result< Decimal64 > sellable_quantity(InstrumentId instrument)
Returns how much of an instrument the account may sell; only where Caps::sellable_source is INQUIRY.
const network::RateLimitStats * rate_limit_stats() const
Returns the client's request-pacing counters.
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.
const Account & account() const noexcept
Returns the bound account.
BrokerTraits< Client > Traits
The client's traits.
static constexpr std::string_view broker_name() noexcept
Returns the broker's name.
WorkingOrders< BrokerTag > WorkingSet
A working-order listing of this broker.
BlockingSession(std::shared_ptr< Client > client, Account account)
Binds a blocking client and an account.
PlacedOrder< BrokerTag > Placed
What an order-writing call returns: acknowledgement and reference.
typename Traits::BrokerTag BrokerTag
The broker's tag type.
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.
auto async_quote(InstrumentId instrument, CompletionToken &&token)
Requests the current quote for an instrument.
const network::RateLimitStats * rate_limit_stats() const
Returns the client's request-pacing counters.
auto async_order_history(OrderHistoryQuery query, CompletionToken &&token)
Requests order history: placed orders and their executions.
PlacedOrder< BrokerTag > Placed
What an order-writing call returns: acknowledgement and reference.
BrokerSession(std::shared_ptr< Client > client, Account account)
Binds a client and an account.
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.
typename Traits::BrokerTag BrokerTag
The broker's tag type.
auto async_buying_power(Currency currency, CompletionToken &&token)
Requests what the account may spend in a currency.
BrokerCaps< Client > Caps
The client's capabilities.
auto async_price_limits(InstrumentId instrument, CompletionToken &&token)
Requests an instrument's price limits for today.
static constexpr std::string_view broker_name() noexcept
Returns the broker's name.
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.
void close()
Cancels the client's transport work and queued operations.
typename Traits::Config Config
The broker's configuration type.
auto async_commissions(CompletionToken &&token)
Requests the account's commission rates.
typename Traits::Account Account
The broker's account selector type.
auto async_instrument(InstrumentId instrument, CompletionToken &&token)
Requests an instrument's reference data.
const std::shared_ptr< Client > & shared_client() const noexcept
Returns the shared client pointer, for binding a second session.
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.
WorkingOrder< BrokerTag > Working
One working order of this broker.
const Account & account() const noexcept
Returns the bound account.
const Client & client() const noexcept
Returns the broker client.
auto async_order(Ref ref, CompletionToken &&token)
Requests one order by its reference.
WorkingOrders< BrokerTag > WorkingSet
A working-order listing of this broker.
BrokerTraits< Client > Traits
The client's traits.
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).
Either a value or a BrokerError.
Result(T value)
Constructs a successful result.
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.
@ INVALID_ARGUMENT
The request was invalid, refused by the client before sending or by the broker.
Result< AccountInfo< Client > > resolve_account(Client &client, std::optional< typename BrokerTraits< Client >::Account > configured, std::string_view number={})
Names the one account a session should bind, or refuses; never guesses.
Country
A country (market) the library supports.
std::optional< Decimal64 > amended_trigger_price(const AmendInstruction &instruction)
Returns the trigger price an amendment leaves the order with.
One account from a broker's account list.
A modification or cancellation of a working order.
What one broker client implements, as compile-time constants.
static constexpr bool has_commission_schedule
Whether the broker publishes the account's commission rates.
static constexpr bool has_batch_prices
Whether the broker quotes several instruments in one request.
static constexpr bool has_price_limits
Whether the broker publishes the day's price limits.
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_buying_power
Whether the broker reports buying power.
static constexpr bool has_order_by_id
Whether the broker can look up one order by its id.
static constexpr bool data_only
Whether the client is a market-data source that takes no orders (built on DataOnlyTraits).
static constexpr bool has_trigger_price
Whether the adapter sends trigger prices (stop-limit orders).
static constexpr bool has_depth
Whether the broker publishes the order book (depth).
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.
Identifies an instrument: its country, venue and symbol.
The filter for an order-history inquiry.
A broker's reference to one order, used to amend or cancel it.
std::string primary_
The order number or id.
An order to place, in broker-neutral form.
An accepted order: the acknowledgement and the reference to address it with.
An order still open to modification or cancellation.
The orders open to modification or cancellation at one point in time.
A rate limiter's counters per traffic class, its current budget, and the broker's refusals (from Rate...