-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CBAdvancedTradeClient.ts
916 lines (841 loc) · 24.1 KB
/
CBAdvancedTradeClient.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
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
import { AxiosRequestConfig } from 'axios';
import { BaseRestClient } from './lib/BaseRestClient.js';
import {
REST_CLIENT_TYPE_ENUM,
RestClientOptions,
RestClientType,
} from './lib/requestUtils.js';
import {
AllocateAdvTradePortfolioRequest,
CloseAdvTradePositionRequest,
GetAdvTradeFillsRequest,
GetAdvTradeMarketTradesRequest,
GetAdvTradeOrdersRequest,
GetAdvTradeProductCandlesRequest,
GetAdvTradeProductsRequest,
GetAdvTradePublicMarketTradesRequest,
GetAdvTradePublicProductCandlesRequest,
GetAdvTradePublicProductsRequest,
GetAdvTradeTransactionSummaryRequest,
MoveAdvTradePortfolioFundsRequest,
PreviewAdvTradeOrderRequest,
SubmitAdvTradeConvertQuoteRequest,
SubmitAdvTradeOrderRequest,
} from './types/request/advanced-trade-client.js';
import {
AdvTradeAccount,
AdvTradeAccountsList,
AdvTradeApiKeyPermissions,
AdvTradeCancelOrdersResponse,
AdvTradeCandle,
AdvTradeClosePositionResponse,
AdvTradeCurrentMarginWindow,
AdvTradeEditOrderPreviewResponse,
AdvTradeEditOrderResponse,
AdvTradeFill,
AdvTradeFuturesBalance,
AdvTradeFuturesPosition,
AdvTradeFuturesSweep,
AdvTradeMarketTrades,
AdvTradeOrder,
AdvTradeOrderPreview,
AdvTradePaymentMethod,
AdvTradePerpetualsPortfolio,
AdvTradePerpetualsPosition,
AdvTradePerpetualsPositionSummary,
AdvTradePortfolio,
AdvTradePortfolioBalance,
AdvTradePortfolioBreakdown,
AdvTradePricebook,
AdvTradeProduct,
AdvTradePublicProduct,
AdvTradeSubmitOrderResponse,
AdvTradeTransactionSummary,
} from './types/response/advanced-trade-client.js';
/**
* REST client for Coinbase's Advanced Trade API:
* https://docs.cdp.coinbase.com/advanced-trade/docs/api-overview/
*/
export class CBAdvancedTradeClient extends BaseRestClient {
constructor(
restClientOptions: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {},
) {
super(restClientOptions, requestOptions);
return this;
}
/**
*
* Custom SDK functions
*
*/
/**
* This method is used to get the latency and time sync between the client and the server.
* This is not official API endpoint and is only used for internal testing purposes.
* Use this method to check the latency and time sync between the client and the server.
* Final values might vary slightly, but it should be within few ms difference.
* If you have any suggestions or improvements to this measurement, please create an issue or pull request on GitHub.
*/
async fetchLatencySummary(): Promise<any> {
const clientTimeReqStart = Date.now();
const serverTime = await this.getServerTime();
const clientTimeReqEnd = Date.now();
console.log('serverTime', serverTime);
const serverTimeMs = Number(serverTime.epochMillis);
const roundTripTime = clientTimeReqEnd - clientTimeReqStart;
const estimatedOneWayLatency = Math.floor(roundTripTime / 2);
// Adjust server time by adding estimated one-way latency
const adjustedServerTime = serverTimeMs + estimatedOneWayLatency;
// Calculate time difference between adjusted server time and local time
const timeDifference = adjustedServerTime - clientTimeReqEnd;
const result = {
localTime: clientTimeReqEnd,
serverTime: serverTimeMs,
roundTripTime,
estimatedOneWayLatency,
adjustedServerTime,
timeDifference,
};
console.log('Time synchronization results:');
console.log(result);
console.log(
`Your approximate latency to exchange server:
One way: ${estimatedOneWayLatency}ms.
Round trip: ${roundTripTime}ms.
`,
);
if (timeDifference > 500) {
console.warn(
`WARNING! Time difference between server and client clock is greater than 500ms. It is currently ${timeDifference}ms.
Consider adjusting your system clock to avoid unwanted clock sync errors!
Visit https://github.com/tiagosiebler/awesome-crypto-examples/wiki/Timestamp-for-this-request-is-outside-of-the-recvWindow for more information`,
);
} else {
console.log(
`Time difference between server and client clock is within acceptable range of 500ms. It is currently ${timeDifference}ms.`,
);
}
return result;
}
getClientType(): RestClientType {
return REST_CLIENT_TYPE_ENUM.advancedTrade;
}
/**
*
* Account Endpoints
*
*/
/**
* List Accounts
*
* Get a list of authenticated accounts for the current user.
*/
getAccounts(params?: {
limit?: number;
cursor?: string;
retail_portfolio_id?: string; // deprecated
}): Promise<AdvTradeAccountsList> {
return this.getPrivate(`/api/v3/brokerage/accounts`, params);
}
/**
* Get Account
*
* Get a list of information about single account, given an account UUID.
* Tip: Use List Accounts (getAccounts funcion) to find account UUIDs.
*/
getAccount(params: { account_id: string }): Promise<{
account: AdvTradeAccount;
}> {
return this.getPrivate(`/api/v3/brokerage/accounts/${params.account_id}`);
}
/**
*
* Products Endpoints
*
*/
/**
* Get Best Bid/Ask
*
* Get the best bid/ask for all products. A subset of all products can be returned instead by using the product_ids input.
*/
getBestBidAsk(params?: { product_ids?: string[] }): Promise<{
pricebooks: AdvTradePricebook[];
}> {
return this.getPrivate(`/api/v3/brokerage/best_bid_ask`, params);
}
/**
* Get Product Book
*
* Get a list of bids/asks for a single product. The amount of detail shown can be customized with the limit parameter.
*/
getProductBook(params: {
product_id: string;
limit?: number;
aggregation_price_increment?: string;
}): Promise<{ pricebook: AdvTradePricebook }> {
return this.getPrivate(`/api/v3/brokerage/product_book`, params);
}
/**
* List Products
*
* Get a list of the available currency pairs for trading.
*
*/
getProducts(params?: GetAdvTradeProductsRequest): Promise<{
products: AdvTradeProduct[];
num_products: number;
}> {
return this.getPrivate(`/api/v3/brokerage/products`, params);
}
/**
* Get Product
*
* Get information on a single product by product ID.
*/
getProduct(params: {
product_id: string;
get_tradability_status?: boolean;
}): Promise<AdvTradeProduct> {
const { product_id, ...queryParams } = params;
return this.getPrivate(
`/api/v3/brokerage/products/${product_id}`,
queryParams,
);
}
/**
* Get Product Candles
*
* Get rates for a single product by product ID, grouped in buckets.
*/
getProductCandles(params: GetAdvTradeProductCandlesRequest): Promise<{
candles: AdvTradeCandle[];
}> {
const { product_id, ...queryParams } = params;
return this.getPrivate(
`/api/v3/brokerage/products/${product_id}/candles`,
queryParams,
);
}
/**
* Get Market Trades
*
* Get snapshot information by product ID about the last trades (ticks) and best bid/ask.
*/
getMarketTrades(
params: GetAdvTradeMarketTradesRequest,
): Promise<AdvTradeMarketTrades> {
const { product_id, ...queryParams } = params;
return this.getPrivate(
`/api/v3/brokerage/products/${product_id}/ticker`,
queryParams,
);
}
/**
*
* Orders Endpoints
*
*/
/**
* Create Order
*
* Create an order with a specified product_id (asset-pair), side (buy/sell), etc.
*
*/
submitOrder(
params: SubmitAdvTradeOrderRequest,
): Promise<AdvTradeSubmitOrderResponse> {
this.validateOrderId(params, 'client_order_id');
return this.postPrivate(`/api/v3/brokerage/orders`, {
body: params,
});
}
/**
* Cancel Orders
*
* Initiate cancel requests for one or more orders.
* The maximum number of order_ids that can be cancelled per request is 100.
* This number may be subject to change in emergency, but if a request exceeds the max,
* then an InvalidArgument error code will be returned with an error message denoting the limit.
*/
cancelOrders(params: {
order_ids: string[];
}): Promise<AdvTradeCancelOrdersResponse> {
return this.postPrivate(`/api/v3/brokerage/orders/batch_cancel`, {
body: params,
});
}
/**
* Edit Order
*
* Edit an order with a specified new size, or new price.
*
* - Your request moves to the back of the queue if you increase the size or increase or decrease the price.
* - If you decrease the size, you keep your place in line.
* - A client can only send an Edit Order request after the previous request for the same order has been fully processed.
*/
updateOrder(params: {
order_id: string;
price?: string;
size?: string;
}): Promise<AdvTradeEditOrderResponse> {
return this.postPrivate(`/api/v3/brokerage/orders/edit`, {
body: params,
});
}
/**
* Edit Order Preview
*
* Preview an edit order request with a specified new size, or new price.
*
*/
updateOrderPreview(params: {
order_id: string;
price?: string;
size?: string;
}): Promise<AdvTradeEditOrderPreviewResponse> {
return this.postPrivate(`/api/v3/brokerage/orders/edit_preview`, {
body: params,
});
}
/**
* List Orders
*
* Get a list of orders filtered by optional query parameters.
*
* - The maximum number of OPEN orders returned is 1000.
* - The parameters start_date and end_date don't apply to open orders.
* - You cannot pair open orders with other order types.
* - You cannot query for OPEN orders with other order types.
*/
getOrders(params?: GetAdvTradeOrdersRequest): Promise<{
orders: AdvTradeOrder[];
sequence?: number;
has_next: boolean;
cursor?: string;
}> {
return this.getPrivate(`/api/v3/brokerage/orders/historical/batch`, params);
}
/**
* List Fills
*
* Get a list of fills filtered by optional query parameters (product_id, order_id, etc).
*
*/
getFills(params?: GetAdvTradeFillsRequest): Promise<{
fills: AdvTradeFill[];
cursor?: string;
}> {
return this.getPrivate(`/api/v3/brokerage/orders/historical/fills`, params);
}
/**
* Get Order
*
* Get a single order by order ID.
*/
getOrder(params: {
order_id: string;
client_order_id?: string;
user_native_currency?: string;
}): Promise<{ order: AdvTradeOrder }> {
const { order_id, ...queryParams } = params;
return this.getPrivate(
`/api/v3/brokerage/orders/historical/${order_id}`,
queryParams,
);
}
/**
* Preview Order
*
* Preview an order.
*
*/
previewOrder(
params: PreviewAdvTradeOrderRequest,
): Promise<AdvTradeOrderPreview> {
return this.postPrivate(`/api/v3/brokerage/orders/preview`, {
body: params,
});
}
/**
* Close Position
*
* Places an order to close any open positions for a specified product_id.
*
*/
closePosition(
params: CloseAdvTradePositionRequest,
): Promise<AdvTradeClosePositionResponse> {
this.validateOrderId(params, 'client_order_id');
return this.postPrivate(`/api/v3/brokerage/orders/close_position`, {
body: params,
});
}
/**
*
* Portfolios Endpoints
*
*/
/**
* List Portfolios
*
* Get all portfolios of a user.
*/
getPortfolios(params?: {
portfolio_type?: 'UNDEFINED' | 'DEFAULT' | 'CONSUMER' | 'INTX';
}): Promise<{
portfolios: AdvTradePortfolio[];
}> {
return this.getPrivate(`/api/v3/brokerage/portfolios`, params);
}
/**
* Create Portfolio
*
* Create a portfolio.
*/
createPortfolio(params: { name: string }): Promise<{
portfolio: AdvTradePortfolio;
}> {
return this.postPrivate(`/api/v3/brokerage/portfolios`, {
body: params,
});
}
/**
* Move Portfolio Funds
*
* Move funds between portfolios.
*/
movePortfolioFunds(params: MoveAdvTradePortfolioFundsRequest): Promise<{
source_portfolio_uuid: string;
target_portfolio_uuid: string;
}> {
return this.postPrivate(`/api/v3/brokerage/portfolios/move_funds`, {
body: params,
});
}
/**
* Get Portfolio Breakdown
*
* Get the breakdown of a portfolio.
*/
getPortfolioBreakdown(params: {
portfolio_uuid: string;
currency?: string;
}): Promise<{ breakdown: AdvTradePortfolioBreakdown }> {
const { portfolio_uuid, ...queryParams } = params;
return this.getPrivate(
`/api/v3/brokerage/portfolios/${portfolio_uuid}`,
queryParams,
);
}
/**
* Delete Portfolio
*
* Delete a portfolio.
*/
deletePortfolio(params: { portfolio_uuid: string }): Promise<any> {
const { portfolio_uuid } = params;
return this.deletePrivate(`/api/v3/brokerage/portfolios/${portfolio_uuid}`);
}
/**
* Edit Portfolio
*
* Edit a portfolio.
*
*/
updatePortfolio(params: {
portfolio_uuid: string;
name: string;
}): Promise<{ portfolio: AdvTradePortfolio }> {
const { portfolio_uuid, ...bodyParams } = params;
return this.putPrivate(`/api/v3/brokerage/portfolios/${portfolio_uuid}`, {
body: bodyParams,
});
}
/**
*
* Futures Endpoints
*
*/
/**
* Get Futures Balance Summary
*
* Get a summary of balances for CFM trading.
*
* Futures vs Spot Accounts:
* - Futures and spot balances are held in different accounts.
* - Cash is always deposited into your Coinbase Inc. (CBI) spot account.
* - Cash is automatically transferred to your Coinbase Financial Markets (CFM) futures account to satisfy margin requirements.
* - You can transfer cash that isn't being used to margin or maintain futures positions into your CBI spot account.
* - Funds held in a CBI spot account do not receive the preferential treatment given to funds held in a regulated futures account.
*
* Intraday vs. Overnight Margin Health:
* - If you are opted in to receive increased leverage on futures trades during the intraday window (from 8am-4pm ET), this endpoint will return your intraday and overnight margin health.
*/
getFuturesBalanceSummary(): Promise<{
balance_summary: AdvTradeFuturesBalance;
}> {
return this.getPrivate(`/api/v3/brokerage/cfm/balance_summary`);
}
/**
* Get Intraday Margin Setting
*
* Get the futures intraday margin setting.
*/
getIntradayMarginSetting(): Promise<{
setting:
| 'INTRADAY_MARGIN_SETTING_UNSPECIFIED'
| 'INTRADAY_MARGIN_SETTING_STANDARD'
| 'INTRADAY_MARGIN_SETTING_INTRADAY';
}> {
return this.getPrivate(`/api/v3/brokerage/cfm/intraday/margin_setting`);
}
/**
* Set Intraday Margin Setting
*
* Set the futures intraday margin setting.
*/
setIntradayMarginSetting(params?: {
setting?:
| 'INTRADAY_MARGIN_SETTING_UNSPECIFIED'
| 'INTRADAY_MARGIN_SETTING_STANDARD'
| 'INTRADAY_MARGIN_SETTING_INTRADAY';
}): Promise<any> {
return this.postPrivate(`/api/v3/brokerage/cfm/intraday/margin_setting`, {
body: params,
});
}
/**
* Get Current Margin Window
*
* Get the futures current margin window.
*/
getCurrentMarginWindow(params?: {
margin_profile_type?:
| 'MARGIN_PROFILE_TYPE_UNSPECIFIED'
| 'MARGIN_PROFILE_TYPE_RETAIL_REGULAR'
| 'MARGIN_PROFILE_TYPE_RETAIL_INTRADAY_MARGIN_1';
}): Promise<AdvTradeCurrentMarginWindow> {
return this.getPrivate(
`/api/v3/brokerage/cfm/intraday/current_margin_window`,
params,
);
}
/**
* List Futures Positions
*
* Get a list of positions in CFM products.
*/
getFuturesPositions(): Promise<{ positions: AdvTradeFuturesPosition[] }> {
return this.getPrivate(`/api/v3/brokerage/cfm/positions`);
}
/**
* Get Futures Position
*
* Get positions for a specific CFM product.
*/
getFuturesPosition(params: {
product_id: string;
}): Promise<{ position: AdvTradeFuturesPosition }> {
const { product_id } = params;
return this.getPrivate(`/api/v3/brokerage/cfm/positions/${product_id}`);
}
/**
* Schedule Futures Sweep
*
* Schedules a sweep of funds from FCM wallet to USD Spot wallet.
*
* Futures Sweep Processing:
* - Sweep requests submitted before 5PM ET each day are processed the following business day.
* - Sweep requests submitted after 5PM ET each day are processed in 2 business days.
* - You can have at most one pending sweep request at a time.
*
* Market movements related to your open positions may impact the final amount that is transferred into your spot account.
* The final funds transferred, up to your specified amount, depend on the available excess in your futures account.
*/
scheduleFuturesSweep(params?: {
usd_amount?: string;
}): Promise<{ success: boolean }> {
return this.postPrivate(`/api/v3/brokerage/cfm/sweeps/schedule`, {
body: params,
});
}
/**
* List Futures Sweeps
*
* Get pending and processing sweeps of funds from FCM wallet to USD Spot wallet.
*
* Pending vs. Processing Sweeps:
* - A pending sweep is a sweep that has not started processing and can be cancelled.
* - A processing sweep is a sweep that is currently being processed and cannot be cancelled.
* - Once a sweep is complete, it no longer appears in the list of sweeps.
*/
getFuturesSweeps(): Promise<{ sweeps: AdvTradeFuturesSweep[] }> {
return this.getPrivate(`/api/v3/brokerage/cfm/sweeps`);
}
/**
* Cancel Pending Futures Sweep
*
* Cancel the pending sweep of funds from FCM wallet to USD Spot wallet.
*/
cancelPendingFuturesSweep(): Promise<{ success: boolean }> {
return this.deletePrivate(`/api/v3/brokerage/cfm/sweeps`);
}
/**
*
* Perpetuals Endpoints
*
*/
/**
* Allocate Portfolio
*
* Allocate portfolio funds to a sub-portfolio on Intx Portfolio.
*
*/
allocatePortfolio(params: AllocateAdvTradePortfolioRequest): Promise<any> {
return this.postPrivate(`/api/v3/brokerage/intx/allocate`, {
body: params,
});
}
/**
* Get Perpetuals Portfolio Summary
*
* Get a summary of your Perpetuals portfolio.
*/
getPerpetualsPortfolioSummary(params: {
portfolio_uuid: string;
}): Promise<AdvTradePerpetualsPortfolio> {
const { portfolio_uuid } = params;
return this.getPrivate(
`/api/v3/brokerage/intx/portfolio/${portfolio_uuid}`,
);
}
/**
* List Perpetuals Positions
*
* Get a list of open positions in your Perpetuals portfolio.
*/
getPerpetualsPositions(params: {
portfolio_uuid: string;
}): Promise<AdvTradePerpetualsPositionSummary> {
const { portfolio_uuid } = params;
return this.getPrivate(
`/api/v3/brokerage/intx/positions/${portfolio_uuid}`,
);
}
/**
* Get Perpetuals Position
*
* Get a specific open position on Intx.
*
*/
getPerpetualsPosition(params: {
portfolio_uuid: string;
symbol: string;
}): Promise<{ position: AdvTradePerpetualsPosition }> {
const { portfolio_uuid, symbol } = params;
return this.getPrivate(
`/api/v3/brokerage/intx/positions/${portfolio_uuid}/${symbol}`,
);
}
/**
* Get Portfolios Balances
*
* Get a list of asset balances on Intx for a given Portfolio.
*/
getPortfoliosBalances(params: { portfolio_uuid: string }): Promise<{
portfolio_balances: AdvTradePortfolioBalance[];
}> {
const { portfolio_uuid } = params;
return this.getPrivate(`/api/v3/brokerage/intx/balances/${portfolio_uuid}`);
}
/**
* Opt In or Out of Multi Asset Collateral
*
* Enable or Disable Multi Asset Collateral for a given Portfolio.
*/
updateMultiAssetCollateral(params?: {
portfolio_uuid?: string;
multi_asset_collateral_enabled?: boolean;
}): Promise<{ multi_asset_collateral_enabled: boolean }> {
return this.postPrivate(`/api/v3/brokerage/intx/multi_asset_collateral`, {
body: params,
});
}
/**
*
* Fees Endpoints
*
*/
/**
* Get Transaction Summary
*
* Get a summary of transactions with fee tiers, total volume, and fees.
*/
getTransactionSummary(
params?: GetAdvTradeTransactionSummaryRequest,
): Promise<AdvTradeTransactionSummary> {
return this.getPrivate(`/api/v3/brokerage/transaction_summary`, params);
}
/**
*
* Converts Endpoints
*
*/
/**
* Create Convert Quote
*
* Create a convert quote with a specified source account, target account, and amount.
* Convert is applicable for USDC-USD and EURC-EUR conversion.
*/
submitConvertQuote(params: SubmitAdvTradeConvertQuoteRequest): Promise<any> {
return this.postPrivate(`/api/v3/brokerage/convert/quote`, {
body: params,
});
}
/**
* Get Convert Trade
*
* Gets a list of information about a convert trade with a specified trade id, source account, and target account.
*/
getConvertTrade(params: {
trade_id: string;
from_account: string;
to_account: string;
}): Promise<any> {
const { trade_id, ...queryParams } = params;
return this.getPrivate(
`/api/v3/brokerage/convert/trade/${trade_id}`,
queryParams,
);
}
/**
* Commit Convert Trade
*
* Commits a convert trade with a specified trade id, source account, and target account.
*/
commitConvertTrade(params: {
trade_id: string;
from_account: string;
to_account: string;
}): Promise<any> {
const { trade_id, ...bodyParams } = params;
return this.postPrivate(`/api/v3/brokerage/convert/trade/${trade_id}`, {
body: bodyParams,
});
}
/**
*
* Public Endpoints
*
*/
getServerTime(): Promise<{
iso: string;
epochSeconds: string;
epochMillis: string;
}> {
return this.get(`/api/v3/brokerage/time`);
}
/**
* Get Public Product Book
*
* Get a list of bids/asks for a single product. The amount of detail shown can be customized with the limit parameter.
*/
getPublicProductBook(params: {
product_id: string;
limit?: number;
aggregation_price_increment?: string;
}): Promise<{ pricebook: AdvTradePricebook }> {
return this.get(`/api/v3/brokerage/market/product_book`, params);
}
/**
* List Public Products
*
* Get a list of the available currency pairs for trading.
*/
getPublicProducts(params?: GetAdvTradePublicProductsRequest): Promise<{
products: AdvTradePublicProduct[];
num_products: number;
}> {
return this.get(`/api/v3/brokerage/market/products`, params);
}
/**
* Get Public Product
*
* Get information on a single product by product ID.
*/
getPublicProduct(params: {
product_id: string;
}): Promise<AdvTradePublicProduct> {
const { product_id } = params;
return this.get(`/api/v3/brokerage/market/products/${product_id}`);
}
/**
* Get Public Product Candles
*
* Get rates for a single product by product ID, grouped in buckets.
*/
getPublicProductCandles(
params: GetAdvTradePublicProductCandlesRequest,
): Promise<{ candles: AdvTradeCandle[] }> {
const { product_id, ...queryParams } = params;
return this.get(
`/api/v3/brokerage/market/products/${product_id}/candles`,
queryParams,
);
}
/**
* Get Public Market Trades
*
* Get snapshot information by product ID about the last trades (ticks) and best bid/ask.
*/
getPublicMarketTrades(
params: GetAdvTradePublicMarketTradesRequest,
): Promise<AdvTradeMarketTrades> {
const { product_id, ...queryParams } = params;
return this.get(
`/api/v3/brokerage/market/products/${product_id}/ticker`,
queryParams,
);
}
/**
*
* Payment Methods Endpoints
*
*/
/**
* List Payment Methods
*
* Get a list of payment methods for the current user.
*/
getPaymentMethods(): Promise<{
payment_methods: AdvTradePaymentMethod[];
}> {
return this.getPrivate(`/api/v3/brokerage/payment_methods`);
}
/**
* Get Payment Method
*
* Get information about a payment method for the current user.
*/
getPaymentMethod(params: { payment_method_id: string }): Promise<{
payment_method: AdvTradePaymentMethod;
}> {
const { payment_method_id } = params;
return this.getPrivate(
`/api/v3/brokerage/payment_methods/${payment_method_id}`,
);
}
/**
*
* Data API Endpoints
*
*/
/**
* Get API Key Permissions
*
* Get information about your CDP API key permissions.
*/
getApiKeyPermissions(): Promise<AdvTradeApiKeyPermissions> {
return this.getPrivate(`/api/v3/brokerage/key_permissions`);
}
}