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
/
TransferAPI.ts
92 lines (86 loc) · 2.57 KB
/
TransferAPI.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import {AxiosInstance} from 'axios';
import {ISO_8601_MS_UTC, PaginatedData, Pagination} from '../payload/common';
import querystring from 'querystring';
export interface TransferInformation {
account_id: string;
amount: string;
canceled_at?: ISO_8601_MS_UTC;
completed_at?: ISO_8601_MS_UTC;
created_at: ISO_8601_MS_UTC;
details: {
coinbase_account_id?: string;
coinbase_payment_method_id?: string;
coinbase_transaction_id?: string;
coinbase_withdrawal_id?: string;
crypto_address?: string;
crypto_transaction_hash?: string;
crypto_transaction_id?: string;
destination_tag: string;
destination_tag_name?: string;
sent_to_address?: string;
};
id: string;
processed_at?: ISO_8601_MS_UTC;
type: string;
user_id: string;
user_nonce?: string;
}
export enum TransferType {
DEPOSIT = 'deposit',
INTERNAL_DEPOSIT = 'internal_deposit',
INTERNAL_WITHDRAW = 'internal_withdraw',
WITHDRAW = 'withdraw',
}
export class TransferAPI {
static readonly URL = {
TRANSFERS: `/transfers`,
};
constructor(private readonly apiClient: AxiosInstance) {}
/**
* Get a list of deposits/withdrawals from the profile of the API key, in descending order by created time.
*
* @param pagination - Pagination field
* @see https://docs.pro.coinbase.com/#list-deposits
* @see https://docs.pro.coinbase.com/#list-withdrawals
*/
async getTransfers(
transferType: TransferType,
profileId?: string,
pagination?: Pagination
): Promise<PaginatedData<TransferInformation>> {
const resource = TransferAPI.URL.TRANSFERS;
const params: Pagination & {
profile_id?: string;
type: TransferType;
} = {
...pagination,
type: transferType,
};
if (profileId) {
params.profile_id = profileId;
}
const response = await this.apiClient.get<TransferInformation[]>(resource, {
params,
paramsSerializer: querystring.stringify,
});
return {
data: response.data,
pagination: {
after: response.headers['cb-after'],
before: response.headers['cb-before'],
},
};
}
/**
* Get information on a single deposit/withdrawal.
*
* @param transferId - id of the requested resource
* @see https://docs.pro.coinbase.com/#single-deposit
* @see https://docs.pro.coinbase.com/#single-withdrawal
*/
async getTransfer(transferId: string): Promise<TransferInformation> {
const resource = `${TransferAPI.URL.TRANSFERS}/${transferId}`;
const response = await this.apiClient.get<TransferInformation>(resource);
return response.data;
}
}