Trading Controller - mmmy/css3demos GitHub Wiki
:chart: All content on this page is relevant for Trading Platform only.
Trading Controller 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 Controller's methods which Platform will expect to have.
Required Methods
supportFloatingPanel()
Function should return true for Floating Trading Panel to be displayed.
supportBottomWidget()
Function should return true for Bottom Trading Panel to be displayed.
buttonDropdownItems()
Bottom Trading Panel has a button with a list of dropdown items. This function is expected to return an array of objects, each of them representing one dropdown item. Objects should have the following properties:
text- the only mandatory field. Use'-'to display a separator line.checkable- set it totrueto have a checkboxchecked- initial value of the checkboxaction- function to perform when the item is clicked
chartContextMenuItems()
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.
bottomContextMenuItems()
Bottom Trading Panel can have a context menu. Return a list of items for this menu. Format is the same as for buttonDropdownItems.
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.
createBottomWidget(container)
This function is called when it is needed to create a Bottom Trading Panel. You should create DOM object and append it to the container. The container shows a vertical scroll bar when it is needed.
showOrderDialog(order)
This function is invoked by the Floating Trading Panel when user requests to create the order. Order is an object with the following properties:
type:"limit"or"market"side:"sell"or"buy"price: price at the moment when a user clicks an ordersymbol: current symbol stringqty: quantitylimit_price: is used when a user clicks on a bid/ask orderformatted_limit_price: is a limit_price formatted for displaying in an edit field
So we give you the ability to use your own dialog and it's 100% up to you how to manage it. But also you can use our default "Create Order" dialog . In this case you won't have to mess with the UI, but also you'll have to implement a few additional methods (see below).
And this is it !
Additional Methods
If you want to use our native "Create Order" dialog instead of creating your own, you also have to implement a few more functions.
placeOrder(symbol, side, orderType, qty, price, stopLoss, takeProfit, expiration)
symbol- symbol stringside:"sell"or"buy"orderType:"limit","market"or"stop"qty: quantityprice: entered pricestopLoss: entered stop loss pricetakeProfit: entered take profit priceexpiration: object with the only valuable propertyexpiration- UTC time of expiration
The function is invoked to finish creating an order. It should return $.Deferred object. When it is resolved it should have an order data argument which is an object with the following properties:
symbol- symbol stringside:"sell"or"buy"type:"limit","market"or"stop"qty: quantityprice: pricestatus: possible values:working,filled,rejected,invalidmisc.reject_reason: reason textid- mandatory unique identified of the order
modifyOrder(id, qty, price, stopLoss, takeProfit, expiration)
The function is invoked to modify an order.
closePosition(symbol)
The function is invoked to create a close position order.
getOrder(id)
The function is invoked to get an order by its id.
reversePosition(symbol)
Create a reverse position order when this function is called.
See Also
- How to connect your trading controller to the chart