algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient > Struct Reference

The BrokerSession adapter for alpaca::AlpacaBlockingClient. More...

#include <algotradelib/src/brokers/alpaca/traits.hpp>

Inheritance diagram for algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >:
Collaboration diagram for algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >:

Public Types

using Client = alpaca::AlpacaBlockingClient
 The client type.
using Config = alpaca::AlpacaConfig
 The keys and environment.
using Account = alpaca::AlpacaAccount
 The account selector, which carries nothing.
using AccountListItem = alpaca::AlpacaAccountInfo
 Item type of the broker's own account listing.
using BrokerTag = alpaca::Broker
 The broker tag.
using PlaceAck = alpaca::AlpacaOrderAck
 Alpaca's acknowledgement of a placement or cancellation.
using Amendment = alpaca::AlpacaAmendment
 A cancellation of one whole order.
using HistoryQuery = OrderHistoryQuery
 The history query, the library's own.
using WorkingOrdersResult = alpaca::AlpacaOpenOrders
 The open orders, before normalizing.

Static Public Member Functions

static constexpr bool supports_interval (BarInterval interval)
 Tests whether this adapter serves bars at an interval.
static constexpr Venue effective_route (Venue) noexcept
 Returns where an order goes: Alpaca routes it, and no venue can be asked for.
static std::optional< BrokerError > validate_bars (const BarQuery &query)
 Refuses a bar request this adapter cannot answer as asked, before any I/O.
static std::optional< BrokerError > validate_calendar (Country country, std::optional< Date > from)
 Refuses a calendar for any market but the US, or with an invalid date.
static std::optional< BrokerError > validate_place (const OrderRequest &order)
 Refuses an order this adapter does not send as described, before any I/O; the same check the client's place_order makes first.
static Result< PlacedOrder< alpaca::Broker > > normalize_place (Result< PlaceAck > raw)
 Normalizes Alpaca's acknowledgement; the reference is the order id.
static Result< WorkingOrders< alpaca::Broker > > normalize_working_orders (Result< WorkingOrdersResult > raw)
 Converts the open orders into working orders, each amendable for its unfilled quantity.
static Result< Amendment > to_replacement (const OrderRef< alpaca::Broker > &, const AmendInstruction &)
 Refuses every replacement: Alpaca's replacement is a new order that drops the client_order_id, and a runner never replaces (it cancels and places).
static Result< Amendment > to_cancellation (const OrderRef< alpaca::Broker > &ref, const AmendInstruction &instruction)
 Converts a cancellation of the whole order; a stated quantity is refused.
static Result< HistoryQuery > to_history_query (const Account &, const OrderHistoryQuery &query)
 Admits a history query with a limit of 1 to 500 and valid dates.
static Account selector_of (const AccountListItem &)
 Returns the account selector a session binds, which is empty. The argument is not used.
static std::string display_of (const AccountListItem &account)
 Returns the account number as Alpaca reports it.
static std::string type_of (const AccountListItem &)
 Returns the account type, which this adapter does not read (the argument is not used).
static const network::RateLimitStats * rate_limit_stats (const Client &client)
 Returns the trading connection's rate-limit statistics.
static Result< QuoteSnapshot > quote (Client &client, InstrumentId instrument)
 Returns a quote.
static Result< BarSeries > bars (Client &client, BarQuery query)
 Returns bars.
static Result< Instrument > instrument (Client &client, InstrumentId subject)
 Returns reference data for one instrument.
static Result< TradingCalendar > calendar (Client &client, Country country, std::optional< Date > from)
 Returns the trading calendar.
static Result< std::vector< AccountListItem > > accounts (Client &client)
 Returns the one account the keys drive.
static Result< HoldingsSnapshot > holdings (Client &client, const Account &account)
 Returns the holdings.
static Result< PlaceAck > place_order (Client &client, const Account &account, OrderRequest order)
 Places an order.
static Result< PlaceAck > replace_order (Client &, const Account &, Amendment)
 Refuses a replacement; to_replacement refuses first, so a session never calls it.
static Result< PlaceAck > cancel_order (Client &client, const Account &account, Amendment amendment)
 Cancels an order.
static Result< WorkingOrdersResult > working_orders (Client &client, const Account &account)
 Returns the open orders.
