Brokerages

Prime Brokerages

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 $15B in volume traded on our servers since 2015. Brokerages supply a connection to the exchanges so that you can automate orders using LEAN. You can use multiple data feeds in live trading algorithms.

LEAN can connect to the Bloomberg™ Desktop API (DAPI) through our Terminal Link plug-in. This product 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.

For instructions on using Terminal Link, refer to the CLI documentation. To view the implementation of Terminal Link, see the Lean.Brokerages.TerminalLink repository.

Asset Classes

Terminal Link supports trading Crypto, Equities, Equity Options, Futures, and Future Options.

AddCrypto("BTCUSD", Resolution.Minute, Market.CoinbasePro);

AddEquity("SPY", Resolution.Minute, Market.USA);

AddOption("SPY", Resolution.Minute, Market.USA);

var goldFutures = AddFuture(Futures.Metals.Gold, Resolution.Minute, Market.CME);

AddFutureOption(goldFutures.Symbol, universe => universe.Strikes(-5, +5));
self.AddCrypto("BTCUSD", Resolution.Minute, Market.CoinbasePro)

self.AddEquity("SPY", Resolution.Minute, Market.USA)

self.AddOption("SPY", Resolution.Minute, Market.USA)

gold_futures = self.AddFuture(Futures.Metals.Gold, Resolution.Minute, Market.CME)

self.AddFutureOption(gold_futures.Symbol, lambda universe: universe.Strikes(-5, +5))

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 TypeCryptoEquityEquity OptionsFuturesFutures Options
MarketOrdergreen checkgreen checkgreen checkgreen checkgreen check
LimitOrdergreen checkgreen checkgreen checkgreen checkgreen check
StopMarketOrdergreen checkgreen checkgreen checkgreen checkgreen check
StopLimitOrdergreen checkgreen checkgreen checkgreen checkgreen check
MarketOrder(_symbol, quantity);
LimitOrder(_symbol, quantity, limitPrice);
StopMarketOrder(_symbol, quantity, stopPrice);
StopLimitOrder(_symbol, quantity, stopPrice, limitPrice);
self.MarketOrder(self.symbol, quantity)
self.LimitOrder(self.symbol, quantity, limit_price)
self.StopMarketOrder(self.symbol, quantity, stop_price)
self.StopLimitOrder(self.symbol, quantity, stop_price, limit_price)

Time In Force

Terminal Link supports the following TimeInForce instructions:

  • Day
  • GoodTilCanceled
  • GoodTilDate
public override void Initialize()
{
    // Set the default order properties
    DefaultOrderProperties.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 OrderProperties
               { 
                   TimeInForce = TimeInForce.Day 
               });
    LimitOrder(_symbol, quantity, limitPrice, 
               orderProperties: new OrderProperties
               { 
                   TimeInForce = TimeInForce.GoodTilDate(new DateTime(year, month, day)) 
               });
}
def Initialize(self) -> None:
    # Set the default order properties
    self.DefaultOrderProperties.TimeInForce = TimeInForce.GoodTilCanceled

def OnData(self, slice: Slice) -> None:
    # Use default order order properties
    self.LimitOrder(self.symbol, quantity, limit_price)
    
    # Override the default order properties
    order_properties = OrderProperties()
    order_properties.TimeInForce = TimeInForce.Day
    self.LimitOrder(self.symbol, quantity, limit_price, orderProperties=order_properties)

    order_properties.TimeInForce = TimeInForce.GoodTilDate(datetime(year, month, day))
    self.LimitOrder(self.symbol, quantity, limit_price, orderProperties=order_properties)

Get Open Orders

Terminal Link lets you access open orders.

var ticket = StopLimitOrder(symbol, quantity, stopPrice, limitPrice, tag);
var order = Transactions.GetOrderById(ticket.OrderId);
ticket = self.StopLimitOrder(symbol, quantity, stop_price, limit_price, tag)
order = self.Transactions.GetOrderById(ticket.OrderId)

Monitor Fills

Terminal Link allows you to monitor orders as they fill. Order events are tracked in LEAN and sent to the OnOrderEvent handler.

