algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::BlockingSession< Client > Class Template Reference

A blocking broker client bound to one account, with the same broker operations as BrokerSession, plus accounts(). More...

#include <algotradelib/src/core/broker_session.hpp>

Public Types

using Traits = BrokerTraits<Client>
 The client's traits.
using Caps = BrokerCaps<Client>
 The client's capabilities.
using Account = typename Traits::Account
 The broker's account selector type.
using Config = typename Traits::Config
 The broker's configuration type.
using BrokerTag = typename Traits::BrokerTag
 The broker's tag type.
using Ref = OrderRef<BrokerTag>
 The order reference type this session issues and accepts.
using Placed = PlacedOrder<BrokerTag>
 What an order-writing call returns: acknowledgement and reference.
using Working = WorkingOrder<BrokerTag>
 One working order of this broker.
using WorkingSet = WorkingOrders<BrokerTag>
 A working-order listing of this broker.

Public Member Functions

 BlockingSession (std::shared_ptr< Client > client, Account account)
 Binds a blocking client and an account.
const Account & account () const noexcept
 Returns the bound account.
Client & client () noexcept
 Returns the broker client, for broker-specific operations the session does not offer.
const Client & client () const noexcept
 Returns the broker client.
const network::RateLimitStats * rate_limit_stats () const
 Returns the client's request-pacing counters.
Result< QuoteSnapshot > quote (InstrumentId instrument)
 Returns the current quote for an instrument.
Result< HoldingsSnapshot > holdings ()
 Returns the account's holdings.
Result< BuyingPower > buying_power (Currency currency)
 Returns what the account may spend in a currency; requires Caps::has_buying_power.
Result< Decimal64 > sellable_quantity (InstrumentId instrument)
 Returns how much of an instrument the account may sell; only where Caps::sellable_source is INQUIRY.
Result< CommissionSchedule > commissions ()
 Returns the account's commission rates; requires Caps::has_commission_schedule.
Result< Instrument > instrument (InstrumentId subject)
 Returns an instrument's reference data; requires Caps::has_reference_data.
Result< TradingCalendar > calendar (Country country, std::optional< Date > from=std::nullopt)
 Returns the trading calendar; requires Caps::has_calendar.
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< std::vector< QuoteSnapshot > > prices (std::vector< InstrumentId > instruments)
 Returns quotes for several instruments in one request; requires Caps::has_batch_prices.
Result< DepthSnapshot > depth (InstrumentId instrument)
 Returns an instrument's order book, best levels first; requires Caps::has_depth.
Result< BarSeries > bars (BarQuery query)
 Returns bars for an instrument, oldest first, paging until count_ bars are read.
Result< Placed > place (OrderRequest order)
 Places a new order.
Result< Placed > replace (const Ref &ref, const AmendInstruction &instruction)
 Modifies a working order.
Result< Placed > cancel (const Ref &ref, const AmendInstruction &instruction)
 Cancels a working order, in full or in part.
Result< WorkingSet > working_orders ()
 Returns the orders still open to modification or cancellation; requires Caps::has_working_orders.
Result< OrderPage > order_history (const OrderHistoryQuery &query)
 Returns order history: placed orders and their executions.
Result< OrderSnapshot > order (const Ref &ref)
 Returns one order by its reference; requires Caps::has_order_by_id.
Result< std::vector< AccountInfo< Client > > > accounts ()
 Lists the broker's accounts; requires Caps::has_account_discovery.

Static Public Member Functions

static constexpr std::string_view broker_name () noexcept
 Returns the broker's name.

Detailed Description

template<typename Client>
class algotradelib::BlockingSession< Client >

A blocking broker client bound to one account, with the same broker operations as BrokerSession, plus accounts().

Every operation returns Result<T>. An operation the broker does not offer does not compile.

Template Parameters
ClientA blocking broker client (BrokerTraits<Client>::blocking is true).

Definition at line 862 of file broker_session.hpp.

Member Typedef Documentation

◆ Account

template<typename Client>
using algotradelib::BlockingSession< Client >::Account = typename Traits::Account

The broker's account selector type.

Definition at line 871 of file broker_session.hpp.

◆ BrokerTag

template<typename Client>
using algotradelib::BlockingSession< Client >::BrokerTag = typename Traits::BrokerTag

The broker's tag type.

Definition at line 877 of file broker_session.hpp.

◆ Caps

template<typename Client>
using algotradelib::BlockingSession< Client >::Caps = BrokerCaps<Client>

The client's capabilities.

Definition at line 868 of file broker_session.hpp.

◆ Config

template<typename Client>
using algotradelib::BlockingSession< Client >::Config = typename Traits::Config

The broker's configuration type.

Definition at line 874 of file broker_session.hpp.

◆ Placed

template<typename Client>
using algotradelib::BlockingSession< Client >::Placed = PlacedOrder<BrokerTag>

What an order-writing call returns: acknowledgement and reference.

Definition at line 883 of file broker_session.hpp.

◆ Ref

