Supported Models
Alpaca
Introduction
This page explains the AlpacaBrokerageModel, including the asset classes it supports, its default security-level models, and its default markets.
SetBrokerageModel(BrokerageName.Alpaca, AccountType.Cash); SetBrokerageModel(BrokerageName.Alpaca, AccountType.Margin);
self.set_brokerage_model(BrokerageName.ALPACA, AccountType.CASH) self.set_brokerage_model(BrokerageName.ALPACA, AccountType.MARGIN)
For more information about this model, see the class reference and implementation.
For more information about this model, see the class reference and implementation.
Orders
The AlpacaBrokerageModel supports several order types, order properties, and most order updates.
Order Types
The following table describes the available order types for each asset class that the AlpacaBrokerageModel supports:
| Order Type | Equity | Equity Options | Index Options | Crypto |
|---|---|---|---|---|
| Market | ![]() | ![]() | ![]() | ![]() |
| Limit | ![]() | ![]() | ![]() | ![]() |
| Stop market | ![]() | |||
| Stop limit | ![]() | ![]() | ||
| Trailing stop | ![]() | |||
| Market on Open | ![]() | |||
| Market on Close | ![]() | |||
| Combo market | ![]() | ![]() | ||
| Combo limit | ![]() | ![]() | ||
| Bracket | ![]() | |||
| One cancels other | ![]() | |||
| One triggers other | ![]() |
Combo orders must have 2 to 4 Option legs.
Order Properties
The AlpacaBrokerageModel supports custom order properties. The following table describes the members of the AlpacaOrderProperties object that you can set to customize order execution.
| Property | Data Type | Description | Default Value |
|---|---|---|---|
TimeInForcetime_in_force | TimeInForce | A TimeInForce instruction to apply to the order. The following instructions are supported:
DayDAY.
| TimeInForce.GoodTilCanceledTimeInForce.GOOD_TIL_CANCELED |
OutsideRegularTradingHoursoutside_regular_trading_hours | bool | A flag to signal that the order may be triggered and filled outside of regular trading hours. Only limit orders with the DayDAY time in force support it. | falseFalse |
public override void Initialize()
{
// Set the default order properties
DefaultOrderProperties = new AlpacaOrderProperties
{
OutsideRegularTradingHours = false,
TimeInForce = TimeInForce.GoodTilCanceled
};
}
public override void OnData(Slice slice)
{
// Use default order order properties
LimitOrder(_symbol, quantity, limitPrice);
// Override the default order properties
LimitOrder(_symbol, quantity, limitPrice,
orderProperties: new AlpacaOrderProperties
{
TimeInForce = TimeInForce.Day
});
LimitOrder(_symbol, quantity, limitPrice,
orderProperties: new AlpacaOrderProperties
{
OutsideRegularTradingHours = true,
TimeInForce = TimeInForce.Day
});
} def initialize(self) -> None:
# Set the default order properties
self.default_order_properties = AlpacaOrderProperties()
self.default_order_properties.outside_regular_trading_hours = False
self.default_order_properties.time_in_force = TimeInForce.GOOD_TIL_CANCELED
def on_data(self, slice: Slice) -> None:
# Use default order order properties
self.limit_order(self._symbol, quantity, limit_price)
# Override the default order properties
order_properties = AlpacaOrderProperties()
order_properties.time_in_force = TimeInForce.DAY
self.limit_order(self._symbol, quantity, limit_price, order_properties=order_properties)
order_properties.outside_regular_trading_hours = True
self.limit_order(self._symbol, quantity, limit_price, order_properties=order_properties)
Contingent Orders
Alpaca accepts contingent orders for Equities with the following rules:
- A set has up to three orders for the same security: a bracket order, an entry order that triggers one exit order, or a one cancels other pair of exit orders.
- An exit order is a limit order (take profit) or a stop market or stop limit order (stop loss).
- A one cancels other pair has one take-profit order and one stop-loss order on the same side, and it exits an existing position.
- You can update the prices of the orders in a set, but not their quantities.
Updates
The AlpacaBrokerageModel supports order updates.
Handling Splits
If you're using raw data normalization and you have active orders with a limit, stop, or trigger price in the market for a US Equity when a stock split occurs, the following properties of your orders automatically adjust to reflect the stock split:
- Quantity
- Limit price
- Stop price
- Trigger price
Fills
The AlpacaBrokerageModel uses the EquityFillModel for Equity trades and the ImmediateFillModel for Option and Crypto trades.
Slippage
The AlpacaBrokerageModel uses the NullSlippageModel.
Fees
The AlpacaBrokerageModel uses the AlpacaFeeModel with the default argument values. We model current Alpaca fees on all assets.
Settlement
The AlpacaBrokerageModel uses the ImmediateSettlementModel for margin accounts and the DelayedSettlementModel with the default settlement rules for cash accounts with Equity and Equity Options.
// For US Equities with a cash account: security.SetSettlementModel(new DelayedSettlementModel(Equity.DefaultSettlementDays, Equity.DefaultSettlementTime)); // For Equity Options with a cash account: security.SetSettlementModel(new DelayedSettlementModel(Option.DefaultSettlementDays, Option.DefaultSettlementTime)); // For remaining cases: security.SetSettlementModel(new ImmediateSettlementModel());
# For US Equities with a cash account: security.set_settlement_model(DelayedSettlementModel(Equity.DEFAULT_SETTLEMENT_DAYS, Equity.DEFAULT_SETTLEMENT_TIME)) # For Equity Options with a cash account: security.set_settlement_model(DelayedSettlementModel(Option.DEFAULT_SETTLEMENT_DAYS, Option.DEFAULT_SETTLEMENT_TIME)) # For remaining cases: security.set_settlement_model(ImmediateSettlementModel())
Margin Interest Rate
The AlpacaBrokerageModel uses the NullMarginInterestRateModel.
Account Currency
The AlpacaBrokerageModel doesn't set a default currency.
To change the algorithm's currency from USD to a different currency, see Set Account Currency.
