![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
The mock broker's client: blocking, answering from a Market, after any faults scripted for the call. More...
#include <algotradelib/src/brokers/mock/client.hpp>
Public Member Functions | |
| MockClient (Market &market) | |
| Builds a client over a market. | |
| Market & | market () const noexcept |
| Returns the market. | |
| void | fail_next (Call call, BrokerError error, int times=1) |
| Answers the next calls of a kind with an error instead of asking the market. | |
| void | lose_next_reply (Call call) |
| Carries out the next placement or cancellation in the market, then answers it with a transport error that reached the broker, as a lost acknowledgement does: its outcome is unknown to the caller. | |
| void | repeat_last (Call call, int times=1) |
| Answers the next reads of an account's state with what the last one answered, stamped now, as a broker that has not yet reported a change does. | |
| Result< QuoteSnapshot > | quote (const InstrumentId &instrument) |
| Answers a quote request. | |
| Result< Instrument > | instrument (const InstrumentId &instrument) |
| Answers a reference-data request. | |
| Result< TradingCalendar > | calendar (Country country) |
| Answers a calendar request. | |
| Result< BarSeries > | bars (const BarQuery &query) |
| Answers a bar request. | |
| Result< HoldingsSnapshot > | holdings () |
| Answers a holdings request. | |
| Result< BuyingPower > | buying_power (const Currency ¤cy) |
| Answers a buying-power request. | |
| Result< PlacedOrder< Broker > > | place (const OrderRequest &order) |
| Places an order. | |
| Result< PlacedOrder< Broker > > | cancel (const MockAmendment &amendment) |
| Cancels an order. | |
| Result< WorkingOrders< Broker > > | working_orders () |
| Answers a working-order request. | |
| Result< OrderPage > | order_history (const OrderHistoryQuery &query) |
| Answers an order-history request. | |
Static Public Member Functions | |
| static constexpr std::string_view | environment () noexcept |
| Returns the environment this client trades in. | |
The mock broker's client: blocking, answering from a Market, after any faults scripted for the call.
Bind it like any blocking client, BlockingSession<MockClient>(std::make_shared<MockClient>(market), MockAccount{}). Nothing leaves the process; environment is "mock".
Definition at line 53 of file client.hpp.
|
inlineexplicit |
Builds a client over a market.
| market | The market; borrowed, and must outlive the client. |
Definition at line 59 of file client.hpp.
Answers a bar request.
| query | The query. |
Definition at line 185 of file client.hpp.
Referenced by algotradelib::BrokerTraits< mock::MockClient >::bars().
|
inline |
Answers a buying-power request.
| currency | The currency. |
Definition at line 207 of file client.hpp.
Referenced by algotradelib::BrokerTraits< mock::MockClient >::buying_power().
|
inline |
Answers a calendar request.
| country | The market. |
Definition at line 173 of file client.hpp.
Referenced by algotradelib::BrokerTraits< mock::MockClient >::calendar().
|
inline |
Cancels an order.
| amendment | The order id. |
Definition at line 238 of file client.hpp.
Referenced by algotradelib::BrokerTraits< mock::MockClient >::cancel_order().
|
inlinestaticconstexprnoexcept |
Returns the environment this client trades in.
Definition at line 65 of file client.hpp.
|
inline |
Answers the next calls of a kind with an error instead of asking the market.
Nothing happens in the market: a placement failed this way was never accepted, whatever the error says. Faults are used in the order scripted.
| call | The kind of call. |
| error | The error those calls answer. |
| times | How many calls, at least one. |
| std::invalid_argument | if times is below one. |
Definition at line 88 of file client.hpp.
|
inline |
Answers a holdings request.
Definition at line 196 of file client.hpp.
Referenced by algotradelib::BrokerTraits< mock::MockClient >::holdings().
|
inline |
Answers a reference-data request.
| instrument | The instrument. |
Definition at line 161 of file client.hpp.
Referenced by algotradelib::BrokerTraits< mock::MockClient >::instrument(), instrument(), and quote().
|
inline |
Carries out the next placement or cancellation in the market, then answers it with a transport error that reached the broker, as a lost acknowledgement does: its outcome is unknown to the caller.
| call | Call::PLACE or Call::CANCEL. |
| std::invalid_argument | for another call, which has no outcome to lose. |
Definition at line 104 of file client.hpp.
|
inlinenoexcept |
Returns the market.
Definition at line 73 of file client.hpp.
Referenced by MockClient().
|
inline |
Answers an order-history request.
| query | The query. |
Definition at line 265 of file client.hpp.
Referenced by algotradelib::BrokerTraits< mock::MockClient >::order_history().
|
inline |
Places an order.
| order | The order. |
Definition at line 221 of file client.hpp.
Referenced by algotradelib::BrokerTraits< mock::MockClient >::place_order().
|
inline |
Answers a quote request.
| instrument | The instrument. |
Definition at line 149 of file client.hpp.
Referenced by algotradelib::BrokerTraits< mock::MockClient >::quote().
|
inline |
Answers the next reads of an account's state with what the last one answered, stamped now, as a broker that has not yet reported a change does.
The market moves on underneath: a fill that happened is missing from these answers, and a cancellation of an order they still list may answer nothing_to_cancel. A read with no earlier answer to repeat answers normally.
| call | Call::HOLDINGS, Call::BUYING_POWER, Call::WORKING_ORDERS or Call::ORDER_HISTORY. |
| times | How many reads, at least one. |
| std::invalid_argument | for another call, or times below one. |
Definition at line 129 of file client.hpp.
|
inline |
Answers a working-order request.
Definition at line 254 of file client.hpp.
Referenced by algotradelib::BrokerTraits< mock::MockClient >::working_orders().