kucoin-api 2.2.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +7 -0
- package/README.md +6 -0
- package/dist/cjs/FuturesClient.d.ts +25 -1
- package/dist/cjs/FuturesClient.js +24 -0
- package/dist/cjs/FuturesClient.js.map +1 -1
- package/dist/cjs/SpotClient.d.ts +11 -0
- package/dist/cjs/SpotClient.js +9 -0
- package/dist/cjs/SpotClient.js.map +1 -1
- package/dist/cjs/UnifiedAPIClient.d.ts +77 -0
- package/dist/cjs/UnifiedAPIClient.js +105 -0
- package/dist/cjs/UnifiedAPIClient.js.map +1 -0
- package/dist/cjs/WebsocketAPIClient.js +7 -1
- package/dist/cjs/WebsocketAPIClient.js.map +1 -1
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/BaseWSClient.js +3 -1
- package/dist/cjs/lib/BaseWSClient.js.map +1 -1
- package/dist/cjs/lib/requestUtils.d.ts +2 -0
- package/dist/cjs/lib/requestUtils.js +3 -0
- package/dist/cjs/lib/requestUtils.js.map +1 -1
- package/dist/cjs/types/request/uta-types.d.ts +50 -0
- package/dist/cjs/types/request/uta-types.js +6 -0
- package/dist/cjs/types/request/uta-types.js.map +1 -0
- package/dist/cjs/types/response/futures.types.d.ts +3 -0
- package/dist/cjs/types/response/uta-types.d.ts +172 -0
- package/dist/cjs/types/response/uta-types.js +6 -0
- package/dist/cjs/types/response/uta-types.js.map +1 -0
- package/dist/mjs/FuturesClient.d.ts +25 -1
- package/dist/mjs/FuturesClient.js +24 -0
- package/dist/mjs/FuturesClient.js.map +1 -1
- package/dist/mjs/SpotClient.d.ts +11 -0
- package/dist/mjs/SpotClient.js +9 -0
- package/dist/mjs/SpotClient.js.map +1 -1
- package/dist/mjs/UnifiedAPIClient.d.ts +77 -0
- package/dist/mjs/UnifiedAPIClient.js +101 -0
- package/dist/mjs/UnifiedAPIClient.js.map +1 -0
- package/dist/mjs/WebsocketAPIClient.js +7 -1
- package/dist/mjs/WebsocketAPIClient.js.map +1 -1
- package/dist/mjs/index.d.ts +3 -0
- package/dist/mjs/index.js +3 -0
- package/dist/mjs/index.js.map +1 -1
- package/dist/mjs/lib/BaseWSClient.js +3 -1
- package/dist/mjs/lib/BaseWSClient.js.map +1 -1
- package/dist/mjs/lib/requestUtils.d.ts +2 -0
- package/dist/mjs/lib/requestUtils.js +3 -0
- package/dist/mjs/lib/requestUtils.js.map +1 -1
- package/dist/mjs/types/request/uta-types.d.ts +50 -0
- package/dist/mjs/types/request/uta-types.js +5 -0
- package/dist/mjs/types/request/uta-types.js.map +1 -0
- package/dist/mjs/types/response/futures.types.d.ts +3 -0
- package/dist/mjs/types/response/uta-types.d.ts +172 -0
- package/dist/mjs/types/response/uta-types.js +5 -0
- package/dist/mjs/types/response/uta-types.js.map +1 -0
- package/llms.txt +734 -222
- package/package.json +1 -1
package/llms.txt
CHANGED
|
@@ -93,6 +93,7 @@ src/
|
|
|
93
93
|
spot-margin-trading.ts
|
|
94
94
|
spot-misc.ts
|
|
95
95
|
spot-trading.ts
|
|
96
|
+
uta-types.ts
|
|
96
97
|
response/
|
|
97
98
|
broker.types.ts
|
|
98
99
|
futures.types.ts
|
|
@@ -106,6 +107,7 @@ src/
|
|
|
106
107
|
spot-misc.ts
|
|
107
108
|
spot-trading.ts
|
|
108
109
|
spot-vip.ts
|
|
110
|
+
uta-types.ts
|
|
109
111
|
ws.ts
|
|
110
112
|
websockets/
|
|
111
113
|
ws-api.ts
|
|
@@ -115,6 +117,7 @@ src/
|
|
|
115
117
|
FuturesClient.ts
|
|
116
118
|
index.ts
|
|
117
119
|
SpotClient.ts
|
|
120
|
+
UnifiedAPIClient.ts
|
|
118
121
|
WebsocketAPIClient.ts
|
|
119
122
|
WebsocketClient.ts
|
|
120
123
|
.eslintrc.cjs
|
|
@@ -1336,6 +1339,116 @@ export interface GetAnnouncementsRequest {
|
|
|
1336
1339
|
endTime?: number;
|
|
1337
1340
|
}
|
|
1338
1341
|
|
|
1342
|
+
================
|
|
1343
|
+
File: src/types/request/uta-types.ts
|
|
1344
|
+
================
|
|
1345
|
+
/**
|
|
1346
|
+
* Unified Trading Account Request Types
|
|
1347
|
+
*/
|
|
1348
|
+
⋮----
|
|
1349
|
+
export interface GetAnnouncementsRequestUTA {
|
|
1350
|
+
language?:
|
|
1351
|
+
| 'zh_HK'
|
|
1352
|
+
| 'ja_JP'
|
|
1353
|
+
| 'ko_KR'
|
|
1354
|
+
| 'en_US'
|
|
1355
|
+
| 'pl_PL'
|
|
1356
|
+
| 'es_ES'
|
|
1357
|
+
| 'fr_FR'
|
|
1358
|
+
| 'ar_AE'
|
|
1359
|
+
| 'it_IT'
|
|
1360
|
+
| 'id_ID'
|
|
1361
|
+
| 'nl_NL'
|
|
1362
|
+
| 'pt_PT'
|
|
1363
|
+
| 'vi_VN'
|
|
1364
|
+
| 'de_DE'
|
|
1365
|
+
| 'tr_TR'
|
|
1366
|
+
| 'ms_MY'
|
|
1367
|
+
| 'ru_RU'
|
|
1368
|
+
| 'th_TH'
|
|
1369
|
+
| 'hi_IN'
|
|
1370
|
+
| 'bn_BD'
|
|
1371
|
+
| 'fil_PH'
|
|
1372
|
+
| 'ur_PK';
|
|
1373
|
+
type?:
|
|
1374
|
+
| 'latest-announcements'
|
|
1375
|
+
| 'activities'
|
|
1376
|
+
| 'product-updates'
|
|
1377
|
+
| 'vip'
|
|
1378
|
+
| 'maintenance-updates'
|
|
1379
|
+
| 'delistings'
|
|
1380
|
+
| 'others'
|
|
1381
|
+
| 'api-campaigns'
|
|
1382
|
+
| 'new-listings'
|
|
1383
|
+
| 'futures-announcements';
|
|
1384
|
+
pageNumber?: number;
|
|
1385
|
+
pageSize?: number;
|
|
1386
|
+
startTime?: number;
|
|
1387
|
+
endTime?: number;
|
|
1388
|
+
}
|
|
1389
|
+
⋮----
|
|
1390
|
+
export interface GetCurrencyRequestUTA {
|
|
1391
|
+
currency?: string;
|
|
1392
|
+
chain?: string;
|
|
1393
|
+
}
|
|
1394
|
+
⋮----
|
|
1395
|
+
export interface GetSymbolRequestUTA {
|
|
1396
|
+
tradeType: 'SPOT' | 'FUTURES' | 'ISOLATED' | 'CROSS';
|
|
1397
|
+
symbol?: string;
|
|
1398
|
+
}
|
|
1399
|
+
⋮----
|
|
1400
|
+
export interface GetTickerRequestUTA {
|
|
1401
|
+
tradeType: 'SPOT' | 'FUTURES';
|
|
1402
|
+
symbol?: string;
|
|
1403
|
+
}
|
|
1404
|
+
⋮----
|
|
1405
|
+
export interface GetTradesRequestUTA {
|
|
1406
|
+
tradeType: 'SPOT' | 'FUTURES';
|
|
1407
|
+
symbol: string;
|
|
1408
|
+
}
|
|
1409
|
+
⋮----
|
|
1410
|
+
export interface GetOrderBookRequestUTA {
|
|
1411
|
+
tradeType: 'SPOT' | 'FUTURES';
|
|
1412
|
+
symbol: string;
|
|
1413
|
+
limit: '20' | '50' | '100' | 'FULL';
|
|
1414
|
+
}
|
|
1415
|
+
⋮----
|
|
1416
|
+
export interface GetKlinesRequestUTA {
|
|
1417
|
+
tradeType: 'SPOT' | 'FUTURES';
|
|
1418
|
+
symbol: string;
|
|
1419
|
+
interval:
|
|
1420
|
+
| '1min'
|
|
1421
|
+
| '3min'
|
|
1422
|
+
| '5min'
|
|
1423
|
+
| '15min'
|
|
1424
|
+
| '30min'
|
|
1425
|
+
| '1hour'
|
|
1426
|
+
| '2hour'
|
|
1427
|
+
| '4hour'
|
|
1428
|
+
| '6hour'
|
|
1429
|
+
| '8hour'
|
|
1430
|
+
| '12hour'
|
|
1431
|
+
| '1day'
|
|
1432
|
+
| '1week'
|
|
1433
|
+
| '1month';
|
|
1434
|
+
startAt?: number;
|
|
1435
|
+
endAt?: number;
|
|
1436
|
+
}
|
|
1437
|
+
⋮----
|
|
1438
|
+
export interface GetCurrentFundingRateRequestUTA {
|
|
1439
|
+
symbol: string;
|
|
1440
|
+
}
|
|
1441
|
+
⋮----
|
|
1442
|
+
export interface GetHistoryFundingRateRequestUTA {
|
|
1443
|
+
symbol: string;
|
|
1444
|
+
startAt: number;
|
|
1445
|
+
endAt: number;
|
|
1446
|
+
}
|
|
1447
|
+
⋮----
|
|
1448
|
+
export interface GetServiceStatusRequestUTA {
|
|
1449
|
+
tradeType: 'SPOT' | 'FUTURES';
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1339
1452
|
================
|
|
1340
1453
|
File: src/types/response/shared.types.ts
|
|
1341
1454
|
================
|
|
@@ -1377,6 +1490,202 @@ export interface Announcements {
|
|
|
1377
1490
|
items: Announcement[];
|
|
1378
1491
|
}
|
|
1379
1492
|
|
|
1493
|
+
================
|
|
1494
|
+
File: src/types/response/uta-types.ts
|
|
1495
|
+
================
|
|
1496
|
+
/**
|
|
1497
|
+
* Unified Trading Account Response Types
|
|
1498
|
+
*/
|
|
1499
|
+
⋮----
|
|
1500
|
+
export interface AnnouncementItemUTA {
|
|
1501
|
+
id: number;
|
|
1502
|
+
title: string;
|
|
1503
|
+
type: string[];
|
|
1504
|
+
description: string;
|
|
1505
|
+
releaseTime: number;
|
|
1506
|
+
language: string;
|
|
1507
|
+
url: string;
|
|
1508
|
+
}
|
|
1509
|
+
⋮----
|
|
1510
|
+
export interface GetAnnouncementsResponseUTA {
|
|
1511
|
+
totalNumber: number;
|
|
1512
|
+
totalPage: number;
|
|
1513
|
+
pageNumber: number;
|
|
1514
|
+
pageSize: number;
|
|
1515
|
+
list: AnnouncementItemUTA[];
|
|
1516
|
+
}
|
|
1517
|
+
⋮----
|
|
1518
|
+
export interface CurrencyChainUTA {
|
|
1519
|
+
chainName: string;
|
|
1520
|
+
minWithdrawSize: string | null;
|
|
1521
|
+
minDepositSize: string | null;
|
|
1522
|
+
withdrawFeeRate: string;
|
|
1523
|
+
minWithdrawFee: string;
|
|
1524
|
+
isWithdrawEnabled: boolean;
|
|
1525
|
+
isDepositEnabled: boolean;
|
|
1526
|
+
confirms: number;
|
|
1527
|
+
preConfirms: number;
|
|
1528
|
+
contractAddress: string;
|
|
1529
|
+
withdrawPrecision: number;
|
|
1530
|
+
maxWithdrawSize: string | null;
|
|
1531
|
+
maxDepositSize: string | null;
|
|
1532
|
+
needTag: boolean;
|
|
1533
|
+
chainId: string;
|
|
1534
|
+
}
|
|
1535
|
+
⋮----
|
|
1536
|
+
export interface GetCurrencyResponseUTA {
|
|
1537
|
+
currency: string;
|
|
1538
|
+
name: string;
|
|
1539
|
+
fullName: string;
|
|
1540
|
+
precision: number;
|
|
1541
|
+
confirms: number | null;
|
|
1542
|
+
contractAddress: string | null;
|
|
1543
|
+
isMarginEnabled: boolean;
|
|
1544
|
+
isDebitEnabled: boolean;
|
|
1545
|
+
list: CurrencyChainUTA[];
|
|
1546
|
+
}
|
|
1547
|
+
⋮----
|
|
1548
|
+
export interface SymbolUTA {
|
|
1549
|
+
symbol: string;
|
|
1550
|
+
name?: string;
|
|
1551
|
+
baseCurrency: string;
|
|
1552
|
+
quoteCurrency: string;
|
|
1553
|
+
market?: string;
|
|
1554
|
+
minBaseOrderSize?: string;
|
|
1555
|
+
minQuoteOrderSize?: string;
|
|
1556
|
+
maxBaseOrderSize?: string | number;
|
|
1557
|
+
maxQuoteOrderSize?: string;
|
|
1558
|
+
baseOrderStep?: string;
|
|
1559
|
+
quoteOrderStep?: string;
|
|
1560
|
+
tickSize?: string | number;
|
|
1561
|
+
feeCurrency?: string;
|
|
1562
|
+
tradingStatus?: string;
|
|
1563
|
+
marginMode?: string;
|
|
1564
|
+
priceLimitRatio?: string;
|
|
1565
|
+
feeCategory?: number;
|
|
1566
|
+
makerFeeCoefficient?: string;
|
|
1567
|
+
takerFeeCoefficient?: string;
|
|
1568
|
+
st?: boolean;
|
|
1569
|
+
settlementCurrency?: string;
|
|
1570
|
+
contractType?: string;
|
|
1571
|
+
isInverse?: boolean;
|
|
1572
|
+
launchTime?: number;
|
|
1573
|
+
expiryTime?: number | null;
|
|
1574
|
+
settlementTime?: number | null;
|
|
1575
|
+
maxPrice?: string | number;
|
|
1576
|
+
lotSize?: string | number;
|
|
1577
|
+
unitSize?: string | number;
|
|
1578
|
+
makerFeeRate?: string | number;
|
|
1579
|
+
takerFeeRate?: string | number;
|
|
1580
|
+
settlementFeeRate?: string | number | null;
|
|
1581
|
+
maxLeverage?: number;
|
|
1582
|
+
indexSourceExchanges?: string[];
|
|
1583
|
+
k?: string | number;
|
|
1584
|
+
m?: string | number;
|
|
1585
|
+
f?: string | number;
|
|
1586
|
+
mmrLimit?: string | number;
|
|
1587
|
+
mmrLevConstant?: string | number;
|
|
1588
|
+
alertRiskRatio?: string;
|
|
1589
|
+
liquidationRiskRatio?: string;
|
|
1590
|
+
baseBorrowEnable?: boolean | string;
|
|
1591
|
+
quoteBorrowEnable?: boolean | string;
|
|
1592
|
+
baseTransferInEnable?: boolean | string;
|
|
1593
|
+
quoteTransferInEnable?: boolean | string;
|
|
1594
|
+
}
|
|
1595
|
+
⋮----
|
|
1596
|
+
export interface GetSymbolResponseUTA {
|
|
1597
|
+
tradeType: string;
|
|
1598
|
+
list: SymbolUTA[];
|
|
1599
|
+
}
|
|
1600
|
+
⋮----
|
|
1601
|
+
export interface TickerUTA {
|
|
1602
|
+
symbol: string;
|
|
1603
|
+
name?: string;
|
|
1604
|
+
bestBidPrice: string;
|
|
1605
|
+
bestBidSize: string;
|
|
1606
|
+
bestAskPrice: string;
|
|
1607
|
+
bestAskSize: string;
|
|
1608
|
+
high: string;
|
|
1609
|
+
low: string;
|
|
1610
|
+
baseVolume: string;
|
|
1611
|
+
quoteVolume: string;
|
|
1612
|
+
lastPrice: string;
|
|
1613
|
+
open: string;
|
|
1614
|
+
size: string;
|
|
1615
|
+
}
|
|
1616
|
+
⋮----
|
|
1617
|
+
export interface GetTickerResponseUTA {
|
|
1618
|
+
tradeType: string;
|
|
1619
|
+
ts: number;
|
|
1620
|
+
list: TickerUTA[];
|
|
1621
|
+
}
|
|
1622
|
+
⋮----
|
|
1623
|
+
export interface TradeUTA {
|
|
1624
|
+
sequence: string;
|
|
1625
|
+
tradeId: string;
|
|
1626
|
+
price: string;
|
|
1627
|
+
size: string;
|
|
1628
|
+
side: 'buy' | 'sell';
|
|
1629
|
+
ts: number;
|
|
1630
|
+
}
|
|
1631
|
+
⋮----
|
|
1632
|
+
export interface GetTradesResponseUTA {
|
|
1633
|
+
tradeType: string;
|
|
1634
|
+
list: TradeUTA[];
|
|
1635
|
+
}
|
|
1636
|
+
⋮----
|
|
1637
|
+
export interface OrderBookLevelUTA {
|
|
1638
|
+
price: string;
|
|
1639
|
+
size: string;
|
|
1640
|
+
}
|
|
1641
|
+
⋮----
|
|
1642
|
+
export interface GetOrderBookResponseUTA {
|
|
1643
|
+
tradeType: string;
|
|
1644
|
+
symbol: string;
|
|
1645
|
+
sequence: string;
|
|
1646
|
+
bids: OrderBookLevelUTA[];
|
|
1647
|
+
asks: OrderBookLevelUTA[];
|
|
1648
|
+
}
|
|
1649
|
+
⋮----
|
|
1650
|
+
export interface GetKlinesResponseUTA {
|
|
1651
|
+
tradeType: string;
|
|
1652
|
+
symbol: string;
|
|
1653
|
+
list: string[][]; // [time, open, close, high, low, volume, turnover]
|
|
1654
|
+
}
|
|
1655
|
+
⋮----
|
|
1656
|
+
list: string[][]; // [time, open, close, high, low, volume, turnover]
|
|
1657
|
+
⋮----
|
|
1658
|
+
export interface GetCurrentFundingRateResponseUTA {
|
|
1659
|
+
symbol: string;
|
|
1660
|
+
nextFundingRate: number;
|
|
1661
|
+
fundingTime: number;
|
|
1662
|
+
fundingRateCap: number;
|
|
1663
|
+
fundingRateFloor: number;
|
|
1664
|
+
}
|
|
1665
|
+
⋮----
|
|
1666
|
+
export interface FundingRateHistoryItemUTA {
|
|
1667
|
+
fundingRate: number;
|
|
1668
|
+
ts: number;
|
|
1669
|
+
}
|
|
1670
|
+
⋮----
|
|
1671
|
+
export interface GetHistoryFundingRateResponseUTA {
|
|
1672
|
+
symbol: string;
|
|
1673
|
+
list: FundingRateHistoryItemUTA[];
|
|
1674
|
+
}
|
|
1675
|
+
⋮----
|
|
1676
|
+
export interface GetCrossMarginConfigResponseUTA {
|
|
1677
|
+
maxLeverage: number;
|
|
1678
|
+
alertRiskRatio: string;
|
|
1679
|
+
liquidationRiskRatio: string;
|
|
1680
|
+
currencyList: string[];
|
|
1681
|
+
}
|
|
1682
|
+
⋮----
|
|
1683
|
+
export interface GetServiceStatusResponseUTA {
|
|
1684
|
+
tradeType: string;
|
|
1685
|
+
serverStatus: 'open' | 'close' | 'cancelonly';
|
|
1686
|
+
msg: string;
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1380
1689
|
================
|
|
1381
1690
|
File: src/types/response/ws.ts
|
|
1382
1691
|
================
|
|
@@ -1393,6 +1702,155 @@ export interface WsConnectionInfo {
|
|
|
1393
1702
|
instanceServers: WsServerInfo[];
|
|
1394
1703
|
}
|
|
1395
1704
|
|
|
1705
|
+
================
|
|
1706
|
+
File: src/UnifiedAPIClient.ts
|
|
1707
|
+
================
|
|
1708
|
+
import { AxiosRequestConfig } from 'axios';
|
|
1709
|
+
⋮----
|
|
1710
|
+
import { BaseRestClient } from './lib/BaseRestClient.js';
|
|
1711
|
+
import {
|
|
1712
|
+
REST_CLIENT_TYPE_ENUM,
|
|
1713
|
+
RestClientOptions,
|
|
1714
|
+
RestClientType,
|
|
1715
|
+
} from './lib/requestUtils.js';
|
|
1716
|
+
import {
|
|
1717
|
+
GetAnnouncementsRequestUTA,
|
|
1718
|
+
GetCurrencyRequestUTA,
|
|
1719
|
+
GetCurrentFundingRateRequestUTA,
|
|
1720
|
+
GetHistoryFundingRateRequestUTA,
|
|
1721
|
+
GetKlinesRequestUTA,
|
|
1722
|
+
GetOrderBookRequestUTA,
|
|
1723
|
+
GetServiceStatusRequestUTA,
|
|
1724
|
+
GetSymbolRequestUTA,
|
|
1725
|
+
GetTickerRequestUTA,
|
|
1726
|
+
GetTradesRequestUTA,
|
|
1727
|
+
} from './types/request/uta-types.js';
|
|
1728
|
+
import { APISuccessResponse } from './types/response/shared.types.js';
|
|
1729
|
+
import {
|
|
1730
|
+
GetAnnouncementsResponseUTA,
|
|
1731
|
+
GetCrossMarginConfigResponseUTA,
|
|
1732
|
+
GetCurrencyResponseUTA,
|
|
1733
|
+
GetCurrentFundingRateResponseUTA,
|
|
1734
|
+
GetHistoryFundingRateResponseUTA,
|
|
1735
|
+
GetKlinesResponseUTA,
|
|
1736
|
+
GetOrderBookResponseUTA,
|
|
1737
|
+
GetServiceStatusResponseUTA,
|
|
1738
|
+
GetSymbolResponseUTA,
|
|
1739
|
+
GetTickerResponseUTA,
|
|
1740
|
+
GetTradesResponseUTA,
|
|
1741
|
+
} from './types/response/uta-types.js';
|
|
1742
|
+
⋮----
|
|
1743
|
+
/**
|
|
1744
|
+
* Unified Trading Account Client
|
|
1745
|
+
*
|
|
1746
|
+
* This client provides access to the Unified Trading Account API endpoints
|
|
1747
|
+
* that unify market data access across Spot, Futures, and Margin trading.
|
|
1748
|
+
*/
|
|
1749
|
+
export class UnifiedAPIClient extends BaseRestClient
|
|
1750
|
+
⋮----
|
|
1751
|
+
constructor(
|
|
1752
|
+
restClientOptions: RestClientOptions = {},
|
|
1753
|
+
requestOptions: AxiosRequestConfig = {},
|
|
1754
|
+
)
|
|
1755
|
+
⋮----
|
|
1756
|
+
getClientType(): RestClientType
|
|
1757
|
+
⋮----
|
|
1758
|
+
/**
|
|
1759
|
+
*
|
|
1760
|
+
* REST - Unified Trading Account - Market Data
|
|
1761
|
+
*
|
|
1762
|
+
*/
|
|
1763
|
+
⋮----
|
|
1764
|
+
/**
|
|
1765
|
+
* Get Announcements
|
|
1766
|
+
* This interface can obtain the latest news announcements, and the default
|
|
1767
|
+
* page search is for announcements within a month.
|
|
1768
|
+
*/
|
|
1769
|
+
getAnnouncements(
|
|
1770
|
+
params?: GetAnnouncementsRequestUTA,
|
|
1771
|
+
): Promise<APISuccessResponse<GetAnnouncementsResponseUTA>>
|
|
1772
|
+
⋮----
|
|
1773
|
+
/**
|
|
1774
|
+
* Get Currency
|
|
1775
|
+
* Request the currency details of a specified currency via this endpoint.
|
|
1776
|
+
*/
|
|
1777
|
+
getCurrency(
|
|
1778
|
+
params?: GetCurrencyRequestUTA,
|
|
1779
|
+
): Promise<APISuccessResponse<GetCurrencyResponseUTA>>
|
|
1780
|
+
⋮----
|
|
1781
|
+
/**
|
|
1782
|
+
* Get Symbol
|
|
1783
|
+
* Request a list of available currency pairs for trading via this endpoint.
|
|
1784
|
+
*/
|
|
1785
|
+
getSymbol(
|
|
1786
|
+
params: GetSymbolRequestUTA,
|
|
1787
|
+
): Promise<APISuccessResponse<GetSymbolResponseUTA>>
|
|
1788
|
+
⋮----
|
|
1789
|
+
/**
|
|
1790
|
+
* Get Ticker
|
|
1791
|
+
* Request market tickers for the trading pairs in the market (including 24h volume).
|
|
1792
|
+
*/
|
|
1793
|
+
getTicker(
|
|
1794
|
+
params: GetTickerRequestUTA,
|
|
1795
|
+
): Promise<APISuccessResponse<GetTickerResponseUTA>>
|
|
1796
|
+
⋮----
|
|
1797
|
+
/**
|
|
1798
|
+
* Get Trades
|
|
1799
|
+
* Request via this endpoint to get the latest 100 public trades of the specified symbol.
|
|
1800
|
+
*/
|
|
1801
|
+
getTrades(
|
|
1802
|
+
params: GetTradesRequestUTA,
|
|
1803
|
+
): Promise<APISuccessResponse<GetTradesResponseUTA>>
|
|
1804
|
+
⋮----
|
|
1805
|
+
/**
|
|
1806
|
+
* Get OrderBook
|
|
1807
|
+
* Query order book depth information (aggregated by price).
|
|
1808
|
+
*/
|
|
1809
|
+
getOrderBook(
|
|
1810
|
+
params: GetOrderBookRequestUTA,
|
|
1811
|
+
): Promise<APISuccessResponse<GetOrderBookResponseUTA>>
|
|
1812
|
+
⋮----
|
|
1813
|
+
/**
|
|
1814
|
+
* Get Klines
|
|
1815
|
+
* Get the Kline of the symbol. Data are returned in grouped buckets based on requested type.
|
|
1816
|
+
*/
|
|
1817
|
+
getKlines(
|
|
1818
|
+
params: GetKlinesRequestUTA,
|
|
1819
|
+
): Promise<APISuccessResponse<GetKlinesResponseUTA>>
|
|
1820
|
+
⋮----
|
|
1821
|
+
/**
|
|
1822
|
+
* Get Current Funding Rate
|
|
1823
|
+
* Get current Futures funding fee rate.
|
|
1824
|
+
*/
|
|
1825
|
+
getCurrentFundingRate(
|
|
1826
|
+
params: GetCurrentFundingRateRequestUTA,
|
|
1827
|
+
): Promise<APISuccessResponse<GetCurrentFundingRateResponseUTA>>
|
|
1828
|
+
⋮----
|
|
1829
|
+
/**
|
|
1830
|
+
* Get History Funding Rate
|
|
1831
|
+
* Query the Futures funding rate at each settlement time point within a certain time range.
|
|
1832
|
+
*/
|
|
1833
|
+
getHistoryFundingRate(
|
|
1834
|
+
params: GetHistoryFundingRateRequestUTA,
|
|
1835
|
+
): Promise<APISuccessResponse<GetHistoryFundingRateResponseUTA>>
|
|
1836
|
+
⋮----
|
|
1837
|
+
/**
|
|
1838
|
+
* Get Cross Margin Config
|
|
1839
|
+
* Request the configure info of the 'spot cross margin' via this endpoint.
|
|
1840
|
+
*/
|
|
1841
|
+
getCrossMarginConfig(): Promise<
|
|
1842
|
+
APISuccessResponse<GetCrossMarginConfigResponseUTA>
|
|
1843
|
+
> {
|
|
1844
|
+
return this.get('api/ua/v1/market/cross-config');
|
|
1845
|
+
⋮----
|
|
1846
|
+
/**
|
|
1847
|
+
* Get Service Status
|
|
1848
|
+
* Get the service status.
|
|
1849
|
+
*/
|
|
1850
|
+
getServiceStatus(
|
|
1851
|
+
params: GetServiceStatusRequestUTA,
|
|
1852
|
+
): Promise<APISuccessResponse<GetServiceStatusResponseUTA>>
|
|
1853
|
+
|
|
1396
1854
|
================
|
|
1397
1855
|
File: .prettierrc
|
|
1398
1856
|
================
|
|
@@ -6680,6 +7138,8 @@ File: src/lib/requestUtils.ts
|
|
|
6680
7138
|
⋮----
|
|
6681
7139
|
/** Broker */
|
|
6682
7140
|
⋮----
|
|
7141
|
+
/** Unified Trading Account */
|
|
7142
|
+
⋮----
|
|
6683
7143
|
export type RestClientType =
|
|
6684
7144
|
(typeof REST_CLIENT_TYPE_ENUM)[keyof typeof REST_CLIENT_TYPE_ENUM];
|
|
6685
7145
|
⋮----
|
|
@@ -6843,6 +7303,7 @@ import {
|
|
|
6843
7303
|
FuturesRiskLimit,
|
|
6844
7304
|
FuturesSubAccount,
|
|
6845
7305
|
FuturesSymbolInfo,
|
|
7306
|
+
GetPositionModeResponse,
|
|
6846
7307
|
IndexListItem,
|
|
6847
7308
|
InterestRateItem,
|
|
6848
7309
|
MarketTradeDetail,
|
|
@@ -7294,11 +7755,20 @@ getMaxOpenSize(
|
|
|
7294
7755
|
/**
|
|
7295
7756
|
* Get Position Details
|
|
7296
7757
|
* Get the position details of a specified position.
|
|
7758
|
+
* @deprecated Use getPositionV2 instead
|
|
7297
7759
|
*/
|
|
7298
7760
|
getPosition(params: {
|
|
7299
7761
|
symbol: string;
|
|
7300
7762
|
}): Promise<APISuccessResponse<FuturesPosition>>
|
|
7301
7763
|
⋮----
|
|
7764
|
+
/**
|
|
7765
|
+
* Get Position Details
|
|
7766
|
+
* Get the position details of a specified position.
|
|
7767
|
+
*/
|
|
7768
|
+
getPositionV2(params: {
|
|
7769
|
+
symbol: string;
|
|
7770
|
+
}): Promise<APISuccessResponse<FuturesPosition>>
|
|
7771
|
+
⋮----
|
|
7302
7772
|
/**
|
|
7303
7773
|
* Get Position List
|
|
7304
7774
|
* Get the position details of a specified position.
|
|
@@ -7410,6 +7880,12 @@ updateRiskLimitLevel(params: {
|
|
|
7410
7880
|
level: number;
|
|
7411
7881
|
}): Promise<boolean>
|
|
7412
7882
|
⋮----
|
|
7883
|
+
/**
|
|
7884
|
+
* Get Position Mode
|
|
7885
|
+
* This interface can query the position mode of this account.
|
|
7886
|
+
*/
|
|
7887
|
+
getPositionMode(): Promise<APISuccessResponse<GetPositionModeResponse>>
|
|
7888
|
+
⋮----
|
|
7413
7889
|
/**
|
|
7414
7890
|
* Switch Position Mode
|
|
7415
7891
|
* This endpoint can switch the position mode of the current symbol.
|
|
@@ -7593,6 +8069,7 @@ updateCopyTradeAutoDepositStatus(params: {
|
|
|
7593
8069
|
* Get download link for broker rebate orders
|
|
7594
8070
|
*
|
|
7595
8071
|
* trade type 1 = spot, trade type 2 = futures
|
|
8072
|
+
* @deprecated Use getBrokerRebateOrderDownloadLinkV2 instead
|
|
7596
8073
|
*/
|
|
7597
8074
|
getBrokerRebateOrderDownloadLink(params: {
|
|
7598
8075
|
begin: string;
|
|
@@ -7600,6 +8077,17 @@ getBrokerRebateOrderDownloadLink(params: {
|
|
|
7600
8077
|
tradeType: 1 | 2;
|
|
7601
8078
|
}): Promise<APISuccessResponse<any>>
|
|
7602
8079
|
⋮----
|
|
8080
|
+
/**
|
|
8081
|
+
* Get download link for broker rebate orders
|
|
8082
|
+
*
|
|
8083
|
+
* trade type SPOT = spot, FUTURE = futures
|
|
8084
|
+
*/
|
|
8085
|
+
getBrokerRebateOrderDownloadLinkV2(params: {
|
|
8086
|
+
begin: string;
|
|
8087
|
+
end: string;
|
|
8088
|
+
tradeType: 'SPOT' | 'FUTURE';
|
|
8089
|
+
}): Promise<APISuccessResponse<any>>
|
|
8090
|
+
⋮----
|
|
7603
8091
|
/**
|
|
7604
8092
|
*
|
|
7605
8093
|
* WebSockets
|
|
@@ -8432,6 +8920,12 @@ export interface BatchMarginModeUpdateResponse {
|
|
|
8432
8920
|
}[];
|
|
8433
8921
|
}
|
|
8434
8922
|
⋮----
|
|
8923
|
+
export interface GetPositionModeResponse {
|
|
8924
|
+
positionMode: 0 | 1; // 0 = one-way mode, 1 = hedge mode
|
|
8925
|
+
}
|
|
8926
|
+
⋮----
|
|
8927
|
+
positionMode: 0 | 1; // 0 = one-way mode, 1 = hedge mode
|
|
8928
|
+
⋮----
|
|
8435
8929
|
export interface MaxOpenSize {
|
|
8436
8930
|
symbol: string;
|
|
8437
8931
|
maxBuyOpenSize: number;
|
|
@@ -9004,22 +9498,223 @@ orderIdsList: ['order-id-1', 'order-id-2'], // Replace with actual order IDs
|
|
|
9004
9498
|
// Start executing the example workflow
|
|
9005
9499
|
|
|
9006
9500
|
================
|
|
9007
|
-
File:
|
|
9501
|
+
File: src/lib/BaseRestClient.ts
|
|
9008
9502
|
================
|
|
9009
|
-
|
|
9010
|
-
|
|
9011
|
-
|
|
9012
|
-
|
|
9013
|
-
|
|
9014
|
-
|
|
9015
|
-
|
|
9016
|
-
|
|
9017
|
-
|
|
9018
|
-
|
|
9019
|
-
|
|
9020
|
-
|
|
9021
|
-
|
|
9022
|
-
|
|
9503
|
+
import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios';
|
|
9504
|
+
import https from 'https';
|
|
9505
|
+
⋮----
|
|
9506
|
+
import { neverGuard } from './misc-util.js';
|
|
9507
|
+
import {
|
|
9508
|
+
APIIDFutures,
|
|
9509
|
+
APIIDFuturesSign,
|
|
9510
|
+
APIIDMain,
|
|
9511
|
+
APIIDMainSign,
|
|
9512
|
+
getRestBaseUrl,
|
|
9513
|
+
REST_CLIENT_TYPE_ENUM,
|
|
9514
|
+
RestClientOptions,
|
|
9515
|
+
RestClientType,
|
|
9516
|
+
serializeParams,
|
|
9517
|
+
} from './requestUtils.js';
|
|
9518
|
+
import {
|
|
9519
|
+
checkWebCryptoAPISupported,
|
|
9520
|
+
SignAlgorithm,
|
|
9521
|
+
SignEncodeMethod,
|
|
9522
|
+
signMessage,
|
|
9523
|
+
} from './webCryptoAPI.js';
|
|
9524
|
+
⋮----
|
|
9525
|
+
export interface SignedRequest<T extends object | undefined = {}> {
|
|
9526
|
+
originalParams: T;
|
|
9527
|
+
paramsWithSign?: T & { sign: string };
|
|
9528
|
+
serializedParams: string;
|
|
9529
|
+
sign: string;
|
|
9530
|
+
queryParamsWithSign: string;
|
|
9531
|
+
timestamp: number;
|
|
9532
|
+
recvWindow: number;
|
|
9533
|
+
}
|
|
9534
|
+
⋮----
|
|
9535
|
+
interface UnsignedRequest<T extends object | undefined = {}> {
|
|
9536
|
+
originalParams: T;
|
|
9537
|
+
paramsWithSign: T;
|
|
9538
|
+
}
|
|
9539
|
+
⋮----
|
|
9540
|
+
type SignMethod = 'kucoin';
|
|
9541
|
+
⋮----
|
|
9542
|
+
// request: {
|
|
9543
|
+
// url: response.config.url,
|
|
9544
|
+
// method: response.config.method,
|
|
9545
|
+
// data: response.config.data,
|
|
9546
|
+
// headers: response.config.headers,
|
|
9547
|
+
// },
|
|
9548
|
+
⋮----
|
|
9549
|
+
export abstract class BaseRestClient
|
|
9550
|
+
⋮----
|
|
9551
|
+
/** Defines the client type (affecting how requests & signatures behave) */
|
|
9552
|
+
abstract getClientType(): RestClientType;
|
|
9553
|
+
⋮----
|
|
9554
|
+
/**
|
|
9555
|
+
* Create an instance of the REST client. Pass API credentials in the object in the first parameter.
|
|
9556
|
+
* @param {RestClientOptions} [restClientOptions={}] options to configure REST API connectivity
|
|
9557
|
+
* @param {AxiosRequestConfig} [networkOptions={}] HTTP networking options for axios
|
|
9558
|
+
*/
|
|
9559
|
+
constructor(
|
|
9560
|
+
restClientOptions: RestClientOptions = {},
|
|
9561
|
+
networkOptions: AxiosRequestConfig = {},
|
|
9562
|
+
)
|
|
9563
|
+
⋮----
|
|
9564
|
+
/** Throw errors if any request params are empty */
|
|
9565
|
+
⋮----
|
|
9566
|
+
/** in ms == 5 minutes by default */
|
|
9567
|
+
⋮----
|
|
9568
|
+
/** inject custom rquest options based on axios specs - see axios docs for more guidance on AxiosRequestConfig: https://github.com/axios/axios#request-config */
|
|
9569
|
+
⋮----
|
|
9570
|
+
// If enabled, configure a https agent with keepAlive enabled
|
|
9571
|
+
⋮----
|
|
9572
|
+
// Extract existing https agent parameters, if provided, to prevent the keepAlive flag from overwriting an existing https agent completely
|
|
9573
|
+
⋮----
|
|
9574
|
+
// For more advanced configuration, raise an issue on GitHub or use the "networkOptions"
|
|
9575
|
+
// parameter to define a custom httpsAgent with the desired properties
|
|
9576
|
+
⋮----
|
|
9577
|
+
// Check Web Crypto API support when credentials are provided
|
|
9578
|
+
⋮----
|
|
9579
|
+
// Throw if one of the 3 values is missing, but at least one of them is set
|
|
9580
|
+
⋮----
|
|
9581
|
+
/**
|
|
9582
|
+
* Generates a timestamp for signing API requests.
|
|
9583
|
+
*
|
|
9584
|
+
* This method can be overridden or customized using `customTimestampFn`
|
|
9585
|
+
* to implement a custom timestamp synchronization mechanism.
|
|
9586
|
+
* If no custom function is provided, it defaults to the current system time.
|
|
9587
|
+
*/
|
|
9588
|
+
private getSignTimestampMs(): number
|
|
9589
|
+
⋮----
|
|
9590
|
+
private hasValidCredentials()
|
|
9591
|
+
⋮----
|
|
9592
|
+
setAccessToken(newAccessToken: string)
|
|
9593
|
+
⋮----
|
|
9594
|
+
hasAccessToken(): boolean
|
|
9595
|
+
⋮----
|
|
9596
|
+
get(endpoint: string, params?: any)
|
|
9597
|
+
⋮----
|
|
9598
|
+
post(endpoint: string, params?: any)
|
|
9599
|
+
⋮----
|
|
9600
|
+
getPrivate(endpoint: string, params?: any)
|
|
9601
|
+
⋮----
|
|
9602
|
+
postPrivate(endpoint: string, params?: any)
|
|
9603
|
+
⋮----
|
|
9604
|
+
deletePrivate(endpoint: string, params?: any)
|
|
9605
|
+
⋮----
|
|
9606
|
+
/**
|
|
9607
|
+
* @private Make a HTTP request to a specific endpoint. Private endpoint API calls are automatically signed.
|
|
9608
|
+
*/
|
|
9609
|
+
private async _call(
|
|
9610
|
+
method: Method,
|
|
9611
|
+
endpoint: string,
|
|
9612
|
+
params?: any,
|
|
9613
|
+
isPublicApi?: boolean,
|
|
9614
|
+
): Promise<any>
|
|
9615
|
+
⋮----
|
|
9616
|
+
// Sanity check to make sure it's only ever prefixed by one forward slash
|
|
9617
|
+
⋮----
|
|
9618
|
+
// Build a request and handle signature process
|
|
9619
|
+
⋮----
|
|
9620
|
+
// Dispatch request
|
|
9621
|
+
⋮----
|
|
9622
|
+
// Throw if API returns an error (e.g. insufficient balance)
|
|
9623
|
+
⋮----
|
|
9624
|
+
/**
|
|
9625
|
+
* @private generic handler to parse request exceptions
|
|
9626
|
+
*/
|
|
9627
|
+
parseException(e: any, requestParams: any): unknown
|
|
9628
|
+
⋮----
|
|
9629
|
+
// Something happened in setting up the request that triggered an error
|
|
9630
|
+
⋮----
|
|
9631
|
+
// request made but no response received
|
|
9632
|
+
⋮----
|
|
9633
|
+
// The request was made and the server responded with a status code
|
|
9634
|
+
// that falls out of the range of 2xx
|
|
9635
|
+
⋮----
|
|
9636
|
+
// console.error('err: ', response?.data);
|
|
9637
|
+
⋮----
|
|
9638
|
+
// Prevent credentials from leaking into error messages
|
|
9639
|
+
⋮----
|
|
9640
|
+
private async signMessage(
|
|
9641
|
+
paramsStr: string,
|
|
9642
|
+
secret: string,
|
|
9643
|
+
method: SignEncodeMethod,
|
|
9644
|
+
algorithm: SignAlgorithm,
|
|
9645
|
+
): Promise<string>
|
|
9646
|
+
⋮----
|
|
9647
|
+
/**
|
|
9648
|
+
* @private sign request and set recv window
|
|
9649
|
+
*/
|
|
9650
|
+
private async signRequest<T extends object | undefined = {}>(
|
|
9651
|
+
data: T,
|
|
9652
|
+
endpoint: string,
|
|
9653
|
+
method: Method,
|
|
9654
|
+
signMethod: SignMethod,
|
|
9655
|
+
): Promise<SignedRequest<T>>
|
|
9656
|
+
⋮----
|
|
9657
|
+
// Only sign when no access token is provided
|
|
9658
|
+
⋮----
|
|
9659
|
+
private async prepareSignParams<TParams extends object | undefined>(
|
|
9660
|
+
method: Method,
|
|
9661
|
+
endpoint: string,
|
|
9662
|
+
signMethod: SignMethod,
|
|
9663
|
+
params?: TParams,
|
|
9664
|
+
isPublicApi?: true,
|
|
9665
|
+
): Promise<UnsignedRequest<TParams>>;
|
|
9666
|
+
⋮----
|
|
9667
|
+
private async prepareSignParams<TParams extends object | undefined>(
|
|
9668
|
+
method: Method,
|
|
9669
|
+
endpoint: string,
|
|
9670
|
+
signMethod: SignMethod,
|
|
9671
|
+
params?: TParams,
|
|
9672
|
+
isPublicApi?: false | undefined,
|
|
9673
|
+
): Promise<SignedRequest<TParams>>;
|
|
9674
|
+
⋮----
|
|
9675
|
+
private async prepareSignParams<TParams extends object | undefined>(
|
|
9676
|
+
method: Method,
|
|
9677
|
+
endpoint: string,
|
|
9678
|
+
signMethod: SignMethod,
|
|
9679
|
+
params?: TParams,
|
|
9680
|
+
isPublicApi?: boolean,
|
|
9681
|
+
)
|
|
9682
|
+
⋮----
|
|
9683
|
+
/** Returns an axios request object. Handles signing process automatically if this is a private API call */
|
|
9684
|
+
private async buildRequest(
|
|
9685
|
+
method: Method,
|
|
9686
|
+
endpoint: string,
|
|
9687
|
+
url: string,
|
|
9688
|
+
params?: any,
|
|
9689
|
+
isPublicApi?: boolean,
|
|
9690
|
+
): Promise<AxiosRequestConfig>
|
|
9691
|
+
⋮----
|
|
9692
|
+
// Support for Authorization header, if provided:
|
|
9693
|
+
// https://github.com/tiagosiebler/kucoin-api/issues/2
|
|
9694
|
+
// Use restClient.setAccessToken(newToken), if you need to store a new access token
|
|
9695
|
+
|
|
9696
|
+
================
|
|
9697
|
+
File: src/index.ts
|
|
9698
|
+
================
|
|
9699
|
+
|
|
9700
|
+
|
|
9701
|
+
================
|
|
9702
|
+
File: README.md
|
|
9703
|
+
================
|
|
9704
|
+
# Node.js & JavaScript SDK for Kucoin REST APIs, Websockets & WebSocket API
|
|
9705
|
+
|
|
9706
|
+
[](https://github.com/tiagosiebler/kucoin-api/actions/workflows/e2etest.yml)
|
|
9707
|
+
[][1]
|
|
9708
|
+
[][1]
|
|
9709
|
+
[][1]
|
|
9710
|
+
[][1]
|
|
9711
|
+
[](https://t.me/nodetraders)
|
|
9712
|
+
|
|
9713
|
+
<p align="center">
|
|
9714
|
+
<a href="https://www.npmjs.com/package/kucoin-api">
|
|
9715
|
+
<picture>
|
|
9716
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/tiagosiebler/kucoin-api/blob/master/docs/images/logoDarkMode2.svg?raw=true#gh-dark-mode-only">
|
|
9717
|
+
<img alt="SDK Logo" src="https://github.com/tiagosiebler/kucoin-api/blob/master/docs/images/logoBrightMode2.svg?raw=true#gh-light-mode-only">
|
|
9023
9718
|
</picture>
|
|
9024
9719
|
</a>
|
|
9025
9720
|
</p>
|
|
@@ -9064,6 +9759,7 @@ Updated & performant JavaScript & Node.js SDK for the Kucoin REST APIs and WebSo
|
|
|
9064
9759
|
- [Spot & Margin Trading](#spot--margin-trading)
|
|
9065
9760
|
- [Futures Trading](#futures-trading)
|
|
9066
9761
|
- [Broker Operations](#broker-operations)
|
|
9762
|
+
- [Unified Trading Account API](#unified-trading-account-api)
|
|
9067
9763
|
- [WebSockets](#websockets)
|
|
9068
9764
|
- [WebSocket Consumers](#websocket-consumers)
|
|
9069
9765
|
- [Public WebSocket Streams](#public-websocket-streams)
|
|
@@ -9150,6 +9846,7 @@ The SDK provides dedicated REST clients for different trading products:
|
|
|
9150
9846
|
- **SpotClient** - for spot trading and margin operations
|
|
9151
9847
|
- **FuturesClient** - for futures trading operations
|
|
9152
9848
|
- **BrokerClient** - for broker and sub-account management
|
|
9849
|
+
- **UnifiedAPIClient** - for unified market data access across all trading products
|
|
9153
9850
|
|
|
9154
9851
|
### Spot & Margin Trading
|
|
9155
9852
|
|
|
@@ -9197,6 +9894,10 @@ Use the `FuturesClient` for futures trading operations. See [FuturesClient](./sr
|
|
|
9197
9894
|
|
|
9198
9895
|
Use the `BrokerClient` for broker and sub-account management operations. See [BrokerClient](./src/BrokerClient.ts) for complete API coverage.
|
|
9199
9896
|
|
|
9897
|
+
### Unified Trading Account API
|
|
9898
|
+
|
|
9899
|
+
The `UnifiedAPIClient` provides access to KuCoin's Unified Trading Account API endpoints, which offer streamlined market data access across Spot, Futures, and Margin trading products.
|
|
9900
|
+
|
|
9200
9901
|
## WebSockets
|
|
9201
9902
|
|
|
9202
9903
|
All WebSocket functionality is supported via the unified `WebsocketClient`. This client handles both spot and futures WebSocket streams with automatic connection management and reconnection.
|
|
@@ -9355,12 +10056,12 @@ const wsClient = new WebsocketAPIClient(
|
|
|
9355
10056
|
// Make WebSocket API calls, very similar to a REST API:
|
|
9356
10057
|
|
|
9357
10058
|
wsClient
|
|
9358
|
-
.
|
|
10059
|
+
.submitNewSpotOrder({
|
|
9359
10060
|
side: 'buy',
|
|
9360
10061
|
symbol: 'BTC-USDT',
|
|
9361
10062
|
type: 'limit',
|
|
9362
|
-
price: '
|
|
9363
|
-
size: '0.
|
|
10063
|
+
price: '150000',
|
|
10064
|
+
size: '0.0001',
|
|
9364
10065
|
})
|
|
9365
10066
|
.then((syncSpotOrderResponse) => {
|
|
9366
10067
|
console.log('Sync spot order response:', syncSpotOrderResponse);
|
|
@@ -9376,7 +10077,7 @@ wsClient
|
|
|
9376
10077
|
symbol: 'XBTUSDTM',
|
|
9377
10078
|
marginMode: 'CROSS',
|
|
9378
10079
|
type: 'limit',
|
|
9379
|
-
price: '1000',
|
|
10080
|
+
price: '1000',
|
|
9380
10081
|
qty: '0.01',
|
|
9381
10082
|
leverage: 10,
|
|
9382
10083
|
positionSide: 'LONG', // needed if trading two-way (hedge) position mode
|
|
@@ -9406,8 +10107,8 @@ const logger = {
|
|
|
9406
10107
|
trace: (...params) => {
|
|
9407
10108
|
if (
|
|
9408
10109
|
[
|
|
10110
|
+
// Selectively prevent some traces from logging
|
|
9409
10111
|
'Sending ping',
|
|
9410
|
-
// 'Sending upstream ws message: ',
|
|
9411
10112
|
'Received pong',
|
|
9412
10113
|
].includes(params[0])
|
|
9413
10114
|
) {
|
|
@@ -9474,207 +10175,6 @@ Contributions are encouraged, I will review any incoming pull requests. See the
|
|
|
9474
10175
|
|
|
9475
10176
|
<!-- template_star_history_end -->
|
|
9476
10177
|
|
|
9477
|
-
================
|
|
9478
|
-
File: src/lib/BaseRestClient.ts
|
|
9479
|
-
================
|
|
9480
|
-
import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios';
|
|
9481
|
-
import https from 'https';
|
|
9482
|
-
⋮----
|
|
9483
|
-
import { neverGuard } from './misc-util.js';
|
|
9484
|
-
import {
|
|
9485
|
-
APIIDFutures,
|
|
9486
|
-
APIIDFuturesSign,
|
|
9487
|
-
APIIDMain,
|
|
9488
|
-
APIIDMainSign,
|
|
9489
|
-
getRestBaseUrl,
|
|
9490
|
-
REST_CLIENT_TYPE_ENUM,
|
|
9491
|
-
RestClientOptions,
|
|
9492
|
-
RestClientType,
|
|
9493
|
-
serializeParams,
|
|
9494
|
-
} from './requestUtils.js';
|
|
9495
|
-
import {
|
|
9496
|
-
checkWebCryptoAPISupported,
|
|
9497
|
-
SignAlgorithm,
|
|
9498
|
-
SignEncodeMethod,
|
|
9499
|
-
signMessage,
|
|
9500
|
-
} from './webCryptoAPI.js';
|
|
9501
|
-
⋮----
|
|
9502
|
-
export interface SignedRequest<T extends object | undefined = {}> {
|
|
9503
|
-
originalParams: T;
|
|
9504
|
-
paramsWithSign?: T & { sign: string };
|
|
9505
|
-
serializedParams: string;
|
|
9506
|
-
sign: string;
|
|
9507
|
-
queryParamsWithSign: string;
|
|
9508
|
-
timestamp: number;
|
|
9509
|
-
recvWindow: number;
|
|
9510
|
-
}
|
|
9511
|
-
⋮----
|
|
9512
|
-
interface UnsignedRequest<T extends object | undefined = {}> {
|
|
9513
|
-
originalParams: T;
|
|
9514
|
-
paramsWithSign: T;
|
|
9515
|
-
}
|
|
9516
|
-
⋮----
|
|
9517
|
-
type SignMethod = 'kucoin';
|
|
9518
|
-
⋮----
|
|
9519
|
-
// request: {
|
|
9520
|
-
// url: response.config.url,
|
|
9521
|
-
// method: response.config.method,
|
|
9522
|
-
// data: response.config.data,
|
|
9523
|
-
// headers: response.config.headers,
|
|
9524
|
-
// },
|
|
9525
|
-
⋮----
|
|
9526
|
-
export abstract class BaseRestClient
|
|
9527
|
-
⋮----
|
|
9528
|
-
/** Defines the client type (affecting how requests & signatures behave) */
|
|
9529
|
-
abstract getClientType(): RestClientType;
|
|
9530
|
-
⋮----
|
|
9531
|
-
/**
|
|
9532
|
-
* Create an instance of the REST client. Pass API credentials in the object in the first parameter.
|
|
9533
|
-
* @param {RestClientOptions} [restClientOptions={}] options to configure REST API connectivity
|
|
9534
|
-
* @param {AxiosRequestConfig} [networkOptions={}] HTTP networking options for axios
|
|
9535
|
-
*/
|
|
9536
|
-
constructor(
|
|
9537
|
-
restClientOptions: RestClientOptions = {},
|
|
9538
|
-
networkOptions: AxiosRequestConfig = {},
|
|
9539
|
-
)
|
|
9540
|
-
⋮----
|
|
9541
|
-
/** Throw errors if any request params are empty */
|
|
9542
|
-
⋮----
|
|
9543
|
-
/** in ms == 5 minutes by default */
|
|
9544
|
-
⋮----
|
|
9545
|
-
/** inject custom rquest options based on axios specs - see axios docs for more guidance on AxiosRequestConfig: https://github.com/axios/axios#request-config */
|
|
9546
|
-
⋮----
|
|
9547
|
-
// If enabled, configure a https agent with keepAlive enabled
|
|
9548
|
-
⋮----
|
|
9549
|
-
// Extract existing https agent parameters, if provided, to prevent the keepAlive flag from overwriting an existing https agent completely
|
|
9550
|
-
⋮----
|
|
9551
|
-
// For more advanced configuration, raise an issue on GitHub or use the "networkOptions"
|
|
9552
|
-
// parameter to define a custom httpsAgent with the desired properties
|
|
9553
|
-
⋮----
|
|
9554
|
-
// Check Web Crypto API support when credentials are provided
|
|
9555
|
-
⋮----
|
|
9556
|
-
// Throw if one of the 3 values is missing, but at least one of them is set
|
|
9557
|
-
⋮----
|
|
9558
|
-
/**
|
|
9559
|
-
* Generates a timestamp for signing API requests.
|
|
9560
|
-
*
|
|
9561
|
-
* This method can be overridden or customized using `customTimestampFn`
|
|
9562
|
-
* to implement a custom timestamp synchronization mechanism.
|
|
9563
|
-
* If no custom function is provided, it defaults to the current system time.
|
|
9564
|
-
*/
|
|
9565
|
-
private getSignTimestampMs(): number
|
|
9566
|
-
⋮----
|
|
9567
|
-
private hasValidCredentials()
|
|
9568
|
-
⋮----
|
|
9569
|
-
setAccessToken(newAccessToken: string)
|
|
9570
|
-
⋮----
|
|
9571
|
-
hasAccessToken(): boolean
|
|
9572
|
-
⋮----
|
|
9573
|
-
get(endpoint: string, params?: any)
|
|
9574
|
-
⋮----
|
|
9575
|
-
post(endpoint: string, params?: any)
|
|
9576
|
-
⋮----
|
|
9577
|
-
getPrivate(endpoint: string, params?: any)
|
|
9578
|
-
⋮----
|
|
9579
|
-
postPrivate(endpoint: string, params?: any)
|
|
9580
|
-
⋮----
|
|
9581
|
-
deletePrivate(endpoint: string, params?: any)
|
|
9582
|
-
⋮----
|
|
9583
|
-
/**
|
|
9584
|
-
* @private Make a HTTP request to a specific endpoint. Private endpoint API calls are automatically signed.
|
|
9585
|
-
*/
|
|
9586
|
-
private async _call(
|
|
9587
|
-
method: Method,
|
|
9588
|
-
endpoint: string,
|
|
9589
|
-
params?: any,
|
|
9590
|
-
isPublicApi?: boolean,
|
|
9591
|
-
): Promise<any>
|
|
9592
|
-
⋮----
|
|
9593
|
-
// Sanity check to make sure it's only ever prefixed by one forward slash
|
|
9594
|
-
⋮----
|
|
9595
|
-
// Build a request and handle signature process
|
|
9596
|
-
⋮----
|
|
9597
|
-
// Dispatch request
|
|
9598
|
-
⋮----
|
|
9599
|
-
// Throw if API returns an error (e.g. insufficient balance)
|
|
9600
|
-
⋮----
|
|
9601
|
-
/**
|
|
9602
|
-
* @private generic handler to parse request exceptions
|
|
9603
|
-
*/
|
|
9604
|
-
parseException(e: any, requestParams: any): unknown
|
|
9605
|
-
⋮----
|
|
9606
|
-
// Something happened in setting up the request that triggered an error
|
|
9607
|
-
⋮----
|
|
9608
|
-
// request made but no response received
|
|
9609
|
-
⋮----
|
|
9610
|
-
// The request was made and the server responded with a status code
|
|
9611
|
-
// that falls out of the range of 2xx
|
|
9612
|
-
⋮----
|
|
9613
|
-
// console.error('err: ', response?.data);
|
|
9614
|
-
⋮----
|
|
9615
|
-
// Prevent credentials from leaking into error messages
|
|
9616
|
-
⋮----
|
|
9617
|
-
private async signMessage(
|
|
9618
|
-
paramsStr: string,
|
|
9619
|
-
secret: string,
|
|
9620
|
-
method: SignEncodeMethod,
|
|
9621
|
-
algorithm: SignAlgorithm,
|
|
9622
|
-
): Promise<string>
|
|
9623
|
-
⋮----
|
|
9624
|
-
/**
|
|
9625
|
-
* @private sign request and set recv window
|
|
9626
|
-
*/
|
|
9627
|
-
private async signRequest<T extends object | undefined = {}>(
|
|
9628
|
-
data: T,
|
|
9629
|
-
endpoint: string,
|
|
9630
|
-
method: Method,
|
|
9631
|
-
signMethod: SignMethod,
|
|
9632
|
-
): Promise<SignedRequest<T>>
|
|
9633
|
-
⋮----
|
|
9634
|
-
// Only sign when no access token is provided
|
|
9635
|
-
⋮----
|
|
9636
|
-
private async prepareSignParams<TParams extends object | undefined>(
|
|
9637
|
-
method: Method,
|
|
9638
|
-
endpoint: string,
|
|
9639
|
-
signMethod: SignMethod,
|
|
9640
|
-
params?: TParams,
|
|
9641
|
-
isPublicApi?: true,
|
|
9642
|
-
): Promise<UnsignedRequest<TParams>>;
|
|
9643
|
-
⋮----
|
|
9644
|
-
private async prepareSignParams<TParams extends object | undefined>(
|
|
9645
|
-
method: Method,
|
|
9646
|
-
endpoint: string,
|
|
9647
|
-
signMethod: SignMethod,
|
|
9648
|
-
params?: TParams,
|
|
9649
|
-
isPublicApi?: false | undefined,
|
|
9650
|
-
): Promise<SignedRequest<TParams>>;
|
|
9651
|
-
⋮----
|
|
9652
|
-
private async prepareSignParams<TParams extends object | undefined>(
|
|
9653
|
-
method: Method,
|
|
9654
|
-
endpoint: string,
|
|
9655
|
-
signMethod: SignMethod,
|
|
9656
|
-
params?: TParams,
|
|
9657
|
-
isPublicApi?: boolean,
|
|
9658
|
-
)
|
|
9659
|
-
⋮----
|
|
9660
|
-
/** Returns an axios request object. Handles signing process automatically if this is a private API call */
|
|
9661
|
-
private async buildRequest(
|
|
9662
|
-
method: Method,
|
|
9663
|
-
endpoint: string,
|
|
9664
|
-
url: string,
|
|
9665
|
-
params?: any,
|
|
9666
|
-
isPublicApi?: boolean,
|
|
9667
|
-
): Promise<AxiosRequestConfig>
|
|
9668
|
-
⋮----
|
|
9669
|
-
// Support for Authorization header, if provided:
|
|
9670
|
-
// https://github.com/tiagosiebler/kucoin-api/issues/2
|
|
9671
|
-
// Use restClient.setAccessToken(newToken), if you need to store a new access token
|
|
9672
|
-
|
|
9673
|
-
================
|
|
9674
|
-
File: src/index.ts
|
|
9675
|
-
================
|
|
9676
|
-
|
|
9677
|
-
|
|
9678
10178
|
================
|
|
9679
10179
|
File: src/lib/BaseWSClient.ts
|
|
9680
10180
|
================
|
|
@@ -12533,6 +13033,7 @@ getAffiliateTransaction(
|
|
|
12533
13033
|
* Get download link for broker rebate orders
|
|
12534
13034
|
*
|
|
12535
13035
|
* trade type 1 = spot, trade type 2 = futures
|
|
13036
|
+
* @deprecated Use getBrokerRebateOrderDownloadLinkV2 instead
|
|
12536
13037
|
*/
|
|
12537
13038
|
getBrokerRebateOrderDownloadLink(params: {
|
|
12538
13039
|
begin: string;
|
|
@@ -12540,6 +13041,17 @@ getBrokerRebateOrderDownloadLink(params: {
|
|
|
12540
13041
|
tradeType: 1 | 2;
|
|
12541
13042
|
}): Promise<APISuccessResponse<any>>
|
|
12542
13043
|
⋮----
|
|
13044
|
+
/**
|
|
13045
|
+
* Get download link for broker rebate orders
|
|
13046
|
+
*
|
|
13047
|
+
* trade type SPOT = spot, FUTURE = futures
|
|
13048
|
+
*/
|
|
13049
|
+
getBrokerRebateOrderDownloadLinkV2(params: {
|
|
13050
|
+
begin: string;
|
|
13051
|
+
end: string;
|
|
13052
|
+
tradeType: 'SPOT' | 'FUTURE';
|
|
13053
|
+
}): Promise<APISuccessResponse<any>>
|
|
13054
|
+
⋮----
|
|
12543
13055
|
/**
|
|
12544
13056
|
*
|
|
12545
13057
|
* WebSockets
|
|
@@ -12846,7 +13358,7 @@ File: package.json
|
|
|
12846
13358
|
================
|
|
12847
13359
|
{
|
|
12848
13360
|
"name": "kucoin-api",
|
|
12849
|
-
"version": "2.
|
|
13361
|
+
"version": "2.3.0",
|
|
12850
13362
|
"description": "Complete & robust Node.js SDK for Kucoin's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
|
|
12851
13363
|
"scripts": {
|
|
12852
13364
|
"clean": "rm -rf dist",
|