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]]
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,902评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,037评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,978评论 0 332
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,867评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,763评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,104评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,565评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,236评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,379评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,313评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,363评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,034评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,637评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,719评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,952评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,371评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,948评论 2 341

推荐阅读更多精彩内容

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