aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect/src/ws_orders_channel.ts
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-08-21 02:42:29 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-08-21 02:42:29 +0800
commit075e3a41c876797907e3ad98f20940e32e8d0762 (patch)
treed1f9db70ee1a56b500a3293a9ee962fd08f7abec /packages/connect/src/ws_orders_channel.ts
parentf2d1d953553adfa59f0a39bf2cf98817fae0a4ff (diff)
downloaddexon-sol-tools-075e3a41c876797907e3ad98f20940e32e8d0762.tar
dexon-sol-tools-075e3a41c876797907e3ad98f20940e32e8d0762.tar.gz
dexon-sol-tools-075e3a41c876797907e3ad98f20940e32e8d0762.tar.bz2
dexon-sol-tools-075e3a41c876797907e3ad98f20940e32e8d0762.tar.lz
dexon-sol-tools-075e3a41c876797907e3ad98f20940e32e8d0762.tar.xz
dexon-sol-tools-075e3a41c876797907e3ad98f20940e32e8d0762.tar.zst
dexon-sol-tools-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.ts15
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,