static Result< OrderSnapshot > order_by_id (Client &client, const Account &account, const std::string &id)
 Returns one order by its id.
static Result< OrderPage > order_history (Client &client, const Account &account, HistoryQuery query)
 Returns a page of order history.

Static Public Attributes

static constexpr std::string_view name = alpaca::Broker::name
 The broker's name.
static constexpr bool blocking = true
 true: requests return their result directly.
static constexpr bool data_only = false
 A broker that takes orders, not a market-data source.
static constexpr bool has_account_discovery = true
 true: /v2/account reports the one account the keys drive.
static constexpr bool has_client_order_id = true
 true: client_order_id, 1 to 128 characters, unique for the account.
static constexpr bool has_working_orders = true
 true: /v2/orders?status=open.
static constexpr bool has_amendable_quantity = true
 true: each order's qty less its filled_qty.
static constexpr bool working_orders_state_terminal = false
 false: the open listing shows open orders only.
static constexpr bool has_trigger_price = false
 false: this adapter sends no stop orders.
static constexpr bool has_order_by_id = true
 true: /v2/orders/{id}.
static constexpr bool has_partial_cancel = false
 false: Alpaca cancels the whole order.
static constexpr bool history_requires_range = false
 false: a range is optional.
static constexpr bool has_history_cursor = true
 true: a full page carries its last row's submission time, sent back as Alpaca's until.
static constexpr bool has_history_limit = true
 true: up to history_limit rows a page.
static constexpr int history_limit = 500
 The most rows one history page may ask for.
static constexpr bool has_history_symbol_filter = true
 true: Alpaca filters by symbols=.
static constexpr bool has_depth = false
 false: served by Alpaca, not adapted.
static constexpr bool has_price_limits = false
 false: no daily price band is published for US equities.
static constexpr bool has_trade_prints = false
 false: served by Alpaca, not adapted.
static constexpr bool has_batch_prices = false
 false: one instrument a request.
static constexpr bool has_buying_power = false
 false: no Alpaca figure is cash net of resting buys without credit (buying_power counts margin), so buys are not checked against cash; a buy above the cash borrows on the account's margin. runner::PollingLoop over it holds every placement unless RiskLimits::run_budget_ is set, which a live runner takes when it keeps its run in the order journal.
static constexpr bool has_buying_power_quantity = false
 false: there is no buying power to express in shares.
static constexpr SellableSource sellable_source = SellableSource::HOLDINGS
 HOLDINGS: each position's qty_available, with the basis AlpacaBlockingClient::holdings states.
static constexpr bool has_commission_schedule = false
 false: commission-free, and the per-share FINRA fee on sells has no CommissionRate shape.
static constexpr bool has_reference_data = true
 true: /v2/assets/{symbol}.
static constexpr bool has_batch_reference_data = false
 false: one instrument a request.
static constexpr bool has_calendar = true
 true: /v3/calendar/XNYS.
static constexpr bool has_calendar_range = true
 true: one request covers the whole range.
static constexpr bool has_calendar_sessions = true
 true: the adapter fills each open day's regular session and, where stated, its extended span, so a live loop takes the market phase from them.

Detailed Description

The BrokerSession adapter for alpaca::AlpacaBlockingClient.

A US listing is InstrumentId{Country::US, Venue::UNSPECIFIED, symbol}, in dollars. Every placement is checked by alpaca::detail::validate_order (this traits' validate_place and the client's own place_order alike), then by the client's reads of the asset, the position and the clock. Replacements are refused: cancel and place instead, as a runner does. It declares no no_account(): the keys are the account, so every AlpacaAccount trades.

Definition at line 33 of file traits.hpp.

Member Typedef Documentation

◆ Account

The account selector, which carries nothing.

Definition at line 41 of file traits.hpp.

◆ AccountListItem

Item type of the broker's own account listing.

Definition at line 44 of file traits.hpp.

◆ Amendment

A cancellation of one whole order.

Definition at line 53 of file traits.hpp.

◆ BrokerTag

The broker tag.

Definition at line 47 of file traits.hpp.

◆ Client

The client type.

Definition at line 35 of file traits.hpp.

◆ Config

The keys and environment.

Definition at line 38 of file traits.hpp.

◆ HistoryQuery

