-
Notifications
You must be signed in to change notification settings - Fork 1
/
listenBookL1.ts
61 lines (52 loc) · 1.15 KB
/
listenBookL1.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
import {invariant} from '@spinfi/shared';
import {websocketErrorMessage} from './messages';
import {createSocket} from '../../utils/createSocket';
/**
* @category listenBookL1
*/
export type BookNode = [string, string];
/**
* @category listenBookL1
*/
export interface Book {
/**
* [price, quantity] tuples arrayy
*/
asks: BookNode[];
/**
* [price, quantity] tuples arrayy
*/
bids: BookNode[];
/**
* Timestamp in nanoseconds (1 second = 1 * 10^9 nanosecond)
*/
ts: string;
}
/**
* @category listenBookL1
*/
export type BookL1Notify = Book;
/**
* @category listenBookL1
*/
export interface ListenBookL1Request {
/**
* Market ID
*/
marketId: number;
}
const CHANNEL_NAME = 'bookL1';
export const listenBookL1 = createSocket(({notify}) => {
const createMethod = notify<ListenBookL1Request, BookL1Notify>((config) => {
return (request, notificationConfig) => {
invariant(config.websocket, websocketErrorMessage('listenBookL1'));
return config.websocket.sendNotify(
[[`${CHANNEL_NAME}|${request.marketId}`]],
notificationConfig,
);
};
});
return {
createMethod,
};
});