Skip to main content

Interface: IBrokerTerminal

Broker.IBrokerTerminal

The Broker API is a key component that enables trading. Its main purpose is to connect TradingView charts with your trading logic. Refer to the Core trading concepts article for more information.

Hierarchy​

Methods​

accountManagerInfo​

accountManagerInfo(): AccountManagerInfo

The library calls accountManagerInfo to get information required for building the Account Manager.

Returns​

AccountManagerInfo

Inherited from​

IBrokerCommon.accountManagerInfo


accountsMetainfo​

accountsMetainfo(): Promise<AccountMetainfo[]>

The library calls accountsMetainfo to get a list of accounts for a particular user. The method should return an array that contains an ID and name for each account.

Note that if accountsMetainfo returns an array containing more than one element, you should implement the setCurrentAccount method. Refer to Multiple accounts for more information.

Returns​

Promise<AccountMetainfo[]>

Inherited from​

IBrokerAccountInfo.accountsMetainfo


cancelOrder​

cancelOrder(orderId): Promise<void>

The library calls cancelOrder to request canceling an order. You should handle this request on your backend side and provide the library with a new order state. To do this, call the IBrokerConnectionAdapterHost.orderUpdate method right afterwards.

Parameters​

NameTypeDescription
orderIdstringThe ID of the order to cancel.

cancelOrders​

Optional

cancelOrders(symbol, side, ordersIds): Promise<void>

The library calls cancelOrders to request canceling multiple orders for a symbol. You should handle this request on your backend side and provide the library with a new order states. To do this, call the IBrokerConnectionAdapterHost.orderUpdate method right afterwards.

cancelOrders is only called when users click the CXL all button in the Depth of Market widget.

Parameters​

NameTypeDescription
symbolstringThe symbol identifier.
sideSideAn order side.
ordersIdsstring[]IDs of the orders to cancel. The orders are selected based on the specified symbol and side.

chartContextMenuActions​

chartContextMenuActions(context, options?): Promise<ActionMetaInfo[]>

The library calls chartContextMenuActions when users open the context menu on the chart. This method also renders the Trade button in the context menu.

This method should return an array of ActionMetaInfo elements, each of them representing one context menu item.

Parameters​

NameTypeDescription
contextTradeContextA context object passed by the library.
options?DefaultContextMenuActionsParamsDefault options for the context menu action parameters.

Returns​

Promise<ActionMetaInfo[]> — A promise that resolves to an array of ActionMetaInfo, which may be empty. In that case, the Trade button will be removed from the context menu.

Inherited from​

IBrokerCommon.chartContextMenuActions


closeIndividualPosition​

Optional

closeIndividualPosition(individualPositionId, amount?, confirmId?): Promise<void>

The library calls closeIndividualPosition if the BrokerConfigFlags.supportCloseIndividualPosition or BrokerConfigFlags.supportPartialCloseIndividualPosition configuration flag is true. closeIndividualPosition allows closing an individual position by ID.

Note that the library expects you to call the IBrokerConnectionAdapterHost.positionUpdate method right afterwards. Otherwise, the library will return a timeout issue.

Parameters​

NameTypeDescription
individualPositionIdstringThe individual position ID.
amount?numberThe amount is specified if supportPartialCloseIndividualPosition is true and the user wants to close only part of the individual position.
confirmId?stringThe ID of the confirmed close position preview. This parameter is passed if supportPreviewClosePosition is true.

closePosition​

Optional

closePosition(positionId, amount?, confirmId?): Promise<void>

The library calls closePosition to request closing a position by ID. You should handle this request on your backend side and provide the library with a new position state. To do this, call the IBrokerConnectionAdapterHost.positionUpdate method right afterwards. Otherwise, the library will return a timeout issue.

closePosition is only called if the BrokerConfigFlags.supportClosePosition or BrokerConfigFlags.supportPartialClosePosition configuration flag is true.

Parameters​

NameTypeDescription
positionIdstringThe position ID.
amount?numberThe amount is specified if supportPartialClosePosition is true and the user wants to close only part of the position.
confirmId?stringThe ID of the confirmed close position preview. This parameter is passed if supportPreviewClosePosition is true.

connectionStatus​

connectionStatus(): ConnectionStatus

Defines a connection status for the Broker API. If any other value than 1 ("Connected") is returned, the Account Manager will display an endless spinner instead of users' trading data. If you want to handle other scenarios, for example when the status is disconnected, you need to manage this scenario within your implementation and use the IBrokerConnectionAdapterHost.connectionStatusUpdate method.

If the method is not implemented or returns a value other than 1, the following error will appear in the console: Method connectionStatus is not properly implemented.

Returns​

ConnectionStatus

Inherited from​

IBrokerCommon.connectionStatus


currentAccount​

currentAccount(): AccountId

The library calls currentAccount to get the current account's ID.

Returns​

AccountId

Inherited from​

IBrokerAccountInfo.currentAccount


editIndividualPositionBrackets​

Optional

editIndividualPositionBrackets(individualPositionId, brackets): Promise<void>

This method is called if the BrokerConfigFlags.supportIndividualPositionBrackets configuration flag is on. It displays a dialog that enables take-profit and stop-loss editing.

Note that the library expects you to call the IBrokerConnectionAdapterHost.positionUpdate method right afterwards.

Parameters​

NameTypeDescription
individualPositionIdstringID of existing individual position to be modified
bracketsBracketsnew Brackets to be set for the individual position

editPositionBrackets​

Optional

editPositionBrackets(positionId, brackets, customFields?): Promise<void>

The library calls editPositionBrackets if the BrokerConfigFlags.supportPositionBrackets configuration flag is true. It shows a dialog that enables take-profit and stop-loss editing.

Note that the library expects you to call the IBrokerConnectionAdapterHost.positionUpdate method right afterwards.

Parameters​

NameTypeDescription
positionIdstringThe ID of the existing position to be modified.
bracketsBracketsNew brackets to be set for the position.
customFields?CustomInputFieldsValuesCustom fields to display in the dialog.

executions​

executions(symbol): Promise<Execution[]>

The library calls executions to request executions for the specified symbol. If you want executions to be displayed on the chart, set the BrokerConfigFlags.supportExecutions to true.

Parameters​

NameTypeDescription
symbolstringThe symbol identifier.

Returns​

Promise<Execution[]>

Inherited from​

IBrokerCommon.executions


formatter​

Optional

formatter(symbol, alignToMinMove): Promise<INumberFormatter>

Provide a custom price formatter for the specified symbol.

Parameters​

NameTypeDescription
symbolstringsymbol identifier
alignToMinMovebooleanalign formatted number to the minimum movement amount of the symbol

Returns​

Promise<INumberFormatter>

Inherited from​

IBrokerCommon.formatter


getOrderDialogOptions​

Optional

getOrderDialogOptions(symbol): Promise<OrderDialogOptions>

Implement this method if you want to add custom fields to the standard Order Ticket.

Use the symbol parameter to return customization options for a particular symbol.

Parameters​

NameTypeDescription
symbolstringsymbol identifier

Returns​

Promise<OrderDialogOptions>

Inherited from​

IBrokerCommon.getOrderDialogOptions


getPositionDialogOptions​

Optional

getPositionDialogOptions(symbol): Promise<PositionDialogOptions>

Implement this method if you want to customize the position dialog.

Use the symbol parameter to return customization options for a particular symbol.

Parameters​

NameTypeDescription
symbolstringsymbol identifier

Returns​

Promise<PositionDialogOptions>

Inherited from​

IBrokerCommon.getPositionDialogOptions


getSymbolSpecificTradingOptions​

Optional

getSymbolSpecificTradingOptions(symbol): Promise<SymbolSpecificTradingOptions>

Implement this method if you want to have custom options available for different symbols.

Parameters​

NameTypeDescription
symbolstringsymbol identifier

Returns​

Promise<SymbolSpecificTradingOptions>

Inherited from​

IBrokerCommon.getSymbolSpecificTradingOptions


individualPositions​

Optional

individualPositions(): Promise<IndividualPosition[]>

Called by Trading Platform to request individual positions. Required if the BrokerConfigFlags.supportPositionNetting flag is set to true.

Returns​

Promise<IndividualPosition[]>

Inherited from​

IBrokerCommon.individualPositions


isTradable​

isTradable(symbol): Promise<boolean | IsTradableResult>

