GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — WebSocket v2 WebSocket v2
martin-nginio edited this page
Please find the latest and most up to date documentation here: https://docs.btcmarkets.net WebSocket feed provides real-time market data covering orderbook updates, order life cycle and trades. note: This will remain beta version for a few weeks before it's released around April 2019. In order to start receiving real time messages, a WebSocket connection needs to be made followed by a message to The endpoint for WebSocket v2 is: WebSocket v2 provides a number of improvements including:
Market ids represent a market and are used in order to filter events for only specific markets you are interested in. You should be able to pass any active markets as per below: https://api.btcmarkets.net/v2/market/active Format: Note: marketIds are only applicable to public events (e.g. All messages published include a Those message types events include: sending The sample event: In order to receive sample event: In order to receive For efficiency the sample event: { marketId: 'BTC-AUD', timestamp: '2019-04-08T22:23:37.643Z', bids: [ [ '7418.46', '0.04' ], [ '7418.45', '0.56' ], [ '7100', '0.01' ] ] asks: [ [ '7437.53', '0.76' ], [ '7437.54', '0.3646349' ], [ '7446.94', '0.6' ], [ '7700', '0.1' ] ] messageType: 'orderbook' } Below sample code connects to const WebSocket = require('ws'); const ws = new WebSocket('wss://socket.btcmarkets.net/v2'); var request = { marketIds:marketIds, channels: channels, messageType: 'subscribe' } ws.on('open', function open() { ws.send(JSON.stringify(request)); }); ws.on('message', function incoming(data) { console.log(data); }); Receiving events about life cycle of your orders require sending authentication information when subscribing to events. The authentication is similar to public trading API authentication using your API key and secret to sign the message when subscribing via WebSocket. Below is sample const crypto = require('crypto'); const WebSocket = require('ws'); const key = 'your api key'; const secret = 'your api key secret'; const ws = new WebSocket('wss://socket.btcmarkets.net/v2'); const now = Date.now(); const strToSign = "/users/self/subscribe" + "\n" + now; const signature = signMessage(secret, strToSign); var request = { marketIds:['BTC-AUD'], channels: ['orderChange', 'heartbeat'], key: key, signature: signature, timestamp: now, messageType: 'subscribe' } ws.on('open', function open() { ws.send(JSON.stringify(request)); }); ws.on('message', function incoming(data) { console.log(data); }); function signMessage(secret, message) { var key = Buffer.from(secret, 'base64'); var hmac = crypto.createHmac('sha512', key); var signature = hmac.update(message).digest('base64'); return signature; } Below are events that are published for every step of order processing.
{ orderId: 79003, marketId: 'BTC-AUD', side: 'Bid', type: 'Limit', openVolume: '1', status: 'Placed', triggerStatus: '', trades: [], timestamp: '2019-04-08T20:41:19.339Z', messageType: 'orderChange' }
Notes:
Those events are published when deposit or withdraws of funds are requested by a user or approved by the system (and result in balance updates). Channel name used is Note: status of a withdraw request is if you subscribe to heartbeat event: { messageType: 'heartbeat', channels: [ { name: 'orderChange' }, { name: 'orderbook', marketIds: [ 'BTC-AUD', 'XRP-AUD' ] }, { name: 'heartbeat' } ] } Note: Once a new subscription request is confirmed, a single Whilst sending In those situations send the same subscription message (all rules applies for authentication, marketIds, etc) and the message type will be In case of errors, a message type of
sample error events:
{ messageType: 'error', code: 3, message: 'invalid channel names' }
{ messageType: 'error', code: 3, message: 'invalid marketIds' }
{ messageType: 'error', code: 1, message: 'authentication failed. invalid key' } Below are working example of how to connect to this WebSocket feed in different languages:
New connections to the WebSocket feed are rate limited to 3 attempts per 10 seconds per IP. Frequent WebSocket connections that exceed the rate limit will be closed by the server. From time to time your WebSocket connection may be disconnected (e.g. as we upgrade software on our servers). We recommend adding logic to your client in order to refresh your connection every 24 hours or in case if the connection drops out. Introduction updated 9/28/18 WebSocket v1 deprecated Market Data API updated 7/24/19 Trading API updated 08/19/19 Account API updated 3/14/19 Fund Transfer API updated 08/06/19 Clone this wiki locally |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |