Create a websocket variable in javascript and send messages in this format:
EKEY|
IN this example, API_KEY = 1.
1). Request Orderbook:
Send this message to websocket server: EKEY|1|RFQ|XBT.USD|
And the response will be:
Acknowledged
{"XBT.USD":[{"sellOrder":[]},{"buyOrder":[]}]}
2). Request Account Snapshot:
Send this message to websocket server: EKEY|1|BALANCE|
And the response will be:
Acknowledged
{"account_snapshot":[{"gross_balance":"500"},{"profit_loss":"0"},{"total_fees":"0"},{"net_balance":"500"},{"used_margin":"0"},{"free_margin":"500"}]}
ORDER ENTRY MESSAGE FORMAT: EKEY|
3). Limit Buy Order Request:
Send this message to websocket server: EKEY|1|LIMITBUY|2.55|1|XBT.USD|
And the response will be:
Acknowledged
{"XBT.USD":[{"sellOrder":[]},{"buyOrder":[{"p":"2.55","q":"1"}]}]}
{"account_snapshot":[{"gross_balance":"500"},{"profit_loss":"0"},{"total_fees":"0"},{"net_balance":"500"},{"used_margin":"25"},
{"free_margin":"475"}]}
4). Limit Sell Order Request:
Send this message to websocket server EKEY|1|LIMITSELL|2.65|1|XBT.USD|
The response will be:
Acknowledged
{"XBT.USD":[{"sellOrder":[{"p":"2.65","q":"1"}]},{"buyOrder":[{"p":"2.55","q":"1"}]}]}
{"account_snapshot":[{"gross_balance":"500"},{"profit_loss":"0"},{"total_fees":"0"},{"net_balance":"500"},{"used_margin":"0"},{"free_margin":"500"}]}
5). Stop Buy & Stop Sell Request: Similar to above, but replace
The response will only include the account_snapshot response.
Now, in this example, lets say another trader put an offer below the current best. 2 contracts @ 2.64 (through the platform). The websocket will push this message to you when a limit orderbook has been modified.
{"XBT.USD":[{"sellOrder":[{"p":"2.64","q":"2"},{"p":"2.65","q":"1"}]},{"buyOrder":[{"p":"2.55","q":"1"}]}]}
6). Market Buy & Market Sell Request: Again, similar to above, replace with
So using the API key, you send an order to buy 1 lot at market.
EKEY|1|MARKETBUY|2.90|1|XBT.USD|
The response will be:
Acknowledged
{"last_trade":[{"execTime":"1403910347545"},{"productSymbol":"XBT.USD"},{"execSide":"true"},{"execPrice":"2.64"},{"execQty":"1"}]}
{"XBT.USD":[{"sellOrder":[{"p":"2.64","q":"1"},{"p":"2.65","q":"1"}]},{"buyOrder":[{"p":"2.55","q":"1"}]}]}
The socket does not push your position information to you. You must populate your position by requesting all executed transactions on your account by doing the following:
7). Viewing transaction history:
Send this message to websocket server EKEY|1|FILLED|
The response will be:
Acknowledged
{"tx_filled":[{"4c1593f619fa259ceb517ccdcce1fd96":[{"entry_time":"1403910347545","productSymbol":"XBT.USD","exec_side":"true","exec_price":"2.64","exec_qty":"1","exec_margin":"25","exec_fee":"1"}]},{"4c1593f619fa259ceb517ccdcce1fd96":[{"entry_time":"1403917072567","productSymbol":"XBT.USD","exec_side":"true","exec_price":"2.64","exec_qty":"1","exec_margin":"25","exec_fee":"1"}]}]}
8 ). Viewing Pending Orders
Send this message to websocket server EKEY|1|PENDING|
The response will be:
Acknowledged
{"tx_pending":[{"cc84f039526ac12fab12cc7d6c4577d7":[{"entry_time":"1403918865034","productSymbol":"XBT.USD","tx_side":"true","tx_price":"2.55","tx_qty":"1","tx_margin":"25","tx_fee":"1"}]},{"678d648f1b8b8c9b1fc28a6fc276ec1":[{"entry_time":"1403918867612","productSymbol":"XBT.USD","tx_side":"false","tx_price":"2.65","tx_qty":"1","tx_margin":"25","tx_fee":"1"}]}]}
9. Cancelling Orders
To cancel a single order you must pass the tx_id of the pending order
EKEY|1|CANCEL_ID|f566025b38ac54b6dfa13d46f20d22c8|
The response will be:
Acknowledged
{"XBT.USD":[{"sellOrder":[{"p":"2.64","q":"1"}]},{"buyOrder":[{"p":"2.55","q":"1"}]}]}
{"account_snapshot":[{"gross_balance":"500"},{"profit_loss":"0"},{"total_fees":"1"},{"net_balance":"499"},{"used_margin":"25"},{"free_margin":"474"}]}
To cancel all orders, just pass this message:
EKEY|1|CANCEL_ALL|
The response will be:
Acknowledged
{"XBT.USD":[{"sellOrder":[{"p":"2.64","q":"1"}]},{"buyOrder":[]}]}
{"XBT.CAD":[{"sellOrder":[]},{"buyOrder":[]}]}
{"XBT.EUR":[{"sellOrder":[]},{"buyOrder":[]}]}
{"XBT.GBP":[{"sellOrder":[]},{"buyOrder":[]}]}
{"XBT.AUD":[{"sellOrder":[]},{"buyOrder":[]}]}
{"XBT.CHF":[{"sellOrder":[]},{"buyOrder":[]}]}
{"XBT.NZD":[{"sellOrder":[]},{"buyOrder":[]}]}
{"XBT.JPY":[{"sellOrder":[]},{"buyOrder":[]}]}
{"BTC.USD":[{"sellOrder":[]},{"buyOrder":[]}]}
{"account_snapshot":[{"gross_balance":"500"},{"profit_loss":"0"},{"total_fees":"1"},{"net_balance":"499"},{"used_margin":"25"},{"free_margin":"474"}]}
Keeping it very simple, all messages encrypted with SSL 128 bit encryption using TLS 1.2.
Let me know if you have questions!