![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
The BrokerSession adapter for alpaca::AlpacaBlockingClient. More...
#include <algotradelib/src/brokers/alpaca/traits.hpp>
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. | |
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.
| using algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::Account = alpaca::AlpacaAccount |
The account selector, which carries nothing.
Definition at line 41 of file traits.hpp.
| using algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::AccountListItem = alpaca::AlpacaAccountInfo |
Item type of the broker's own account listing.
Definition at line 44 of file traits.hpp.
| using algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::Amendment = alpaca::AlpacaAmendment |
A cancellation of one whole order.
Definition at line 53 of file traits.hpp.
| using algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::BrokerTag = alpaca::Broker |
The broker tag.
Definition at line 47 of file traits.hpp.
| using algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::Client = alpaca::AlpacaBlockingClient |
The client type.
Definition at line 35 of file traits.hpp.
| using algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::Config = alpaca::AlpacaConfig |
The keys and environment.
Definition at line 38 of file traits.hpp.
| using algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::HistoryQuery = OrderHistoryQuery |
The history query, the library's own.
Definition at line 56 of file traits.hpp.
| using algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::PlaceAck = alpaca::AlpacaOrderAck |
Alpaca's acknowledgement of a placement or cancellation.
Definition at line 50 of file traits.hpp.
| using algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::WorkingOrdersResult = alpaca::AlpacaOpenOrders |
The open orders, before normalizing.
Definition at line 59 of file traits.hpp.
|
inlinestatic |
Returns the one account the keys drive.
| client | The client. |
Definition at line 372 of file traits.hpp.
|
inlinestatic |
Returns bars.
| client | The client. |
| query | The query. |
Definition at line 342 of file traits.hpp.
|
inlinestatic |
Returns the trading calendar.
| client | The client. |
| country | The market. |
| from | The first date, or empty for the default range. |
Definition at line 363 of file traits.hpp.
|
inlinestatic |
Cancels an order.
| client | The client. |
| account | The bound account. |
| amendment | The order. |
Definition at line 414 of file traits.hpp.
|
inlinestatic |
Returns the account number as Alpaca reports it.
| account | The account. |
Definition at line 305 of file traits.hpp.
|
inlinestaticconstexprnoexcept |
Returns where an order goes: Alpaca routes it, and no venue can be asked for.
Definition at line 171 of file traits.hpp.
|
inlinestatic |
Returns the holdings.
| client | The client. |
| account | The bound account. |
Definition at line 382 of file traits.hpp.
|
inlinestatic |
Returns reference data for one instrument.
| client | The client. |
| subject | The instrument. |
Definition at line 352 of file traits.hpp.
Referenced by quote().
|
inlinestatic |
Normalizes Alpaca's acknowledgement; the reference is the order id.
| raw | The client's result. |
Definition at line 215 of file traits.hpp.
|
inlinestatic |
Converts the open orders into working orders, each amendable for its unfilled quantity.
| raw | The client's result. |
Definition at line 232 of file traits.hpp.
|
inlinestatic |
Returns one order by its id.
| client | The client. |
| account | The bound account. |
| id | The order id. |
Definition at line 435 of file traits.hpp.
|
inlinestatic |
Returns a page of order history.
| client | The client. |
| account | The bound account. |
| query | The admitted query. |
Definition at line 446 of file traits.hpp.
|
inlinestatic |
Places an order.
| client | The client. |
| account | The bound account. |
| order | The order. |
Definition at line 393 of file traits.hpp.
|
inlinestatic |
Returns a quote.
| client | The client. |
| instrument | The instrument. |
Definition at line 332 of file traits.hpp.
|
inlinestatic |
Returns the trading connection's rate-limit statistics.
| client | The client. |
Definition at line 322 of file traits.hpp.
|
inlinestatic |
Refuses a replacement; to_replacement refuses first, so a session never calls it.
Definition at line 401 of file traits.hpp.
|
inlinestatic |
Returns the account selector a session binds, which is empty. The argument is not used.
Definition at line 296 of file traits.hpp.
|
inlinestaticconstexpr |
Tests whether this adapter serves bars at an interval.
| interval | The interval. |
Definition at line 161 of file traits.hpp.
|
inlinestatic |
Converts a cancellation of the whole order; a stated quantity is refused.
| ref | The order. |
| instruction | The cancellation. |
Definition at line 265 of file traits.hpp.
|
inlinestatic |
Admits a history query with a limit of 1 to 500 and valid dates.
| query | The query. |
Definition at line 282 of file traits.hpp.
|
inlinestatic |
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).
Definition at line 253 of file traits.hpp.
|
inlinestatic |
Returns the account type, which this adapter does not read (the argument is not used).
Definition at line 313 of file traits.hpp.
|
inlinestatic |
Refuses a bar request this adapter cannot answer as asked, before any I/O.
| query | The query. |
Definition at line 180 of file traits.hpp.
|
inlinestatic |
Refuses a calendar for any market but the US, or with an invalid date.
| country | The market. |
| from | The first date. |
Definition at line 190 of file traits.hpp.
|
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.
| order | The order. |
Definition at line 206 of file traits.hpp.
|
inlinestatic |
Returns the open orders.
| client | The client. |
| account | The bound account. |
Definition at line 424 of file traits.hpp.
|
staticconstexpr |
true: requests return their result directly.
Definition at line 65 of file traits.hpp.
|
staticconstexpr |
A broker that takes orders, not a market-data source.
Definition at line 68 of file traits.hpp.
|
staticconstexpr |
true: /v2/account reports the one account the keys drive.
Definition at line 71 of file traits.hpp.
|
staticconstexpr |
true: each order's qty less its filled_qty.
Definition at line 80 of file traits.hpp.
|
staticconstexpr |
false: one instrument a request.
Definition at line 119 of file traits.hpp.
|
staticconstexpr |
false: one instrument a request.
Definition at line 142 of file traits.hpp.
|
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.
|
staticconstexpr |
false: there is no buying power to express in shares.
Definition at line 130 of file traits.hpp.
|
staticconstexpr |
true: /v3/calendar/XNYS.
Definition at line 145 of file traits.hpp.
|
staticconstexpr |
true: one request covers the whole range.
Definition at line 148 of file traits.hpp.
|
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.
|
staticconstexpr |
true: client_order_id, 1 to 128 characters, unique for the account.
Definition at line 74 of file traits.hpp.
|
staticconstexpr |
false: commission-free, and the per-share FINRA fee on sells has no CommissionRate shape.
Definition at line 136 of file traits.hpp.
|
staticconstexpr |
false: served by Alpaca, not adapted.
Definition at line 110 of file traits.hpp.
|
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.
|
staticconstexpr |
true: up to history_limit rows a page.
Definition at line 101 of file traits.hpp.
|
staticconstexpr |
true: Alpaca filters by symbols=.
Definition at line 107 of file traits.hpp.
|
staticconstexpr |
true: /v2/orders/{id}.
Definition at line 89 of file traits.hpp.
|
staticconstexpr |
false: Alpaca cancels the whole order.
Definition at line 92 of file traits.hpp.
|
staticconstexpr |
false: no daily price band is published for US equities.
Definition at line 113 of file traits.hpp.
|
staticconstexpr |
true: /v2/assets/{symbol}.
Definition at line 139 of file traits.hpp.
|
staticconstexpr |
false: served by Alpaca, not adapted.
Definition at line 116 of file traits.hpp.
|
staticconstexpr |
false: this adapter sends no stop orders.
Definition at line 86 of file traits.hpp.
|
staticconstexpr |
true: /v2/orders?status=open.
Definition at line 77 of file traits.hpp.
|
staticconstexpr |
The most rows one history page may ask for.
Definition at line 104 of file traits.hpp.
Referenced by to_history_query().
|
staticconstexpr |
false: a range is optional.
Definition at line 95 of file traits.hpp.
|
staticconstexpr |
The broker's name.
Definition at line 62 of file traits.hpp.
|
staticconstexpr |
HOLDINGS: each position's qty_available, with the basis AlpacaBlockingClient::holdings states.
Definition at line 133 of file traits.hpp.
|
staticconstexpr |
false: the open listing shows open orders only.
Definition at line 83 of file traits.hpp.