The history query, the library's own.

Definition at line 56 of file traits.hpp.

◆ PlaceAck

Alpaca's acknowledgement of a placement or cancellation.

Definition at line 50 of file traits.hpp.

◆ WorkingOrdersResult

The open orders, before normalizing.

Definition at line 59 of file traits.hpp.

Member Function Documentation

◆ accounts()

Result< std::vector< AccountListItem > > algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::accounts ( Client & client)
inlinestatic

Returns the one account the keys drive.

Parameters
clientThe client.
Returns
The result, or an error.

Definition at line 372 of file traits.hpp.

◆ bars()

Returns bars.

Parameters
clientThe client.
queryThe query.
Returns
The result, or an error.

Definition at line 342 of file traits.hpp.

◆ calendar()

Result< TradingCalendar > algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::calendar ( Client & client,
Country country,
std::optional< Date > from )
inlinestatic

Returns the trading calendar.

Parameters
clientThe client.
countryThe market.
fromThe first date, or empty for the default range.
Returns
The result, or an error.

Definition at line 363 of file traits.hpp.

◆ cancel_order()

Result< PlaceAck > algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::cancel_order ( Client & client,
const Account & account,
Amendment amendment )
inlinestatic

Cancels an order.

Parameters
clientThe client.
accountThe bound account.
amendmentThe order.
Returns
The result, or an error.

Definition at line 414 of file traits.hpp.

◆ display_of()

std::string algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::display_of ( const AccountListItem & account)
inlinestatic

Returns the account number as Alpaca reports it.

Parameters
accountThe account.
Returns
The number.

Definition at line 305 of file traits.hpp.

◆ effective_route()

constexpr Venue algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::effective_route ( Venue )
inlinestaticconstexprnoexcept

Returns where an order goes: Alpaca routes it, and no venue can be asked for.

Returns
Venue::UNSPECIFIED.

Definition at line 171 of file traits.hpp.

◆ holdings()

Result< HoldingsSnapshot > algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::holdings ( Client & client,
const Account & account )
inlinestatic

Returns the holdings.

Parameters
clientThe client.
accountThe bound account.
Returns
The result, or an error.

Definition at line 382 of file traits.hpp.

◆ instrument()

Result< Instrument > algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::instrument ( Client & client,
InstrumentId subject )
inlinestatic

Returns reference data for one instrument.

Parameters
clientThe client.
subjectThe instrument.
Returns
The result, or an error.

Definition at line 352 of file traits.hpp.

Referenced by quote().

◆ normalize_place()

Normalizes Alpaca's acknowledgement; the reference is the order id.

Parameters
rawThe client's result.
Returns
The placed order, or the error.

Definition at line 215 of file traits.hpp.

◆ normalize_working_orders()

Converts the open orders into working orders, each amendable for its unfilled quantity.

Parameters
rawThe client's result.
Returns
The working orders, or the error.

Definition at line 232 of file traits.hpp.

◆ order_by_id()

Result< OrderSnapshot > algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::order_by_id ( Client & client,
const Account & account,
const std::string & id )
inlinestatic

Returns one order by its id.

Parameters
clientThe client.
accountThe bound account.
idThe order id.
Returns
The result, or an error.

Definition at line 435 of file traits.hpp.

◆ order_history()

Result< OrderPage > algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::order_history ( Client & client,
const Account & account,
HistoryQuery query )
inlinestatic

Returns a page of order history.

Parameters
clientThe client.
accountThe bound account.
queryThe admitted query.
Returns
The result, or an error.

Definition at line 446 of file traits.hpp.

◆ place_order()

Result< PlaceAck > algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::place_order ( Client & client,
const Account & account,
OrderRequest order )
inlinestatic

Places an order.

Parameters
clientThe client.
accountThe bound account.
orderThe order.
Returns
The result, or an error.

Definition at line 393 of file traits.hpp.

◆ quote()

Returns a quote.

Parameters
clientThe client.
instrumentThe instrument.
Returns
The result, or an error.

Definition at line 332 of file traits.hpp.

◆ rate_limit_stats()

const network::RateLimitStats * algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::rate_limit_stats ( const Client & client)
inlinestatic

Returns the trading connection's rate-limit statistics.

