-
Notifications
You must be signed in to change notification settings - Fork 1
/
listenAccountOrders.ts
66 lines (57 loc) · 1.39 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import {invariant} from '@spinfi/shared';
import {websocketErrorMessage} from './messages';
import {createSocket} from '../../utils/createSocket';
/**
* @category listenAccountOrders
*/
export interface OrderInfo {
account_id: string;
average_price: string;
block_number: number;
client_order_id: string | null;
market_id: number;
order_id: string;
price: string;
quantity: string;
remaining: string;
side: 'ask' | 'bid';
status: 'new' | 'filled' | 'partially_filled' | 'cancelled' | 'expired';
txn_hash: string;
ts: string;
}
/**
* @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,
};
});