Skip to main content

Interface: IBrokerWithoutRealtime

Broker.IBrokerWithoutRealtime

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

This function should return the information that will be used to build 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 User accounts for more information.

Returns

Promise<AccountMetainfo[]>

Inherited from

IBrokerAccountInfo.accountsMetainfo


cancelOrder

cancelOrder(orderId): Promise<void>

This method is called to cancel a single order with the given id.

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

Parameters

NameTypeDescription
orderIdstringID for the order to cancel

Returns

Promise<void>


cancelOrders

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

This method is called to cancel multiple orders for a symbol and side. The ordersIds parameter should contain the list of order ids to be cancelled.

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

Parameters

NameTypeDescription
symbolstringsymbol identifier
sideSideorder side
ordersIdsstring[]ids already collected by symbol and side

Returns

Promise<void>


chartContextMenuActions

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

Chart can have a sub-menu Trading in the context menu. This method should return an array of ActionMetaInfo elements, each of them representing one context menu item.

Parameters

NameTypeDescription
contextTradeContextcontext object passed by a browser
options?DefaultContextMenuActionsParamsdefault options for the context menu action parameters

Returns

Promise<ActionMetaInfo[]>

Inherited from

IBrokerCommon.chartContextMenuActions


closeIndividualPosition

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

This method is called if the BrokerConfigFlags.supportCloseIndividualPosition or BrokerConfigFlags.supportPartialCloseIndividualPosition configuration flag is on. It allows closing the 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
individualPositionIdstringIndividual position ID.
amount?numberThe amount is specified if supportPartialCloseIndividualPosition is true and the user wants to close only part of the individual position.

Returns

Promise<void>


closePosition

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

This method is called if the BrokerConfigFlags.supportClosePosition or BrokerConfigFlags.supportPartialClosePosition configuration flag is on. It allows closing 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 ID.
amount?numberThe amount is specified if supportPartialClosePosition is true and the user wants to close only part of the position.

Returns

Promise<void>


connectionStatus

connectionStatus(): ConnectionStatus

Defines the connection status for the Broker API. You don't need to return values other than 1 (Connected) since the broker is already connected when you create the widget.

If the method is not implemented, the Account Manager will have a spinner instead of the user's trading data. In the console, the Trading.Core:Broker broker creation error will also be displayed.

Returns

ConnectionStatus

Inherited from

IBrokerCommon.connectionStatus


currentAccount

currentAccount(): AccountId

The library calls currentAccount to get the current account ID.

Returns

AccountId

Inherited from

IBrokerAccountInfo.currentAccount


editIndividualPositionBrackets

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

Returns

Promise<void>


editPositionBrackets

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

This method is called if the BrokerConfigFlags.supportPositionBrackets configuration flag is on. 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
positionIdstringis an ID of an existing position to be modified
bracketsBracketsnew Brackets to be set for the position
customFields?CustomInputFieldsValuescustom fields to display in the dialog

Returns

Promise<void>


executions

executions(symbol): Promise<Execution[]>

Called by Trading Platform to request executions for the specified symbol

Parameters

NameTypeDescription
symbolstringsymbol identifier

Returns

Promise<Execution[]>

Inherited from

IBrokerCommon.executions


formatter

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

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

getPositionDialogOptions(): PositionDialogOptions

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

Returns

PositionDialogOptions

Inherited from

IBrokerCommon.getPositionDialogOptions


getSymbolSpecificTradingOptions

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

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 this method 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 show 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
symbolstringsymbol identifier

Returns

Promise<boolean | IsTradableResult>

Inherited from

IBrokerCommon.isTradable


leverageInfo

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>

Method is called when a user wants to modify an existing order.

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

To enable order preview before modifying it, set BrokerConfigFlags.supportModifyOrderPreview to true.

Parameters

NameTypeDescription
orderOrderorder information
confirmId?stringis passed if supportModifyOrderPreview configuration flag is on.

