-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathBrokerClient.ts
More file actions
240 lines (226 loc) · 6.88 KB
/
BrokerClient.ts
File metadata and controls
240 lines (226 loc) · 6.88 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import { BaseRestClient } from './lib/BaseRestClient.js';
import { REST_CLIENT_TYPE_ENUM, RestClientType } from './lib/requestUtils.js';
import {
BrokerTransferRequest,
CreateBrokerSubAccountApiRequest,
DeleteBrokerSubAccountApiRequest,
GetBrokerDepositListRequest,
GetBrokerInfoRequest,
GetBrokerSubAccountApisRequest,
GetBrokerSubAccountsRequest,
UpdateBrokerSubAccountApiRequest,
} from './types/request/broker.types.js';
import {
BrokerDepositRecord,
BrokerInfo,
BrokerSubAccountApi,
BrokerTransferHistory,
BrokerWithdrawalRecord,
CreateBrokerSubAccountApiResponse,
CreateBrokerSubAccountResponse,
GetBrokerSubAccountsResponse,
} from './types/response/broker.types.js';
import { APISuccessResponse } from './types/response/shared.types.js';
/**
*
*/
export class BrokerClient extends BaseRestClient {
getClientType(): RestClientType {
return REST_CLIENT_TYPE_ENUM.broker;
}
/**
* Get Broker Info
*
* This endpoint supports querying the basic information of the current Broker
*/
getBrokerInfo(
params: GetBrokerInfoRequest,
): Promise<APISuccessResponse<BrokerInfo>> {
return this.getPrivate('api/v1/broker/nd/info', params);
}
/**
* Add SubAccount
*
* This endpoint supports Broker users to create sub-accounts.
* Note that the account name is unique across the exchange.
* It is recommended to add a special identifier to prevent name duplication.
*/
createSubAccount(params: {
accountName: string;
}): Promise<APISuccessResponse<CreateBrokerSubAccountResponse>> {
return this.postPrivate('api/v1/broker/nd/account', params);
}
/**
* Get SubAccount
*
* This interface supports querying sub-accounts created by Broker.
* Returns paginated results with default page size of 20 (max 100).
*/
getSubAccounts(
params: GetBrokerSubAccountsRequest,
): Promise<APISuccessResponse<GetBrokerSubAccountsResponse>> {
return this.getPrivate('api/v1/broker/nd/account', params);
}
/**
* Add SubAccount API
*
* This interface supports the creation of Broker sub-account APIKEY.
* Supports up to 20 IPs in the whitelist.
* Only General, Spot, and Futures permissions can be set.
* Label must be between 4 and 32 characters.
*/
createSubAccountApi(
params: CreateBrokerSubAccountApiRequest,
): Promise<APISuccessResponse<CreateBrokerSubAccountApiResponse>> {
return this.postPrivate('api/v1/broker/nd/account/apikey', params);
}
/**
* Get SubAccount API
*
* This interface supports querying the Broker's sub-account APIKEYs.
* Can optionally filter by specific apiKey.
*/
getSubAccountApis(
params: GetBrokerSubAccountApisRequest,
): Promise<APISuccessResponse<BrokerSubAccountApi[]>> {
return this.getPrivate('api/v1/broker/nd/account/apikey', params);
}
/**
* Modify SubAccount API
*
* This interface supports modifying the Broker's sub-account APIKEY.
* Supports up to 20 IPs in the whitelist.
* Only General, Spot, and Futures permissions can be set.
* Label must be between 4 and 32 characters.
*/
updateSubAccountApi(
params: UpdateBrokerSubAccountApiRequest,
): Promise<APISuccessResponse<BrokerSubAccountApi>> {
return this.postPrivate('api/v1/broker/nd/account/update-apikey', params);
}
/**
* Delete SubAccount API
*
* This interface supports deleting Broker's sub-account APIKEY.
*/
deleteSubAccountApi(
params: DeleteBrokerSubAccountApiRequest,
): Promise<APISuccessResponse<boolean>> {
return this.deletePrivate('api/v1/broker/nd/account/apikey', params);
}
/**
* Transfer
*
* This endpoint supports fund transfer between Broker account and Broker sub-accounts.
* Please be aware that withdrawal from sub-account is not directly supported.
* Broker has to transfer funds from broker sub-account to broker account to initiate the withdrawals.
*
* Direction:
* - OUT: Broker account is transferred to Broker sub-account
* - IN: Broker sub-account is transferred to Broker account
*
* Account Types:
* - MAIN: Funding account
* - TRADE: Spot trading account
*/
submitTransfer(params: BrokerTransferRequest): Promise<
APISuccessResponse<{
orderId: string;
}>
> {
return this.postPrivate('api/v1/broker/nd/transfer', params);
}
/**
* Get Transfer History
*
* This endpoint supports querying transfer records of the broker itself and its created sub-accounts.
*
* Account Types:
* - MAIN: Funding account
* - TRADE: Spot trading account
* - CONTRACT: Contract account
* - MARGIN: Margin account
* - ISOLATED: Isolated margin account
*
* Status:
* - PROCESSING: Processing
* - SUCCESS: Successful
* - FAILURE: Failed
*/
getTransferHistory(params: {
orderId: string;
}): Promise<APISuccessResponse<BrokerTransferHistory>> {
return this.getPrivate('api/v3/broker/nd/transfer/detail', params);
}
/**
* Get Deposit List
*
* This endpoint can obtain the deposit records of each sub-account under the ND Broker.
* Default limit is 1000 records (max 1000).
* Results are sorted in descending order by default.
*
* Status:
* - PROCESSING: Processing
* - SUCCESS: Successful
* - FAILURE: Failed
*/
getDeposits(
params?: GetBrokerDepositListRequest,
): Promise<APISuccessResponse<BrokerDepositRecord[]>> {
return this.getPrivate('api/v1/asset/ndbroker/deposit/list', params);
}
/**
* Get Deposit Detail
*
* This endpoint supports querying the deposit record of sub-accounts created by a Broker
* (excluding main account of nd broker).
*
* Status:
* - PROCESSING: Processing
* - SUCCESS: Successful
* - FAILURE: Failed
*/
getDeposit(params: {
currency: string;
hash: string;
}): Promise<APISuccessResponse<BrokerDepositRecord>> {
return this.getPrivate('api/v3/broker/nd/deposit/detail', params);
}
/**
* Get Withdrawal Detail
*
* This endpoint supports querying the withdrawal records of sub-accounts created by a Broker
* (excluding main account of nd broker).
*
* Status:
* - PROCESSING: Processing
* - WALLET_PROCESSING: Wallet Processing
* - REVIEW: Under Review
* - SUCCESS: Successful
* - FAILURE: Failed
*/
getWithdrawal(params: {
withdrawalId: string;
}): Promise<APISuccessResponse<BrokerWithdrawalRecord>> {
return this.getPrivate('api/v3/broker/nd/withdraw/detail', params);
}
/**
* Get Broker Rebate
*
* This interface supports downloading Broker rebate orders.
* Returns a URL to download a CSV file containing the rebate data.
* The URL is valid for 1 day.
* Maximum interval between begin and end dates is 6 months.
*/
getBrokerRebate(params: {
begin: string;
end: string;
tradeType: '1' | '2';
}): Promise<
APISuccessResponse<{
url: string;
}>
> {
return this.getPrivate('api/v1/broker/nd/rebase/download', params);
}
}