template<typename Client>
using algotradelib::BlockingSession< Client >::Ref = OrderRef<BrokerTag>

The order reference type this session issues and accepts.

Definition at line 880 of file broker_session.hpp.

◆ Traits

template<typename Client>
using algotradelib::BlockingSession< Client >::Traits = BrokerTraits<Client>

The client's traits.

Definition at line 865 of file broker_session.hpp.

◆ Working

template<typename Client>
using algotradelib::BlockingSession< Client >::Working = WorkingOrder<BrokerTag>

One working order of this broker.

Definition at line 886 of file broker_session.hpp.

◆ WorkingSet

template<typename Client>
using algotradelib::BlockingSession< Client >::WorkingSet = WorkingOrders<BrokerTag>

A working-order listing of this broker.

Definition at line 889 of file broker_session.hpp.

Constructor & Destructor Documentation

◆ BlockingSession()

template<typename Client>
algotradelib::BlockingSession< Client >::BlockingSession ( std::shared_ptr< Client > client,
Account account )
inline

Binds a blocking client and an account.

Parameters
clientThe client; must not be null.
accountThe account to act for.
Exceptions
std::invalid_argumentif client is null.

Definition at line 903 of file broker_session.hpp.

Member Function Documentation

◆ account()

template<typename Client>
const Account & algotradelib::BlockingSession< Client >::account ( ) const
inlinenoexcept

Returns the bound account.

Returns
The account selector.

Definition at line 920 of file broker_session.hpp.

Referenced by BlockingSession().

◆ accounts()

template<typename Client>
Result< std::vector< AccountInfo< Client > > > algotradelib::BlockingSession< Client >::accounts ( )
inline

Lists the broker's accounts; requires Caps::has_account_discovery.

Returns
The accounts, or an error.

Definition at line 1246 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ bars()

template<typename Client>
Result< BarSeries > algotradelib::BlockingSession< Client >::bars ( BarQuery query)
inline

Returns bars for an instrument, oldest first, paging until count_ bars are read.

Parameters
queryWhat to fetch.
Returns
The bars, or an error (an unsupported interval is refused before any I/O).

Definition at line 1125 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ broker_name()

template<typename Client>
constexpr std::string_view algotradelib::BlockingSession< Client >::broker_name ( )
inlinestaticconstexprnoexcept

Returns the broker's name.

Returns
Traits::name.

Definition at line 914 of file broker_session.hpp.

◆ buying_power()

template<typename Client>
Result< BuyingPower > algotradelib::BlockingSession< Client >::buying_power ( Currency currency)
inline

Returns what the account may spend in a currency; requires Caps::has_buying_power.

Parameters
currencyThe currency.
Returns
The buying power, or an error.

Definition at line 967 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ calendar()

template<typename Client>
Result< TradingCalendar > algotradelib::BlockingSession< Client >::calendar ( Country country,
std::optional< Date > from = std::nullopt )
inline

Returns the trading calendar; requires Caps::has_calendar.

Parameters
countryThe market.
fromThe date the answer is anchored to; empty means today.
Returns
The calendar, or an error.

Definition at line 1036 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ cancel()

template<typename Client>
Result< Placed > algotradelib::BlockingSession< Client >::cancel ( const Ref & ref,
const AmendInstruction & instruction )
inline

Cancels a working order, in full or in part.

Warning
An error for which runner::outcome_of returns INDETERMINATE (reached_broker_ set and a category of TRANSPORT, CANCELLED or PROTOCOL, or HTTP 500 or more) leaves the outcome unknown: the request may have taken effect. The request is never resent automatically. Check working orders or order history before sending it again.
Parameters
refThe order.
instructionBuild it with cancel_all or cancel_quantity; the session's has_trigger_price check does not apply, though the adapter still validates it.
Returns
The acknowledgement and reference, or an error.

Definition at line 1185 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ client() [1/2]

template<typename Client>
const Client & algotradelib::BlockingSession< Client >::client ( ) const
inlinenoexcept

Returns the broker client.

Returns
The client.

Definition at line 932 of file broker_session.hpp.

◆ client() [2/2]

template<typename Client>
Client & algotradelib::BlockingSession< Client >::client ( )
inlinenoexcept

Returns the broker client, for broker-specific operations the session does not offer.

Returns
The client.

Definition at line 926 of file broker_session.hpp.

Referenced by BlockingSession(), and algotradelib::conformance::call_claimed_blocking_verbs().

◆ commissions()

template<typename Client>
Result< CommissionSchedule > algotradelib::BlockingSession< Client >::commissions ( )
inline

Returns the account's commission rates; requires Caps::has_commission_schedule.

Returns
The schedule, or an error.

Definition at line 1001 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ depth()

template<typename Client>
Result< DepthSnapshot > algotradelib::BlockingSession< Client >::depth ( InstrumentId instrument)
inline

Returns an instrument's order book, best levels first; requires Caps::has_depth.

Parameters
instrumentThe instrument.
Returns
The book, or an error.

Definition at line 1108 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ holdings()

