aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/connect/src')
-rw-r--r--packages/connect/src/orders_channel_factory.ts (renamed from packages/connect/src/orderbook_channel_factory.ts)18
-rw-r--r--packages/connect/src/types.ts18
-rw-r--r--packages/connect/src/utils/assert.ts4
-rw-r--r--packages/connect/src/ws_orders_channel.ts (renamed from packages/connect/src/ws_orderbook_channel.ts)30
4 files changed, 34 insertions, 36 deletions
diff --git a/packages/connect/src/orderbook_channel_factory.ts b/packages/connect/src/orders_channel_factory.ts
index 5134af323..4e9b74b2c 100644
--- a/packages/connect/src/orderbook_channel_factory.ts
+++ b/packages/connect/src/orders_channel_factory.ts
@@ -1,27 +1,27 @@
import * as WebSocket from 'websocket';
-import { OrderbookChannel, OrderbookChannelHandler } from './types';
+import { OrdersChannel, OrdersChannelHandler } from './types';
import { assert } from './utils/assert';
-import { WebSocketOrderbookChannel } from './ws_orderbook_channel';
+import { WebSocketOrdersChannel } from './ws_orders_channel';
-export const orderbookChannelFactory = {
+export const ordersChannelFactory = {
/**
- * Instantiates a new WebSocketOrderbookChannel instance
+ * 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 createWebSocketOrderbookChannelAsync(
+ async createWebSocketOrdersChannelAsync(
url: string,
- handler: OrderbookChannelHandler,
- ): Promise<OrderbookChannel> {
+ handler: OrdersChannelHandler,
+ ): Promise<OrdersChannel> {
assert.isUri('url', url);
assert.isOrderbookChannelHandler('handler', handler);
- return new Promise<OrderbookChannel>((resolve, reject) => {
+ return new Promise<OrdersChannel>((resolve, reject) => {
const client = new WebSocket.w3cwebsocket(url);
client.onopen = () => {
- const orderbookChannel = new WebSocketOrderbookChannel(client, handler);
+ const orderbookChannel = new WebSocketOrdersChannel(client, handler);
resolve(orderbookChannel);
};
client.onerror = err => {
diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts
index 44ea4abd6..e85a0542c 100644
--- a/packages/connect/src/types.ts
+++ b/packages/connect/src/types.ts
@@ -11,32 +11,30 @@ export interface Client {
submitOrderAsync: (signedOrder: SignedOrder) => Promise<void>;
}
-export interface OrderbookChannel {
- subscribe: (subscriptionOpts: OrderbookChannelSubscriptionOpts) => void;
+export interface OrdersChannel {
+ subscribe: (subscriptionOpts: OrdersChannelSubscriptionOpts) => void;
close: () => void;
}
/**
* baseAssetData: The address of assetData designated as the baseToken in the currency pair calculation of price
* quoteAssetData: The address of assetData designated as the quoteToken in the currency pair calculation of price
- * snapshot: If true, a snapshot of the orderbook will be sent before the updates to the orderbook
* limit: Maximum number of bids and asks in orderbook snapshot
*/
-export interface OrderbookChannelSubscriptionOpts {
+export interface OrdersChannelSubscriptionOpts {
baseAssetData: string;
quoteAssetData: string;
- snapshot: boolean;
limit: number;
}
-export interface OrderbookChannelHandler {
+export interface OrdersChannelHandler {
onUpdate: (
- channel: OrderbookChannel,
- subscriptionOpts: OrderbookChannelSubscriptionOpts,
+ channel: OrdersChannel,
+ subscriptionOpts: OrdersChannelSubscriptionOpts,
order: APIOrder,
) => void;
- onError: (channel: OrderbookChannel, err: Error, subscriptionOpts?: OrderbookChannelSubscriptionOpts) => void;
- onClose: (channel: OrderbookChannel) => void;
+ onError: (channel: OrdersChannel, err: Error, subscriptionOpts?: OrdersChannelSubscriptionOpts) => void;
+ onClose: (channel: OrdersChannel) => void;
}
export type OrdersChannelMessage =
diff --git a/packages/connect/src/utils/assert.ts b/packages/connect/src/utils/assert.ts
index 353b7f29f..3d8f1c799 100644
--- a/packages/connect/src/utils/assert.ts
+++ b/packages/connect/src/utils/assert.ts
@@ -10,14 +10,14 @@ import * as _ from 'lodash';
export const assert = {
...sharedAssert,
- isOrderbookChannelSubscriptionOpts(variableName: string, subscriptionOpts: any): void {
+ isOrdersChannelSubscriptionOpts(variableName: string, subscriptionOpts: any): void {
sharedAssert.doesConformToSchema(
variableName,
subscriptionOpts,
schemas.relayerApiOrdersChannelSubscribePayload,
);
},
- isOrderbookChannelHandler(variableName: string, handler: any): void {
+ isOrdersChannelHandler(variableName: string, handler: any): void {
sharedAssert.isFunction(`${variableName}.onUpdate`, _.get(handler, 'onUpdate'));
sharedAssert.isFunction(`${variableName}.onError`, _.get(handler, 'onError'));
sharedAssert.isFunction(`${variableName}.onClose`, _.get(handler, 'onClose'));
diff --git a/packages/connect/src/ws_orderbook_channel.ts b/packages/connect/src/ws_orders_channel.ts
index 425ba8afb..9d45b6570 100644
--- a/packages/connect/src/ws_orderbook_channel.ts
+++ b/packages/connect/src/ws_orders_channel.ts
@@ -3,10 +3,10 @@ import { v4 as uuid } from 'uuid';
import * as WebSocket from 'websocket';
import {
- OrderbookChannel,
- OrderbookChannelHandler,
- OrderbookChannelSubscriptionOpts,
+ OrdersChannel,
+ OrdersChannelHandler,
OrdersChannelMessageTypes,
+ OrdersChannelSubscriptionOpts,
} from './types';
import { assert } from './utils/assert';
import { ordersChannelMessageParser } from './utils/orderbook_channel_message_parser';
@@ -15,19 +15,19 @@ import { ordersChannelMessageParser } from './utils/orderbook_channel_message_pa
* This class includes all the functionality related to interacting with a websocket endpoint
* that implements the standard relayer API v0
*/
-export class WebSocketOrderbookChannel implements OrderbookChannel {
+export class WebSocketOrdersChannel implements OrdersChannel {
private readonly _client: WebSocket.w3cwebsocket;
- private readonly _handler: OrderbookChannelHandler;
- private readonly _subscriptionOptsList: OrderbookChannelSubscriptionOpts[] = [];
+ private readonly _handler: OrdersChannelHandler;
+ private readonly _subscriptionOptsList: OrdersChannelSubscriptionOpts[] = [];
/**
- * Instantiates a new WebSocketOrderbookChannel instance
+ * Instantiates a new WebSocketOrdersChannel instance
* @param client A WebSocket client
- * @param handler An OrderbookChannelHandler instance that responds to various
+ * @param handler An OrdersChannelHandler instance that responds to various
* channel updates
- * @return An instance of WebSocketOrderbookChannel
+ * @return An instance of WebSocketOrdersChannel
*/
- constructor(client: WebSocket.w3cwebsocket, handler: OrderbookChannelHandler) {
- assert.isOrderbookChannelHandler('handler', handler);
+ constructor(client: WebSocket.w3cwebsocket, handler: OrdersChannelHandler) {
+ assert.isOrdersChannelHandler('handler', handler);
// set private members
this._client = client;
this._handler = handler;
@@ -44,16 +44,16 @@ export class WebSocketOrderbookChannel implements OrderbookChannel {
}
/**
* Subscribe to orderbook snapshots and updates from the websocket
- * @param subscriptionOpts An OrderbookChannelSubscriptionOpts instance describing which
+ * @param subscriptionOpts An OrdersChannelSubscriptionOpts instance describing which
* assetData pair to subscribe to
*/
- public subscribe(subscriptionOpts: OrderbookChannelSubscriptionOpts): void {
- assert.isOrderbookChannelSubscriptionOpts('subscriptionOpts', subscriptionOpts);
+ 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 subscribeMessage = {
type: 'subscribe',
- channel: 'orderbook',
+ channel: 'orders',
requestId: uuid(),
payload: subscriptionOpts,
};