Broker-API

:chart: All content on this page is relevant for [[Trading Terminal]] only.

Broker API is a thing which will make your trading live. 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 which Terminal will expect to have.

Required Methods

constructor(host)

The constructor of the Broker API usually takes [[Trading Host]].

positions : Promise

This methods is called by the Trading Terminal to request positions. You should return an array of [[positions|Trading-Objects-and-Constants#position]].

orders : Promise

This methods is called by the Trading Terminal to request orders. You should return an array of [[orders|Trading-Objects-and-Constants#order]].

executions(symbol) : Promise

This methods is called by the Trading Terminal to request executions. You should return an array of [[executions|Trading-Objects-and-Constants#execution]].

trades : Promise

This methods is called by the Trading Terminal to request trades (individual positions). You should return an array of [[trades|Trading-Objects-and-Constants#trade]].

chartContextMenuActions(e)

Chart can have a sub-menu Trading in the context menu. Return the list of items for a sub-menu. Format is the same as for buttonDropdownItems.

e is a context object passed by a browser

connectionStatus()

Usually you don't need to return values other then 1, because 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 loaded.
Possible return values are:

ConnectionStatus.Connected = 1
ConnectionStatus.Connecting = 2
ConnectionStatus.Disconnected = 3
ConnectionStatus.Error = 4

isTradable(symbol)

This function is required for the Floating Trading Panel. Ability to trade via the panel depends on the result of this function: true or false. You don't need to imlement this method if all the symbols can be traded.

accountManagerInfo()

This function should return information that will be used to build an account manager.
See [[Account Manager]] for more information.

showOrderDialog([[order|Trading-Objects-and-Constants#order]])

This function is invoked by the chart when user requests to create or modify an order.

So we give you the ability to use your own dialog and it's 100% up to you how to manage it.

placeOrder([[order|Trading-Objects-and-Constants#order]], silently)

Method is invoked when a user want to place an order. Order is pre-filled with partial or full information.
If silently is true no order dialog should be shown.

modifyOrder([[order|Trading-Objects-and-Constants#order]], silently, focus)

  1. order is an order object to modify
  2. silently - if it is true no order dialog should be shown
  3. focus - [[OrderTicketFocusControl constants|Trading-Objects-and-Constants#orderticketfocuscontrol]]. It can be already initialized by the chart.

Method is invoked when a user want to modify an existing order.

cancelOrder(orderId, silently)

This method is invoked to cancel single order with given id.
If silently is true no dialogs should be shown.

cancelOrders(symbol, side, ordersIds, silently)

  1. symbol - symbol string
  2. side: [[Side constant|Trading-Objects-and-Constants#side]] or undefined
  3. ordersIds - ids already collected by symbol and side
    If silently is true no dialogs should be shown.

This method is invoked to cancel multiple orders for a symbol and side.

editPositionBrackets(positionId, focus)

This method is invoked if supportPositionBrackets configuration flag is on to display a dialog for editing of take profit and stop loss.

  1. positionId is ID of existing position to be modified
  2. focus - [[Focus constant|Trading-Objects-and-Constants#focusoptions]].

closePosition(positionId, silently)

This method is invoked if supportClosePosition configuration flag is on to close the position by id.
If silently is true no dialogs show be shown.

reversePosition(positionId, silently)

This method is invoked if supportReversePosition configuration flag is on to reverse the position by id.
If silently is true no dialogs should be shown.

editTradeBrackets(tradeId, focus)

This method is invoked if supportTradeBrackets configuration flag is on to display a dialog for editing of take profit and stop loss.

  1. tradeId is ID of existing trade to be modified
  2. focus - [[Focus constant|Trading-Objects-and-Constants#focusoptions]].

closeTrade(tradeId, silently)

This method is invoked if supportCloseTrade configuration flag is on to close the trade by id.
If silently is true no dialogs show be shown.

symbolInfo(symbol) : Deferred (or Promise)

  1. symbol - symbol string

This method is invoked by the internal Order Dialog, DOM panel and floating trading panel to get symbol information.
Result is an object with the following data:

  • qty - object with fields min, max and step that specifies Quantity field step and boundaries.
  • pipSize - size of 1 pip (e.g., 0.0001 for EURUSD)
  • pipValue - values of 1 pip in account currency (e.g., 1 for EURUSD for an account in USD)
  • minTick - minimal price change (e.g., 0.00001 for EURUSD). It is used for price fields.
  • description - a description to be displayed in the dialog
  • type - instrument type, only forex matters - it enables negative pips check in the order dialog
  • domVolumePrecision - number of decimal places of DOM asks/bids volume (optional, 0 by default)

accountInfo() : Deferred (or Promise)

This method is invoked by the internal Order Dialog to get account information.
It should return only one field for now:

  1. currencySign: string - which is a sign of acccount currency

Since this method is called the broker should stop providing profit/loss.

subscribeEquity()

Method should be implemented if you use standard order dialog and support stop loss.
Since this method is called the broker should provide equity updates via [[equityUpdate|Trading-Host#equityupdateequity]] method.

unsubscribeEquity()

Method should be implemented if you use standard order dialog and support stop loss.
Since this method is called the broker should stop providing equity updates.

And this is it !

See Also

  • [[How to connect|Widget-Constructor#chart-trading_controller]] your trading controller to the chart
  • [[Trading Host]]
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,507评论 0 23
  • 一次只做一件事 今天要跟大家分享的话题是专注去做一件事情,只有专注才能把事情做好,只有用心才能把事情做到位。所以当...
    竹海星空阅读 2,532评论 0 0
  • 他们就是一道屏障,但方正心里清楚,他们并不是坚不可摧牢不可破的屏障,此时方正只能寄希望于这些英勇的武警战士以自己的...
    长白居士阅读 1,378评论 0 0
  • 昨夜知道kimi去世,一夜未睡。高三的时候一直粉他,不知道生命怎么会这么脆弱。刚看完他的电影,他一下子就没了。我的...
    兰兰欧尼阅读 1,544评论 0 0
  • 仓库主路径 /home/svndata 执行后,自动建立project库,查看/home/svndata/proj...
    万总有点菜阅读 4,712评论 0 0

友情链接更多精彩内容