The library calls isTradable to check if a symbol can be traded. If the method returns false, users will see the Non-tradable symbol message in the UI when creating orders. You can also display a custom message with the reason why the symbol cannot be traded and the possible solution to resolve the issue. To do this, return an IsTradableResult object.

Parameters​

NameTypeDescription
symbolstringThe symbol identifier.

Returns​

Promise<boolean | IsTradableResult>

Inherited from​

IBrokerCommon.isTradable


leverageInfo​

Optional

leverageInfo(leverageInfoParams): Promise<LeverageInfo>

This method is called to receive leverageInfo from the broker.

Parameters​

NameTypeDescription
leverageInfoParamsLeverageInfoParamsinformation about the specific symbol to provide leverage information for

Returns​

Promise<LeverageInfo>


modifyOrder​

modifyOrder(order, confirmId?): Promise<void>

The library calls modifyOrder to request modifying an existing order. You should handle this request on your backend side and provide the library with a new order state. To do this, call the IBrokerConnectionAdapterHost.orderUpdate method right afterwards. Otherwise, the library will return a timeout issue.

Note that market orders cannot be modified.

To enable an order preview before modification, set the BrokerConfigFlags.supportModifyOrderPreview configuration flag to true. Refer to Enable order preview for more information.

Parameters​

NameTypeDescription
orderOrderOrder information.
confirmId?stringThe ID of the confirmed order. This parameter is passed if supportModifyOrderPreview is true.

orders​

orders(): Promise<Order[]>

The library calls orders to request data on the user's active orders. This data is displayed on the Orders and Positions pages of the Account Manager.

Returns​

Promise<Order[]>

Inherited from​

IBrokerCommon.orders


ordersHistory​

Optional

ordersHistory(): Promise<Order[]>

The library calls ordersHistory to retrieve past orders for display on the History page of the Account Manager. This method is required because the BrokerConfigFlags.supportOrdersHistory flag is enabled by default. If the method is not implemented while the flag is enabled, the Account Manager will not function. For details, refer to the History section.

Note that returned orders must have a final status: rejected, filled, or cancelled.

Returns​

Promise<Order[]>

Inherited from​

IBrokerCommon.ordersHistory


placeOrder​

placeOrder(order, confirmId?): Promise<PlaceOrderResult>

The library calls placeOrder to request placing an order pre-filled with partial or complete information. You should handle this request on your backend side. For more information, refer to Order creation.

To display an order preview before placing it, set BrokerConfigFlags.supportPlaceOrderPreview to true. Refer to Enable order preview for more information.

Parameters​

NameTypeDescription
orderPreOrderOrder information.
confirmId?stringThe ID of the confirmed order. This parameter is passed if supportPlaceOrderPreview is true.

Returns​

Promise<PlaceOrderResult> — An object with the order ID.


positions​

Optional

positions(): Promise<Position[]>

Called by Trading Platform to request positions. Required if the BrokerConfigFlags.supportPositions flag is set to true.

Returns​

Promise<Position[]>

Inherited from​

IBrokerCommon.positions


previewLeverage​

Optional

previewLeverage(leverageSetParams): Promise<LeveragePreviewResult>

This method is called to receive LeveragePreviewResult object which holds messages about the leverage value set by the user.

Parameters​

NameTypeDescription
leverageSetParamsLeverageSetParamsleverageSetParams is an object similar to leverageInfoParams, but contains an additional leverage: number field, which holds the leverage value set by the user.

Returns​

Promise<LeveragePreviewResult>


previewOrder​

Optional

previewOrder(order): Promise<OrderPreviewResult>

The library calls previewOrder to show an order preview when a user clicks Buy order or Modify order in the Order Ticket. To enable order preview, set the BrokerConfigFlags.supportPlaceOrderPreview or BrokerConfigFlags.supportModifyOrderPreview configuration flag to true.

This method returns estimated commission, fees, margin, and other information for the order without it actually being placed.

Parameters​

NameTypeDescription
orderPreOrderOrder information.

Returns​

Promise<OrderPreviewResult>


quantityFormatter​

Optional

quantityFormatter(symbol): Promise<INumberFormatter>

Provide a custom quantity formatter for the specified symbol.

Parameters​

NameTypeDescription
symbolstringsymbol identifier

