Supported Models
Bloomberg
Introduction
This page explains the Bloomberg™ brokerage models, including the asset classes they support, their default security-level models, and their default markets.
// Terminal Link (Bloomberg EMSX) SetBrokerageModel(BrokerageName.TerminalLink, AccountType.Cash); SetBrokerageModel(BrokerageName.TerminalLink, AccountType.Margin); // Bloomberg FIX SetBrokerageModel(BrokerageName.BloombergFix, AccountType.Margin);
# Terminal Link (Bloomberg EMSX) self.set_brokerage_model(BrokerageName.TERMINAL_LINK, AccountType.CASH) self.set_brokerage_model(BrokerageName.TERMINAL_LINK, AccountType.MARGIN) # Bloomberg FIX self.set_brokerage_model(BrokerageName.BLOOMBERG_FIX, AccountType.MARGIN)
Both models support the same asset classes and use the same default security-level models. They differ in the order types they accept, whether they accept order updates, and the order properties class they use. The BloombergFixBrokerageModel only supports margin accounts, so it throws an exception if you pass AccountType.CashAccountType.CASH.
For more information about these models, see their respective class reference and implementation.
| Model | Class Reference | Implementation |
|---|---|---|
TerminalLinkBrokerageModel |
|
|
BloombergFixBrokerageModel |
|
|
Orders
Both Bloomberg™ connections enable you to create and manage Bloomberg™ orders. Terminal Link routes them through the Execution Management System (EMSX), while the Bloomberg™ FIX connection routes them through the FixNet HUB.
Order Types
The following table describes the available order types for each asset class that Terminal Link supports:
| Order Type | Equity | Equity Options | Index Options | Futures |
|---|---|---|---|---|
| Market | ![]() | ![]() | ![]() | ![]() |
| Market on open | ![]() | |||
| Limit | ![]() | ![]() | ![]() | ![]() |
| Stop market | ![]() | ![]() | ![]() | ![]() |
| Stop limit | ![]() | ![]() | ![]() | ![]() |
The following table describes the available order types for each asset class that the Bloomberg™ FIX connection supports:
| Order Type | Equity | Equity Options | Index Options | Futures |
|---|---|---|---|---|
| Market | ![]() | ![]() | ![]() | ![]() |
| Market on open | ![]() | ![]() | ![]() | |
| Market on close | ![]() | ![]() | ![]() | ![]() |
| Limit | ![]() | ![]() | ![]() | ![]() |
| Stop market | ![]() | ![]() | ![]() | ![]() |
| Stop limit | ![]() | ![]() | ![]() | ![]() |
Order Properties
We model custom order properties from the Bloomberg EMSX API. The following table describes the members of the TerminalLinkOrderProperties 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:
| TimeInForce.GoodTilCanceledTimeInForce.GOOD_TIL_CANCELED |
Notesnotes | stringstr | The free form instructions that may be sent to the broker. | |
HandlingInstructionhandling_instruction | stringstr | The instructions for handling the order or route. The values can be preconfigured or a value customized by the broker. | |
CustomNotes1custom_notes_1 | stringstr | Custom user order notes 1. For more information about custom order notes, see Custom Notes & Free Text Fields in the EMSX API documentation | |
CustomNotes2custom_notes_2 | stringstr | Custom user order notes 2. | |
CustomNotes3custom_notes_3 | stringstr | Custom user order notes 3. | |
CustomNotes4custom_notes_4 | stringstr | Custom user order notes 4. | |
CustomNotes5custom_notes_5 | stringstr | Custom user order notes 5. | |
Accountaccount | stringstr | The EMSX account. | |
Brokerbroker | stringstr | The EMSX broker code. | |
LocateBrokerlocate_broker | stringstr |
The EMSX locate broker code that identifies the counterparty the shares are borrowed from for a short equity sale (for example, "BMTB").
Maps to the LocBrkr field on the EMSX trading ticket.
Setting this property (or LocateIdlocate_id) on a short equity sale causes the brokerage to emit EMSX_LOCATE_REQ = "Y" alongside.
| |
LocateIdlocate_id | stringstr | The EMSX locate confirmation/ticket Id that the lending broker returns. Maps to the LocId field on the EMSX trading ticket. | |
IsCfdTradeis_cfd_trade | bool |
A flag that books the order as a contract for differences (CFD) instead of a regular trade.
Maps to the CFD option of the Booking Type drop-down on the EMSX trading ticket and sets the EMSX_CFD_FLAG element.
EMSX applies this flag at the order level, not per security.
A regular trade is the EMSX default, so the brokerage only sends the element when you set this property to trueTrue.
| falseFalse |
Strategystrategy | StrategyParameters | An object that represents the EMSX order strategy details. You must append strategy parameters in the order that the EMSX API expects. The following strategy names are supported: "DMA", "DESK", "VWAP", "TWAP", "FLOAT", "HIDDEN", "VOLUMEINLINE", "CUSTOM", "TAP", "CUSTOM2", "WORKSTRIKE", "TAPNOW", "TIMED", "LIMITTICK", "STRIKE" | |
ExecutionInstructionexecution_instruction | stringstr | The execution instruction field. | |
AutomaticPositionSidesautomatic_position_sides | bool | A flag that determines whether to automatically include the position side in the order direction (buy-to-open, sell-to-close, etc.) instead of the default (buy, sell). | |
PositionSideposition_side | OrderPosition?OrderPosition/NoneType |
An OrderPosition object that specifies the position side in the order direction (buy-to-open, sell-to-close, etc.) instead of the default (buy, sell).
This member has precedence over AutomaticPositionSidesautomatic_position_sides.
| |
Exchangeexchange | Exchange | Defines the exchange name for sending the order to. | |
AdditionalPropertiesadditional_properties | BaseExtendedDictionary<string, string>BaseExtendedDictionary[str, str] | The custom EMSX elements to send with the order. The key is the EMSX element name and the value is the element value. The other order properties take precedence, so an entry that targets an element they already set has no effect. The brokerage skips entries that the EMSX schema doesn't define instead of rejecting the order. | An empty dictionary |
public override void Initialize()
{
// Set the default order properties
DefaultOrderProperties = new TerminalLinkOrderProperties
{
TimeInForce = TimeInForce.GoodTilCanceled,
Strategy = new TerminalLinkOrderProperties.StrategyParameters(
"VWAP",
new List<TerminalLinkOrderProperties.StrategyField>
{
new("09:30:00"),
new("10:30:00"),
new(),
new()
}
)
};
}
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 TerminalLinkOrderProperties
{
TimeInForce = TimeInForce.Day,
Account = "account1"
});
LimitOrder(_symbol, quantity, limitPrice,
orderProperties: new TerminalLinkOrderProperties
{
TimeInForce = TimeInForce.GoodTilDate(new DateTime(year, month, day)),
Account = "account2"
});
} def initialize(self) -> None:
# Set the default order properties
self.default_order_properties = TerminalLinkOrderProperties()
self.default_order_properties.time_in_force = TimeInForce.GOOD_TIL_CANCELED
self.default_order_properties.strategy = TerminalLinkOrderProperties.StrategyParameters(
"VWAP",
[
TerminalLinkOrderProperties.StrategyField("09:30:00"),
TerminalLinkOrderProperties.StrategyField("10:30:00"),
TerminalLinkOrderProperties.StrategyField(),
TerminalLinkOrderProperties.StrategyField()
]
)
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 = TerminalLinkOrderProperties()
order_properties.time_in_force = TimeInForce.DAY
order_properties.account = "account1"
self.limit_order(self._symbol, quantity, limit_price, order_properties=order_properties)
order_properties.time_in_force = TimeInForce.good_til_date(datetime(year, month, day))
order_properties.account = "account2"
self.limit_order(self._symbol, quantity, limit_price, order_properties=order_properties)
The AdditionalPropertiesadditional_properties dictionary lets you set EMSX elements that the preceding properties don't cover, without waiting for a new LEAN release. IsCfdTradeis_cfd_trade reads and writes the EMSX_CFD_FLAG entry of this dictionary, so setting either of them is equivalent. The following example books the orders as CFD trades and adds the odd lot element, which no dedicated property covers:
public override void Initialize()
{
// Set the default order properties to book the orders as CFD trades and to flag them as odd lots
var orderProperties = new TerminalLinkOrderProperties { IsCfdTrade = true };
orderProperties.AdditionalProperties["EMSX_ODD_LOT"] = "1";
DefaultOrderProperties = orderProperties;
} def initialize(self) -> None:
# Set the default order properties to book the orders as CFD trades and to flag them as odd lots
order_properties = TerminalLinkOrderProperties()
order_properties.is_cfd_trade = True
order_properties.additional_properties["EMSX_ODD_LOT"] = "1"
self.default_order_properties = order_properties
The dictionary starts empty and you can't replace it with a plain Python dictionary. To add several elements at once, call the update method with a dictionary. To remove all the elements, call the clear method.
For more information about the format that the Bloomberg EMSX API expects, see Create Order and Route Extended Request in the EMSX API documentation and the createOrderAndRouteWithStrat documentation on the MathWorks website.
The BloombergFixBrokerageModel supports custom order properties. The BloombergFixOrderProperties class inherits the FixOrderProperties class that every FIX connection shares. The following table describes the members of the BloombergFixOrderProperties 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. | TimeInForce.GoodTilCanceledTimeInForce.GOOD_TIL_CANCELED |
HandleInstructionhandle_instruction | char?str/NoneType | The instruction for order handling on the broker floor. The following values are supported:
| |
Notesnotes | stringstr | The free form text instructions that may be sent to the broker. | |
LocateBrokerlocate_broker | stringstr | The broker that the shares are borrowed from for a short sale. Reads and writes the LocateBroker FIX tag 5700. | |
LocateReqdlocate_reqd | stringstr | Whether a locate is required for the short sale, "Y" or "N". Reads and writes the LocateReqd FIX tag 114. | |
AdditionalPropertiesadditional_properties | BaseExtendedDictionary<string, string>BaseExtendedDictionary[str, str] | The custom FIX tags to send with the order. The key is the FIX tag number and the value is the tag value. | An empty dictionary |
public override void Initialize()
{
// Set the default order properties to borrow the shares of short sales from a specific broker
DefaultOrderProperties = new BloombergFixOrderProperties
{
TimeInForce = TimeInForce.GoodTilCanceled,
LocateBroker = "BMTB",
LocateReqd = "Y"
};
} def initialize(self) -> None:
# Set the default order properties to borrow the shares of short sales from a specific broker
self.default_order_properties = BloombergFixOrderProperties()
self.default_order_properties.time_in_force = TimeInForce.GOOD_TIL_CANCELED
self.default_order_properties.locate_broker = "BMTB"
self.default_order_properties.locate_reqd = "Y"
Your FIX counterparty may require tags that the preceding properties don't cover. To send them with your orders, add them to the AdditionalPropertiesadditional_properties dictionary. For example, the following code marks the orders as direct market access (DMA) with tag 9301:
public override void Initialize()
{
// Set the default order properties to mark orders as direct market access (DMA)
var orderProperties = new BloombergFixOrderProperties();
orderProperties.AdditionalProperties["9301"] = "1";
DefaultOrderProperties = orderProperties;
} def initialize(self) -> None:
# Set the default order properties to mark orders as direct market access (DMA)
order_properties = BloombergFixOrderProperties()
order_properties.additional_properties["9301"] = "1"
self.default_order_properties = order_properties
The dictionary starts empty and you can't replace it with a plain Python dictionary. To add several tags at once, call the update method with a dictionary. To remove all the tags, call the clear method.
Get Open Orders
Terminal Link lets you access open orders.
Monitor Fills
Terminal Link allows you to monitor orders as they fill through order events.
Updates
Terminal Link doesn't support order updates, but you can cancel an existing order and then create a new order with the desired arguments. For more information about this workaround, see the Workaround for Brokerages That Don’t Support Updates.
The Bloomberg™ FIX connection does support order updates. The FixNet HUB accepts cancel/replace requests (FIX tag 35=G), so you can update the quantity, limit price, stop price, order type, and time in force of an open order.
Cancellations
Terminal Link enables you to cancel open orders.
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
Brokerage-Side Orders
By default, your algorithm doesn't record orders that you submit to your account by third-parties instead of through LEAN. To accept these orders, create a custom brokerage message handler.
Fills
To view how we model fills in backtests, see Fills.
Slippage
To view how we model slippage in backtests, see Slippage.
Fees
To view how we model fees in backtests, see Fees.
Buying Power
To view how we model buying power in backtests, see Buying Power.
Settlement
To view how we model settlements in backtests, see Settlement.
Margin Interest Rate
To view how we model margin interest rates in backtests, see Margin Interest Rate.
Default Markets
To view the default markets of each asset class when you use either Bloomberg™ connection, see Default Markets.
Account Currency
Neither the TerminalLinkBrokerageModel nor the BloombergFixBrokerageModel sets a default currency.
To change the algorithm's currency from USD to a different currency, see Set Account Currency.