Returns

Promise<void>


orders

orders(): Promise<Order[]>

Called by Trading Platform to request orders

Returns

Promise<Order[]>

Inherited from

IBrokerCommon.orders


ordersHistory

ordersHistory(): Promise<Order[]>

This method is called by the Trading Platform to request orders history. It is expected that returned orders will have a final status (rejected, filled, cancelled).

This method is optional. If you don't support orders history, please set the BrokerConfigFlags.supportOrdersHistory flag to false.

Returns

Promise<Order[]>

Inherited from

IBrokerCommon.ordersHistory


placeOrder

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

Method is called when a user wants to place an order. Order is pre-filled with partial or complete information. This function returns an object with the order ID. To enable order preview before placing it, set BrokerConfigFlags.supportPlaceOrderPreview to true.

Parameters

NameTypeDescription
orderPreOrderorder information
confirmId?stringis passed if the supportPlaceOrderPreview configuration flag is on.

Returns

Promise<PlaceOrderResult>

PlaceOrderResult, which should include an orderId


positions

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

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

previewOrder(order): Promise<OrderPreviewResult>

Returns estimated commission, fees, margin, and other information for the order without it actually being placed. The method is called if the BrokerConfigFlags.supportPlaceOrderPreview or BrokerConfigFlags.supportModifyOrderPreview configuration flag is on.

Parameters

NameTypeDescription
orderPreOrderorder information

Returns

Promise<OrderPreviewResult>


quantityFormatter

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

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

Returns

Promise<void>


setCurrentAccount

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

NameType
idAccountId

Returns

void

Inherited from

IBrokerAccountInfo.setCurrentAccount


setLeverage

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

spreadFormatter(symbol): Promise<INumberFormatter>

Provide a custom spread formatter for the specified symbol.

Parameters

NameTypeDescription
symbolstringsymbol identifier

Returns

Promise<INumberFormatter>

Inherited from

IBrokerCommon.spreadFormatter


subscribeDOM

subscribeDOM(symbol): void

Library is requesting that realtime DOM (Depth of Market) updates should be supplied for this symbol

Parameters

NameTypeDescription
symbolstringsymbol identifier

Returns

void


subscribeEquity

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.

Returns

void


subscribeMarginAvailable

subscribeMarginAvailable(symbol): void

The method should be implemented if you use the standard Order Ticket and want to show the margin meter.

Once this method is called the broker should provide margin available updates via IBrokerConnectionAdapterHost.marginAvailableUpdate method.

Parameters

NameTypeDescription
symbolstringsymbol identifier

Returns

void


subscribePipValue

subscribePipValue(symbol): void

The method should be implemented if you use a standard Order Ticket. pipValues is displayed in the Order info and it is used to calculate the Trade Value and risks. If this method is not implemented then pipValue from the symbolInfo is used in the order panel/dialog.

Once this method is called the broker should provide pipValue updates via IBrokerConnectionAdapterHost.pipValueUpdate method.

Parameters

NameTypeDescription
symbolstringsymbol identifier

Returns

void


symbolInfo

symbolInfo(symbol): Promise<InstrumentInfo>

Called by the Order Ticket and DOM panel to get symbol information.

Parameters

NameTypeDescription
symbolstringsymbol identifier

Returns

Promise<InstrumentInfo>

Inherited from

IBrokerCommon.symbolInfo


unsubscribeDOM

unsubscribeDOM(symbol): void

Library is notifying that realtime DOM (Depth of Market) updates are no longer required for this symbol.

Parameters

NameTypeDescription
symbolstringsymbol identifier

Returns

void


unsubscribeEquity

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.

Returns

void


unsubscribeMarginAvailable

unsubscribeMarginAvailable(symbol): void

The method should be implemented if you use the standard Order Ticket want to show the margin meter.

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

Parameters

NameTypeDescription
symbolstringsymbol identifier

Returns

void


unsubscribePipValue

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

Returns

void