Parameters
clientThe client.
Returns
The statistics, or null if the connection has no budget.

Definition at line 322 of file traits.hpp.

◆ replace_order()

Result< PlaceAck > algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::replace_order ( Client & ,
const Account & ,
Amendment  )
inlinestatic

Refuses a replacement; to_replacement refuses first, so a session never calls it.

Returns
An INVALID_ARGUMENT error (replace_unsupported, not sent).

Definition at line 401 of file traits.hpp.

◆ selector_of()

Returns the account selector a session binds, which is empty. The argument is not used.

Returns
An empty selector.

Definition at line 296 of file traits.hpp.

◆ supports_interval()

constexpr bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::supports_interval ( BarInterval interval)
inlinestaticconstexpr

Tests whether this adapter serves bars at an interval.

Parameters
intervalThe interval.
Returns
true for 1, 5, 15 and 30 minutes, an hour and a day.

Definition at line 161 of file traits.hpp.

◆ to_cancellation()

Result< Amendment > algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::to_cancellation ( const OrderRef< alpaca::Broker > & ref,
const AmendInstruction & instruction )
inlinestatic

Converts a cancellation of the whole order; a stated quantity is refused.

Parameters
refThe order.
instructionThe cancellation.
Returns
The amendment, or an INVALID_ARGUMENT error.

Definition at line 265 of file traits.hpp.

◆ to_history_query()

Result< HistoryQuery > algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::to_history_query ( const Account & ,
const OrderHistoryQuery & query )
inlinestatic

Admits a history query with a limit of 1 to 500 and valid dates.

Parameters
queryThe query.
Returns
The query, or an INVALID_ARGUMENT error.

Definition at line 282 of file traits.hpp.

◆ to_replacement()

Refuses every replacement: Alpaca's replacement is a new order that drops the client_order_id, and a runner never replaces (it cancels and places).

Returns
An INVALID_ARGUMENT error (replace_unsupported, not sent).

Definition at line 253 of file traits.hpp.

◆ type_of()

std::string algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::type_of ( const AccountListItem & )
inlinestatic

Returns the account type, which this adapter does not read (the argument is not used).

Returns
An empty string.

Definition at line 313 of file traits.hpp.

◆ validate_bars()

std::optional< BrokerError > algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::validate_bars ( const BarQuery & query)
inlinestatic

Refuses a bar request this adapter cannot answer as asked, before any I/O.

Parameters
queryThe query.
Returns
An error if refused (nothing is sent), otherwise std::nullopt.

Definition at line 180 of file traits.hpp.

◆ validate_calendar()

std::optional< BrokerError > algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::validate_calendar ( Country country,
std::optional< Date > from )
inlinestatic

Refuses a calendar for any market but the US, or with an invalid date.

Parameters
countryThe market.
fromThe first date.
Returns
An error if refused (nothing is sent), otherwise std::nullopt.

Definition at line 190 of file traits.hpp.

◆ validate_place()

std::optional< BrokerError > algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::validate_place ( const OrderRequest & order)
inlinestatic

Refuses an order this adapter does not send as described, before any I/O; the same check the client's place_order makes first.

Parameters
orderThe order.
Returns
An error if refused (nothing is sent), otherwise std::nullopt.

Definition at line 206 of file traits.hpp.

◆ working_orders()

Result< WorkingOrdersResult > algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::working_orders ( Client & client,
const Account & account )
inlinestatic

Returns the open orders.

Parameters
clientThe client.
accountThe bound account.
Returns
The result, or an error.

Definition at line 424 of file traits.hpp.

Member Data Documentation

◆ blocking

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::blocking = true
staticconstexpr

true: requests return their result directly.

Definition at line 65 of file traits.hpp.

◆ data_only

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::data_only = false
staticconstexpr

A broker that takes orders, not a market-data source.

Definition at line 68 of file traits.hpp.

◆ has_account_discovery

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_account_discovery = true
staticconstexpr

true: /v2/account reports the one account the keys drive.

Definition at line 71 of file traits.hpp.

◆ has_amendable_quantity

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_amendable_quantity = true
staticconstexpr

true: each order's qty less its filled_qty.

Definition at line 80 of file traits.hpp.

◆ has_batch_prices

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_batch_prices = false
staticconstexpr

