algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::mock::MockClient Class Reference

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 &currency)
 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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ MockClient()

algotradelib::mock::MockClient::MockClient ( Market & market)
inlineexplicit

Builds a client over a market.

Parameters
marketThe market; borrowed, and must outlive the client.

Definition at line 59 of file client.hpp.

Member Function Documentation

◆ bars()

Result< BarSeries > algotradelib::mock::MockClient::bars ( const BarQuery & query)
inline

Answers a bar request.

Parameters
queryThe query.
Returns
As Market::bars.

Definition at line 185 of file client.hpp.

Referenced by algotradelib::BrokerTraits< mock::MockClient >::bars().

◆ buying_power()

Result< BuyingPower > algotradelib::mock::MockClient::buying_power ( const Currency & currency)
inline

Answers a buying-power request.

Parameters
currencyThe currency.
Returns
As Market::buying_power.

Definition at line 207 of file client.hpp.

Referenced by algotradelib::BrokerTraits< mock::MockClient >::buying_power().

◆ calendar()

Result< TradingCalendar > algotradelib::mock::MockClient::calendar ( Country country)
inline

Answers a calendar request.

Parameters
countryThe market.
Returns
As Market::calendar.

Definition at line 173 of file client.hpp.

Referenced by algotradelib::BrokerTraits< mock::MockClient >::calendar().

◆ cancel()

Result< PlacedOrder< Broker > > algotradelib::mock::MockClient::cancel ( const MockAmendment & amendment)
inline

Cancels an order.

Parameters
amendmentThe order id.
Returns
As Market::cancel.

Definition at line 238 of file client.hpp.

Referenced by algotradelib::BrokerTraits< mock::MockClient >::cancel_order().

◆ environment()

constexpr std::string_view algotradelib::mock::MockClient::environment ( )
inlinestaticconstexprnoexcept

Returns the environment this client trades in.

Returns
Always "mock".

Definition at line 65 of file client.hpp.

◆ fail_next()

void algotradelib::mock::MockClient::fail_next ( Call call,
BrokerError error,
int times = 1 )
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.

Parameters
callThe kind of call.
errorThe error those calls answer.
timesHow many calls, at least one.
Exceptions
std::invalid_argumentif times is below one.

Definition at line 88 of file client.hpp.

◆ holdings()

Result< HoldingsSnapshot > algotradelib::mock::MockClient::holdings ( )
inline

Answers a holdings request.

Returns
As Market::holdings.

Definition at line 196 of file client.hpp.

Referenced by algotradelib::BrokerTraits< mock::MockClient >::holdings().

◆ instrument()

Result< Instrument > algotradelib::mock::MockClient::instrument ( const InstrumentId & instrument)
inline

Answers a reference-data request.

Parameters
instrumentThe instrument.
Returns
As Market::instrument.

Definition at line 161 of file client.hpp.

Referenced by algotradelib::BrokerTraits< mock::MockClient >::instrument(), instrument(), and quote().

◆ lose_next_reply()

void algotradelib::mock::MockClient::lose_next_reply ( Call call)
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.

Parameters
callCall::PLACE or Call::CANCEL.
Exceptions
std::invalid_argumentfor another call, which has no outcome to lose.

Definition at line 104 of file client.hpp.

◆ market()

Market & algotradelib::mock::MockClient::market ( ) const
inlinenoexcept

Returns the market.

Returns
The market this client answers from.

Definition at line 73 of file client.hpp.

Referenced by MockClient().

◆ order_history()

Result< OrderPage > algotradelib::mock::MockClient::order_history ( const OrderHistoryQuery & query)
inline

Answers an order-history request.

Parameters
queryThe query.
Returns
As Market::order_history.

Definition at line 265 of file client.hpp.

Referenced by algotradelib::BrokerTraits< mock::MockClient >::order_history().

◆ place()

Result< PlacedOrder< Broker > > algotradelib::mock::MockClient::place ( const OrderRequest & order)
inline

Places an order.

Parameters
orderThe order.
Returns
As Market::place.

Definition at line 221 of file client.hpp.

Referenced by algotradelib::BrokerTraits< mock::MockClient >::place_order().

◆ quote()

Result< QuoteSnapshot > algotradelib::mock::MockClient::quote ( const InstrumentId & instrument)
inline

Answers a quote request.

Parameters
instrumentThe instrument.
Returns
As Market::quote.

Definition at line 149 of file client.hpp.

Referenced by algotradelib::BrokerTraits< mock::MockClient >::quote().

◆ repeat_last()

void algotradelib::mock::MockClient::repeat_last ( Call call,
int times = 1 )
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.

Parameters
callCall::HOLDINGS, Call::BUYING_POWER, Call::WORKING_ORDERS or Call::ORDER_HISTORY.
timesHow many reads, at least one.
Exceptions
std::invalid_argumentfor another call, or times below one.

Definition at line 129 of file client.hpp.

◆ working_orders()

Result< WorkingOrders< Broker > > algotradelib::mock::MockClient::working_orders ( )
inline

Answers a working-order request.

Returns
As Market::working_orders.

Definition at line 254 of file client.hpp.

Referenced by algotradelib::BrokerTraits< mock::MockClient >::working_orders().


The documentation for this class was generated from the following file: