Brokerages

Bloomberg EMSX

Introduction

QuantConnect enables you to run your algorithms in live mode with real-time market data.

Quant Bridge icon

QuantConnect Cloud supports routing trades to the Bloomberg™ EMSX API Server. In this environment, you can route orders to any of the 1,300+ 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 Quant Bridge, you need to be a member of an organization on the Trading Firm or Institution tier.

QuantConnect Local Platform can integrate with the Bloomberg™ EMSX API Server or Desktop API (DAPI). This integration allows research, backtesting, opitimization, and live trading through the Bloomberg APIs, on-premises. Quant Bridge is in no way affiliated with or endorsed by Bloomberg™; it is simply an add-on.

Account Types

Quant Bridge supports order routing via the Bloomberg™ EMSX API Server. It's treated as a margin account that's similiar to a FIX API, where you set the buying power in the wizard when you're deploying to a professional prime brokerage account.

Asset Classes

Quant Bridge supports trading the following asset classes:

Data Providers

The Bloomberg™ EMSX API Server doesn't provide data, so we recommend the QuantConnect data provider, which is free and supplies US Equities, US Equity Options, US Index Options, and Futures data during live trading. It also supplies SPX and VIX Index data, which SPX and VIX Index Options need for the underlying index. For more information about live data providers, see Datasets.

This limitation applies to QuantConnect Cloud, which connects to the EMSX API Server. Local deployments connect to the Bloomberg™ Desktop API (DAPI) instead, so Quant Bridge can source live and historical data from your Bloomberg™ Terminal, within your Bloomberg™ license permissions. Intraday history goes back up to 6 months, and historical open interest and custom data aren't available. For more information, see Quant Bridge.

Orders

Quant Bridge enables you to create and manage Bloomberg™ orders.

Order Types

The following table describes the available order types for each asset class that Quant Bridge supports:

Order TypeEquityEquity OptionsIndex OptionsFutures
Marketgreen checkgreen checkgreen checkgreen check
Market on opengreen check
Limitgreen checkgreen checkgreen checkgreen check
Stop marketgreen checkgreen checkgreen checkgreen check
Stop limitgreen checkgreen checkgreen checkgreen check

Order Properties

We model custom order properties from the Bloomberg EMSX API. The following table describes the members of the QuantBridgeOrderProperties object that you can set to customize order execution:

PropertyData TypeDescriptionDefault Value
TimeInForcetime_in_forceTimeInForceA TimeInForce instruction to apply to the order. The following instructions are supported:
  • DayDAY
  • GoodTilCanceledGOOD_TIL_CANCELED
  • GoodTilDategood_til_date
TimeInForce.GoodTilCanceledTimeInForce.GOOD_TIL_CANCELED
NotesnotesstringstrThe free form instructions that may be sent to the broker.
HandlingInstructionhandling_instructionstringstrThe instructions for handling the order or route. The values can be preconfigured or a value customized by the broker.
CustomNotes1custom_notes_1stringstrCustom user order notes 1. For more information about custom order notes, see Custom Notes & Free Text Fields in the EMSX API documentation
CustomNotes2custom_notes_2stringstrCustom user order notes 2.
CustomNotes3custom_notes_3stringstrCustom user order notes 3.
CustomNotes4custom_notes_4stringstrCustom user order notes 4.
CustomNotes5custom_notes_5stringstrCustom user order notes 5.
AccountaccountstringstrThe EMSX account.
BrokerbrokerstringstrThe EMSX broker code.
LocateBrokerlocate_brokerstringstr 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_idstringstrThe EMSX locate confirmation/ticket Id that the lending broker returns. Maps to the LocId field on the EMSX trading ticket.
IsCfdTradeis_cfd_tradebool 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
StrategystrategyStrategyParameters 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_instructionstringstrThe execution instruction field.
AutomaticPositionSidesautomatic_position_sidesboolA 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_sideOrderPosition?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.
ExchangeexchangeExchangeDefines the exchange name for sending the order to.
AdditionalPropertiesadditional_propertiesBaseExtendedDictionary<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

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:

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.

Get Open Orders

Quant Bridge lets you access open orders.

Monitor Fills

Quant Bridge allows you to monitor orders as they fill through order events.

Updates

Quant Bridge 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

Quant Bridge 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 Quant Bridge 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 Quant Bridge. You need Bloomberg™ EMSX and EMSX API Server permissions to use this brokerage connection, 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™ EMSX API Server is for order routing only. It doesn't provide data and can't be used for black-box trading.

The following table shows the activities each of the Bloomberg technologies support:

TechnologyResearchBacktestingPaper UAT TradingLive Trading
EMSX API Servergreen checkgreen checkgreen checkgreen check

Set Up EMSX API Server

The following few sections explain how to download the Bloomberg™ EMSX API Server, install it on a cloud server, and add firewall rules so it can connect to QuantConnect Cloud.

Download the EMSX API Server

Follow these steps to download the EMSX API Server:

  1. Install the Bloomberg™ Terminal.
  2. Create a Bloomberg™ Terminal account.
  3. In the Bloomberg™ Terminal, run WAPI<GO>.
  4. On the API Developer's Help Site, click EMSX API.
  5. On the EMSX API page, under the Server API Process section, click Link.
  6. On the Server API Software Install page, click the correct download icons.
  7. Click System Requirements.

Install the EMSX API Server

Follow these steps to install the EMSX API Server:

  1. Spin up an E12x9 AWS instance or higher that your organization controls.
  2. Run the EMSX API Server installer on the cloud server.
  3. 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.

  4. Ask Bloomberg™ Support to activate your registration key.
  5. Start the serverapi program.
  6. On Windows, the default location is C: \ BLP \ ServerApi \ bin \ serverapi.exe.

Set Up Your Account

Follow these steps to set up your EMSX API Server account:

  1. Contact Bloomberg Support and ask them to enable the Server Side EMSX API.
  2. Ask Bloomberg Support for your unique user identifier (UUID).
  3. Save it somewhere safe. You will need it when you deploy live algorithms.

  4. Contact the EMSX brokerage you plan to use and give them your UUID.

Add Firewall Rules

Follow these steps to configure the firewall rules on the AWS instance so that the EMSX API Server can connect to QuantConnect Cloud:

  1. Click Start.
  2. Enter Windows Defender Firewall with Advanced Security and then press Enter.
  3. In the left panel, click Inbound Rules.
  4. In the right panel, click New Rule....
  5. Follow the prompts to create a program rule for the serverapi.
  6. In the Windows Defender Firewall with Advanced Security window, double-click the serverapi row.
  7. In the serverapi window, click the Scope tab.
  8. In the Remote IP address section, add the QuantConnect Cloud IP address, 207.182.16.137.
  9. Click OK.
  10. 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™ EMSX API Server before you can deploy cloud algorithms with Quant Bridge.

You must have an available live trading node for each live trading algorithm you deploy.

Follow these steps to deploy a live algorithm:

  1. Open the project you want to deploy.
  2. Click the Lightning icon Deploy Live icon.
  3. On the Deploy Live page, click the Brokerage field and then click Quant Bridge from the drop-down menu.
  4. Click the Connection Type field and then click SAPI from the drop-down menu.
  5. In the Server Auth Id field, enter your unique user identifier (UUID).
  6. The UUID is a unique integer identifier that's assigned to each Bloomberg Anywhere user. If you don't know your UUID, contact Bloomberg.

  7. In the EMSX Broker field, enter the EMSX broker to use.
  8. In the Server Port field, enter the port where the EMSX API Server is listening.
  9. The default port is 8194.

  10. In the Server Host field, enter the public IP address of the AWS instance that runs the EMSX API Server.
  11. In the EMSX Account field, enter the account to which LEAN should route orders.
  12. In the EMSX Team field, enter the team account to receive events of your team's orders.
  13. The default value is empty, which means LEAN disregards these notifications.

  14. In the OpenFIGI Api Key field, enter your API key.
  15. Click the Environment field and then click one of the options from the drop-down menu.
  16. In the Region section, click the region where you want to run the algorithm.
  17. Click the Node field and then click the live trading node that you want to use from the drop-down menu.
  18. (Optional) In the Data Provider section, click Show and change the data provider or add additional providers.
  19. If your brokerage account has existing cash holdings, follow these steps (see video):
    1. In the Algorithm Cash State section, click Show.
    2. Click Add Currency.
    3. Enter the currency ticker (for example, USD or CAD) and a quantity.
  20. If your brokerage account has existing position holdings, follow these steps (see video):
    1. In the Algorithm Holdings State section, click Show.
    2. Click Add Holding.
    3. Enter the symbol ID, symbol, quantity, and average price.
  21. (Optional) Set up notifications.
  22. Configure the Automatically restart algorithm setting.
  23. 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.

  24. Click Deploy.

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.

Restarts, including automatic restarts and redeployments, don't save the state of your algorithm. To learn what a restart recovers and how to persist the rest, see State Persistence.

Deployment Details

When you deploy a live algorithm with Quant Bridge, the brokerage shares some details of the deployment, like the account it trades. Use them to tell concurrent deployments apart or to check that the algorithm connected to the account you expect. The details never include credentials.

The following table describes the deployment details that Quant Bridge shares:

KeyDescription
quant-bridge-server-auth-idThe Server Auth Id, which is the unique user identifier (UUID) of the Bloomberg Anywhere user.
quant-bridge-emsx-brokerThe EMSX broker that receives the orders.
quant-bridge-emsx-accountThe EMSX account to which LEAN routes orders.
quant-bridge-emsx-teamThe EMSX team account that receives events of your team's orders. It's empty if you didn't set one.

The DeploymentDetailsdeployment_details property of your algorithm is a read-only dictionary of the details. LEAN populates it before it calls the Initializeinitialize method, so you can read it anywhere in your algorithm.

var deploymentDetails = DeploymentDetails.Select(kvp => $"{kvp.Key}:{kvp.Value}");
Log($"deploymentDetails: {string.Join(", ", deploymentDetails)}");
deployment_details = [f'{kvp.key}:{kvp.value}' for kvp in self.deployment_details]
self.log(f'deployment_details: {deployment_details}')

The /live/read API endpoint also returns the details in its deploymentDetails field, so you can read them outside of the algorithm.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: