Repository navigation
Broker API
💹 All content on this page is related to Trading Terminal only.
Broker API is a key component that enables live trading. Its main purpose is to connect our charts with your trading logic. In terms of JS, it is an object which is expected to expose the specific interface. Here is a list of API's methods that Terminal is expected to have.
The constructor of the Broker API usually takes Trading Host.
This method is called by the Trading Terminal to request positions.
This method is called by the Trading Terminal to request orders.
This method is called by the Trading Terminal to request executions.
This method is called by the Trading Terminal to request trades (individual positions).
-
eis a context object passed by a browser
Chart can have a sub-menu Trading in the context menu. It returns the list of items in a sub-menu. The format is the same as in buttonDropdownItems.
You don't need to return values other than 1 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.
Possible return values are:
ConnectionStatus.Connected = 1
ConnectionStatus.Connecting = 2
ConnectionStatus.Disconnected = 3
ConnectionStatus.Error = 4This 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. It has only two keys: tradable (true or false) and reason (string).
This function should return the information that will be used to build an account manager. See Account Manager for more information.
showOrderDialog(order)
This function is requested by the chart when a user creates or modifies an order.
You have the ability to use your own dialog and manage it as you see fit.
placeOrder(order)
Method is requested when a user wants to place an order. Order is pre-filled with partial or complete information.
modifyOrder(order)
-
orderis an order object to modify
Method is requested when a user wants to modify an existing order.
This method is requested to cancel a single order with a given id.
If silently is true no dialogs should be shown.
-
symbol- symbol string -
side: Side constant orundefined -
ordersIds- ids already collected bysymbolandside
If silently is true no dialogs should be shown.
This method is requested to cancel multiple orders for a symbol and side.
editPositionBrackets(positionId, brackets)
-
positionIdis an ID of an existing position to be modified -
brackets- new brackets (optional).
This method is requested if supportPositionBrackets configuration flag is on. It shows a dialog that enables take profit and stop loss editing.
This method is requested if supportClosePosition configuration flag is on. It allows to close the position by id.
This method is requested if supportReversePosition configuration flag is on. It allows to reverse the position by id.
editTradeBrackets(tradeId, brackets)
-
tradeIdis ID of existing trade to be modified -
brackets- new brackets (optional).
This method is requested if supportTradeBrackets configuration flag is on. It displays a dialog that enables take profit and stop loss editing.
This method is requested if supportCloseTrade configuration flag is on. It allows to close the trade by id.
-
symbol- symbol string
This method is requested by the internal Order Dialog, DOM panel and floating trading panel to get symbol information.
The result is an object with the following data:
-
qty- object with fieldsmin,maxandstepthat specifies Quantity, field step and boundaries. -
pipSize- size of 1 pip (e.g., 0.0001 for EURUSD). -
pipValue- value of 1 pip for the instrument in the account currency. -
minTick- minimal price change (e.g., 0.00001 for EURUSD). Used for price fields. -
description- a description to be displayed in the dialog. -
type- instrument type, onlyforexmatters - it enables negative pips. You can check that in the order dialog. -
domVolumePrecision- number of decimal places of DOM asks/bids volume (optional, 0 by default). -
marginRate- the margin requirement for the instrument. A 3% margin rate should be represented as 0.03.
This method is requested by the internal Order Dialog to get the account information. It should return only one field for now:
- currencySign: string - which is a sign of account currency
Once this method is called the broker should stop providing profit/loss.
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 equityUpdate method.
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.
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 marginAvailableUpdate method.
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.
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 pipValueUpdate method.
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.
- How to connect your trading controller to the chart
- Trading Host
- What is Charting Library
- Getting Started
- Data Binding
- Chart Customization
- Customization Overview
- Client-Side Customization
- Server-Side Customization
- Customization Use Cases
- Trading Terminal
- Saving/Loading Charts
- Creating Custom Studies
- Breaking changes in versions