Returns​

Promise<INumberFormatter>

Inherited from​

IBrokerCommon.quantityFormatter


reversePosition​

Optional

reversePosition(positionId): Promise<void>

This method is called if the BrokerConfigFlags.supportNativeReversePosition configuration flag is on. It allows reversing the position by ID.

Note that the library expects you to call the IBrokerConnectionAdapterHost.positionUpdate method right afterwards. Otherwise, the library will return a timeout issue.

Parameters​

NameTypeDescription
positionIdstringposition

setCurrentAccount​

Optional

setCurrentAccount(id): void

The library calls setCurrentAccount when users switch accounts using the drop-down menu in the Account Manager. This method provides your backend server with the ID of the selected account.

Note that setCurrentAccount is required if accountsMetainfo returns an array containing more than one element. Refer to Multiple accounts for more information.

Parameters​

NameTypeDescription
idAccountIdThe ID of the selected account.

Returns​

void

Inherited from​

IBrokerAccountInfo.setCurrentAccount


setLeverage​

Optional

setLeverage(leverageSetParams): Promise<LeverageSetResult>

This method is called to send user's leverage value to the broker. The value should be verified and corrected on the broker's side if required, and sent back in the response.

Parameters​

NameTypeDescription
leverageSetParamsLeverageSetParamsleverageSetParams is an object similar to leverageInfoParams, but contains an additional leverage: number field, which holds the leverage value set by the user.

Returns​

Promise<LeverageSetResult>


spreadFormatter​

Optional

spreadFormatter(symbol): Promise<INumberFormatter>

Provide a custom spread formatter for the specified symbol.

Parameters​

NameTypeDescription
symbolstringsymbol identifier

Returns​

Promise<INumberFormatter>

Inherited from​

IBrokerCommon.spreadFormatter


subscribeEquity​

Optional

subscribeEquity(): void

The method should be implemented if you use the standard Order Ticket and support stop loss. Equity is used to calculate Risk in Percent.

Once this method is called the broker should provide equity (Balance + P/L) updates via IBrokerConnectionAdapterHost.equityUpdate method.


subscribeMarginAvailable​

Optional

subscribeMarginAvailable(symbol): void

The library calls subscribeMarginAvailable to request margin updates for the given symbol to display the margin meter in the Order Ticket. Once called, your implementation should provide the current margin available value via IBrokerConnectionAdapterHost.marginAvailableUpdate.

Parameters​

NameTypeDescription
symbolstringsymbol identifier

subscribePipValue​

Optional

subscribePipValue(symbol): void

Use this method to enable dynamic updates of the pip value defined in InstrumentInfo.pipValue. The pip value is displayed in the Order info section of the Order Ticket and is used to calculate the trade value and risks. Once subscribePipValue is called, your Broker API implementation should provide pip value updates through the IBrokerConnectionAdapterHost.pipValueUpdate method.

If subscribePipValue is not implemented, the static value from InstrumentInfo.pipValue is displayed in the UI.

Parameters​

NameTypeDescription
symbolstringsymbol identifier

symbolInfo​

symbolInfo(symbol): Promise<InstrumentInfo>

The library calls symbolInfo to request symbol information for the Order Ticket and Depth of Market widget.

Parameters​

NameTypeDescription
symbolstringThe symbol identifier.

Returns​

Promise<InstrumentInfo>

Inherited from​

IBrokerCommon.symbolInfo


unsubscribeEquity​

Optional

unsubscribeEquity(): void

The method should be implemented if you use the standard Order Ticket and support stop loss.

Once this method is called the broker should stop providing equity updates.


unsubscribeMarginAvailable​

Optional

unsubscribeMarginAvailable(symbol): void

The library calls unsubscribeMarginAvailable when it no longer needs margin available updates for the given symbol. Once called, your implementation should stop providing updates via IBrokerConnectionAdapterHost.marginAvailableUpdate for this symbol.

Parameters​

NameTypeDescription
symbolstringsymbol identifier

unsubscribePipValue​

Optional

unsubscribePipValue(symbol): void

The method should be implemented if you use a standard Order Ticket and implement subscribePipValue.

Once this method is called the broker should stop providing pipValue updates.

Parameters​

NameTypeDescription
symbolstringsymbol identifier