-
Notifications
You must be signed in to change notification settings - Fork 1
/
getUserTrades.ts
52 lines (45 loc) · 1.07 KB
/
getUserTrades.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
import {invariant} from '@spinfi/shared';
import {nanoid} from 'nanoid';
import {TradeWithId} from './getTrades';
import {websocketErrorMessage} from './messages';
import {createSocket} from '../../utils/createSocket';
/**
* @category getUserTrades
*/
export type GetUserTradesResponse = TradeWithId[];
/**
* @category getUserTrades
*/
export interface GetUserTradesRequest {
/**
* User ID
*/
accountId: number;
/**
* Limit
*/
limit: number;
/**
* Offset
*/
offset: number;
}
const METHOD_NAME = 'get_user_trades';
export const getUserTrades = createSocket(({methodify}) => {
const createMethod = methodify<GetUserTradesRequest, GetUserTradesResponse>((config) => {
return (request, methodConfig) => {
invariant(config.websocket, websocketErrorMessage('getUserTrades'));
return config.websocket.sendMethod(
{
method: METHOD_NAME,
id: nanoid(),
params: [request.accountId, request.limit, request.offset],
},
methodConfig,
);
};
});
return {
createMethod,
};
});