-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CBInternationalClient.ts
675 lines (612 loc) · 17 KB
/
CBInternationalClient.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
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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
import { AxiosRequestConfig } from 'axios';
import { BaseRestClient } from './lib/BaseRestClient.js';
import {
REST_CLIENT_TYPE_ENUM,
RestClientOptions,
RestClientType,
} from './lib/requestUtils.js';
import {
CancelINTXOrdersRequest,
GetINTXAggregatedCandlesData,
GetINTXDailyTradingVolumes,
GetINTXFillsByPortfoliosRequest,
GetINTXIndexCandlesRequest,
GetINTXIndexCompositionHistory,
GetINTXMatchingTransfersRequest,
GetINTXOpenOrdersRequest,
GetINTXPortfolioFillsRequest,
INTXWithdrawToCounterpartyIdRequest,
INTXWithdrawToCryptoAddressRequest,
SubmitINTXOrderRequest,
TransferINTXFundsBetweenPortfoliosRequest,
TransferINTXPositionsBetweenPortfoliosRequest,
UpdateINTXOpenOrderRequest,
UpdateINTXPortfolioParametersRequest,
} from './types/request/coinbase-international.js';
/**
* REST client for Coinbase's Institutional International Exchange API:
* https://docs.cdp.coinbase.com/intx/docs/welcome
*/
export class CBInternationalClient extends BaseRestClient {
constructor(
restClientOptions: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {},
) {
super(restClientOptions, requestOptions);
return this;
}
getClientType(): RestClientType {
return REST_CLIENT_TYPE_ENUM.international;
}
/**
*
* Assets Endpoints
*
*/
/**
* List assets
*
* Returns a list of all supported assets.
*/
getAssets(): Promise<any> {
return this.get('/api/v1/assets');
}
/**
* Get asset details
*
* Retrieves information for a specific asset.
*/
getAssetDetails(params: { asset: string }): Promise<any> {
return this.get(`/api/v1/assets/${params.asset}`);
}
/**
* Get supported networks per asset
*
* Returns a list of supported networks and network information for a specific asset.
*/
getSupportedNetworksPerAsset(params: { asset: string }): Promise<any> {
return this.get(`/api/v1/assets/${params.asset}/networks`);
}
/**
*
* Index Endpoints
*
*/
/**
* Get index composition
*
* Retrieves the latest index composition (metadata) with an ordered set of constituents.
*/
getIndexComposition(params: { index: string }): Promise<any> {
return this.get(`/api/v1/index/${params.index}/composition`);
}
/**
* Get index composition history
*
* Retrieves a history of index composition records in a descending time order.
* The results are an array of index composition data recorded at different "timestamps".
*/
getIndexCompositionHistory(
params: GetINTXIndexCompositionHistory,
): Promise<any> {
const { index, ...query } = params;
return this.get(`/api/v1/index/${index}/composition-history`, query);
}
/**
* Get index price
*
* Retrieves the latest index price.
*/
getIndexPrice(params: { index: string }): Promise<any> {
return this.get(`/api/v1/index/${params.index}/price`);
}
/**
* Get index candles
*
* Retrieves the historical daily index prices in time descending order.
* The daily values are represented as aggregated entries for the day in typical OHLC format.
*/
getIndexCandles(params: GetINTXIndexCandlesRequest): Promise<any> {
const { index, ...query } = params;
return this.get(`/api/v1/index/${index}/candles`, query);
}
/**
*
* Instruments Endpoints
*
*/
/**
* List instruments
*
* Returns all of the instruments available for trading.
*/
getInstruments(): Promise<any> {
return this.get('/api/v1/instruments');
}
/**
* Get instrument details
*
* Retrieves market information for a specific instrument.
*/
getInstrumentDetails(params: { instrument: string }): Promise<any> {
return this.get(`/api/v1/instruments/${params.instrument}`);
}
/**
* Get quote per instrument
*
* Retrieves the current quote for a specific instrument.
*/
getQuotePerInstrument(params: { instrument: string }): Promise<any> {
return this.get(`/api/v1/instruments/${params.instrument}/quote`);
}
/**
* Get daily trading volumes
*
* Retrieves the trading volumes for each instrument separated by day.
*/
getDailyTradingVolumes(params: GetINTXDailyTradingVolumes): Promise<any> {
return this.get('/api/v1/instruments/volumes/daily', params);
}
/**
* Get aggregated candles data per instrument
*
* Retrieves a list of aggregated candles data for a given instrument, granularity, and time range.
*/
getAggregatedCandlesData(params: GetINTXAggregatedCandlesData): Promise<any> {
const { instrument, ...query } = params;
return this.get(`/api/v1/instruments/${instrument}/candles`, query);
}
/**
* Get historical funding rates
*
* Retrieves the historical funding rates for a specific instrument.
*/
getHistoricalFundingRates(params: {
instrument: string;
result_limit?: number;
result_offset?: number;
}): Promise<any> {
const { instrument, ...query } = params;
return this.get(`/api/v1/instruments/${instrument}/funding`, query);
}
/**
*
* Position Offsets Endpoints
*
*/
/**
* List position offsets
*
* Returns all active position offsets.
*/
getPositionOffsets(): Promise<any> {
return this.get('/api/v1/position-offsets');
}
/**
*
* Orders Endpoints
*
*/
/**
* Create order
*
* Creates a new order.
*/
submitOrder(params: SubmitINTXOrderRequest): Promise<any> {
this.validateOrderId(params, 'client_order_id');
return this.postPrivate('/api/v1/orders', { body: params });
}
/**
* List open orders
*
* Returns a list of active orders resting on the order book matching the requested criteria.
* Does not return any rejected, cancelled, or fully filled orders as they are not active.
*/
getOpenOrders(params?: GetINTXOpenOrdersRequest): Promise<any> {
return this.getPrivate('/api/v1/orders', params);
}
/**
* Cancel orders
*
* Cancels all orders matching the requested criteria.
*/
cancelOrders(params: CancelINTXOrdersRequest): Promise<any> {
return this.deletePrivate('/api/v1/orders', {
query: params,
});
}
/**
* Modify open order
*
* Modifies an open order.
*/
updateOpenOrder(params: UpdateINTXOpenOrderRequest): Promise<any> {
const { id, ...body } = params;
return this.putPrivate(`/api/v1/orders/${id}`, { body: body });
}
/**
* Get order details
*
* Retrieves a single order. The order retrieved can be either active or inactive.
*/
getOrderDetails(params: { id: string; portfolio: string }): Promise<any> {
const { id, ...query } = params;
return this.getPrivate(`/api/v1/orders/${id}`, query);
}
/**
* Cancel order
*
* Cancels a single open order.
*/
cancelOrder(params: { id: string; portfolio: string }): Promise<any> {
const { id, ...query } = params;
return this.deletePrivate(`/api/v1/orders/${id}`, {
query: query,
});
}
/**
*
* Portfolios Endpoints
*
*/
/**
* List all user portfolios
*
* Returns all of the user's portfolios.
*/
getUserPortfolios(): Promise<any> {
return this.getPrivate('/api/v1/portfolios');
}
/**
* Create portfolio
*
* Create a new portfolio. Request will fail if no name is provided or if user already has max number of portfolios. Max number of portfolios is 20.
*/
createPortfolio(params: { name: string }): Promise<any> {
return this.postPrivate('/api/v1/portfolios', { body: params });
}
/**
* Patch portfolio
*
* Update parameters for existing portfolio.
*/
updatePortfolioParameters(
params: UpdateINTXPortfolioParametersRequest,
): Promise<any> {
return this.patchPrivate('/api/v1/portfolios', { body: params });
}
/**
* Get user portfolio
*
* Returns the user's specified portfolio.
*/
getUserPortfolio(params: { portfolio: string }): Promise<any> {
return this.getPrivate(`/api/v1/portfolios/${params.portfolio}`);
}
/**
* Update portfolio
*
* Update existing user portfolio.
*/
updatePortfolio(params: { portfolio: string; name: string }): Promise<any> {
const { portfolio, ...body } = params;
return this.putPrivate(`/api/v1/portfolios/${portfolio}`, { body: body });
}
/**
* Get portfolio details
*
* Retrieves the summary, positions, and balances of a portfolio.
*/
getPortfolioDetails(params: { portfolio: string }): Promise<any> {
return this.getPrivate(`/api/v1/portfolios/${params.portfolio}/detail`);
}
/**
* Get portfolio summary
*
* Retrieves the high level overview of a portfolio.
*/
getPortfolioSummary(params: { portfolio: string }): Promise<any> {
return this.getPrivate(`/api/v1/portfolios/${params.portfolio}/summary`);
}
/**
* List portfolio balances
*
* Returns all of the balances for a given portfolio.
*/
getPortfolioBalances(params: { portfolio: string }): Promise<any> {
return this.getPrivate(`/api/v1/portfolios/${params.portfolio}/balances`);
}
/**
* Get balance for portfolio/asset
*
* Retrieves the balance for a given portfolio and asset.
*/
getBalanceForPortfolioAsset(params: {
portfolio: string;
asset: string;
}): Promise<any> {
return this.getPrivate(
`/api/v1/portfolios/${params.portfolio}/balances/${params.asset}`,
);
}
/**
* List active loans for the portfolio
*
* Retrieves all loan info for a given portfolio.
*/
getActiveLoansForPortfolio(params: { portfolio: string }): Promise<any> {
return this.getPrivate(`/api/v1/portfolios/${params.portfolio}/loans`);
}
/**
* Get loan info for portfolio/asset
*
* Retrieves the loan info for a given portfolio and asset.
*/
getLoanInfoForPortfolioAsset(params: {
portfolio: string;
asset: string;
}): Promise<any> {
return this.getPrivate(
`/api/v1/portfolios/${params.portfolio}/loans/${params.asset}`,
);
}
/**
* Acquire/repay loan
*
* Acquire or repay loan for a given portfolio and asset.
*/
acquireOrRepayLoan(params: {
portfolio: string;
asset: string;
amount: number;
action: 'ACQUIRE' | 'REPAY';
}): Promise<any> {
const { portfolio, asset, ...body } = params;
return this.postPrivate(`/api/v1/portfolios/${portfolio}/loans/${asset}`, {
body,
});
}
/**
* Preview loan update
*
* Preview acquire or repay loan for a given portfolio and asset.
*/
previewLoanUpdate(params: {
portfolio: string;
asset: string;
action: 'ACQUIRE' | 'REPAY';
amount: string;
}): Promise<any> {
const { portfolio, asset, ...body } = params;
return this.postPrivate(
`/api/v1/portfolios/${portfolio}/loans/${asset}/preview`,
{ body },
);
}
/**
* View max loan availability
*
* View the maximum amount of loan that could be acquired now for a given portfolio and asset.
*/
getMaxLoanAvailability(params: {
portfolio: string;
asset: string;
}): Promise<any> {
return this.getPrivate(
`/api/v1/portfolios/${params.portfolio}/loans/${params.asset}/availability`,
);
}
/**
* List portfolio positions
*
* Returns all of the positions for a given portfolio.
*/
getPortfolioPositions(params: { portfolio: string }): Promise<any> {
return this.getPrivate(`/api/v1/portfolios/${params.portfolio}/positions`);
}
/**
* Get position for portfolio/instrument
*
* Retrieves the position for a given portfolio and symbol.
*/
getPositionForPortfolioInstrument(params: {
portfolio: string;
instrument: string;
}): Promise<any> {
return this.getPrivate(
`/api/v1/portfolios/${params.portfolio}/positions/${params.instrument}`,
);
}
/**
* List fills by portfolios
*
* Returns fills for specified portfolios or fills for all portfolios if none are provided.
*/
getFillsByPortfolios(params?: GetINTXFillsByPortfoliosRequest): Promise<any> {
return this.getPrivate('/api/v1/portfolios/fills', params);
}
/**
* List portfolio fills
*
* Returns all of the fills for a given portfolio.
*/
getPortfolioFills(params: GetINTXPortfolioFillsRequest): Promise<any> {
const { portfolio, ...query } = params;
return this.getPrivate(`/api/v1/portfolios/${portfolio}/fills`, query);
}
/**
* Enable/Disable portfolio cross collateral
*
* Enable or disable the cross collateral feature for the portfolio, which allows the portfolio to use non-USDC assets as collateral for margin trading.
*/
setCrossCollateral(params: {
portfolio: string;
enabled: boolean;
}): Promise<any> {
const { portfolio, ...body } = params;
return this.postPrivate(
`/api/v1/portfolios/${portfolio}/cross-collateral-enabled`,
{ body: body },
);
}
/**
* Enable/Disable portfolio auto margin mode
*
* Enable or disable the auto margin feature, which lets the portfolio automatically
* post margin amounts required to exceed the high leverage position restrictions.
*/
setAutoMargin(params: { portfolio: string; enabled: boolean }): Promise<any> {
const { portfolio, ...body } = params;
return this.postPrivate(
`/api/v1/portfolios/${portfolio}/auto-margin-enabled`,
{ body: body },
);
}
/**
* Set portfolio margin override
*
* Specify the margin override value for a portfolio to either increase notional requirements or opt-in to higher leverage.
*/
setPortfolioMarginOverride(params: {
portfolio_id: string;
margin_override: string;
}): Promise<any> {
return this.postPrivate('/api/v1/portfolios/margin', { body: params });
}
/**
* Transfer funds between portfolios
*
* Transfer assets from one portfolio to another.
*/
transferFundsBetweenPortfolios(
params: TransferINTXFundsBetweenPortfoliosRequest,
): Promise<any> {
return this.postPrivate('/api/v1/portfolios/transfer', { body: params });
}
/**
* Transfer positions between portfolios
*
* Transfer an existing position from one portfolio to another. The position transfer must fulfill the same portfolio-level margin requirements as submitting a new order on the opposite side for the sender's portfolio and a new order on the same side for the recipient's portfolio.
* Additionally, organization-level requirements must be satisfied when evaluating the outcome of the position transfer.
*/
transferPositionsBetweenPortfolios(
params: TransferINTXPositionsBetweenPortfoliosRequest,
): Promise<any> {
return this.postPrivate('/api/v1/portfolios/transfer-position', {
body: params,
});
}
/**
* List portfolio fee rates
*
* Retrieves the Perpetual Future and Spot fee rate tiers for the user.
*/
getPortfolioFeeRates(): Promise<any> {
return this.getPrivate('/api/v1/portfolios/fee-rates');
}
/**
*
* Rankings Endpoints
*
*/
/**
* Get your rankings
*
* Retrieve your volume rankings for maker, taker, and total volume.
*/
getRankings(params: {
instrument_type: string;
period?: string;
instruments?: string;
}): Promise<any> {
return this.getPrivate('/api/v1/rankings/statistics', params);
}
/**
*
* Transfers Endpoints
*
*/
/**
* List matching transfers
*
* List matching transfers.
*/
getMatchingTransfers(params?: GetINTXMatchingTransfersRequest): Promise<any> {
return this.getPrivate('/api/v1/transfers', params);
}
/**
* Get transfer
*
* Get transfer.
*/
getTransfer(params: { transfer_uuid: string }): Promise<any> {
return this.getPrivate(`/api/v1/transfers/${params.transfer_uuid}`);
}
/**
* Withdraw to crypto address
*
* Withdraw to crypto address.
*/
withdrawToCryptoAddress(
params: INTXWithdrawToCryptoAddressRequest,
): Promise<any> {
return this.postPrivate('/api/v1/transfers/withdraw', { body: params });
}
/**
* Create crypto address
*
* Create crypto address.
*/
createCryptoAddress(params: {
portfolio: string;
asset: string;
network_arn_id: string;
}): Promise<any> {
return this.postPrivate('/api/v1/transfers/address', { body: params });
}
/**
* Create counterparty Id
*
* Create counterparty Id.
*/
createCounterpartyId(params: { portfolio: string }): Promise<any> {
return this.postPrivate('/api/v1/transfers/create-counterparty-id', {
body: params,
});
}
/**
* Validate counterparty Id
*
* Validate counterparty Id.
*/
validateCounterpartyId(params: { counterparty_id: string }): Promise<any> {
return this.postPrivate('/api/v1/transfers/validate-counterparty-id', {
body: params,
});
}
/**
* Withdraw to counterparty Id
*
* Withdraw to counterparty Id.
*/
withdrawToCounterpartyId(
params: INTXWithdrawToCounterpartyIdRequest,
): Promise<any> {
return this.postPrivate('/api/v1/transfers/withdraw/counterparty', {
body: params,
});
}
/**
*
* Fee Rates Endpoints
*
*/
/**
* List fee rate tiers
*
* Return all the fee rate tiers.
*/
getFeeRateTiers(): Promise<any> {
return this.getPrivate('/api/v1/fee-rate-tiers');
}
}