public override void OnOrderEvent(OrderEvent orderEvent)
{
    var quantity = orderEvent.FillQuantity;
}
def OnOrderEvent(self, orderEvent: OrderEvent) -> None:
    quantity = orderEvent.FillQuantity

Updates

Terminal Link supports order updates. You can define the following members of an UpdateOrderFields object to update active orders:

  • Quantity
  • LimitPrice
  • StopPrice
  • Tag
var ticket = StopLimitOrder(symbol, quantity, stopPrice, limitPrice, tag);
var orderFields = new UpdateOrderFields { 
Quantity = newQuantity,
LimitPrice = newLimitPrice,
StopPrice = newStopPrice,
Tag = newTag
}; ticket.Update(orderFields);
ticket = self.StopLimitOrder(symbol, quantity, stop_price, limit_price, tag)
update_fields = UpdateOrderFields() update_fields.Quantity = new_quantity
update_fields.LimitPrice = new_limit_price
update_fields.StopPrice = new_stop_price update_fields.Tag = new_tag ticket.Update(update_fields)

Cancellations

Terminal Link enables you to cancel open orders. 

var ticket = StopLimitOrder(symbol, quantity, stopPrice, limitPrice, tag);
ticket.Cancel();
ticket = self.StopLimitOrder(symbol, quantity, stop_price, limit_price, tag)
ticket.Cancel()

Fees

Orders filled with Terminal Link are subject to the fees of the Bloomberg Execution Management System.

Historical Data

When LEAN taps into Bloomberg™ via Terminal Link, it can run backtests and research notebooks with rich historical data sourced from the Bloomberg™ Terminal. LEAN provides accurate slippage, spread, and transaction fee models for realistic backtesting. All models are customizable to adapt to your strategy requirements. Historical data is cached locally in an efficient format for quick backtesting in the LEAN engine.

Live Data Feeds

Terminal Link lets you source a live data feed from the Bloomberg™ Terminal for live trading. You also can use the LEAN paper trading functionality to test your strategy on Bloomberg™’s live data feed.

Compliance

Bloomberg™ is not affiliated with QuantConnect, nor does it endorse Terminal Link. All users of the integration must hold a Bloomberg™ License to be defined as an “Entitled User.” All products must be used in accordance with established licensing terms set by Bloomberg™. All data accessed via the Bloomberg™ Desktop API must remain on the host computer. The Bloomberg™ Terminal and the LEAN instance must be on the same computer. The Bloomberg™ Server API cannot be used for black-box trading. Any Bloomberg™ Server API Data usage will require soliciting permission via the Bloomberg™ Permission System. QuantConnect requires installing the LEAN GUI along with any Terminal Link subscription.

The following rules apply:

  • All users of the integration must hold a Bloomberg License to be defined as an "Entitled User".
  • All data accessed via the Bloomberg Desktop API must remain on the host computer. The Bloomberg Terminal and the LEAN instance must be on the same computer.
  • The Bloomberg Server API cannot be used for black-box trading. Any Bloomberg Server API Data usage will require soliciting permission via the Bloomberg Permission System.

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

TechnologyResearchBacktestingPaper TradingLive Trading
Desktop APIgreen checkgreen checkgreen checkgreen check
B.PIPEgreen checkgreen checkgreen checkgreen check
Server APIgreen checkgreen checkgreen check-

CLI Commands

Execute the CLI commands in the following sections to interact with Terminal Link. If you need further assistance, see the CLI Reference.

Run Local Backtests

Launch local backtests with data from the Bloomberg Terminal desktop API. Lean automatically fetches the data required for your backtest.

$ lean backtest "<projectName>" --data-provider "Terminal Link"

Launch Research Notebooks

Start Jupyter Research Notebooks, tapping into the entire QuantConnect API with the data sourced from a Bloomberg Terminal.

$ lean research "<projectName>" --data-provider "Terminal Link"

Deploy Live Algorithms

Launch live trading algorithms to trade with any of the 1300+ routing destinations in the Bloomberg EMSX network.

$ lean live "<projectName>" --brokerage "Terminal Link" --data-feed "Terminal Link"

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: