Clone our Wealth-Lab 8 Extension Demo project on GitHub to get a head start in developing your own Extensions!

Broker Adapter API

A Broker Adapter extension allows WealthLab 9 to connect to a live broker, retrieve account and position information, place and cancel orders, and monitor order status. Once connected, WealthLab tools such as the Strategy Monitor and Streaming Chart can automatically stage or place Strategy-generated Signals through the Broker Adapter.

Build Environment

You can create a Broker Adapter in a .NET development tool such as Visual Studio 2026. Create a class library project that targets .NET10, then reference the WealthLab.Core library DLL that you'll find in the WL9 installation folder.

Your Broker Adapter will be a class in this library that descends from BrokerBase, which is defined in the WealthLab.Core library, in the WealthLab.Backtest namespace. After you implement and build your library, simply copy the resulting assembly DLL into the WL9 installation folder. The next time WL9 starts up, it will discover your Broker Adapter, making it available in appropriate locations of the WL9 user interface.

Visual Studio 2026 Build Environment

Configuring a Broker Adapter

Broker Adapters derive from the BrokerBase class, which in turn derives from Configurable. The Configurable framework provides the standard mechanism for allowing users to configure an extension. By default, BrokerBase sets its ConfigurableType property to ParameterListType. Your Broker Adapter can therefore define its configuration using a collection of Parameter instances. Define these Parameters by overriding GenerateParameters, as described in the Configurable class reference.

Descriptive Properties

The Configurable class also provides properties that determine how your Broker Adapter appears in WealthLab. The most important properties to override are:

  • Name
  • GlyphResource
  • Description
  • URL

Accessing the Host (WL9) Environment

The IHost interface provides access to the current WealthLab environment. Extensions can use it to retrieve application-level information and services, such as the location of the user's WealthLab data folder or the DataSets defined by the user.

You can access the current IHost instance from anywhere in your extension through the WLHost singleton and its Instance property. For example, the following code retrieves the path to the user's WealthLab data folder:

string folder = WLHost.Instance.DataFolder;

Use WLHost.Instance whenever your extension needs access to functionality exposed by the IHost interface.

Connecting to the Broker

protected virtual bool Connect()

WealthLab calls Connect when it needs to establish a connection to the broker. Override this method to perform the actual broker connection and return true if the connection succeeds or false if it fails.

Before attempting the connection, you will typically want to verify that the Broker Adapter has been properly configured. You can inspect its Parameters or Configuration property for the information required to establish the connection.

After a successful connection, call UpdateAccounts to initially populate the Broker Adapter's Accounts collection.

public virtual bool IsConnected

Returns true when the Broker Adapter is currently connected. The default implementation maintains a bool value based on the result returned by Connect. Override this property if your broker API provides a more reliable way to determine the current connection state.

public void Disconnect()

Call Disconnect if your Broker Adapter detects that its connection to the broker has been lost. This notifies WealthLab that the Broker Adapter is no longer connected.

public void DisplayBrokerMessage(string msg, WLColor color, Exception ex = null)

Call DisplayBrokerMessage to report connection or broker-related information to WealthLab. The color parameter convention is:

  • Red for errors
  • Yellow for warnings
  • Green for informational messages

Keep informational messages to a reasonable minimum to avoid unnecessary clutter in the WealthLab Log Viewer.

Account Information

public List<BrokerAccount> Accounts

Returns the collection of BrokerAccount instances associated with the broker. Your Broker Adapter should populate this collection by calling UpdateAccounts after successfully connecting.

public virtual void UpdateAccounts()

Override this method to refresh account balances and broker positions. For each broker account, call FindOrCreateAccount rather than creating a new BrokerAccount instance yourself. WealthLab expects BrokerAccount instances to remain persistent between updates. FindOrCreateAccount automatically adds new accounts to the Accounts collection and clears the account's Positions collection so that you can repopulate it with the broker's current positions.

WealthLab calls UpdateAccounts when the user explicitly requests an account refresh and after trades are filled. After all accounts, balances, and positions have been updated, call AccountsUpdated to notify WealthLab that the refresh is complete.

public BrokerAccount FindOrCreateAccount(string accountID)

Returns the BrokerAccount associated with the specified account ID. If the account does not yet exist, a new BrokerAccount is created and added to the Accounts collection. The method also clears the account's Positions collection. During UpdateAccounts, populate this collection with the current BrokerPosition instances reported by the broker.

public void AccountsUpdated()

Call this method after UpdateAccounts has completely refreshed all accounts and their positions. This notifies WealthLab that the account information has changed and causes open Accounts windows and other relevant interfaces to refresh.

public List<string> AccountNumbers

Returns a list containing the account IDs of all accounts currently associated with the Broker Adapter.

public virtual List<Transaction> GetActiveOrders()

Override this method to return orders that are currently active at the broker, such as working Limit or Stop orders. Create a Transaction instance for each active order and populate the appropriate properties, including:

  • Broker with the instance of your Broker extension (this)
  • Account with the broker account ID
  • BrokerTag with the broker-specific order ID
  • Symbol
  • TransactionType
  • Quantity
  • OrderType
  • OrderPrice

Also establish any internal mapping your Broker Adapter requires to associate the Transaction with the broker's order identifier.

Market and Symbol Information

public virtual int GetSymbolDecimals(string symbol, double price)

Override this method to return the number of decimal places the broker allows for Limit and Stop order prices for the specified symbol and price. WealthLab uses this value to calculate the Transaction OrderPriceAdjusted property. Use OrderPriceAdjusted, rather than the unadjusted order price, when submitting the order in PlaceTrade. The default value is 2 decimal places.

public virtual int GetSymbolQuantityDecimals(string symbol)

Override this method to return the number of decimal places the broker allows for order quantities for the specified symbol. This is especially important for brokers that support fractional shares, cryptocurrency quantities, or other fractional position sizes. WealthLab uses this value to calculate the Transaction QuantityAdjusted property. Use QuantityAdjusted when submitting the order in PlaceTrade. The default value is 0 decimal places.

public virtual MarketDetails GetMarketForSymbol(string symbol)

Override this method to return the MarketDetails instance representing the market in which the specified symbol trades. MarketDetails instances can be obtained through MarketManager, including its Markets collection and FindMarket method. The default implementation returns MarketManager.USAStocks.

public virtual MarketDetails DefaultMarket

Override this property to return the default MarketDetails instance for the Broker Adapter. The default value is MarketManager.USAStocks.

Placing and Canceling Trades

protected abstract void PlaceTrade(Transaction t)

WealthLab calls PlaceTrade whenever an order should be submitted to the broker. The supplied Transaction contains the information required to place the order. Important properties include:

  • MappedSymbol - Use this property instead of Symbol when submitting the symbol to the broker. WealthLab supports symbol mapping between data providers and brokers. Symbol might therefore contain the data provider's symbology, while MappedSymbol contains the broker-specific symbol.
  • TransactionType - Indicates Buy, Sell, Short, or Cover.
  • OrderType - Indicates the requested order type. LimitMove can generally be handled as a Limit order, and MarketClose can be handled as a Market order when native Market-on-Close orders are not being used.
  • QuantityAdjusted - The requested quantity rounded according to the value returned by GetSymbolQuantityDecimals.
  • OrderPriceAdjusted - The Stop or Limit price rounded according to the value returned by GetSymbolDecimals.

Your implementation should submit the order to the broker and associate any broker-generated identifier with the original Transaction. The Transaction BrokerTag property is normally used to store the broker's order ID.

protected abstract void CancelTrade(Transaction t)

WealthLab calls CancelTrade when an active order should be canceled. Use the supplied Transaction, typically its BrokerTag property, to locate the corresponding broker order and submit the cancellation request.

OCO Orders

public virtual bool SupportsOco

Override this property and return true if the broker supports native OCO (One-Cancels-Other) orders.

protected virtual void PlaceOcoTradePair(Transaction t1, Transaction t2)

WealthLab calls this method when two Transactions should be submitted as an OCO pair. This occurs only when SupportsOco returns true and the user has enabled Use OCO orders when possible in Trading Preferences.

Order Replacement

public virtual bool SupportsReplace

Override this property and return true if the broker supports native modification or replacement of an existing order.

protected virtual void ReplaceTrade(Transaction oldOrder, Transaction newOrder)

WealthLab calls this method when an active order should be replaced. This method is called only when SupportsReplace returns true.

Market and Limit on Close Orders

public virtual bool SupportsMOC

Override this property and return true if the broker supports native Market-on-Close orders. If it returns false, WealthLab stages MarketClose orders in the Order Manager with a WaitForClose status and submits them as Market orders shortly before the market closes.

public virtual bool SupportsLOC

Override this property and return true if the broker supports native Limit-on-Close orders. If it returns false, WealthLab stages these orders in the Order Manager with a WaitForClose status and submits them as Limit orders shortly before the market closes.

Validating Exit Orders

public virtual bool AllowExit(BrokerAccount acct, string symbol, PositionType pt)

WealthLab calls this method to determine whether a Sell or Cover order can be placed for a particular account and symbol. The default implementation checks the specified BrokerAccount for a broker position whose symbol and PositionType match the supplied values. Override this method when the broker does not represent holdings using traditional positions. Some cryptocurrency providers, for example, expose coin holdings through account balances rather than positions.

Final Orders

public virtual int FinalOrderDelayMinutes

Some brokers cancel Day orders intended for the next trading session if they are submitted immediately after the current session closes. Orders generated for the final bar of a session can therefore enter the FinalOrder state in the Order Manager. WealthLab waits the number of minutes specified by FinalOrderDelayMinutes after the market close before submitting these orders. The default value is 15 minutes.

Monitoring Order Status

After successfully connecting, your Broker Adapter should establish a mechanism for receiving order status updates from the broker. Depending on the broker API, this might involve a socket connection, events raised by a broker library, or periodic polling of the broker's API.

public void UpdateSignalStatus(Transaction t, SignalStatuses newStatus)

When the broker reports a change to an order's status, call UpdateSignalStatus to communicate the change to the WealthLab Order Manager. Pass the corresponding Transaction, typically located using the order ID stored in BrokerTag, along with the new SignalStatuses value. Available statuses include:

  • Staged
  • Placed
  • Active
  • Filled
  • PartialFilled
  • CancelPending
  • Canceled
  • Error
  • WaitForClose
  • Published

WaitForClose is used for orders that WealthLab is holding until near the market close.

Published is used by signal publishing services that integrate through a Broker Adapter.

When an order is partially or completely filled, populate the Transaction's FillPrice and FillQty properties before calling UpdateSignalStatus.

You can also add information returned by the broker to the Transaction's Messages collection.

Companion Providers

WealthLab can associate a Broker Adapter with companion Streaming and Historical Data Providers. This allows WealthLab to automatically use the appropriate market data provider in broker-related interfaces. For example, the Order Manager can display streaming quotes from the companion Streaming Provider when the corresponding broker is selected and connected.

public virtual string CompanionStreamingProviderName

Override this property to return the Name of the Streaming Provider associated with the Broker Adapter. Return no provider name if the Broker Adapter does not have a companion Streaming Provider.

public virtual string CompanionDataProviderName

Override this property to return the Name of the Historical Data Provider associated with the Broker Adapter. Return no provider name if the Broker Adapter does not have a companion Historical Data Provider.