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
-
↳
IBrokerTerminal
Methods
accountManagerInfo
▸ accountManagerInfo(): AccountManagerInfo
This function should return the information that will be used to build an Account manager.
Returns
Inherited from
IBrokerWithoutRealtime.accountManagerInfo
cancelOrder
▸ cancelOrder(orderId
): Promise
<void
>
This method is called to cancel a single order with the given id
.
Parameters
Name | Type | Description |
---|---|---|
orderId | string | id for the order to cancel |
Returns
Promise
<void
>
Inherited from
IBrokerWithoutRealtime.cancelOrder
cancelOrders
▸ cancelOrders(symbol
, side
, ordersIds
): Promise
<void
>
This method is called to cancel multiple orders for a symbol
and side
.
ordersIds
parameter should contain the list of order ids to be cancelled.
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
side | Side | order side |
ordersIds | string [] | ids already collected by symbol and side |
Returns
Promise
<void
>
Inherited from
IBrokerWithoutRealtime.cancelOrders
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
Name | Type | Description |
---|---|---|
context | TradeContext | context object passed by a browser |
options? | DefaultContextMenuActionsParams | - |
Returns
Promise
<ActionMetaInfo
[]>
Inherited from
IBrokerWithoutRealtime.chartContextMenuActions
closePosition
▸ closePosition(positionId
, amount?
): Promise
<void
>
This method is called if supportClosePosition
configuration flag is on. It allows to close the position by id.
Parameters
Name | Type | Description |
---|---|---|
positionId | string | position id |
amount? | number | The amount is specified if supportPartialClosePosition is true and the user wants to close only part of the position. |
Returns
Promise
<void
>
Inherited from
IBrokerWithoutRealtime.closePosition
closeTrade
▸ closeTrade(tradeId
, amount?
): Promise
<void
>
This method is called if supportCloseTrade
configuration flag is on. It allows to close the trade by id.
Parameters
Name | Type | Description |
---|---|---|
tradeId | string | trade id |
amount? | number | The amount is specified if supportPartialCloseTrade is true and the user wants to close only part of the trade. |
Returns
Promise
<void
>
Inherited from
IBrokerWithoutRealtime.closeTrade
connectionStatus
▸ connectionStatus(): ConnectionStatus
Connection status for the Broker API.
You don't need to return values other than 1
(Connected
) typically since the broker is already connected when you create the widget.
You can use it if you want to display a spinner in the bottom panel while the data is being loaded.
Returns
Inherited from
IBrokerWithoutRealtime.connectionStatus
editPositionBrackets
▸ editPositionBrackets(positionId
, brackets
, customFields?
): Promise
<void
>
This method is called if supportPositionBrackets
configuration flag is on. It shows a dialog that enables take profit
and stop loss
editing.
Parameters
Name | Type | Description |
---|---|---|
positionId | string | is an ID of an existing position to be modified |
brackets | Brackets | new Brackets to be set for the position |
customFields? | CustomInputFieldsValues | custom fields to display in the dialog |
Returns
Promise
<void
>
Inherited from
IBrokerWithoutRealtime.editPositionBrackets
editTradeBrackets
▸ editTradeBrackets(tradeId
, brackets
): Promise
<void
>
This method is called if supportTradeBrackets
configuration flag is on. It displays a dialog that enables take profit and stop loss editing.
Parameters
Name | Type | Description |
---|---|---|
tradeId | string | ID of existing trade to be modified |
brackets | Brackets | new Brackets to be set for the trade |
Returns
Promise
<void
>
Inherited from
IBrokerWithoutRealtime.editTradeBrackets
executions
▸ executions(symbol
): Promise
<Execution
[]>
Called by Trading Platform to request executions for the specified symbol
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
Promise
<Execution
[]>
Inherited from
IBrokerWithoutRealtime.executions
formatter
▸ formatter(symbol
, alignToMinMove
): Promise
<INumberFormatter
>
Provide a custom price formatter for the specified symbol.
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
alignToMinMove | boolean | align formatted number to the minimum movement amount of the symbol |
Returns
Promise
<INumberFormatter
>
Inherited from
IBrokerWithoutRealtime.formatter
getOrderDialogOptions
▸ getOrderDialogOptions(symbol
): Promise
<OrderDialogOptions
>
Implement this method if you use the standard Order dialog and want to customize it.
Use the symbol
parameter to return customization options for a particular symbol.
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
Promise
<OrderDialogOptions
>
Inherited from
IBrokerWithoutRealtime.getOrderDialogOptions
getPositionDialogOptions
▸ getPositionDialogOptions(): PositionDialogOptions
Implement this method if you want to customize the position dialog.
Returns
Inherited from
IBrokerWithoutRealtime.getPositionDialogOptions
isTradable
▸ isTradable(symbol
): Promise
<boolean
| IsTradableResult
>
This function is required for the Floating Trading Panel.
The ability to trade via the panel depends on the result of this function: true
or false
.
You don't need to implement this method if all symbols can be traded.
If you want to show a custom message with the reason why the symbol cannot be traded then you can return an object IsTradableResult
.
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
Promise
<boolean
| IsTradableResult
>
Inherited from
IBrokerWithoutRealtime.isTradable
leverageInfo
▸ leverageInfo(leverageInfoParams
): Promise
<LeverageInfo
>
This method is called to receive leverageInfo from the broker.
Parameters
Name | Type | Description |
---|---|---|
leverageInfoParams | LeverageInfoParams | information about the specific symbol to provide leverage info for |
Returns
Promise
<LeverageInfo
>
Inherited from
IBrokerWithoutRealtime.leverageInfo
modifyOrder
▸ modifyOrder(order
, confirmId?
): Promise
<void
>
Method is called when a user wants to modify an existing order.
Parameters
Name | Type | Description |
---|---|---|
order | Order | order information |
confirmId? | string | is passed if supportPlaceOrderPreview configuration flag is on. |
Returns
Promise
<void
>
Inherited from
IBrokerWithoutRealtime.modifyOrder
orders
▸ orders(): Promise
<Order
[]>
Called by Trading Platform to request orders
Returns
Promise
<Order
[]>
Inherited from
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 supportOrdersHistory
flag to false
.
Returns
Promise
<Order
[]>
Inherited from
IBrokerWithoutRealtime.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.
Parameters
Name | Type | Description |
---|---|---|
order | PreOrder | order information |
confirmId? | string | is passed if supportPlaceOrderPreview configuration flag is on. |
Returns
Promise
<PlaceOrderResult
>
PlaceOrderResult, which should include an orderId
Inherited from
IBrokerWithoutRealtime.placeOrder
positions
▸ positions(): Promise
<Position
[]>
Called by Trading Platform to request positions
Returns
Promise
<Position
[]>
Inherited from
IBrokerWithoutRealtime.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
Name | Type | Description |
---|---|---|
leverageSetParams | LeverageSetParams | leverageSetParams 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
>
Inherited from
IBrokerWithoutRealtime.previewLeverage
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 supportPlaceOrderPreview
configuration flag is on.
Parameters
Name | Type | Description |
---|---|---|
order | PreOrder | order information |
Returns
Promise
<OrderPreviewResult
>
Inherited from
IBrokerWithoutRealtime.previewOrder
quantityFormatter
▸ quantityFormatter(symbol
): Promise
<INumberFormatter
>
Provide a custom quantity formatter for the specified symbol.
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
Promise
<INumberFormatter
>
Inherited from
IBrokerWithoutRealtime.quantityFormatter
reversePosition
▸ reversePosition(positionId
): Promise
<void
>
This method is called if supportNativeReversePosition
configuration flag is on. It allows to reverse the position by id.
Parameters
Name | Type | Description |
---|---|---|
positionId | string | position |
Returns
Promise
<void
>
Inherited from
IBrokerWithoutRealtime.reversePosition
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
Name | Type | Description |
---|---|---|
leverageSetParams | LeverageSetParams | leverageSetParams 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
>
Inherited from
IBrokerWithoutRealtime.setLeverage
spreadFormatter
▸ spreadFormatter(symbol
): Promise
<INumberFormatter
>
Provide a custom spread formatter for the specified symbol.
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
Promise
<INumberFormatter
>
Inherited from
IBrokerWithoutRealtime.spreadFormatter
subscribeDOM
▸ subscribeDOM(symbol
): void
Library is requesting that realtime DOM (Depth of Market) updates should be supplied for this symbol
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
void
Inherited from
IBrokerWithoutRealtime.subscribeDOM
subscribeEquity
▸ subscribeEquity(): void
The method should be implemented if you use the standard Order dialog 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
Inherited from
IBrokerWithoutRealtime.subscribeEquity
subscribeMarginAvailable
▸ subscribeMarginAvailable(symbol
): void
The method should be implemented if you use the standard Order dialog and want to show the margin meter.
Once this method is called the broker should provide margin available updates via IBrokerConnectionAdapterHost.marginAvailableUpdate method.
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
void
Inherited from
IBrokerWithoutRealtime.subscribeMarginAvailable
subscribePipValue
▸ subscribePipValue(symbol
): void
The method should be implemented if you use a standard Order dialog.
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
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
void
Inherited from
IBrokerWithoutRealtime.subscribePipValue
subscribeRealtime
▸ subscribeRealtime(symbol
): void
Library is requesting that realtime updates should be supplied for this symbol.
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
void
symbolInfo
▸ symbolInfo(symbol
): Promise
<InstrumentInfo
>
Called by the internal Order dialog, DOM panel, and floating trading panel to get symbol information.
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
Promise
<InstrumentInfo
>
Inherited from
IBrokerWithoutRealtime.symbolInfo
trades
▸ trades(): Promise
<Trade
[]>
Called by Trading Platform to request trades
Returns
Promise
<Trade
[]>
Inherited from
unsubscribeDOM
▸ unsubscribeDOM(symbol
): void
Library is notifying that realtime DOM (Depth of Market) updates are no longer required for this symbol.
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
void
Inherited from
IBrokerWithoutRealtime.unsubscribeDOM
unsubscribeEquity
▸ unsubscribeEquity(): void
The method should be implemented if you use the standard Order dialog and support stop loss.
Once this method is called the broker should stop providing equity updates.
Returns
void
Inherited from
IBrokerWithoutRealtime.unsubscribeEquity
unsubscribeMarginAvailable
▸ unsubscribeMarginAvailable(symbol
): void
The method should be implemented if you use the standard Order dialog want to show the margin meter.
Once this method is called the broker should stop providing margin available updates.
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
void
Inherited from
IBrokerWithoutRealtime.unsubscribeMarginAvailable
unsubscribePipValue
▸ unsubscribePipValue(symbol
): void
The method should be implemented if you use a standard Order dialog and implement subscribePipValue
.
Once this method is called the broker should stop providing pipValue
updates.
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
void
Inherited from
IBrokerWithoutRealtime.unsubscribePipValue
unsubscribeRealtime
▸ unsubscribeRealtime(symbol
): void
Library is notifying that realtime updates are no longer required for this symbol.
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
void