diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-08-21 02:42:29 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-08-21 02:42:29 +0800 |
commit | 075e3a41c876797907e3ad98f20940e32e8d0762 (patch) | |
tree | d1f9db70ee1a56b500a3293a9ee962fd08f7abec /packages/connect/src/ws_orders_channel.ts | |
parent | f2d1d953553adfa59f0a39bf2cf98817fae0a4ff (diff) | |
download | dexon-0x-contracts-075e3a41c876797907e3ad98f20940e32e8d0762.tar.gz dexon-0x-contracts-075e3a41c876797907e3ad98f20940e32e8d0762.tar.zst dexon-0x-contracts-075e3a41c876797907e3ad98f20940e32e8d0762.zip |
Update websocket for SRA v2
Diffstat (limited to 'packages/connect/src/ws_orders_channel.ts')
-rw-r--r-- | packages/connect/src/ws_orders_channel.ts | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/packages/connect/src/ws_orders_channel.ts b/packages/connect/src/ws_orders_channel.ts index 9d45b6570..62960d23a 100644 --- a/packages/connect/src/ws_orders_channel.ts +++ b/packages/connect/src/ws_orders_channel.ts @@ -9,7 +9,11 @@ import { OrdersChannelSubscriptionOpts, } from './types'; import { assert } from './utils/assert'; -import { ordersChannelMessageParser } from './utils/orderbook_channel_message_parser'; +import { ordersChannelMessageParser } from './utils/orders_channel_message_parser'; + +export interface OrdersChannelSubscriptionOptsMap { + [key: string]: OrdersChannelSubscriptionOpts; +} /** * This class includes all the functionality related to interacting with a websocket endpoint @@ -18,7 +22,7 @@ import { ordersChannelMessageParser } from './utils/orderbook_channel_message_pa export class WebSocketOrdersChannel implements OrdersChannel { private readonly _client: WebSocket.w3cwebsocket; private readonly _handler: OrdersChannelHandler; - private readonly _subscriptionOptsList: OrdersChannelSubscriptionOpts[] = []; + private readonly _subscriptionOptsMap: OrdersChannelSubscriptionOptsMap = {}; /** * Instantiates a new WebSocketOrdersChannel instance * @param client A WebSocket client @@ -50,11 +54,12 @@ export class WebSocketOrdersChannel implements OrdersChannel { public subscribe(subscriptionOpts: OrdersChannelSubscriptionOpts): void { assert.isOrdersChannelSubscriptionOpts('subscriptionOpts', subscriptionOpts); assert.assert(this._client.readyState === WebSocket.w3cwebsocket.OPEN, 'WebSocket connection is closed'); - this._subscriptionOptsList.push(subscriptionOpts); + const requestId = uuid(); + this._subscriptionOptsMap[requestId] = subscriptionOpts; const subscribeMessage = { type: 'subscribe', channel: 'orders', - requestId: uuid(), + requestId, payload: subscriptionOpts, }; this._client.send(JSON.stringify(subscribeMessage)); @@ -73,7 +78,7 @@ export class WebSocketOrdersChannel implements OrdersChannel { try { const data = message.data; const parserResult = ordersChannelMessageParser.parse(data); - const subscriptionOpts = this._subscriptionOptsList[parserResult.requestId]; + const subscriptionOpts = this._subscriptionOptsMap[parserResult.requestId]; if (_.isUndefined(subscriptionOpts)) { this._handler.onError( this, |