3#include "./broker_traits.hpp"
6#include "../network/rate_limit.hpp"
8#include <boost/asio/associated_executor.hpp>
9#include <boost/asio/bind_executor.hpp>
10#include <boost/asio/post.hpp>
11#include <boost/asio/system_executor.hpp>
19namespace net = boost::asio;
52 error.
message_ =
"a market-data source holds no account and takes no order";
66template <
typename Executor,
typename =
void>
67struct postable : std::false_type {};
69template <
typename Executor>
71 Executor, std::void_t<decltype(net::post(std::declval<const Executor&>(), std::declval<void (*)()>()))>
89template <
typename Out,
typename Handler>
91 auto executor = net::get_associated_executor(handler, net::system_executor());
92 auto complete = [handler = std::forward<Handler>(handler)]()
mutable {
95 if constexpr (detail::postable<
decltype(executor)>::value) {
96 net::post(executor, std::move(complete));
98 net::post(net::system_executor(), net::bind_executor(executor, std::move(complete)));
147template <
typename Tag>
167 static constexpr bool has_account_discovery =
false;
168 static constexpr bool has_client_order_id =
false;
169 static constexpr bool has_trigger_price =
false;
170 static constexpr bool has_working_orders =
false;
171 static constexpr bool has_amendable_quantity =
false;
172 static constexpr bool has_order_by_id =
false;
173 static constexpr bool has_partial_cancel =
false;
174 static constexpr bool history_requires_range =
false;
175 static constexpr bool has_history_cursor =
false;
176 static constexpr bool has_history_limit =
false;
177 static constexpr bool has_history_symbol_filter =
false;
178 static constexpr bool has_depth =
false;
179 static constexpr bool has_price_limits =
false;
180 static constexpr bool has_trade_prints =
false;
181 static constexpr bool has_batch_prices =
false;
182 static constexpr bool has_buying_power =
false;
183 static constexpr bool has_buying_power_quantity =
false;
185 static constexpr bool has_commission_schedule =
false;
186 static constexpr bool has_reference_data =
false;
187 static constexpr bool has_batch_reference_data =
false;
188 static constexpr bool has_calendar =
false;
189 static constexpr bool has_calendar_range =
false;
190 static constexpr bool has_calendar_sessions =
false;
198 template <
typename Client>
247 template <
typename Client>
258 template <
typename Client,
typename Handler>
268 template <
typename Client>
279 template <
typename Client,
typename Handler>
289 template <
typename Client>
300 template <
typename Client,
typename Handler>
310 template <
typename Client>
321 template <
typename Client,
typename Handler>
331 template <
typename Client>
342 template <
typename Client,
typename Handler>
Either a value or a BrokerError.
Result(T value)
Constructs a successful result.
BrokerError & error()
Returns the error.
Placeholder types and the refusal used by DataOnlyTraits.
void post_refusal(Handler &&handler)
Completes an asynchronous call with refusal(), posted through the handler's associated executor.
BrokerError refusal()
Returns the error every account-side member of DataOnlyTraits answers with.
The library: broker-neutral types (core), and the modules below.
SellableSource
Where the library gets a broker's sellable quantity.
@ NONE
No per-instrument inquiry: any figure comes on the holdings rows (Kiwoom), or there is none.
@ INVALID_ARGUMENT
The request was invalid, refused by the client before sending or by the broker.
A modification or cancellation of a working order.
The error a broker or transport operation returns.
std::string message_
A human-readable description, for logs; do not parse it.
ErrorCategory category_
The kind of failure; the field to branch on.
std::string broker_code_
The broker's own error code, verbatim (for example KIS's EGW00201).
bool reached_broker_
Whether a request was sent before this error.
A base for the BrokerTraits of a market-data client that cannot trade.
static std::optional< BrokerError > validate_place(const OrderRequest &)
Refuses every order before it is built.
static void place_order(Client &, Account &, OrderRequest, Handler &&handler)
Refuses a placement, asynchronously.
static void holdings(Client &, Account &, Handler &&handler)
Refuses holdings, asynchronously.
static constexpr bool data_only
true: the client is a market-data source; see BrokerCaps::data_only.
data_only::NoAck PlaceAck
Never produced: placement refuses.
static Result< PlaceAck > cancel_order(Client &, Account &, Amendment)
Refuses a cancellation.
data_only::NoWorkingOrders WorkingOrdersResult
Never produced: working orders are not claimed.
static Result< PlacedOrder< Tag > > normalize_place(Result< PlaceAck > raw)
Passes the refusal through (an acknowledgement is refused too).
static Result< PlaceAck > replace_order(Client &, Account &, Amendment)
Refuses a replacement.
static void replace_order(Client &, Account &, Amendment, Handler &&handler)
Refuses a replacement, asynchronously.
static Result< Amendment > to_replacement(const OrderRef< Tag > &, const AmendInstruction &)
Refuses an amendment.
static void order_history(Client &, Account &, HistoryQuery, Handler &&handler)
Refuses order history, asynchronously.
Tag BrokerTag
The vendor's tag type.
static Result< Amendment > to_cancellation(const OrderRef< Tag > &, const AmendInstruction &)
Refuses a cancellation.
data_only::NoHistoryQuery HistoryQuery
Never produced: history refuses.
static Result< OrderPage > order_history(Client &, Account &, HistoryQuery)
Refuses order history.
static Result< PlaceAck > place_order(Client &, Account &, OrderRequest)
Refuses a placement.
static void cancel_order(Client &, Account &, Amendment, Handler &&handler)
Refuses a cancellation, asynchronously.
data_only::NoAccount Account
No account; the session binds an empty one.
static Result< HoldingsSnapshot > holdings(Client &, Account &)
Refuses holdings.
static Result< HistoryQuery > to_history_query(const Account &, const OrderHistoryQuery &)
Refuses a history query.
data_only::NoAmendment Amendment
Never produced: amendment refuses.
static const network::RateLimitStats * rate_limit_stats(const Client &)
Reports that the client runs no rate limiter; declare your own if it does.
The filter for an order-history inquiry.
A broker's reference to one order, used to amend or cancel it.
An order to place, in broker-neutral form.
The (empty) account a data-only session binds.
Placeholder order acknowledgement; never produced.
Placeholder amendment; never produced.
Placeholder history query; never produced.
Placeholder working-order listing; never produced.
A rate limiter's counters per traffic class, its current budget, and the broker's refusals (from Rate...