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.
Methods
accountManagerInfo
The library calls accountManagerInfo
to get information required for building the Account Manager.
Signature
accountManagerInfo() => AccountManagerInfo
Returns
accountsMetainfo
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.
Signature
accountsMetainfo() => Promise<AccountMetainfo[]>
Returns
Promise<AccountMetainfo[]>
cancelOrder
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.
Signature
cancelOrder(orderId: string) => Promise<void>
Parameters
Name | Type | Description |
---|---|---|
orderId | string | The ID of the order to cancel. |
Returns
Promise<void>
cancelOrders
OptionalThe 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.
Signature
cancelOrders(symbol: string, side: Side, ordersIds: string[]) => Promise<void>
Parameters
Name | Type | Description |
---|---|---|
symbol | string | The symbol identifier. |
side | Side | An order side. |
ordersIds | string[] | IDs of the orders to cancel. The orders are selected based on the specified symbol and side . |
Returns
Promise<void>
chartContextMenuActions
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.
Signature
chartContextMenuActions(context: TradeContext, options?: DefaultContextMenuActionsParams) => Promise<ActionMetaInfo[]>
Parameters
Name | Type | Description |
---|---|---|
context | TradeContext | A context object passed by the library. |
options? | DefaultContextMenuActionsParams | Default options for the context menu action parameters. |
Returns
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.
Promise<ActionMetaInfo[]>
closeIndividualPosition
OptionalThe 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.
Signature
closeIndividualPosition(individualPositionId: string, amount?: number) => Promise<void>
Parameters
Name | Type | Description |
---|---|---|
individualPositionId | string | The individual position ID. |
amount? | number | The amount is specified if supportPartialCloseIndividualPosition is true and the user wants to close only part of the individual position. |
Returns
Promise<void>
closePosition
OptionalThe 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 order 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
.
Signature
closePosition(positionId: string, amount?: number) => Promise<void>
Parameters
Name | Type | Description |
---|---|---|
positionId | string | The 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>
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.
Signature
connectionStatus() => ConnectionStatus
Returns
currentAccount
The library calls currentAccount
to get the current account's ID.
Signature
currentAccount() => AccountId
Returns
editIndividualPositionBrackets
OptionalThis 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.
Signature
editIndividualPositionBrackets(individualPositionId: string, brackets: Brackets) => Promise<void>
Parameters
Name | Type | Description |
---|---|---|
individualPositionId | string | ID of existing individual position to be modified |
brackets | Brackets | new Brackets to be set for the individual position |
Returns
Promise<void>
editPositionBrackets
OptionalThe 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.
Signature
editPositionBrackets(positionId: string, brackets: Brackets, customFields?: CustomInputFieldsValues) => Promise<void>
Parameters
Name | Type | Description |
---|---|---|
positionId | string | The ID of the 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>
executions
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
.
Signature
executions(symbol: string) => Promise<Execution[]>
Parameters
Name | Type | Description |
---|---|---|
symbol | string | The symbol identifier. |
Returns
Promise<Execution[]>
formatter
OptionalProvide a custom price formatter for the specified symbol.
Signature
formatter(symbol: string, alignToMinMove: boolean) => Promise<INumberFormatter>
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
alignToMinMove | boolean | align formatted number to the minimum movement amount of the symbol |
Returns
Promise<INumberFormatter>
getOrderDialogOptions
OptionalImplement 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.
Signature
getOrderDialogOptions(symbol: string) => Promise<OrderDialogOptions>
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
Promise<OrderDialogOptions>
getPositionDialogOptions
OptionalImplement this method if you want to customize the position dialog.
Signature
getPositionDialogOptions() => PositionDialogOptions
Returns
getSymbolSpecificTradingOptions
OptionalImplement this method if you want to have custom options available for different symbols.
Signature
getSymbolSpecificTradingOptions(symbol: string) => Promise<SymbolSpecificTradingOptions>
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
Promise<SymbolSpecificTradingOptions>
individualPositions
OptionalCalled by Trading Platform to request individual positions.
Required if the BrokerConfigFlags.supportPositionNetting flag is set to true
.
Signature
individualPositions() => Promise<IndividualPosition[]>
Returns
Promise<IndividualPosition[]>
isTradable
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.
Signature
isTradable(symbol: string) => Promise<boolean | IsTradableResult>
Parameters
Name | Type | Description |
---|---|---|
symbol | string | The symbol identifier. |
Returns
Promise<boolean | IsTradableResult>
leverageInfo
OptionalThis method is called to receive leverageInfo from the broker.
Signature
leverageInfo(leverageInfoParams: LeverageInfoParams) => Promise<LeverageInfo>
Parameters
Name | Type | Description |
---|---|---|
leverageInfoParams | LeverageInfoParams | information about the specific symbol to provide leverage information for |
Returns
Promise<LeverageInfo>
modifyOrder
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.
To enable an order preview before modification, set the BrokerConfigFlags.supportModifyOrderPreview configuration flag to true
.
Refer to Enable order preview for more information.
Signature
modifyOrder(order: Order, confirmId?: string) => Promise<void>
Parameters
Name | Type | Description |
---|---|---|
order | Order | Order information. |
confirmId? | string | The ID of the confirmed order. This parameter is passed if supportModifyOrderPreview is true . |
Returns
Promise<void>
orders
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.
Signature
orders() => Promise<Order[]>
Returns
Promise<Order[]>
ordersHistory
OptionalThe library calls ordersHistory
to request orders history.
It is expected that returned orders will have a final status (rejected
, filled
, cancelled
).
This method is only required when you set the BrokerConfigFlags.supportOrdersHistory flag to true
.
This flag adds the History page, where order history is displayed, to the Account Manager.
Refer to the History section for more information.
Signature
ordersHistory() => Promise<Order[]>
Returns
Promise<Order[]>
placeOrder
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.
Signature
placeOrder(order: PreOrder, confirmId?: string) => Promise<PlaceOrderResult>
Parameters
Name | Type | Description |
---|---|---|
order | PreOrder | Order information. |
confirmId? | string | The ID of the confirmed order. This parameter is passed if supportPlaceOrderPreview is true . |
Returns
An object with the order ID.
Promise<PlaceOrderResult>
positions
OptionalCalled by Trading Platform to request positions.
Required if the BrokerConfigFlags.supportPositions flag is set to true
.
Signature
positions() => Promise<Position[]>
Returns
Promise<Position[]>
previewLeverage
OptionalThis method is called to receive LeveragePreviewResult object which holds messages about the leverage value set by the user.
Signature
previewLeverage(leverageSetParams: LeverageSetParams) => Promise<LeveragePreviewResult>
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>
previewOrder
OptionalThe 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.
Signature
previewOrder(order: PreOrder) => Promise<OrderPreviewResult>
Parameters
Name | Type | Description |
---|---|---|
order | PreOrder | Order information. |
Returns
Promise<OrderPreviewResult>
quantityFormatter
OptionalProvide a custom quantity formatter for the specified symbol.
Signature
quantityFormatter(symbol: string) => Promise<INumberFormatter>
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
Promise<INumberFormatter>
reversePosition
OptionalThis 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.
Signature
reversePosition(positionId: string) => Promise<void>
Parameters
Name | Type | Description |
---|---|---|
positionId | string | position |
Returns
Promise<void>
setCurrentAccount
OptionalThe 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.
Signature
setCurrentAccount(id: AccountId) => void
Parameters
Name | Type | Description |
---|---|---|
id | AccountId | The ID of the selected account. |
Returns
void
setLeverage
OptionalThis 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.
Signature
setLeverage(leverageSetParams: LeverageSetParams) => Promise<LeverageSetResult>
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>
spreadFormatter
OptionalProvide a custom spread formatter for the specified symbol.
Signature
spreadFormatter(symbol: string) => Promise<INumberFormatter>
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
Promise<INumberFormatter>
subscribeDOM
OptionalLibrary is requesting that realtime DOM (Depth of Market) updates should be supplied for this symbol
Signature
subscribeDOM(symbol: string) => void
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
void
subscribeEquity
OptionalThe 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.
Signature
subscribeEquity() => void
Returns
void
subscribeMarginAvailable
OptionalThe 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.
Signature
subscribeMarginAvailable(symbol: string) => void
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
void
subscribePipValue
OptionalThe 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.
Signature
subscribePipValue(symbol: string) => void
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
void
symbolInfo
The library calls symbolInfo
to request symbol information for the Order Ticket and Depth of Market widget.
Signature
symbolInfo(symbol: string) => Promise<InstrumentInfo>
Parameters
Name | Type | Description |
---|---|---|
symbol | string | The symbol identifier. |
Returns
Promise<InstrumentInfo>
unsubscribeDOM
OptionalLibrary is notifying that realtime DOM (Depth of Market) updates are no longer required for this symbol.
Signature
unsubscribeDOM(symbol: string) => void
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
void
unsubscribeEquity
OptionalThe 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.
Signature
unsubscribeEquity() => void
Returns
void
unsubscribeMarginAvailable
OptionalThe 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.
Signature
unsubscribeMarginAvailable(symbol: string) => void
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
void
unsubscribePipValue
OptionalThe 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.
Signature
unsubscribePipValue(symbol: string) => void
Parameters
Name | Type | Description |
---|---|---|
symbol | string | symbol identifier |
Returns
void