-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPartnerClient.ts
More file actions
576 lines (529 loc) · 15.1 KB
/
Copy pathPartnerClient.ts
File metadata and controls
576 lines (529 loc) · 15.1 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
import { BaseRestClient } from './lib/BaseRestClient.js';
import { REST_CLIENT_TYPE_ENUM, RestClientType } from './lib/requestUtils.js';
import {
PartnerCancelCustomOrderParams,
PartnerCreateCustomOrderParams,
PartnerCreateUserParams,
PartnerExecuteQuoteParams,
PartnerGetAssetParams,
PartnerGetCustomOrderParams,
PartnerGetEarnSummaryParams,
PartnerGetPortfolioHistoryParams,
PartnerGetPortfolioSummaryParams,
PartnerGetQuoteLimitsParams,
PartnerGetQuoteParams,
PartnerGetRampCheckoutUrlParams,
PartnerGetRampLimitsParams,
PartnerGetRampProspectiveQuoteParams,
PartnerGetSettlementReportParams,
PartnerListAssetRatesParams,
PartnerListAssetsParams,
PartnerListCustomOrdersParams,
PartnerListEarnAssetsParams,
PartnerListFundingTransactionsParams,
PartnerListPortfolioDetailsParams,
PartnerListPortfolioTransactionsParams,
PartnerListSettlementReportsParams,
PartnerRequestProspectiveQuoteParams,
PartnerRequestQuoteParams,
PartnerSubmitVerificationParams,
PartnerToggleAutoEarnParams,
PartnerUpdateUserParams,
PartnerWithdrawFundsParams,
} from './types/request/partner.types.js';
import {
PartnerCancelCustomOrderResponse,
PartnerCreateCustomOrderResponse,
PartnerCreateUserResponse,
PartnerExecuteQuoteResponse,
PartnerGetAssetResponse,
PartnerGetCustomOrderResponse,
PartnerGetEarnSummaryResponse,
PartnerGetPortfolioHistoryResponse,
PartnerGetPortfolioSummaryResponse,
PartnerGetQuoteLimitsResponse,
PartnerGetQuoteResponse,
PartnerGetRampCheckoutUrlResponse,
PartnerGetRampLimitsResponse,
PartnerGetRampProspectiveQuoteResponse,
PartnerGetSettlementReportResponse,
PartnerGetUserResponse,
PartnerListAssetRatesResponse,
PartnerListAssetsResponse,
PartnerListCustomOrdersResponse,
PartnerListEarnAssetsResponse,
PartnerListFundingTransactionsResponse,
PartnerListPortfolioDetailsResponse,
PartnerListPortfolioTransactionsResponse,
PartnerListRampBuyCryptoAssetsResponse,
PartnerListRampCountriesResponse,
PartnerListRampFiatCurrenciesResponse,
PartnerListRampPaymentMethodsResponse,
PartnerListSettlementReportsResponse,
PartnerRequestProspectiveQuoteResponse,
PartnerRequestQuoteResponse,
PartnerSubmitVerificationResponse,
PartnerToggleAutoEarnResponse,
PartnerUpdateUserResponse,
PartnerWithdrawFundsResponse,
} from './types/response/partner.types.js';
/**
* The PartnerClient provides integration to the Kraken Partner API.
*
* Docs:
* - https://docs.kraken.com/api/docs/embed-api
* - https://docs.kraken.com/api/docs/ramp-api
*/
export class PartnerClient extends BaseRestClient {
getClientType(): RestClientType {
return REST_CLIENT_TYPE_ENUM.partner;
}
/**
*
* Partner REST API - Embed API - Users
*
*/
/**
* Create User
*
* Create a new user in the Kraken system.
*/
createEmbedUser(
params: PartnerCreateUserParams,
): Promise<PartnerCreateUserResponse> {
return this.postPrivate('b2b/users', {
body: params,
});
}
/**
* Get User
*
* Get a previously created user.
*/
getEmbedUser(params: { user: string }): Promise<PartnerGetUserResponse> {
return this.getPrivate(`b2b/users/${params.user}`);
}
/**
* Update User
*
* Update an existing user's profile.
*/
updateEmbedUser(
params: PartnerUpdateUserParams,
): Promise<PartnerUpdateUserResponse> {
const { user, ...bodyParams } = params;
return this.patchPrivate(`b2b/users/${user}`, {
body: bodyParams,
});
}
/**
*
* Partner REST API - Embed API - Verifications
*
*/
/**
* Submit Verification
*
* Submit a verification for a user with documents and details.
* A verification is defined as a check that has been performed on a user to verify information provided by the user.
* Note: This endpoint uses multipart/form-data for file uploads.
*/
submitEmbedVerification(
params: PartnerSubmitVerificationParams,
): Promise<PartnerSubmitVerificationResponse> {
const { user, ...bodyParams } = params;
return this.postPrivate(`b2b/verifications/${user}`, {
body: bodyParams,
});
}
/**
*
* Partner REST API - Embed API - Assets
*
*/
/**
* List Assets
*
* List all assets available on the platform.
* This endpoint returns a list of all assets available on the platform.
*/
listEmbedAssets(
params?: PartnerListAssetsParams,
): Promise<PartnerListAssetsResponse> {
return this.getPrivate('b2b/assets', params);
}
/**
* Get Asset
*
* Get information about a specific asset.
*/
getEmbedAsset(
params: PartnerGetAssetParams,
): Promise<PartnerGetAssetResponse> {
const { asset, ...queryParams } = params;
return this.getPrivate(`b2b/assets/${asset}`, queryParams);
}
/**
* List Asset Rates
*
* Returns historical rates for a given asset.
* This endpoint returns historical rates for a given asset with timestamp and median price for each period.
*/
listEmbedAssetRates(
params: PartnerListAssetRatesParams,
): Promise<PartnerListAssetRatesResponse> {
const { asset, ...queryParams } = params;
return this.getPrivate(`b2b/assets/${asset}/rates`, queryParams);
}
/**
*
* Partner REST API - Embed API - Quotes
*
*/
/**
* Request Quote
*
* Request a price quote for an asset, that may be used to execute a trade later on.
*/
requestEmbedQuote(
params: PartnerRequestQuoteParams,
): Promise<PartnerRequestQuoteResponse> {
const { user, ...bodyParams } = params;
return this.postPrivate('b2b/quotes', {
query: { user },
body: bodyParams,
});
}
/**
* Get Quote
*
* Gets the status of a quote that was previously requested.
*/
getEmbedQuote(
params: PartnerGetQuoteParams,
): Promise<PartnerGetQuoteResponse> {
const { quote_id, user } = params;
return this.getPrivate(`b2b/quotes/${quote_id}`, { user });
}
/**
* Execute Quote
*
* Executes a quote that was previously requested.
*/
executeEmbedQuote(
params: PartnerExecuteQuoteParams,
): Promise<PartnerExecuteQuoteResponse> {
const { quote_id, ...queryParams } = params;
return this.putPrivate(`b2b/quotes/${quote_id}`, {
query: queryParams,
});
}
/**
* Get Quote Limits (RFQ)
*
* Request minimum, maximum and precision for trade using a given asset pair.
*/
getEmbedQuoteLimits(
params: PartnerGetQuoteLimitsParams,
): Promise<PartnerGetQuoteLimitsResponse> {
return this.getPrivate('b2b/quotes/limits', params);
}
/**
* Request Prospective Quote (RFQ)
*
* Request a prospective quote for an asset pair, to receive an indicative price and fee.
*/
requestEmbedProspectiveQuote(
params: PartnerRequestProspectiveQuoteParams,
): Promise<PartnerRequestProspectiveQuoteResponse> {
const { user, ...bodyParams } = params;
return this.postPrivate('b2b/quotes/prospective', {
query: { user },
body: bodyParams,
});
}
/**
*
* Partner REST API - Embed API - Custom Orders
*
*/
/**
* Create Custom Order
*
* Submit a custom order with a specified trigger condition (e.g. price-triggered).
*/
createEmbedCustomOrder(
params: PartnerCreateCustomOrderParams,
): Promise<PartnerCreateCustomOrderResponse> {
const { user, ...bodyParams } = params;
return this.postPrivate('b2b/custom-orders', {
query: { user },
body: bodyParams,
});
}
/**
* List Custom Orders
*
* Get a list of custom orders that were previously submitted.
*/
listEmbedCustomOrders(
params: PartnerListCustomOrdersParams,
): Promise<PartnerListCustomOrdersResponse> {
return this.getPrivate('b2b/custom-orders', params);
}
/**
* Get Custom Order
*
* Get a single custom order by ID.
*/
getEmbedCustomOrder(
params: PartnerGetCustomOrderParams,
): Promise<PartnerGetCustomOrderResponse> {
const { user, order_id } = params;
return this.getPrivate(`b2b/custom-orders/${order_id}`, { user });
}
/**
* Cancel Custom Order
*
* Cancels a custom order that was previously submitted but not yet completed.
*/
cancelEmbedCustomOrder(
params: PartnerCancelCustomOrderParams,
): Promise<PartnerCancelCustomOrderResponse> {
const { user, id } = params;
return this.postPrivate(`b2b/custom-orders/${id}/cancel`, {
query: { user },
});
}
/**
*
* Partner REST API - Embed API - Portfolios
*
*/
/**
* Get Portfolio Summary
*
* Get the portfolio summary for a user.
*/
getEmbedPortfolioSummary(
params: PartnerGetPortfolioSummaryParams,
): Promise<PartnerGetPortfolioSummaryResponse> {
const { user, ...queryParams } = params;
return this.getPrivate(`b2b/portfolio/${user}/summary`, queryParams);
}
/**
* Get Portfolio History
*
* Gets a portfolio's historical balances and valuations over time.
* Note: Balance for the last day shows up at UTC + 5h due to processing times.
*/
getEmbedPortfolioHistory(
params: PartnerGetPortfolioHistoryParams,
): Promise<PartnerGetPortfolioHistoryResponse> {
const { user, ...queryParams } = params;
return this.getPrivate(`b2b/portfolio/${user}/history`, queryParams);
}
/**
* List Portfolio Details
*
* Lists owned assets in a user's portfolio.
*/
listEmbedPortfolioDetails(
params: PartnerListPortfolioDetailsParams,
): Promise<PartnerListPortfolioDetailsResponse> {
const { user, ...queryParams } = params;
return this.getPrivate(`b2b/portfolio/${user}/details`, queryParams);
}
/**
* List Portfolio Transactions
*
* Lists the user's trades and transactions.
*/
listEmbedPortfolioTransactions(
params: PartnerListPortfolioTransactionsParams,
): Promise<PartnerListPortfolioTransactionsResponse> {
const { user, ...queryParams } = params;
return this.getPrivate(`b2b/portfolio/${user}/transactions`, queryParams);
}
/**
*
* Partner REST API - Embed API - Earn
*
*/
/**
* Get Earn Summary
*
* Get Earn summary of a user.
* Response holds total amounts (all-time). For per-asset granularity, use listEarnAssets().
*/
getEmbedEarnSummary(
params: PartnerGetEarnSummaryParams,
): Promise<PartnerGetEarnSummaryResponse> {
const { user, ...queryParams } = params;
return this.getPrivate(`b2b/earn/${user}`, queryParams);
}
/**
* List Earn Assets
*
* List Earn Assets.
* The user can optionally be passed in the request, which shows active asset allocations of the user in the response.
*/
listEmbedEarnAssets(
params?: PartnerListEarnAssetsParams,
): Promise<PartnerListEarnAssetsResponse> {
return this.getPrivate('b2b/earn/assets', params);
}
/**
* Toggle Auto-Earn
*
* Toggle Auto-Earn of a user.
* Toggling Auto-Earn is an async operation. The response is empty on success.
* To fetch the user's current Auto-Earn status, use getEarnSummary().
*/
toggleEmbedAutoEarn(
params: PartnerToggleAutoEarnParams,
): Promise<PartnerToggleAutoEarnResponse> {
const { user, ...queryParams } = params;
return this.putPrivate(`b2b/earn/${user}/auto`, {
query: queryParams,
});
}
/**
*
* Partner REST API - Embed API - Transfers
*
*/
/**
* Withdraw Funds
*
* Withdraw funds.
* Note: Currently, this is a master-only operation. No User parameter exists.
*/
withdrawEmbedFunds(
params: PartnerWithdrawFundsParams,
): Promise<PartnerWithdrawFundsResponse> {
return this.postPrivate('b2b/funds/withdrawals', {
body: params,
});
}
/**
* List Funding Transactions
*
* List Funding transactions.
* Funding transactions can be of type withdrawal or deposit.
* Note: Currently, this is a master-only operation. No User parameter exists.
*/
listEmbedFundingTransactions(
params: PartnerListFundingTransactionsParams,
): Promise<PartnerListFundingTransactionsResponse> {
return this.getPrivate('b2b/funds/transactions', params);
}
/**
*
* Partner REST API - Embed API - Reports
*
*/
/**
* List Settlement Reports
*
* Retrieves a paginated list of settlement reports available to the authenticated master user,
* with optional filters for date range and report type.
*/
listEmbedSettlementReports(
params?: PartnerListSettlementReportsParams,
): Promise<PartnerListSettlementReportsResponse> {
return this.getPrivate('b2b/reports/settlement', params);
}
/**
* Get Settlement Report
*
* Retrieves a settlement report and provides a secure download URL for the authenticated master user.
*/
getEmbedSettlementReport(
params: PartnerGetSettlementReportParams,
): Promise<PartnerGetSettlementReportResponse> {
return this.getPrivate(`b2b/reports/settlement/${params.id}`);
}
/**
*
* Partner REST API - Ramp API - Supported Options
*
*/
/**
* List Buy Crypto Assets
*
* List cryptocurrency assets available for Ramp buy transactions,
* including the networks, withdrawal methods, and provider-specific identifiers.
*/
listRampBuyCryptoAssets(): Promise<PartnerListRampBuyCryptoAssetsResponse> {
return this.getPrivate('b2b/ramp/buy/crypto');
}
/**
* List Fiat Currencies
*
* List fiat currencies supported for funding Ramp transactions.
*/
listRampFiatCurrencies(): Promise<PartnerListRampFiatCurrenciesResponse> {
return this.getPrivate('b2b/ramp/fiat-currencies');
}
/**
* List Payment Methods
*
* List fiat payment methods supported for Ramp deposits,
* including optional mapping to provider-specific identifiers.
*/
listRampPaymentMethods(): Promise<PartnerListRampPaymentMethodsResponse> {
return this.getPrivate('b2b/ramp/payment-methods');
}
/**
* List Countries
*
* List countries and regions where Ramp is available.
* Depending on regulatory rules, availability may be scoped to specific states, provinces, or regions.
*/
listRampCountries(): Promise<PartnerListRampCountriesResponse> {
return this.getPrivate('b2b/ramp/countries');
}
/**
*
* Partner REST API - Ramp API - Quotes
*
*/
/**
* Get Limits
*
* Retrieve combined min/max limits for a Ramp transaction configuration.
*/
getRampLimits(
params: PartnerGetRampLimitsParams,
): Promise<PartnerGetRampLimitsResponse> {
return this.getPrivate('b2b/ramp/limits', params);
}
/**
* Get Prospective Quote
*
* Retrieve a prospective quote for a Ramp transaction without reserving liquidity.
* Use this to preview spend/receive amounts before creating a checkout URL.
*/
getRampProspectiveQuote(
params: PartnerGetRampProspectiveQuoteParams,
): Promise<PartnerGetRampProspectiveQuoteResponse> {
return this.getPrivate('b2b/ramp/quotes/prospective', params);
}
/**
*
* Partner REST API - Ramp API - Checkout
*
*/
/**
* Get Checkout URL
*
* Generate a hosted Ramp checkout URL for the provided transaction configuration.
* The response echoes the request parameters so the Ramp partner can confirm what was submitted.
*/
getRampCheckoutUrl(
params: PartnerGetRampCheckoutUrlParams,
): Promise<PartnerGetRampCheckoutUrlResponse> {
return this.getPrivate('b2b/ramp/checkout', params);
}
}