-
Notifications
You must be signed in to change notification settings - Fork 1
/
listenAccountOrders.ts
48 lines (40 loc) · 1.04 KB
/
listenAccountOrders.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {invariant} from '@spinfi/shared';
import {OrderInfo} from './listenOrders';
import {websocketErrorMessage} from './messages';
import {createSocket} from '../../utils/createSocket';
/**
* @category listenAccountOrders
*/
export type AccountOrdersState = OrderInfo[];
/**
* @category listenAccountOrders
*/
export type AccountOrdersNotify = OrderInfo;
/**
* @category listenAccountOrders
*/
export interface ListenAccountOrdersRequest {
/**
* Account ID
*/
accountId: string;
}
const CHANNEL_NAME = 'account|orders';
export const listenAccountOrders = createSocket(({snapshotify}) => {
const createMethod = snapshotify<
ListenAccountOrdersRequest,
AccountOrdersNotify,
AccountOrdersState
>((config) => {
return (request, snapshotConfig) => {
invariant(config.websocket, websocketErrorMessage('listenAccountOrders'));
return config.websocket.sendNotifyWithState(
[[`${CHANNEL_NAME}|${request.accountId}`]],
snapshotConfig,
);
};
});
return {
createMethod,
};
});