false: one instrument a request.

Definition at line 119 of file traits.hpp.

◆ has_batch_reference_data

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_batch_reference_data = false
staticconstexpr

false: one instrument a request.

Definition at line 142 of file traits.hpp.

◆ has_buying_power

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_buying_power = false
staticconstexpr

false: no Alpaca figure is cash net of resting buys without credit (buying_power counts margin), so buys are not checked against cash; a buy above the cash borrows on the account's margin. runner::PollingLoop over it holds every placement unless RiskLimits::run_budget_ is set, which a live runner takes when it keeps its run in the order journal.

Definition at line 127 of file traits.hpp.

◆ has_buying_power_quantity

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_buying_power_quantity = false
staticconstexpr

false: there is no buying power to express in shares.

Definition at line 130 of file traits.hpp.

◆ has_calendar

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_calendar = true
staticconstexpr

true: /v3/calendar/XNYS.

Definition at line 145 of file traits.hpp.

◆ has_calendar_range

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_calendar_range = true
staticconstexpr

true: one request covers the whole range.

Definition at line 148 of file traits.hpp.

◆ has_calendar_sessions

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_calendar_sessions = true
staticconstexpr

true: the adapter fills each open day's regular session and, where stated, its extended span, so a live loop takes the market phase from them.

Definition at line 154 of file traits.hpp.

◆ has_client_order_id

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_client_order_id = true
staticconstexpr

true: client_order_id, 1 to 128 characters, unique for the account.

Definition at line 74 of file traits.hpp.

◆ has_commission_schedule

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_commission_schedule = false
staticconstexpr

false: commission-free, and the per-share FINRA fee on sells has no CommissionRate shape.

Definition at line 136 of file traits.hpp.

◆ has_depth

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_depth = false
staticconstexpr

false: served by Alpaca, not adapted.

Definition at line 110 of file traits.hpp.

◆ has_history_cursor

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_history_cursor = true
staticconstexpr

true: a full page carries its last row's submission time, sent back as Alpaca's until.

Definition at line 98 of file traits.hpp.

◆ has_history_limit

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_history_limit = true
staticconstexpr

true: up to history_limit rows a page.

Definition at line 101 of file traits.hpp.

◆ has_history_symbol_filter

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_history_symbol_filter = true
staticconstexpr

true: Alpaca filters by symbols=.

Definition at line 107 of file traits.hpp.

◆ has_order_by_id

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_order_by_id = true
staticconstexpr

true: /v2/orders/{id}.

Definition at line 89 of file traits.hpp.

◆ has_partial_cancel

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_partial_cancel = false
staticconstexpr

false: Alpaca cancels the whole order.

Definition at line 92 of file traits.hpp.

◆ has_price_limits

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_price_limits = false
staticconstexpr

false: no daily price band is published for US equities.

Definition at line 113 of file traits.hpp.

◆ has_reference_data

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_reference_data = true
staticconstexpr

true: /v2/assets/{symbol}.

Definition at line 139 of file traits.hpp.

◆ has_trade_prints

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_trade_prints = false
staticconstexpr

false: served by Alpaca, not adapted.

Definition at line 116 of file traits.hpp.

◆ has_trigger_price

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_trigger_price = false
staticconstexpr

false: this adapter sends no stop orders.

Definition at line 86 of file traits.hpp.

◆ has_working_orders

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::has_working_orders = true
staticconstexpr

true: /v2/orders?status=open.

Definition at line 77 of file traits.hpp.

◆ history_limit

int algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::history_limit = 500
staticconstexpr

The most rows one history page may ask for.

Definition at line 104 of file traits.hpp.

Referenced by to_history_query().

◆ history_requires_range

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::history_requires_range = false
staticconstexpr

false: a range is optional.

Definition at line 95 of file traits.hpp.

◆ name

The broker's name.

Definition at line 62 of file traits.hpp.

◆ sellable_source

HOLDINGS: each position's qty_available, with the basis AlpacaBlockingClient::holdings states.

Definition at line 133 of file traits.hpp.

◆ working_orders_state_terminal

bool algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::working_orders_state_terminal = false
staticconstexpr

false: the open listing shows open orders only.

Definition at line 83 of file traits.hpp.


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