8#define ATL_BROKER_ADAPTER_PRESENT 1
10#include "./client.hpp"
12#include "../../core/broker_session.hpp"
13#include "../../core/broker_traits.hpp"
127 return refusal(
"unsupported_interval",
"the mock broker holds minute to daily bars only");
147 return refusal(
"idempotency_key_unsupported",
"the mock broker takes no client order id");
174 refusal(
"replace_unsupported",
"the mock broker does not modify orders; cancel and place")
187 refusal(
"partial_cancel_unsupported",
"the mock broker cancels the whole remainder only")
201 refusal(
"history_filter_unsupported",
"the mock broker's history takes no symbol filter or row limit")
252 return client.
bars(query);
281 return client.
place(order);
289 return Result<PlaceAck>(refusal(
"replace_unsupported",
"the mock broker does not modify orders; cancel and place"));
299 return client.
cancel(amendment);
323 static BrokerError refusal(
const char* code,
const char* message) {
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 mock broker's client: blocking, answering from a Market, after any faults scripted for the call.
Result< HoldingsSnapshot > holdings()
Answers a holdings request.
Result< Instrument > instrument(const InstrumentId &instrument)
Answers a reference-data request.
Result< TradingCalendar > calendar(Country country)
Answers a calendar request.
Result< OrderPage > order_history(const OrderHistoryQuery &query)
Answers an order-history request.
Result< PlacedOrder< Broker > > cancel(const MockAmendment &amendment)
Cancels an order.
Result< WorkingOrders< Broker > > working_orders()
Answers a working-order request.
Result< PlacedOrder< Broker > > place(const OrderRequest &order)
Places an order.
Result< BuyingPower > buying_power(const Currency ¤cy)
Answers a buying-power request.
Result< BarSeries > bars(const BarQuery &query)
Answers a bar request.
Result< QuoteSnapshot > quote(const InstrumentId &instrument)
Answers a quote request.
The mock broker: an in-memory market over bars the caller gives, bound like any broker.
The library: broker-neutral types (core), and the modules below.
constexpr std::optional< std::chrono::seconds > bar_interval_length(BarInterval interval) noexcept
Returns an interval's fixed length, for an intraday interval.
SellableSource
Where the library gets a broker's sellable quantity.
@ HOLDINGS
On the holdings snapshot, at no extra request.
@ INVALID_ARGUMENT
The request was invalid, refused by the client before sending or by the broker.
Country
A country (market) the library supports.
BarInterval
The period one bar covers.
A modification or cancellation of a working order.
bool all_remaining_
Whether the whole remaining quantity is affected, rather than quantity_.
BarInterval interval_
The period of each bar; an interval the broker does not publish is refused.
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.
static Result< WorkingOrdersResult > working_orders(Client &client, const Account &)
Forwards a working-order request.
static Result< WorkingOrders< mock::Broker > > normalize_working_orders(Result< WorkingOrdersResult > raw)
Returns the listing as it is.
static Result< Amendment > to_cancellation(const OrderRef< mock::Broker > &ref, const AmendInstruction &instruction)
Converts a cancellation of the whole remainder; refuses a stated quantity.
static Result< Instrument > instrument(Client &client, InstrumentId instrument)
Forwards a reference-data request.
static constexpr bool data_only
It takes orders.
static constexpr bool has_working_orders
Lists open orders.
static constexpr bool has_partial_cancel
Cancels the whole remainder only.
static Result< PlaceAck > place_order(Client &client, const Account &, OrderRequest order)
Forwards a placement.
static constexpr bool has_account_discovery
No account listing: there is one account.
static constexpr bool has_price_limits
No price band.
static Result< HistoryQuery > to_history_query(const Account &, const OrderHistoryQuery &query)
Passes a history query through; refuses a symbol filter or a row limit.
static constexpr bool has_batch_prices
One quote per request.
static constexpr bool has_batch_reference_data
No reference data.
static constexpr bool has_commission_schedule
No commission schedule; costs come from the market's fill model.
static Result< TradingCalendar > calendar(Client &client, Country country, std::optional< Date >)
Forwards a calendar request; the answer covers every date the market has, whatever from.
static std::optional< BrokerError > validate_bars(const BarQuery &query)
Refuses a bar request for an interval no market can hold, before the client.
static constexpr bool has_calendar_range
One answer covers every date the market has.
static constexpr bool has_depth
No order book.
static constexpr bool has_trigger_price
No stop-limit orders.
static constexpr std::string_view name
The broker's name, "mock".
static constexpr bool has_buying_power_quantity
No affordable quantity.
mock::MockClient Client
The client.
static Result< BarSeries > bars(Client &client, BarQuery query)
Forwards a bar request.
static const network::RateLimitStats * rate_limit_stats(const Client &)
The mock broker is never paced.
OrderHistoryQuery HistoryQuery
The history query, the library's own.
static constexpr bool has_history_symbol_filter
No symbol filter.
static constexpr bool has_trade_prints
No trade prints.
static Result< PlaceAck > cancel_order(Client &client, const Account &, Amendment amendment)
Forwards a cancellation.
static Result< OrderPage > order_history(Client &client, const Account &, HistoryQuery query)
Forwards an order-history request.
static constexpr bool has_history_cursor
The whole history comes in one answer.
static constexpr bool history_requires_range
The history needs no date range.
WorkingOrders< mock::Broker > WorkingOrdersResult
The working-order listing, already normalized.
mock::MarketSettings Config
The configuration: the market's settings.
static Result< QuoteSnapshot > quote(Client &client, InstrumentId instrument)
Forwards a quote request.
static constexpr bool has_history_limit
No row limit.
PlacedOrder< mock::Broker > PlaceAck
The acknowledgement, already normalized.
mock::MockAccount Account
The account; the mock has one.
static constexpr bool supports_interval(BarInterval interval)
Tests whether the mock can hold bars of an interval: minute to daily.
mock::Broker BrokerTag
The broker tag.
static constexpr bool has_reference_data
Answers reference data: what the market was given, or its default.
static constexpr bool has_calendar
Publishes a calendar: what the market was given, or the dates of its bars.
static constexpr bool has_calendar_sessions
No session hours.
static Result< BuyingPower > buying_power(Client &client, const Account &, Currency currency)
Forwards a buying-power request.
static std::optional< BrokerError > validate_place(const OrderRequest &order)
Refuses an idempotency key, before the client.
static Result< PlaceAck > replace_order(Client &, const Account &, Amendment)
Never called: to_replacement refuses every modification.
static constexpr bool has_buying_power
Reports buying power.
static constexpr bool blocking
The client returns each result.
mock::MockAmendment Amendment
A cancellation.
static constexpr bool has_client_order_id
No idempotency key.
static Result< PlacedOrder< mock::Broker > > normalize_place(Result< PlaceAck > raw)
Returns the acknowledgement as it is: the market answers in the library's own shape.
static constexpr SellableSource sellable_source
The holdings rows carry the sellable quantity.
static constexpr bool has_order_by_id
No single-order inquiry.
static constexpr bool working_orders_state_terminal
The listing shows open orders only, as every shipped broker's does.
static Result< HoldingsSnapshot > holdings(Client &client, const Account &)
Forwards a holdings request.
static std::optional< BrokerError > validate_calendar(Country, std::optional< Date >)
Admits every calendar request; the market refuses another country itself.
static constexpr bool has_amendable_quantity
Reports each open order's quantity as amendable.
static Result< Amendment > to_replacement(const OrderRef< mock::Broker > &, const AmendInstruction &)
Refuses every modification: the mock broker cancels but does not modify orders.
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.
std::optional< std::string > symbol_
Only this symbol, where the broker supports the filter.
std::optional< int > limit_
The most rows to return, where the broker supports a limit.
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.
std::optional< std::string > client_order_id_
An idempotency key, if the broker offers one; never generated by the library.
An accepted order: the acknowledgement and the reference to address it with.
The orders open to modification or cancellation at one point in time.
The mock broker's tag: its order references are typed by it, so they work with no other broker.
static constexpr std::string_view name
The broker's name, "mock".
How a Market starts and what it charges.
The mock broker's one account; it has no selector.
A cancellation for the mock broker: the order id.
A rate limiter's counters per traffic class, its current budget, and the broker's refusals (from Rate...