Brokerages
Bloomberg EMSX
Introduction
QuantConnect enables you to run your algorithms in live mode with real-time market data. We have successfully hosted more than 200,000 live algorithms and have had more than $22B in volume traded on our servers since 2015.
QuantConnect can integrate with the Bloomberg™ Server API (SAPI) or Desktop API (DAPI) in different cloud environments. This integration allows research, backtesting, opitimization, and live trading through the Bloomberg APIs. Terminal Link is in no way affiliated with or endorsed by Bloomberg™; it is simply an add-on. Add Terminal link to your organization to access the 1,300+ prime brokerages in the Bloomberg Execution Management System network.
QuantConnect Cloud only supports routing trades to the Bloomberg™ Server API. In this environment, you can route orders to any of the prime brokerages that Bloomberg supports and you get to leverage the data, server management, and data management from QuantConnect, giving you the best of both worlds. To use Terminal Link, you need to be a member of an organization on the Trading Firm or Institution tier.
Data Providers
To use the Bloomberg™ EMSX network and SAPI on QuantConnect, you must use the QuantConnect data provider.
Orders
Terminal Link enables you to create and manage Bloomberg™ orders.
Order Types
The following table describes the available order types for each asset class that Terminal Link supports:
Order Type | Equity | Equity Options | Futures | Index Options |
---|---|---|---|---|
Market | ||||
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 |
---|---|---|---|
TimeInForce time_in_force | TimeInForce | A TimeInForce instruction to apply to the order. The following instructions are supported:
| TimeInForce.GoodTilCanceled TimeInForce.GOOD_TIL_CANCELED |
Notes notes | string str | The free form instructions that may be sent to the broker. | |
HandlingInstruction handling_instruction | string str | The instructions for handling the order or route. The values can be preconfigured or a value customized by the broker. | |
CustomNotes1 custom_notes_1 | string str | Custom user order notes 1. For more information about custom order notes, see Custom Notes & Free Text Fields in the EMSX API documentation | |
CustomNotes2 custom_notes_2 | string str | Custom user order notes 2. | |
CustomNotes3 custom_notes_3 | string str | Custom user order notes 3. | |
CustomNotes4 custom_notes_4 | string str | Custom user order notes 4. | |
CustomNotes5 custom_notes_5 | string str | Custom user order notes 5. | |
Account account | string str | The EMSX account. | |
Broker broker | string str | The EMSX broker code. | |
Strategy strategy | 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" | |
ExecutionInstruction execution_instruction | string str | The execution instruction field. | |
AutomaticPositionSides automatic_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). | |
PositionSide position_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 AutomaticPositionSides automatic_position_sides .
| |
Exchange exchange | Exchange | Defines the exchange name for sending the order to. |
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.
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.
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.
Fees
Orders filled with Terminal Link are subject to the fees of the Bloomberg™ Execution Management System and your prime brokerage destination. To view how we model their fees, see Fees.
Margin
Set your cash and holdings state in the wizard when you deploy to the Bloomberg™ EMSX environment. We use these states to model buying power and margin calls to ensure your algorithm stays within the margin requirements.
Fills
In live trading, LEAN routes your orders to the exchange or prime brokerage you select. The order fills and then routes back to you.
To view how we model Bloomberg™ Execution Management System order fills, see Fills.
Compliance
Bloomberg™ is not affiliated with QuantConnect, nor does it endorse Terminal Link. A Bloomberg™ SAPI permission and EMSX permission is required to use this brokerage connection, along with a Trading Firm or Institutional subscription on QuantConnect.
The following rules apply:
- All users of the integration must hold a Bloomberg License to be defined as an "Entitled User".
- The Bloomberg SAPI will only be used for order routing and no data is permitted. The Bloomberg SAPI cannot be used for black-box trading.
The following table shows the activities each of the Bloomberg technologies support:
Technology | Research | Backtesting | Paper UAT Trading | Live Trading |
---|---|---|---|---|
Server API |
Set Up SAPI
The following few sections explain how to download the Bloomberg™ Server API (SAPI), install it on a cloud server, and add firewall rules so it can connect to QuantConnect Cloud.
Download SAPI
Follow these steps to download the SAPI:
- Install the Bloomberg™ Terminal.
- Create a Bloomberg™ Terminal account.
- In the Bloomberg™ Terminal, run
WAPI<GO>
. - On the API Developer's Help Site, click .
- On the EMSX API page, under the Server API Process section, click .
- On the Server API Software Install page, click the correct download icons.
- Click .
Install the SAPI
Follow these steps to install the SAPI:
- Spin up an E12x9 AWS instance or higher that your organization controls.
- Run the SAPI installer on the cloud server.
- Ask Bloomberg™ Support to activate your registration key.
- Start the serverapi program.
For more information about this step, see How to install serverapi.exe in the EMSX API Programmers Guide. At the end of the installion, you get a registration key.
On Windows, the default location is C: \ BLP \ ServerApi \ bin \ serverapi.exe.
Set Up Your Account
Follow these steps to set up your SAPI account:
- Contact Bloomberg Support and ask them to enable the Server Side EMSX API.
- Ask Bloomberg Support for your unique user identifier (UUID).
- Contact the EMSX brokerage you plan to use and give them your UUID.
Save it somewhere safe. You will need it when you deploy live algorithms.
Add Firewall Rules
Follow these steps to configure the firewall rules on the AWS instance so that the SAPI can connect to QuantConnect Cloud:
- Click .
- Enter Windows Defender Firewall with Advanced Security and then press Enter.
- In the left panel, click .
- In the right panel, click .
- Follow the prompts to create a program rule for the serverapi.
- In the Windows Defender Firewall with Advanced Security window, double-click the serverapi row.
- In the serverapi window, click the Scope tab.
- In the Remote IP address section, add the QuantConnect Cloud IP address, 207.182.16.137.
- Click .
- Add the QuantConnect Cloud IP address to the other row in the table that has the serverapi name.
Deploy Live Algorithms
You need to set up the Bloomberg SAPI before you can deploy cloud algorithms with Terminal Link.
You must have an available live trading node for each live trading algorithm you deploy.
Follow these steps to deploy a live algorithm:
- Open the project you want to deploy.
- Click the Deploy Live icon.
- On the Deploy Live page, click the Brokerage field and then click from the drop-down menu.
- Click the Connection Type field and then click from the drop-down menu.
- In the Server Auth Id field, enter your unique user identifier (UUID).
- In the EMSX Broker field, enter the EMSX broker to use.
- In the Server Port field, enter the port where SAPI is listening.
- In the Server Host field, enter the public IP address of the SAPI AWS server.
- In the EMSX Account field, enter the account to which LEAN should route orders.
- In the EMSX Team field, enter the team account to receive events of your team's orders.
- In the OpenFIGI Api Key field, enter your API key.
- Click the Environment field and then click one of the options from the drop-down menu.
- Click the Node field and then click the live trading node that you want to use from the drop-down menu.
- (Optional) In the Data Provider section, click and change the data provider or add additional providers.
- If your brokerage account has existing cash holdings, follow these steps (see video):
- In the Algorithm Cash State section, click .
- Click .
- Enter the currency ticker (for example, USD or CAD) and a quantity.
- If your brokerage account has existing position holdings, follow these steps (see video):
- In the Algorithm Holdings State section, click .
- Click .
- Enter the symbol ID, symbol, quantity, and average price.
- (Optional) Set up notifications.
- Configure the Automatically restart algorithm setting.
- Click .
The UUID is a unique integer identifier that's assigned to each Bloomberg Anywhere user. If you don't know your UUID, contact Bloomberg.
The default port is 8194.
The default value is empty, which means LEAN disregards these notifications.
By enabling automatic restarts, the algorithm will use best efforts to restart the algorithm if it fails due to a runtime error. This can help improve the algorithm's resilience to temporary outages such as a brokerage API disconnection.
The deployment process can take up to 5 minutes. When the algorithm deploys, the live results page displays. If you know your brokerage positions before you deployed, you can verify they have been loaded properly by checking your equity value in the runtime statistics, your cashbook holdings, and your position holdings.