template<typename Client>
Result< HoldingsSnapshot > algotradelib::BlockingSession< Client >::holdings ( )
inline

Returns the account's holdings.

Returns
The holdings, or an error.

Definition at line 960 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ instrument()

template<typename Client>
Result< Instrument > algotradelib::BlockingSession< Client >::instrument ( InstrumentId subject)
inline

Returns an instrument's reference data; requires Caps::has_reference_data.

Parameters
subjectThe instrument.
Returns
The reference data, or an error.

Definition at line 1018 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs(), depth(), price_limits(), quote(), sellable_quantity(), and trades().

◆ order()

template<typename Client>
Result< OrderSnapshot > algotradelib::BlockingSession< Client >::order ( const Ref & ref)
inline

Returns one order by its reference; requires Caps::has_order_by_id.

Parameters
refThe order.
Returns
The order, or an error.

Definition at line 1229 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs(), and place().

◆ order_history()

template<typename Client>
Result< OrderPage > algotradelib::BlockingSession< Client >::order_history ( const OrderHistoryQuery & query)
inline

Returns order history: placed orders and their executions.

Parameters
queryThe filter.
Returns
One page, or an error (a filter the broker cannot apply is refused before any I/O).

Definition at line 1216 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ place()

template<typename Client>
Result< Placed > algotradelib::BlockingSession< Client >::place ( OrderRequest order)
inline

Places a new order.

Warning
An error for which runner::outcome_of returns INDETERMINATE (reached_broker_ set and a category of TRANSPORT, CANCELLED or PROTOCOL, or HTTP 500 or more) leaves the outcome unknown: the request may have taken effect. The request is never resent automatically. Check working orders or order history before sending it again.
Parameters
orderThe order; refused before any I/O as for BrokerSession::async_place.
Returns
The acknowledgement and reference, or an error.

Definition at line 1143 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ price_limits()

template<typename Client>
Result< PriceLimits > algotradelib::BlockingSession< Client >::price_limits ( InstrumentId instrument)
inline

Returns an instrument's price limits for today; requires Caps::has_price_limits.

Parameters
instrumentThe instrument.
Returns
The limits, or an error.

Definition at line 1056 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ prices()

template<typename Client>
Result< std::vector< QuoteSnapshot > > algotradelib::BlockingSession< Client >::prices ( std::vector< InstrumentId > instruments)
inline

Returns quotes for several instruments in one request; requires Caps::has_batch_prices.

Parameters
instrumentsThe instruments.
Returns
The quotes, or an error.

Definition at line 1091 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ quote()

template<typename Client>
Result< QuoteSnapshot > algotradelib::BlockingSession< Client >::quote ( InstrumentId instrument)
inline

Returns the current quote for an instrument.

Parameters
instrumentThe instrument.
Returns
The quote, or an error.

Definition at line 952 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ rate_limit_stats()

template<typename Client>
const network::RateLimitStats * algotradelib::BlockingSession< Client >::rate_limit_stats ( ) const
inline

Returns the client's request-pacing counters.

A rising delayed_ on a polling group while TRADING stays undelayed means trading capacity is being kept free; a rising shed_ means the queue was full or the budget is too slow for the timeout. Safe to read between calls.

Returns
The counters, or nullptr if the client is not paced.

Definition at line 943 of file broker_session.hpp.

◆ replace()

template<typename Client>
Result< Placed > algotradelib::BlockingSession< Client >::replace ( const Ref & ref,
const AmendInstruction & instruction )
inline

Modifies a working order.

Warning
An error for which runner::outcome_of returns INDETERMINATE (reached_broker_ set and a category of TRANSPORT, CANCELLED or PROTOCOL, or HTTP 500 or more) leaves the outcome unknown: the request may have taken effect. The request is never resent automatically. Check working orders or order history before sending it again.
Parameters
refThe order.
instructionWhat to change; build it with replace_with or reprice.
Returns
The acknowledgement and reference, or an error.

Definition at line 1162 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ sellable_quantity()

template<typename Client>
Result< Decimal64 > algotradelib::BlockingSession< Client >::sellable_quantity ( InstrumentId instrument)
inline

Returns how much of an instrument the account may sell; only where Caps::sellable_source is INQUIRY.

Parameters
instrumentThe instrument.
Returns
The quantity, or an error.

Definition at line 984 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ trades()

template<typename Client>
Result< std::vector< TradePrint > > algotradelib::BlockingSession< Client >::trades ( InstrumentId instrument,
int count )
inline

Returns recent trades for an instrument, newest first; requires Caps::has_trade_prints.

Parameters
instrumentThe instrument.
countHow many trades to request.
Returns
The trades, or an error.

Definition at line 1074 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().

◆ working_orders()

template<typename Client>
Result< WorkingSet > algotradelib::BlockingSession< Client >::working_orders ( )
inline

Returns the orders still open to modification or cancellation; requires Caps::has_working_orders.

Returns
The listing, or an error.

Definition at line 1199 of file broker_session.hpp.

Referenced by algotradelib::conformance::call_claimed_blocking_verbs().


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