This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
generated from bennycode/ts-node-starter
-
Notifications
You must be signed in to change notification settings - Fork 63
/
FillAPI.ts
71 lines (65 loc) · 2.02 KB
/
FillAPI.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
67
68
69
70
71
import {AxiosInstance} from 'axios';
import {ISO_8601_MS_UTC, UUID_V4, OrderSide, Pagination, PaginatedData} from '../payload/common';
export enum Liquidity {
MAKER = 'M',
TAKER = 'T',
}
export interface Fill {
created_at: ISO_8601_MS_UTC;
fee: string;
liquidity: Liquidity;
order_id: UUID_V4;
price: string;
product_id: string;
profile_id: UUID_V4;
settled: boolean;
side: OrderSide;
size: string;
trade_id: number;
usd_volume: string;
user_id: string;
}
export class FillAPI {
static readonly URL = {
FILLS: `/fills`,
};
constructor(private readonly apiClient: AxiosInstance) {}
/**
* Get a list of recent fills for a given Order of the API key's profile.
*
* @param orderId - ID of previously placed order
* @param pagination - Pagination field
* @see https://docs.pro.coinbase.com/#list-fills
* @see https://pro.coinbase.com/orders/filled
*/
async getFillsByOrderId(orderId: string, pagination?: Pagination): Promise<PaginatedData<Fill>> {
const resource = FillAPI.URL.FILLS;
const response = await this.apiClient.get<Fill[]>(resource, {params: {order_id: orderId, ...pagination}});
return {
data: response.data,
pagination: {
after: response.headers['cb-after'],
before: response.headers['cb-before'],
},
};
}
/**
* Get a list of recent fills for a given Product of the API key's profile.
*
* @param productId - Representation for base and counter
* @param pagination - Pagination field
* @see https://docs.pro.coinbase.com/#list-fills
* @see https://pro.coinbase.com/orders/filled
*/
async getFillsByProductId(productId: string, pagination?: Pagination): Promise<PaginatedData<Fill>> {
const resource = FillAPI.URL.FILLS;
const response = await this.apiClient.get<Fill[]>(resource, {params: {product_id: productId, ...pagination}});
return {
data: response.data,
pagination: {
after: response.headers['cb-after'],
before: response.headers['cb-before'],
},
};
}
}