aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect/src/orders_channel_factory.ts
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-08-17 08:03:11 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-08-17 08:03:11 +0800
commit64a85dfb9cc60212dcf1c70ca7be4874936dd332 (patch)
tree9052883b8893d2bfeb40525c3640987698481c68 /packages/connect/src/orders_channel_factory.ts
parente079790f7fe82452471fc69fa9583c07848f801d (diff)
downloaddexon-sol-tools-64a85dfb9cc60212dcf1c70ca7be4874936dd332.tar.gz
dexon-sol-tools-64a85dfb9cc60212dcf1c70ca7be4874936dd332.tar.zst
dexon-sol-tools-64a85dfb9cc60212dcf1c70ca7be4874936dd332.zip
Rename websocket files and types
Diffstat (limited to 'packages/connect/src/orders_channel_factory.ts')
-rw-r--r--packages/connect/src/orders_channel_factory.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/packages/connect/src/orders_channel_factory.ts b/packages/connect/src/orders_channel_factory.ts
new file mode 100644
index 000000000..4e9b74b2c
--- /dev/null
+++ b/packages/connect/src/orders_channel_factory.ts
@@ -0,0 +1,32 @@
+import * as WebSocket from 'websocket';
+
+import { OrdersChannel, OrdersChannelHandler } from './types';
+import { assert } from './utils/assert';
+import { WebSocketOrdersChannel } from './ws_orders_channel';
+
+export const ordersChannelFactory = {
+ /**
+ * Instantiates a new WebSocketOrdersChannel instance
+ * @param url The relayer API base WS url you would like to interact with
+ * @param handler An OrderbookChannelHandler instance that responds to various
+ * channel updates
+ * @return An OrderbookChannel Promise
+ */
+ async createWebSocketOrdersChannelAsync(
+ url: string,
+ handler: OrdersChannelHandler,
+ ): Promise<OrdersChannel> {
+ assert.isUri('url', url);
+ assert.isOrderbookChannelHandler('handler', handler);
+ return new Promise<OrdersChannel>((resolve, reject) => {
+ const client = new WebSocket.w3cwebsocket(url);
+ client.onopen = () => {
+ const orderbookChannel = new WebSocketOrdersChannel(client, handler);
+ resolve(orderbookChannel);
+ };
+ client.onerror = err => {
+ reject(err);
+ };
+ });
+ },
+};