Trading and Orders
Financial Advisors
Group Routing
To place trades using a subset of client accounts, create Account Groups in Trader Workstation and then define the InteractiveBrokersOrderProperties
when you create orders.
DefaultOrderProperties = new InteractiveBrokersOrderProperties { FaGroup = "TestGroupEQ", FaMethod = "EqualQuantity", Account = "DU123456" };
self.default_order_properties = InteractiveBrokersOrderProperties() self.default_order_properties.fa_group = "TestGroupEQ" self.default_order_properties.fa_method = "EqualQuantity" self.default_order_properties.account = "DU123456"
SecurityHolding objects aggregate your positions across all the account groups. If you have two groups where group A has 10 shares of SPY and group B has -10 shares of SPY, then self.portfolio["SPY"].quantity
Portfolio["SPY"].Quantity
is zero.
Allocation Methods
LEAN supports several allocation methods for FA group orders. If you intend to use the same group allocation method for every order, set the DefaultOrderProperties
default_order_properties
of your algorithm, which sets the order properties for all of your orders.
public override void Initialize() { // Set the default order properties DefaultOrderProperties = new InteractiveBrokersOrderProperties() { FaGroup = "TestGroupEQ", FaMethod = "EqualQuantity", Account = "DU123456" }; } public override void OnData(Slice slice) { // Use default order order properties LimitOrder(_symbol, quantity, limitPrice); }
def initialize(self) -> None: # Set the default order properties self.default_order_properties = InteractiveBrokersOrderProperties() self.default_order_properties.fa_group = "TestGroupEQ" self.default_order_properties.fa_method = "EqualQuantity" self.default_order_properties.account = "DU123456" def on_data(self, slice: Slice) -> None: # Use default order order properties LimitOrder(_symbol, quantity, limitPrice);
To adjust the order properties of an order, change the DefaultOrderProperties
default_order_properties
or pass an order properties object to the order method. The following sections explain the FA group allocation methods.
Equal Quantity
This group allocation method distributes shares equally between all accounts in the group. When you use this method, you need to specify an order quantity.
For example, say your Account Group includes four accounts and you place an order to buy 400 shares of a stock. In this case, each account receives 100 shares. If your Account Group includes six accounts, each account receives 66 shares, and then 1 share is allocated to each account until all are distributed. After you submit the order, your algorithm receives order events to track the order progress. When all the shares are bought, the order status is OrderStatus.Filled
OrderStatus.FILLED
. If one of the accounts in the group can't afford 10 of the shares it needs to buy, 10 shares are cancelled and you'll only end up buying 390 shares in total.
LimitOrder( _symbol, quantity, limitPrice, orderProperties: new InteractiveBrokersOrderProperties { FaMethod = "EqualQuantity" } );
order_properties = InteractiveBrokersOrderProperties() order_properties.fa_method = "EqualQuantity" self.limit_order(self._symbol, quantity, limit_price, order_properties=order_properties)
Net Liquidation Value
This group allocation method distributes shares based on the net liquidation value of each account. The system calculates ratios based on the net liquidation value in each account and allocates shares based on these ratios. When you use this method, you need to specify an order quantity.
For example, say your account group includes three accounts, A, B and C with Net Liquidation values of $25,000, $50,000 and $100,000, respectively. In this case, the system calculates a ratio of 1:2:4. If you place an order for 700 shares of a stock, it allocates 100 shares to Client A, 200 shares to Client B, and 400 shares to Client C.
LimitOrder(_symbol, quantity, limitPrice, orderProperties: new InteractiveBrokersOrderProperties { FaMethod = "NetLiq" } );
order_properties = InteractiveBrokersOrderProperties() order_properties.fa_method = "NetLiq" self.limit_order(self._symbol, quantity, limit_price, order_properties=order_properties)
Available Equity
This group allocation method distributes shares based on the amount of available equity in each account. The system calculates ratios based on the available equity in each account and allocates shares based on these ratios. When you use this method, you need to specify an order quantity.
For example, say your account group includes three accounts, A, B and C with available equity of $25,000, $50,000 and $100,000, respectively. In this case, the system calculates a ratio of 1:2:4. If you place an order for 700 shares of a stock, it allocates 100 shares to Client A, 200 shares to Client B, and 400 shares to Client C.
LimitOrder(_symbol, quantity, limitPrice, orderProperties: new InteractiveBrokersOrderProperties { FaMethod = "AvailableEquity" } );
order_properties = InteractiveBrokersOrderProperties() order_properties.fa_method = "AvailableEquity" self.limit_order(self._symbol, quantity, limit_price, order_properties=order_properties)
Subscription Requirements
To use FA group orders through our Interactive Brokers integration, you need to connect as a member of a Trading Firm and Institution organization. If you aren't currently on either of these tiers, upgrade your organization.