kucoin-api 2.1.21 → 2.1.22
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/dist/cjs/SpotClient.d.ts +102 -10
- package/dist/cjs/SpotClient.js +128 -8
- package/dist/cjs/SpotClient.js.map +1 -1
- package/dist/cjs/types/request/spot-affiliate.d.ts +9 -0
- package/dist/cjs/types/request/spot-margin-trading.d.ts +87 -0
- package/dist/cjs/types/response/spot-affiliate.d.ts +15 -0
- package/dist/cjs/types/response/spot-margin-trading.d.ts +94 -0
- package/dist/cjs/types/response/spot-trading.d.ts +1 -0
- package/dist/mjs/SpotClient.d.ts +102 -10
- package/dist/mjs/SpotClient.js +128 -8
- package/dist/mjs/SpotClient.js.map +1 -1
- package/dist/mjs/types/request/spot-affiliate.d.ts +9 -0
- package/dist/mjs/types/request/spot-margin-trading.d.ts +87 -0
- package/dist/mjs/types/response/spot-affiliate.d.ts +15 -0
- package/dist/mjs/types/response/spot-margin-trading.d.ts +94 -0
- package/dist/mjs/types/response/spot-trading.d.ts +1 -0
- package/llms.txt +2199 -1642
- package/package.json +1 -1
package/llms.txt
CHANGED
|
@@ -1653,37 +1653,6 @@ File: src/lib/misc-util.ts
|
|
|
1653
1653
|
================
|
|
1654
1654
|
export function neverGuard(x: never, msg: string): Error
|
|
1655
1655
|
|
|
1656
|
-
================
|
|
1657
|
-
File: src/lib/webCryptoAPI.ts
|
|
1658
|
-
================
|
|
1659
|
-
import { neverGuard } from './misc-util.js';
|
|
1660
|
-
⋮----
|
|
1661
|
-
function bufferToB64(buffer: ArrayBuffer): string
|
|
1662
|
-
⋮----
|
|
1663
|
-
export type SignEncodeMethod = 'hex' | 'base64';
|
|
1664
|
-
export type SignAlgorithm = 'SHA-256' | 'SHA-512';
|
|
1665
|
-
⋮----
|
|
1666
|
-
/**
|
|
1667
|
-
* Similar to node crypto's `createHash()` function
|
|
1668
|
-
*/
|
|
1669
|
-
export async function hashMessage(
|
|
1670
|
-
message: string,
|
|
1671
|
-
method: SignEncodeMethod,
|
|
1672
|
-
algorithm: SignAlgorithm,
|
|
1673
|
-
): Promise<string>
|
|
1674
|
-
⋮----
|
|
1675
|
-
/**
|
|
1676
|
-
* Sign a message, with a secret, using the Web Crypto API
|
|
1677
|
-
*/
|
|
1678
|
-
export async function signMessage(
|
|
1679
|
-
message: string,
|
|
1680
|
-
secret: string,
|
|
1681
|
-
method: SignEncodeMethod,
|
|
1682
|
-
algorithm: SignAlgorithm,
|
|
1683
|
-
): Promise<string>
|
|
1684
|
-
⋮----
|
|
1685
|
-
export function checkWebCryptoAPISupported()
|
|
1686
|
-
|
|
1687
1656
|
================
|
|
1688
1657
|
File: src/types/request/spot-margin-trading.ts
|
|
1689
1658
|
================
|
|
@@ -1877,6 +1846,174 @@ export interface GetLendingSubscriptionOrdersV3Request {
|
|
|
1877
1846
|
currentPage?: number;
|
|
1878
1847
|
pageSize?: number;
|
|
1879
1848
|
}
|
|
1849
|
+
⋮----
|
|
1850
|
+
export interface GetBorrowInterestRateRequest {
|
|
1851
|
+
vipLevel?: number; // optional - If empty, default to current user vip level (0-12)
|
|
1852
|
+
currency?: string; // optional - Supports multiple currencies (up to 50), comma-separated
|
|
1853
|
+
}
|
|
1854
|
+
⋮----
|
|
1855
|
+
vipLevel?: number; // optional - If empty, default to current user vip level (0-12)
|
|
1856
|
+
currency?: string; // optional - Supports multiple currencies (up to 50), comma-separated
|
|
1857
|
+
⋮----
|
|
1858
|
+
/**
|
|
1859
|
+
* Margin Stop Order Requests
|
|
1860
|
+
*/
|
|
1861
|
+
export interface SubmitMarginStopOrderRequest {
|
|
1862
|
+
clientOid: string; // Client Order ID
|
|
1863
|
+
side: 'buy' | 'sell'; // Order side
|
|
1864
|
+
symbol: string; // Trading symbol
|
|
1865
|
+
type?: 'limit' | 'market'; // Order type, default: limit
|
|
1866
|
+
remark?: string; // Order note, max 100 characters
|
|
1867
|
+
stop?: string; // Stop condition, default: loss
|
|
1868
|
+
stopPrice: string; // Trigger price (required)
|
|
1869
|
+
stp?: 'DC' | 'CO' | 'CN' | 'CB'; // Self Trade Prevention
|
|
1870
|
+
isIsolated: boolean; // True - isolated margin; false - cross margin
|
|
1871
|
+
autoRepay: boolean; // AutoPay for borrowed assets
|
|
1872
|
+
autoBorrow: boolean; // Auto borrow for insufficient balance
|
|
1873
|
+
price?: string; // Order price (required for limit orders)
|
|
1874
|
+
size?: string; // Order quantity (required for limit orders)
|
|
1875
|
+
timeInForce?: 'GTC' | 'GTT' | 'IOC' | 'FOK'; // Time in force
|
|
1876
|
+
cancelAfter?: number; // Cancel after n seconds (GTT strategy)
|
|
1877
|
+
postOnly?: boolean; // Passive order labels
|
|
1878
|
+
hidden?: boolean; // Hidden order
|
|
1879
|
+
iceberg?: boolean; // Iceberg order
|
|
1880
|
+
visibleSize?: string; // Visible size for iceberg orders
|
|
1881
|
+
funds?: string; // Order funds (for market orders)
|
|
1882
|
+
}
|
|
1883
|
+
⋮----
|
|
1884
|
+
clientOid: string; // Client Order ID
|
|
1885
|
+
side: 'buy' | 'sell'; // Order side
|
|
1886
|
+
symbol: string; // Trading symbol
|
|
1887
|
+
type?: 'limit' | 'market'; // Order type, default: limit
|
|
1888
|
+
remark?: string; // Order note, max 100 characters
|
|
1889
|
+
stop?: string; // Stop condition, default: loss
|
|
1890
|
+
stopPrice: string; // Trigger price (required)
|
|
1891
|
+
stp?: 'DC' | 'CO' | 'CN' | 'CB'; // Self Trade Prevention
|
|
1892
|
+
isIsolated: boolean; // True - isolated margin; false - cross margin
|
|
1893
|
+
autoRepay: boolean; // AutoPay for borrowed assets
|
|
1894
|
+
autoBorrow: boolean; // Auto borrow for insufficient balance
|
|
1895
|
+
price?: string; // Order price (required for limit orders)
|
|
1896
|
+
size?: string; // Order quantity (required for limit orders)
|
|
1897
|
+
timeInForce?: 'GTC' | 'GTT' | 'IOC' | 'FOK'; // Time in force
|
|
1898
|
+
cancelAfter?: number; // Cancel after n seconds (GTT strategy)
|
|
1899
|
+
postOnly?: boolean; // Passive order labels
|
|
1900
|
+
hidden?: boolean; // Hidden order
|
|
1901
|
+
iceberg?: boolean; // Iceberg order
|
|
1902
|
+
visibleSize?: string; // Visible size for iceberg orders
|
|
1903
|
+
funds?: string; // Order funds (for market orders)
|
|
1904
|
+
⋮----
|
|
1905
|
+
export interface CancelMarginStopOrderByClientOidRequest {
|
|
1906
|
+
clientOid: string; // Client order ID
|
|
1907
|
+
}
|
|
1908
|
+
⋮----
|
|
1909
|
+
clientOid: string; // Client order ID
|
|
1910
|
+
⋮----
|
|
1911
|
+
export interface BatchCancelMarginStopOrdersRequest {
|
|
1912
|
+
symbol?: string; // Trading symbol
|
|
1913
|
+
tradeType: 'MARGIN_TRADE' | 'MARGIN_ISOLATED_TRADE'; // Margin type (required)
|
|
1914
|
+
orderIds?: string; // Comma separated order IDs
|
|
1915
|
+
}
|
|
1916
|
+
⋮----
|
|
1917
|
+
symbol?: string; // Trading symbol
|
|
1918
|
+
tradeType: 'MARGIN_TRADE' | 'MARGIN_ISOLATED_TRADE'; // Margin type (required)
|
|
1919
|
+
orderIds?: string; // Comma separated order IDs
|
|
1920
|
+
⋮----
|
|
1921
|
+
export interface GetMarginStopOrdersListRequest {
|
|
1922
|
+
symbol?: string; // Trading symbol
|
|
1923
|
+
side?: string; // Order side (buy/sell)
|
|
1924
|
+
type?: 'limit' | 'market' | 'limit_stop' | 'market_stop'; // Order type
|
|
1925
|
+
tradeType?: 'MARGIN_TRADE' | 'MARGIN_ISOLATED_TRADE'; // Margin type
|
|
1926
|
+
startAt?: number; // Start time (millisecond)
|
|
1927
|
+
endAt?: number; // End time (millisecond)
|
|
1928
|
+
currentPage?: number; // Current page (>=1, default: 1)
|
|
1929
|
+
orderIds?: string; // Comma separated order IDs
|
|
1930
|
+
pageSize?: number; // Page size (>=10, <=500, default: 50)
|
|
1931
|
+
stop?: 'stop' | 'oco'; // Order type
|
|
1932
|
+
}
|
|
1933
|
+
⋮----
|
|
1934
|
+
symbol?: string; // Trading symbol
|
|
1935
|
+
side?: string; // Order side (buy/sell)
|
|
1936
|
+
type?: 'limit' | 'market' | 'limit_stop' | 'market_stop'; // Order type
|
|
1937
|
+
tradeType?: 'MARGIN_TRADE' | 'MARGIN_ISOLATED_TRADE'; // Margin type
|
|
1938
|
+
startAt?: number; // Start time (millisecond)
|
|
1939
|
+
endAt?: number; // End time (millisecond)
|
|
1940
|
+
currentPage?: number; // Current page (>=1, default: 1)
|
|
1941
|
+
orderIds?: string; // Comma separated order IDs
|
|
1942
|
+
pageSize?: number; // Page size (>=10, <=500, default: 50)
|
|
1943
|
+
stop?: 'stop' | 'oco'; // Order type
|
|
1944
|
+
⋮----
|
|
1945
|
+
export interface GetMarginStopOrderByOrderIdRequest {
|
|
1946
|
+
orderId: string; // Order ID
|
|
1947
|
+
}
|
|
1948
|
+
⋮----
|
|
1949
|
+
orderId: string; // Order ID
|
|
1950
|
+
⋮----
|
|
1951
|
+
export interface GetMarginStopOrderByClientOidRequest {
|
|
1952
|
+
clientOid: string; // Client order ID
|
|
1953
|
+
}
|
|
1954
|
+
⋮----
|
|
1955
|
+
clientOid: string; // Client order ID
|
|
1956
|
+
⋮----
|
|
1957
|
+
/**
|
|
1958
|
+
* Margin OCO Order Requests
|
|
1959
|
+
*/
|
|
1960
|
+
export interface SubmitMarginOcoOrderRequest {
|
|
1961
|
+
symbol: string; // Trading symbol (required)
|
|
1962
|
+
side: 'buy' | 'sell'; // Order side (required)
|
|
1963
|
+
price: string; // Order price (required)
|
|
1964
|
+
size: string; // Order quantity (required)
|
|
1965
|
+
stopPrice: string; // Trigger price (required)
|
|
1966
|
+
limitPrice: string; // Limit order price after trigger (required)
|
|
1967
|
+
clientOid: string; // Client Order ID (required)
|
|
1968
|
+
isIsolated: boolean; // true - isolated, false - cross (required)
|
|
1969
|
+
autoRepay?: boolean; // Auto repay
|
|
1970
|
+
autoBorrow?: boolean; // Auto borrow
|
|
1971
|
+
}
|
|
1972
|
+
⋮----
|
|
1973
|
+
symbol: string; // Trading symbol (required)
|
|
1974
|
+
side: 'buy' | 'sell'; // Order side (required)
|
|
1975
|
+
price: string; // Order price (required)
|
|
1976
|
+
size: string; // Order quantity (required)
|
|
1977
|
+
stopPrice: string; // Trigger price (required)
|
|
1978
|
+
limitPrice: string; // Limit order price after trigger (required)
|
|
1979
|
+
clientOid: string; // Client Order ID (required)
|
|
1980
|
+
isIsolated: boolean; // true - isolated, false - cross (required)
|
|
1981
|
+
autoRepay?: boolean; // Auto repay
|
|
1982
|
+
autoBorrow?: boolean; // Auto borrow
|
|
1983
|
+
⋮----
|
|
1984
|
+
export interface CancelMarginOcoOrderByOrderIdRequest {
|
|
1985
|
+
orderId: string; // Order ID
|
|
1986
|
+
}
|
|
1987
|
+
⋮----
|
|
1988
|
+
orderId: string; // Order ID
|
|
1989
|
+
⋮----
|
|
1990
|
+
export interface CancelMarginOcoOrderByClientOidRequest {
|
|
1991
|
+
clientOid: string; // Client order ID
|
|
1992
|
+
}
|
|
1993
|
+
⋮----
|
|
1994
|
+
clientOid: string; // Client order ID
|
|
1995
|
+
⋮----
|
|
1996
|
+
export interface BatchCancelMarginOcoOrdersRequest {
|
|
1997
|
+
orderIds?: string; // Comma separated order IDs
|
|
1998
|
+
symbol?: string; // Trading symbol
|
|
1999
|
+
tradeType?: 'MARGIN_TRADE' | 'MARGIN_ISOLATED_TRADE'; // Margin type
|
|
2000
|
+
}
|
|
2001
|
+
⋮----
|
|
2002
|
+
orderIds?: string; // Comma separated order IDs
|
|
2003
|
+
symbol?: string; // Trading symbol
|
|
2004
|
+
tradeType?: 'MARGIN_TRADE' | 'MARGIN_ISOLATED_TRADE'; // Margin type
|
|
2005
|
+
⋮----
|
|
2006
|
+
export interface GetMarginOcoOrderByClientOidRequest {
|
|
2007
|
+
clientOid: string; // Client order ID
|
|
2008
|
+
}
|
|
2009
|
+
⋮----
|
|
2010
|
+
clientOid: string; // Client order ID
|
|
2011
|
+
⋮----
|
|
2012
|
+
export interface GetMarginOcoOrderDetailByOrderIdRequest {
|
|
2013
|
+
orderId: string; // Order ID
|
|
2014
|
+
}
|
|
2015
|
+
⋮----
|
|
2016
|
+
orderId: string; // Order ID
|
|
1880
2017
|
|
|
1881
2018
|
================
|
|
1882
2019
|
File: src/types/request/spot-misc.ts
|
|
@@ -2468,6 +2605,37 @@ deleteTopic(key: WsKey, topic: TWSTopicSubscribeEventArgs)
|
|
|
2468
2605
|
⋮----
|
|
2469
2606
|
// Check if we're subscribed to a topic like this
|
|
2470
2607
|
|
|
2608
|
+
================
|
|
2609
|
+
File: src/lib/webCryptoAPI.ts
|
|
2610
|
+
================
|
|
2611
|
+
import { neverGuard } from './misc-util.js';
|
|
2612
|
+
⋮----
|
|
2613
|
+
function bufferToB64(buffer: ArrayBuffer): string
|
|
2614
|
+
⋮----
|
|
2615
|
+
export type SignEncodeMethod = 'hex' | 'base64';
|
|
2616
|
+
export type SignAlgorithm = 'SHA-256' | 'SHA-512';
|
|
2617
|
+
⋮----
|
|
2618
|
+
/**
|
|
2619
|
+
* Similar to node crypto's `createHash()` function
|
|
2620
|
+
*/
|
|
2621
|
+
export async function hashMessage(
|
|
2622
|
+
message: string,
|
|
2623
|
+
method: SignEncodeMethod,
|
|
2624
|
+
algorithm: SignAlgorithm,
|
|
2625
|
+
): Promise<string>
|
|
2626
|
+
⋮----
|
|
2627
|
+
/**
|
|
2628
|
+
* Sign a message, with a secret, using the Web Crypto API
|
|
2629
|
+
*/
|
|
2630
|
+
export async function signMessage(
|
|
2631
|
+
message: string,
|
|
2632
|
+
secret: string,
|
|
2633
|
+
method: SignEncodeMethod,
|
|
2634
|
+
algorithm: SignAlgorithm,
|
|
2635
|
+
): Promise<string>
|
|
2636
|
+
⋮----
|
|
2637
|
+
export function checkWebCryptoAPISupported()
|
|
2638
|
+
|
|
2471
2639
|
================
|
|
2472
2640
|
File: src/types/request/broker.types.ts
|
|
2473
2641
|
================
|
|
@@ -2585,6 +2753,24 @@ registrationStartAt?: number; // optional - Registration start timestamp
|
|
|
2585
2753
|
registrationEndAt?: number; // optional - Registration end timestamp
|
|
2586
2754
|
page?: number; // optional - Page number >= 1, default: 1
|
|
2587
2755
|
pageSize?: number; // optional - Max number of records per page >= 1, <= 500, default: 10
|
|
2756
|
+
⋮----
|
|
2757
|
+
export interface GetAffiliateTransactionRequest {
|
|
2758
|
+
uid?: string; // optional - The uid of the invitee
|
|
2759
|
+
tradeType?: 'SPOT' | 'FEATURE'; // optional - Trade type
|
|
2760
|
+
tradeStartAt: number; // required - Transaction start time (13-digit timestamp)
|
|
2761
|
+
tradeEndAt: number; // required - Transaction end time (13-digit timestamp)
|
|
2762
|
+
lastId?: number; // optional - The offset ID of the query
|
|
2763
|
+
direction?: 'PRE' | 'NEXT'; // optional - Page direction, default: 'NEXT'
|
|
2764
|
+
pageSize?: number; // optional - Page size >= 1, <= 500, default: 10
|
|
2765
|
+
}
|
|
2766
|
+
⋮----
|
|
2767
|
+
uid?: string; // optional - The uid of the invitee
|
|
2768
|
+
tradeType?: 'SPOT' | 'FEATURE'; // optional - Trade type
|
|
2769
|
+
tradeStartAt: number; // required - Transaction start time (13-digit timestamp)
|
|
2770
|
+
tradeEndAt: number; // required - Transaction end time (13-digit timestamp)
|
|
2771
|
+
lastId?: number; // optional - The offset ID of the query
|
|
2772
|
+
direction?: 'PRE' | 'NEXT'; // optional - Page direction, default: 'NEXT'
|
|
2773
|
+
pageSize?: number; // optional - Page size >= 1, <= 500, default: 10
|
|
2588
2774
|
|
|
2589
2775
|
================
|
|
2590
2776
|
File: src/types/request/spot-convert.ts
|
|
@@ -2994,6 +3180,36 @@ pageSize: number; // Page size
|
|
|
2994
3180
|
totalNum: number; // Total number of records
|
|
2995
3181
|
totalPage: number; // Total number of pages
|
|
2996
3182
|
items: AffiliateInviteeItem[]; // Array of invited user items
|
|
3183
|
+
⋮----
|
|
3184
|
+
export interface AffiliateTransactionItem {
|
|
3185
|
+
uid: string; // The uid of the invitee
|
|
3186
|
+
tradeTime: number; // Trade time (13-digit timestamp)
|
|
3187
|
+
tradeType: 'SPOT' | 'FEATURE'; // Trade type
|
|
3188
|
+
tradeCurrency: string; // Trade currency
|
|
3189
|
+
tradeAmount: string; // Trade amount
|
|
3190
|
+
tradeAmountU: string; // Trade amount transfer to U(USDT or usdt)
|
|
3191
|
+
feeU: string; // Fee transfer to U(USDT or usdt)
|
|
3192
|
+
commission: string; // Trade commission
|
|
3193
|
+
currency: 'USDT' | 'USDC'; // Transaction volume or amount converted to U
|
|
3194
|
+
}
|
|
3195
|
+
⋮----
|
|
3196
|
+
uid: string; // The uid of the invitee
|
|
3197
|
+
tradeTime: number; // Trade time (13-digit timestamp)
|
|
3198
|
+
tradeType: 'SPOT' | 'FEATURE'; // Trade type
|
|
3199
|
+
tradeCurrency: string; // Trade currency
|
|
3200
|
+
tradeAmount: string; // Trade amount
|
|
3201
|
+
tradeAmountU: string; // Trade amount transfer to U(USDT or usdt)
|
|
3202
|
+
feeU: string; // Fee transfer to U(USDT or usdt)
|
|
3203
|
+
commission: string; // Trade commission
|
|
3204
|
+
currency: 'USDT' | 'USDC'; // Transaction volume or amount converted to U
|
|
3205
|
+
⋮----
|
|
3206
|
+
export interface AffiliateTransaction {
|
|
3207
|
+
items: AffiliateTransactionItem[]; // Array of transaction items
|
|
3208
|
+
lastId: string; // The offset ID for pagination
|
|
3209
|
+
}
|
|
3210
|
+
⋮----
|
|
3211
|
+
items: AffiliateTransactionItem[]; // Array of transaction items
|
|
3212
|
+
lastId: string; // The offset ID for pagination
|
|
2997
3213
|
|
|
2998
3214
|
================
|
|
2999
3215
|
File: src/types/response/spot-convert.ts
|
|
@@ -3459,1105 +3675,1105 @@ File: tsconfig.json
|
|
|
3459
3675
|
}
|
|
3460
3676
|
|
|
3461
3677
|
================
|
|
3462
|
-
File: src/
|
|
3678
|
+
File: src/types/request/spot-account.ts
|
|
3463
3679
|
================
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
WebsocketClientOptions,
|
|
3469
|
-
WSClientConfigurableOptions,
|
|
3470
|
-
} from '../types/websockets/client.js';
|
|
3471
|
-
import { WsOperation } from '../types/websockets/requests.js';
|
|
3472
|
-
import { WS_LOGGER_CATEGORY } from '../WebsocketClient.js';
|
|
3473
|
-
import { checkWebCryptoAPISupported } from './webCryptoAPI.js';
|
|
3474
|
-
import { DefaultLogger } from './websocket/logger.js';
|
|
3475
|
-
import {
|
|
3476
|
-
isMessageEvent,
|
|
3477
|
-
MessageEventLike,
|
|
3478
|
-
safeTerminateWs,
|
|
3479
|
-
WsTopicRequest,
|
|
3480
|
-
WsTopicRequestOrStringTopic,
|
|
3481
|
-
} from './websocket/websocket-util.js';
|
|
3482
|
-
import { WsStore } from './websocket/WsStore.js';
|
|
3483
|
-
import {
|
|
3484
|
-
WSConnectedResult,
|
|
3485
|
-
WsConnectionStateEnum,
|
|
3486
|
-
} from './websocket/WsStore.types.js';
|
|
3680
|
+
export interface GetBalancesRequest {
|
|
3681
|
+
currency?: string;
|
|
3682
|
+
type?: 'main' | 'trade';
|
|
3683
|
+
}
|
|
3487
3684
|
⋮----
|
|
3488
|
-
interface
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
authenticated: (event: { wsKey: WsKey; event: any }) => void;
|
|
3685
|
+
export interface GetSpotTransactionsRequest {
|
|
3686
|
+
currency?: string;
|
|
3687
|
+
direction?: 'in' | 'out';
|
|
3688
|
+
bizType?:
|
|
3689
|
+
| 'DEPOSIT'
|
|
3690
|
+
| 'WITHDRAW'
|
|
3691
|
+
| 'TRANSFER'
|
|
3692
|
+
| 'SUB_TRANSFER'
|
|
3693
|
+
| 'TRADE_EXCHANGE'
|
|
3694
|
+
| 'MARGIN_EXCHANGE'
|
|
3695
|
+
| 'KUCOIN_BONUS'
|
|
3696
|
+
| 'BROKER_TRANSFER'
|
|
3697
|
+
| 'REBATE';
|
|
3698
|
+
startAt?: number;
|
|
3699
|
+
endAt?: number;
|
|
3700
|
+
currentPage?: number;
|
|
3701
|
+
pageSize?: number;
|
|
3506
3702
|
}
|
|
3507
3703
|
⋮----
|
|
3508
|
-
|
|
3704
|
+
export interface AccountHFTransactionsRequest {
|
|
3705
|
+
currency?: string;
|
|
3706
|
+
direction?: 'in' | 'out';
|
|
3707
|
+
bizType?:
|
|
3708
|
+
| 'TRANSFER'
|
|
3709
|
+
| 'TRADE_EXCHANGE'
|
|
3710
|
+
| 'RETURNED_FEES'
|
|
3711
|
+
| 'DEDUCTION_FEES'
|
|
3712
|
+
| 'OTHER';
|
|
3713
|
+
lastId?: number;
|
|
3714
|
+
limit?: number;
|
|
3715
|
+
startAt?: number;
|
|
3716
|
+
endAt?: number;
|
|
3717
|
+
}
|
|
3509
3718
|
⋮----
|
|
3510
|
-
|
|
3719
|
+
export interface AccountHFMarginTransactionsRequest {
|
|
3720
|
+
currency?: string;
|
|
3721
|
+
direction?: 'in' | 'out';
|
|
3722
|
+
bizType?:
|
|
3723
|
+
| 'TRANSFER'
|
|
3724
|
+
| 'MARGIN_EXCHANGE'
|
|
3725
|
+
| 'ISOLATED_EXCHANGE'
|
|
3726
|
+
| 'LIQUIDATION'
|
|
3727
|
+
| 'ASSERT_RETURN';
|
|
3728
|
+
lastId?: number;
|
|
3729
|
+
limit?: number;
|
|
3730
|
+
startAt?: number;
|
|
3731
|
+
endAt?: number;
|
|
3732
|
+
}
|
|
3511
3733
|
⋮----
|
|
3512
|
-
|
|
3734
|
+
export interface CreateSubAccountRequest {
|
|
3735
|
+
password: string;
|
|
3736
|
+
remarks?: string;
|
|
3737
|
+
subName: string;
|
|
3738
|
+
access: string;
|
|
3739
|
+
}
|
|
3513
3740
|
⋮----
|
|
3514
|
-
|
|
3741
|
+
export interface CreateSubAccountAPIRequest {
|
|
3742
|
+
subName: string;
|
|
3743
|
+
passphrase: string;
|
|
3744
|
+
remark: string;
|
|
3745
|
+
permission?: string;
|
|
3746
|
+
ipWhitelist?: string;
|
|
3747
|
+
expire?: string;
|
|
3748
|
+
}
|
|
3515
3749
|
⋮----
|
|
3516
|
-
|
|
3750
|
+
export interface UpdateSubAccountAPIRequest {
|
|
3751
|
+
subName: string;
|
|
3752
|
+
apiKey: string;
|
|
3753
|
+
passphrase: string;
|
|
3754
|
+
permission?: string;
|
|
3755
|
+
ipWhitelist?: string;
|
|
3756
|
+
expire?: string;
|
|
3757
|
+
}
|
|
3517
3758
|
⋮----
|
|
3518
|
-
|
|
3759
|
+
export interface DeleteSubAccountAPIRequest {
|
|
3760
|
+
apiKey: string;
|
|
3761
|
+
passphrase: string;
|
|
3762
|
+
subName: string;
|
|
3763
|
+
}
|
|
3764
|
+
|
|
3765
|
+
================
|
|
3766
|
+
File: src/types/request/spot-funding.ts
|
|
3767
|
+
================
|
|
3768
|
+
/**
|
|
3769
|
+
*
|
|
3770
|
+
***********
|
|
3771
|
+
* Funding
|
|
3772
|
+
***********
|
|
3773
|
+
*
|
|
3774
|
+
*/
|
|
3519
3775
|
⋮----
|
|
3520
|
-
|
|
3776
|
+
export interface CreateDepositAddressV3Request {
|
|
3777
|
+
currency: string;
|
|
3778
|
+
chain?: string;
|
|
3779
|
+
to?: 'main' | 'trade';
|
|
3780
|
+
amount?: string;
|
|
3781
|
+
}
|
|
3521
3782
|
⋮----
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
eventType:
|
|
3526
|
-
| 'response'
|
|
3527
|
-
| 'update'
|
|
3528
|
-
| 'exception'
|
|
3529
|
-
| 'authenticated'
|
|
3530
|
-
| 'connectionReady'; // tied to "requireConnectionReadyConfirmation"
|
|
3531
|
-
event: TEvent;
|
|
3783
|
+
export interface GetMarginBalanceRequest {
|
|
3784
|
+
quoteCurrency?: string;
|
|
3785
|
+
queryType?: 'MARGIN' | 'MARGIN_V2' | 'ALL';
|
|
3532
3786
|
}
|
|
3533
3787
|
⋮----
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
on<U extends keyof WSClientEventMap<TWSKey>>(
|
|
3539
|
-
event: U,
|
|
3540
|
-
listener: WSClientEventMap<TWSKey>[U],
|
|
3541
|
-
): this;
|
|
3542
|
-
|
|
3543
|
-
emit<U extends keyof WSClientEventMap<TWSKey>>(
|
|
3544
|
-
event: U,
|
|
3545
|
-
...args: Parameters<WSClientEventMap<TWSKey>[U]>
|
|
3546
|
-
): boolean;
|
|
3788
|
+
export interface GetIsolatedMarginBalanceRequest {
|
|
3789
|
+
symbol?: string;
|
|
3790
|
+
quoteCurrency?: string;
|
|
3791
|
+
queryType?: 'ISOLATED' | 'ISOLATED_V2' | 'ALL';
|
|
3547
3792
|
}
|
|
3548
3793
|
⋮----
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3794
|
+
/**
|
|
3795
|
+
*
|
|
3796
|
+
* Deposit
|
|
3797
|
+
*
|
|
3798
|
+
*/
|
|
3553
3799
|
⋮----
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3800
|
+
export interface GetDepositsRequest {
|
|
3801
|
+
currency?: string;
|
|
3802
|
+
startAt?: number;
|
|
3803
|
+
endAt?: number;
|
|
3804
|
+
status?: 'PROCESSING' | 'SUCCESS' | 'FAILURE';
|
|
3805
|
+
currentPage?: number;
|
|
3806
|
+
pageSize?: number;
|
|
3807
|
+
}
|
|
3558
3808
|
⋮----
|
|
3559
3809
|
/**
|
|
3560
|
-
* Users can conveniently pass topics as strings or objects (object has topic name + optional params).
|
|
3561
3810
|
*
|
|
3562
|
-
*
|
|
3811
|
+
* Withdrawals
|
|
3812
|
+
*
|
|
3563
3813
|
*/
|
|
3564
|
-
function getNormalisedTopicRequests(
|
|
3565
|
-
wsTopicRequests: WsTopicRequestOrStringTopic<string>[],
|
|
3566
|
-
): WsTopicRequest<string>[]
|
|
3567
|
-
⋮----
|
|
3568
|
-
// passed as string, convert to object
|
|
3569
3814
|
⋮----
|
|
3570
|
-
|
|
3815
|
+
export interface GetWithdrawalsRequest {
|
|
3816
|
+
currency?: string;
|
|
3817
|
+
status?: 'PROCESSING' | 'WALLET_PROCESSING' | 'SUCCESS' | 'FAILURE';
|
|
3818
|
+
startAt?: number;
|
|
3819
|
+
endAt?: number;
|
|
3820
|
+
currentPage?: number;
|
|
3821
|
+
pageSize?: number;
|
|
3822
|
+
}
|
|
3571
3823
|
⋮----
|
|
3572
|
-
|
|
3824
|
+
export interface ApplyWithdrawRequest {
|
|
3825
|
+
currency: string;
|
|
3826
|
+
address: string;
|
|
3827
|
+
amount: number;
|
|
3828
|
+
memo?: string;
|
|
3829
|
+
isInner?: boolean;
|
|
3830
|
+
remark?: string;
|
|
3831
|
+
chain?: string;
|
|
3832
|
+
feeDeductType?: 'INTERNAL' | 'EXTERNAL';
|
|
3833
|
+
}
|
|
3573
3834
|
⋮----
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3835
|
+
export interface SubmitWithdrawV3Request {
|
|
3836
|
+
currency: string;
|
|
3837
|
+
toAddress: string;
|
|
3838
|
+
amount: number;
|
|
3839
|
+
memo?: string;
|
|
3840
|
+
isInner?: boolean;
|
|
3841
|
+
remark?: string;
|
|
3842
|
+
chain?: string;
|
|
3843
|
+
feeDeductType?: 'INTERNAL' | 'EXTERNAL';
|
|
3844
|
+
withdrawType: 'ADDRESS' | 'UID' | 'MAIL' | 'PHONE';
|
|
3845
|
+
}
|
|
3577
3846
|
⋮----
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3847
|
+
/**
|
|
3848
|
+
*
|
|
3849
|
+
* Transfer
|
|
3850
|
+
*
|
|
3851
|
+
*/
|
|
3582
3852
|
⋮----
|
|
3583
|
-
|
|
3853
|
+
export interface GetTransferableRequest {
|
|
3854
|
+
currency: string;
|
|
3855
|
+
type:
|
|
3856
|
+
| 'MAIN'
|
|
3857
|
+
| 'TRADE'
|
|
3858
|
+
| 'TRADE_HF'
|
|
3859
|
+
| 'MARGIN'
|
|
3860
|
+
| 'ISOLATED'
|
|
3861
|
+
| 'OPTION'
|
|
3862
|
+
| 'MARGIN_V2'
|
|
3863
|
+
| 'ISOLATED_V2';
|
|
3864
|
+
tag?: string;
|
|
3865
|
+
}
|
|
3584
3866
|
⋮----
|
|
3585
|
-
|
|
3867
|
+
export interface FlexTransferRequest {
|
|
3868
|
+
clientOid: string;
|
|
3869
|
+
currency?: string;
|
|
3870
|
+
amount: string;
|
|
3871
|
+
fromUserId?: string;
|
|
3872
|
+
fromAccountType:
|
|
3873
|
+
| 'MAIN'
|
|
3874
|
+
| 'TRADE'
|
|
3875
|
+
| 'CONTRACT'
|
|
3876
|
+
| 'MARGIN'
|
|
3877
|
+
| 'ISOLATED'
|
|
3878
|
+
| 'TRADE_HF'
|
|
3879
|
+
| 'MARGIN_V2'
|
|
3880
|
+
| 'ISOLATED_V2'
|
|
3881
|
+
| 'OPTION';
|
|
3882
|
+
fromAccountTag?: string;
|
|
3883
|
+
type: 'INTERNAL' | 'PARENT_TO_SUB' | 'SUB_TO_PARENT';
|
|
3884
|
+
toUserId?: string;
|
|
3885
|
+
toAccountType:
|
|
3886
|
+
| 'MAIN'
|
|
3887
|
+
| 'TRADE'
|
|
3888
|
+
| 'CONTRACT'
|
|
3889
|
+
| 'MARGIN'
|
|
3890
|
+
| 'ISOLATED'
|
|
3891
|
+
| 'TRADE_HF'
|
|
3892
|
+
| 'MARGIN_V2'
|
|
3893
|
+
| 'ISOLATED_V2'
|
|
3894
|
+
| 'OPTION';
|
|
3895
|
+
toAccountTag?: string;
|
|
3896
|
+
}
|
|
3586
3897
|
⋮----
|
|
3587
|
-
|
|
3898
|
+
export interface submitTransferMasterSubRequest {
|
|
3899
|
+
clientOid: string;
|
|
3900
|
+
currency: string;
|
|
3901
|
+
amount: string;
|
|
3902
|
+
direction: 'OUT' | 'IN';
|
|
3903
|
+
accountType?:
|
|
3904
|
+
| 'MAIN'
|
|
3905
|
+
| 'TRADE'
|
|
3906
|
+
| 'TRADE_HF'
|
|
3907
|
+
| 'MARGIN'
|
|
3908
|
+
| 'CONTRACT'
|
|
3909
|
+
| 'OPTION';
|
|
3910
|
+
subAccountType?:
|
|
3911
|
+
| 'MAIN'
|
|
3912
|
+
| 'TRADE'
|
|
3913
|
+
| 'TRADE_HF'
|
|
3914
|
+
| 'MARGIN'
|
|
3915
|
+
| 'CONTRACT'
|
|
3916
|
+
| 'OPTION';
|
|
3917
|
+
subUserId: string;
|
|
3918
|
+
}
|
|
3588
3919
|
⋮----
|
|
3589
|
-
|
|
3920
|
+
export interface InnerTransferRequest {
|
|
3921
|
+
clientOid: string;
|
|
3922
|
+
currency: string;
|
|
3923
|
+
from:
|
|
3924
|
+
| 'main'
|
|
3925
|
+
| 'trade'
|
|
3926
|
+
| 'trade_hf'
|
|
3927
|
+
| 'margin'
|
|
3928
|
+
| 'isolated'
|
|
3929
|
+
| 'margin_v2'
|
|
3930
|
+
| 'isolated_v2'
|
|
3931
|
+
| 'contract'
|
|
3932
|
+
| 'option';
|
|
3933
|
+
to:
|
|
3934
|
+
| 'main'
|
|
3935
|
+
| 'trade'
|
|
3936
|
+
| 'trade_hf'
|
|
3937
|
+
| 'margin'
|
|
3938
|
+
| 'isolated'
|
|
3939
|
+
| 'margin_v2'
|
|
3940
|
+
| 'isolated_v2'
|
|
3941
|
+
| 'contract'
|
|
3942
|
+
| 'option';
|
|
3943
|
+
amount: string;
|
|
3944
|
+
fromTag?: string;
|
|
3945
|
+
toTag?: string;
|
|
3946
|
+
}
|
|
3947
|
+
|
|
3948
|
+
================
|
|
3949
|
+
File: src/types/response/spot-account.ts
|
|
3950
|
+
================
|
|
3951
|
+
export interface SpotAccountSummary {
|
|
3952
|
+
level: number;
|
|
3953
|
+
subQuantity: number;
|
|
3954
|
+
spotSubQuantity: number;
|
|
3955
|
+
marginSubQuantity: number;
|
|
3956
|
+
futuresSubQuantity: number;
|
|
3957
|
+
optionSubQuantity: number;
|
|
3958
|
+
maxSubQuantity: number;
|
|
3959
|
+
maxDefaultSubQuantity: number;
|
|
3960
|
+
maxSpotSubQuantity: number;
|
|
3961
|
+
maxMarginSubQuantity: number;
|
|
3962
|
+
maxFuturesSubQuantity: number;
|
|
3963
|
+
maxOptionSubQuantity: number;
|
|
3964
|
+
}
|
|
3590
3965
|
⋮----
|
|
3591
|
-
|
|
3966
|
+
export interface Balances {
|
|
3967
|
+
id: string;
|
|
3968
|
+
currency: string;
|
|
3969
|
+
type: 'main' | 'trade';
|
|
3970
|
+
balance: string;
|
|
3971
|
+
available: string;
|
|
3972
|
+
holds: string;
|
|
3973
|
+
}
|
|
3592
3974
|
⋮----
|
|
3593
|
-
|
|
3975
|
+
export interface Account {
|
|
3976
|
+
currency: string;
|
|
3977
|
+
balance: string;
|
|
3978
|
+
available: string;
|
|
3979
|
+
holds: string;
|
|
3980
|
+
}
|
|
3594
3981
|
⋮----
|
|
3595
|
-
|
|
3982
|
+
export interface SpotAccountTransaction {
|
|
3983
|
+
id: string;
|
|
3984
|
+
currency: string;
|
|
3985
|
+
amount: string;
|
|
3986
|
+
fee: string;
|
|
3987
|
+
tax: string;
|
|
3988
|
+
balance: string;
|
|
3989
|
+
accountType: string; // 'TRADE_HF'
|
|
3990
|
+
bizType: string;
|
|
3991
|
+
direction: 'out' | 'in';
|
|
3992
|
+
createdAt: string;
|
|
3993
|
+
context: string;
|
|
3994
|
+
}
|
|
3596
3995
|
⋮----
|
|
3597
|
-
|
|
3996
|
+
accountType: string; // 'TRADE_HF'
|
|
3598
3997
|
⋮----
|
|
3599
|
-
|
|
3998
|
+
export interface SpotAccountTransactions {
|
|
3999
|
+
currentPage: number;
|
|
4000
|
+
pageSize: number;
|
|
4001
|
+
totalNum: number;
|
|
4002
|
+
totalPage: number;
|
|
4003
|
+
items: SpotAccountTransaction[];
|
|
4004
|
+
}
|
|
3600
4005
|
⋮----
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
4006
|
+
export interface AccountHFMarginTransactions {
|
|
4007
|
+
id: string;
|
|
4008
|
+
currency: string;
|
|
4009
|
+
amount: string;
|
|
4010
|
+
fee: string;
|
|
4011
|
+
balance: string;
|
|
4012
|
+
accountType: 'MARGIN_V2' | 'ISOLATED_V2';
|
|
4013
|
+
bizType:
|
|
4014
|
+
| 'TRANSFER'
|
|
4015
|
+
| 'MARGIN_EXCHANGE'
|
|
4016
|
+
| 'ISOLATED_EXCHANGE'
|
|
4017
|
+
| 'LIQUIDATION'
|
|
4018
|
+
| 'ASSERT_RETURN';
|
|
4019
|
+
direction: 'out' | 'in';
|
|
4020
|
+
createdAt: string;
|
|
4021
|
+
tax: string;
|
|
4022
|
+
context: string;
|
|
4023
|
+
}
|
|
3607
4024
|
⋮----
|
|
3608
4025
|
/**
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
wsKey: TWSKey,
|
|
3614
|
-
operation: WsOperation,
|
|
3615
|
-
): Promise<string[]>;
|
|
4026
|
+
*
|
|
4027
|
+
* Sub-Account
|
|
4028
|
+
*
|
|
4029
|
+
*/
|
|
3616
4030
|
⋮----
|
|
3617
|
-
|
|
4031
|
+
export interface SubAccountInfo {
|
|
4032
|
+
userId: string;
|
|
4033
|
+
uid: number;
|
|
4034
|
+
subName: string;
|
|
4035
|
+
status: number;
|
|
4036
|
+
type: number;
|
|
4037
|
+
access: string;
|
|
4038
|
+
createdAt: number;
|
|
4039
|
+
remarks: string;
|
|
4040
|
+
tradeTypes: string[];
|
|
4041
|
+
openedTradeTypes: string[];
|
|
4042
|
+
hostedStatus: null | string;
|
|
4043
|
+
}
|
|
3618
4044
|
⋮----
|
|
3619
|
-
|
|
4045
|
+
export interface SubAccountsV2 {
|
|
4046
|
+
currentPage: number;
|
|
4047
|
+
pageSize: number;
|
|
4048
|
+
totalNum: number;
|
|
4049
|
+
totalPage: number;
|
|
4050
|
+
items: SubAccountInfo[];
|
|
4051
|
+
}
|
|
3620
4052
|
⋮----
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
4053
|
+
export interface SubAccountItem {
|
|
4054
|
+
userId: string;
|
|
4055
|
+
uid: number;
|
|
4056
|
+
subName: string;
|
|
4057
|
+
status: number;
|
|
4058
|
+
type: number;
|
|
4059
|
+
access: string;
|
|
4060
|
+
createdAt: number;
|
|
4061
|
+
remarks: string;
|
|
4062
|
+
tradeTypes: string[];
|
|
4063
|
+
openedTradeTypes: string[];
|
|
4064
|
+
hostedStatus: null | string;
|
|
4065
|
+
}
|
|
3624
4066
|
⋮----
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
4067
|
+
export interface CreateSubAccount {
|
|
4068
|
+
currentPage: number;
|
|
4069
|
+
pageSize: number;
|
|
4070
|
+
totalNum: number;
|
|
4071
|
+
totalPage: number;
|
|
4072
|
+
items: SubAccountItem[];
|
|
4073
|
+
}
|
|
3632
4074
|
⋮----
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
4075
|
+
export interface SubAccountBalance {
|
|
4076
|
+
currency: string;
|
|
4077
|
+
balance: string;
|
|
4078
|
+
available: string;
|
|
4079
|
+
holds: string;
|
|
4080
|
+
baseCurrency: string;
|
|
4081
|
+
baseCurrencyPrice: string;
|
|
4082
|
+
baseAmount: string;
|
|
4083
|
+
}
|
|
3637
4084
|
⋮----
|
|
3638
|
-
|
|
4085
|
+
// deprecated
|
|
4086
|
+
export interface SubAccountBalances {
|
|
4087
|
+
subUserId: string;
|
|
4088
|
+
subName: string;
|
|
4089
|
+
mainAccounts: SubAccountBalance[];
|
|
4090
|
+
tradeAccounts: SubAccountBalance[];
|
|
4091
|
+
marginAccounts: SubAccountBalance[];
|
|
4092
|
+
}
|
|
3639
4093
|
⋮----
|
|
3640
|
-
|
|
3641
|
-
|
|
4094
|
+
export interface SubAccountBalancesV2 {
|
|
4095
|
+
currentPage: number;
|
|
4096
|
+
pageSize: number;
|
|
4097
|
+
totalNum: number;
|
|
4098
|
+
totalPage: number;
|
|
4099
|
+
items: {
|
|
4100
|
+
subUserId: string;
|
|
4101
|
+
subName: string;
|
|
4102
|
+
mainAccounts: SubAccountBalance[];
|
|
4103
|
+
}[];
|
|
4104
|
+
}
|
|
4105
|
+
export interface SubAccountV2Details {
|
|
4106
|
+
currency?: string;
|
|
4107
|
+
balance?: string;
|
|
4108
|
+
available?: string;
|
|
4109
|
+
holds?: string;
|
|
4110
|
+
baseCurrency?: string;
|
|
4111
|
+
baseCurrencyPrice?: string;
|
|
4112
|
+
baseAmount?: string;
|
|
4113
|
+
tag?: string;
|
|
4114
|
+
}
|
|
3642
4115
|
⋮----
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
4116
|
+
export interface SubAccountBalanceItemV2 {
|
|
4117
|
+
subUserId: string;
|
|
4118
|
+
subName: string;
|
|
4119
|
+
mainAccounts: SubAccountV2Details[]; // Funding Account
|
|
4120
|
+
tradeAccounts: SubAccountV2Details[]; // Spot Account
|
|
4121
|
+
marginAccounts: SubAccountV2Details[]; // Margin Account
|
|
4122
|
+
tradeHFAccounts: string[]; // Deprecated, only for old users
|
|
4123
|
+
}
|
|
3648
4124
|
⋮----
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
): Promise<unknown>;
|
|
4125
|
+
mainAccounts: SubAccountV2Details[]; // Funding Account
|
|
4126
|
+
tradeAccounts: SubAccountV2Details[]; // Spot Account
|
|
4127
|
+
marginAccounts: SubAccountV2Details[]; // Margin Account
|
|
4128
|
+
tradeHFAccounts: string[]; // Deprecated, only for old users
|
|
3654
4129
|
⋮----
|
|
3655
4130
|
/**
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
* - Topics are automatically resubscribed to, if something happens to the connection, unless you call unsubsribeTopicsForWsKey(topics, key).
|
|
3662
|
-
*
|
|
3663
|
-
* @param wsTopicRequests array of topics to subscribe to
|
|
3664
|
-
* @param wsKey ws key referring to the ws connection these topics should be subscribed on
|
|
3665
|
-
*/
|
|
3666
|
-
public subscribeTopicsForWsKey(
|
|
3667
|
-
wsTopicRequests: WsTopicRequestOrStringTopic<WSTopic>[],
|
|
3668
|
-
wsKey: TWSKey,
|
|
3669
|
-
)
|
|
4131
|
+
*
|
|
4132
|
+
* Sub-Account API
|
|
4133
|
+
*
|
|
4134
|
+
*
|
|
4135
|
+
*/
|
|
3670
4136
|
⋮----
|
|
3671
|
-
|
|
4137
|
+
export interface SubAccountAPIInfo {
|
|
4138
|
+
subName: string;
|
|
4139
|
+
remark: string;
|
|
4140
|
+
apiKey: string;
|
|
4141
|
+
apiVersion: number;
|
|
4142
|
+
permission: string;
|
|
4143
|
+
ipWhitelist: string;
|
|
4144
|
+
createdAt: number;
|
|
4145
|
+
uid: number;
|
|
4146
|
+
isMaster: boolean;
|
|
4147
|
+
}
|
|
3672
4148
|
⋮----
|
|
3673
|
-
|
|
4149
|
+
export interface CreateSubAPI {
|
|
4150
|
+
subName: string;
|
|
4151
|
+
remark: string;
|
|
4152
|
+
apiKey: string;
|
|
4153
|
+
apiSecret: string;
|
|
4154
|
+
apiVersion: number;
|
|
4155
|
+
passphrase: string;
|
|
4156
|
+
permission: string;
|
|
4157
|
+
createdAt: number;
|
|
4158
|
+
}
|
|
3674
4159
|
⋮----
|
|
3675
|
-
|
|
4160
|
+
export interface UpdateSubAPI {
|
|
4161
|
+
apiKey: string;
|
|
4162
|
+
ipWhitelist: string;
|
|
4163
|
+
permission: string;
|
|
4164
|
+
subName: string;
|
|
4165
|
+
}
|
|
4166
|
+
⋮----
|
|
4167
|
+
export interface DeleteSubAccountAPI {
|
|
4168
|
+
subName: string;
|
|
4169
|
+
apiKey: string;
|
|
4170
|
+
}
|
|
4171
|
+
|
|
4172
|
+
================
|
|
4173
|
+
File: src/BrokerClient.ts
|
|
4174
|
+
================
|
|
4175
|
+
import { BaseRestClient } from './lib/BaseRestClient.js';
|
|
4176
|
+
import { REST_CLIENT_TYPE_ENUM, RestClientType } from './lib/requestUtils.js';
|
|
4177
|
+
import {
|
|
4178
|
+
BrokerTransferRequest,
|
|
4179
|
+
CreateBrokerSubAccountApiRequest,
|
|
4180
|
+
DeleteBrokerSubAccountApiRequest,
|
|
4181
|
+
GetBrokerDepositListRequest,
|
|
4182
|
+
GetBrokerInfoRequest,
|
|
4183
|
+
GetBrokerSubAccountApisRequest,
|
|
4184
|
+
GetBrokerSubAccountsRequest,
|
|
4185
|
+
UpdateBrokerSubAccountApiRequest,
|
|
4186
|
+
} from './types/request/broker.types.js';
|
|
4187
|
+
import {
|
|
4188
|
+
BrokerDepositRecord,
|
|
4189
|
+
BrokerInfo,
|
|
4190
|
+
BrokerSubAccountApi,
|
|
4191
|
+
BrokerTransferHistory,
|
|
4192
|
+
BrokerWithdrawalRecord,
|
|
4193
|
+
CreateBrokerSubAccountApiResponse,
|
|
4194
|
+
CreateBrokerSubAccountResponse,
|
|
4195
|
+
GetBrokerSubAccountsResponse,
|
|
4196
|
+
} from './types/response/broker.types.js';
|
|
4197
|
+
import { APISuccessResponse } from './types/response/shared.types.js';
|
|
3676
4198
|
⋮----
|
|
3677
4199
|
/**
|
|
3678
|
-
|
|
3679
|
-
|
|
4200
|
+
*
|
|
4201
|
+
*/
|
|
4202
|
+
export class BrokerClient extends BaseRestClient
|
|
3680
4203
|
⋮----
|
|
3681
|
-
|
|
4204
|
+
getClientType(): RestClientType
|
|
3682
4205
|
⋮----
|
|
3683
4206
|
/**
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
protected unsubscribeTopicsForWsKey(
|
|
3692
|
-
wsTopicRequests: WsTopicRequestOrStringTopic<string>[],
|
|
3693
|
-
wsKey: TWSKey,
|
|
3694
|
-
)
|
|
3695
|
-
⋮----
|
|
3696
|
-
// Store topics, so future automation (post-auth, post-reconnect) has everything needed to resubscribe automatically
|
|
3697
|
-
⋮----
|
|
3698
|
-
// If not connected, don't need to do anything.
|
|
3699
|
-
// Removing the topic from the store is enough to stop it from being resubscribed to on reconnect.
|
|
3700
|
-
⋮----
|
|
3701
|
-
// We're connected. Check if auth is needed and if already authenticated
|
|
4207
|
+
* Get Broker Info
|
|
4208
|
+
*
|
|
4209
|
+
* This endpoint supports querying the basic information of the current Broker
|
|
4210
|
+
*/
|
|
4211
|
+
getBrokerInfo(
|
|
4212
|
+
params: GetBrokerInfoRequest,
|
|
4213
|
+
): Promise<APISuccessResponse<BrokerInfo>>
|
|
3702
4214
|
⋮----
|
|
3703
4215
|
/**
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
4216
|
+
* Add SubAccount
|
|
4217
|
+
*
|
|
4218
|
+
* This endpoint supports Broker users to create sub-accounts.
|
|
4219
|
+
* Note that the account name is unique across the exchange.
|
|
4220
|
+
* It is recommended to add a special identifier to prevent name duplication.
|
|
4221
|
+
*/
|
|
4222
|
+
createSubAccount(params: {
|
|
4223
|
+
accountName: string;
|
|
4224
|
+
}): Promise<APISuccessResponse<CreateBrokerSubAccountResponse>>
|
|
3709
4225
|
⋮----
|
|
3710
4226
|
/**
|
|
3711
|
-
*
|
|
4227
|
+
* Get SubAccount
|
|
4228
|
+
*
|
|
4229
|
+
* This interface supports querying sub-accounts created by Broker.
|
|
4230
|
+
* Returns paginated results with default page size of 20 (max 100).
|
|
3712
4231
|
*/
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
):
|
|
3717
|
-
⋮----
|
|
3718
|
-
/** Get the WsStore that tracks websockets & topics */
|
|
3719
|
-
public getWsStore(): WsStore<TWSKey, WsTopicRequest<string>>
|
|
3720
|
-
⋮----
|
|
3721
|
-
public close(wsKey: TWSKey, force?: boolean)
|
|
3722
|
-
⋮----
|
|
3723
|
-
public closeAll(force?: boolean)
|
|
3724
|
-
⋮----
|
|
3725
|
-
public isConnected(wsKey: TWSKey): boolean
|
|
4232
|
+
getSubAccounts(
|
|
4233
|
+
params: GetBrokerSubAccountsRequest,
|
|
4234
|
+
): Promise<APISuccessResponse<GetBrokerSubAccountsResponse>>
|
|
3726
4235
|
⋮----
|
|
3727
4236
|
/**
|
|
3728
|
-
*
|
|
4237
|
+
* Add SubAccount API
|
|
4238
|
+
*
|
|
4239
|
+
* This interface supports the creation of Broker sub-account APIKEY.
|
|
4240
|
+
* Supports up to 20 IPs in the whitelist.
|
|
4241
|
+
* Only General, Spot, and Futures permissions can be set.
|
|
4242
|
+
* Label must be between 4 and 32 characters.
|
|
3729
4243
|
*/
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
⋮----
|
|
3734
|
-
private parseWsError(context: string, error: any, wsKey: TWSKey)
|
|
3735
|
-
⋮----
|
|
3736
|
-
/** Get a signature, build the auth request and send it */
|
|
3737
|
-
private async sendAuthRequest(wsKey: TWSKey): Promise<void>
|
|
3738
|
-
⋮----
|
|
3739
|
-
private reconnectWithDelay(wsKey: TWSKey, connectionDelayMs: number)
|
|
3740
|
-
⋮----
|
|
3741
|
-
private ping(wsKey: TWSKey)
|
|
3742
|
-
⋮----
|
|
3743
|
-
private clearTimers(wsKey: TWSKey)
|
|
3744
|
-
⋮----
|
|
3745
|
-
// Send a ping at intervals
|
|
3746
|
-
private clearPingTimer(wsKey: TWSKey)
|
|
3747
|
-
⋮----
|
|
3748
|
-
// Expect a pong within a time limit
|
|
3749
|
-
private clearPongTimer(wsKey: TWSKey)
|
|
3750
|
-
⋮----
|
|
3751
|
-
// this.logger.trace(`Cleared pong timeout for "${wsKey}"`);
|
|
3752
|
-
⋮----
|
|
3753
|
-
// this.logger.trace(`No active pong timer for "${wsKey}"`);
|
|
4244
|
+
createSubAccountApi(
|
|
4245
|
+
params: CreateBrokerSubAccountApiRequest,
|
|
4246
|
+
): Promise<APISuccessResponse<CreateBrokerSubAccountApiResponse>>
|
|
3754
4247
|
⋮----
|
|
3755
4248
|
/**
|
|
3756
|
-
*
|
|
4249
|
+
* Get SubAccount API
|
|
3757
4250
|
*
|
|
3758
|
-
*
|
|
4251
|
+
* This interface supports querying the Broker's sub-account APIKEYs.
|
|
4252
|
+
* Can optionally filter by specific apiKey.
|
|
3759
4253
|
*/
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
)
|
|
3764
|
-
⋮----
|
|
3765
|
-
// Automatically splits requests into smaller batches, if needed
|
|
3766
|
-
⋮----
|
|
3767
|
-
`Subscribing to ${topics.length} "${wsKey}" topics in ${subscribeWsMessages.length} batches.`, // Events: "${JSON.stringify(topics)}"
|
|
3768
|
-
⋮----
|
|
3769
|
-
// this.logger.trace(`Sending batch via message: "${wsMessage}"`);
|
|
4254
|
+
getSubAccountApis(
|
|
4255
|
+
params: GetBrokerSubAccountApisRequest,
|
|
4256
|
+
): Promise<APISuccessResponse<BrokerSubAccountApi[]>>
|
|
3770
4257
|
⋮----
|
|
3771
4258
|
/**
|
|
3772
|
-
*
|
|
4259
|
+
* Modify SubAccount API
|
|
3773
4260
|
*
|
|
3774
|
-
*
|
|
4261
|
+
* This interface supports modifying the Broker's sub-account APIKEY.
|
|
4262
|
+
* Supports up to 20 IPs in the whitelist.
|
|
4263
|
+
* Only General, Spot, and Futures permissions can be set.
|
|
4264
|
+
* Label must be between 4 and 32 characters.
|
|
3775
4265
|
*/
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
)
|
|
4266
|
+
updateSubAccountApi(
|
|
4267
|
+
params: UpdateBrokerSubAccountApiRequest,
|
|
4268
|
+
): Promise<APISuccessResponse<BrokerSubAccountApi>>
|
|
3780
4269
|
⋮----
|
|
3781
4270
|
/**
|
|
3782
|
-
*
|
|
4271
|
+
* Delete SubAccount API
|
|
4272
|
+
*
|
|
4273
|
+
* This interface supports deleting Broker's sub-account APIKEY.
|
|
3783
4274
|
*/
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
4275
|
+
deleteSubAccountApi(
|
|
4276
|
+
params: DeleteBrokerSubAccountApiRequest,
|
|
4277
|
+
): Promise<APISuccessResponse<boolean>>
|
|
3787
4278
|
⋮----
|
|
3788
4279
|
/**
|
|
3789
|
-
*
|
|
3790
|
-
* - Some exchanges are ready immediately after the connections open.
|
|
3791
|
-
* - Some exchanges send an event to confirm the connection is ready for us.
|
|
4280
|
+
* Transfer
|
|
3792
4281
|
*
|
|
3793
|
-
* This
|
|
4282
|
+
* This endpoint supports fund transfer between Broker account and Broker sub-accounts.
|
|
4283
|
+
* Please be aware that withdrawal from sub-account is not directly supported.
|
|
4284
|
+
* Broker has to transfer funds from broker sub-account to broker account to initiate the withdrawals.
|
|
4285
|
+
*
|
|
4286
|
+
* Direction:
|
|
4287
|
+
* - OUT: Broker account is transferred to Broker sub-account
|
|
4288
|
+
* - IN: Broker sub-account is transferred to Broker account
|
|
4289
|
+
*
|
|
4290
|
+
* Account Types:
|
|
4291
|
+
* - MAIN: Funding account
|
|
4292
|
+
* - TRADE: Spot trading account
|
|
3794
4293
|
*/
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
// Some websockets require an auth packet to be sent after opening the connection
|
|
3802
|
-
⋮----
|
|
3803
|
-
// Reconnect to topics known before it connected
|
|
3804
|
-
⋮----
|
|
3805
|
-
// Request sub to public topics, if any
|
|
3806
|
-
⋮----
|
|
3807
|
-
// Request sub to private topics, if auth on connect isn't needed
|
|
4294
|
+
submitTransfer(params: BrokerTransferRequest): Promise<
|
|
4295
|
+
APISuccessResponse<{
|
|
4296
|
+
orderId: string;
|
|
4297
|
+
}>
|
|
4298
|
+
> {
|
|
4299
|
+
return this.postPrivate('api/v1/broker/nd/transfer', params);
|
|
3808
4300
|
⋮----
|
|
3809
4301
|
/**
|
|
3810
|
-
*
|
|
4302
|
+
* Get Transfer History
|
|
3811
4303
|
*
|
|
3812
|
-
*
|
|
4304
|
+
* This endpoint supports querying transfer records of the broker itself and its created sub-accounts.
|
|
4305
|
+
*
|
|
4306
|
+
* Account Types:
|
|
4307
|
+
* - MAIN: Funding account
|
|
4308
|
+
* - TRADE: Spot trading account
|
|
4309
|
+
* - CONTRACT: Contract account
|
|
4310
|
+
* - MARGIN: Margin account
|
|
4311
|
+
* - ISOLATED: Isolated margin account
|
|
4312
|
+
*
|
|
4313
|
+
* Status:
|
|
4314
|
+
* - PROCESSING: Processing
|
|
4315
|
+
* - SUCCESS: Successful
|
|
4316
|
+
* - FAILURE: Failed
|
|
3813
4317
|
*/
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
)
|
|
3818
|
-
⋮----
|
|
3819
|
-
private onWsMessage(event: unknown, wsKey: TWSKey, ws: WebSocket)
|
|
3820
|
-
⋮----
|
|
3821
|
-
// any message can clear the pong timer - wouldn't get a message if the ws wasn't working
|
|
3822
|
-
⋮----
|
|
3823
|
-
// console.log(`raw event: `, { data, dataType, emittableEvents });
|
|
3824
|
-
⋮----
|
|
3825
|
-
private onWsClose(event: unknown, wsKey: TWSKey)
|
|
3826
|
-
⋮----
|
|
3827
|
-
// clean up any pending promises for this connection
|
|
3828
|
-
⋮----
|
|
3829
|
-
// clean up any pending promises for this connection
|
|
3830
|
-
⋮----
|
|
3831
|
-
private getWs(wsKey: TWSKey)
|
|
3832
|
-
⋮----
|
|
3833
|
-
private setWsState(wsKey: TWSKey, state: WsConnectionStateEnum)
|
|
4318
|
+
getTransferHistory(params: {
|
|
4319
|
+
orderId: string;
|
|
4320
|
+
}): Promise<APISuccessResponse<BrokerTransferHistory>>
|
|
3834
4321
|
⋮----
|
|
3835
4322
|
/**
|
|
3836
|
-
*
|
|
4323
|
+
* Get Deposit List
|
|
4324
|
+
*
|
|
4325
|
+
* This endpoint can obtain the deposit records of each sub-account under the ND Broker.
|
|
4326
|
+
* Default limit is 1000 records (max 1000).
|
|
4327
|
+
* Results are sorted in descending order by default.
|
|
4328
|
+
*
|
|
4329
|
+
* Status:
|
|
4330
|
+
* - PROCESSING: Processing
|
|
4331
|
+
* - SUCCESS: Successful
|
|
4332
|
+
* - FAILURE: Failed
|
|
3837
4333
|
*/
|
|
3838
|
-
|
|
4334
|
+
getDeposits(
|
|
4335
|
+
params?: GetBrokerDepositListRequest,
|
|
4336
|
+
): Promise<APISuccessResponse<BrokerDepositRecord[]>>
|
|
3839
4337
|
⋮----
|
|
3840
|
-
|
|
4338
|
+
/**
|
|
4339
|
+
* Get Deposit Detail
|
|
4340
|
+
*
|
|
4341
|
+
* This endpoint supports querying the deposit record of sub-accounts created by a Broker
|
|
4342
|
+
* (excluding main account of nd broker).
|
|
4343
|
+
*
|
|
4344
|
+
* Status:
|
|
4345
|
+
* - PROCESSING: Processing
|
|
4346
|
+
* - SUCCESS: Successful
|
|
4347
|
+
* - FAILURE: Failed
|
|
4348
|
+
*/
|
|
4349
|
+
getDeposit(params: {
|
|
4350
|
+
currency: string;
|
|
4351
|
+
hash: string;
|
|
4352
|
+
}): Promise<APISuccessResponse<BrokerDepositRecord>>
|
|
3841
4353
|
⋮----
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
4354
|
+
/**
|
|
4355
|
+
* Get Withdrawal Detail
|
|
4356
|
+
*
|
|
4357
|
+
* This endpoint supports querying the withdrawal records of sub-accounts created by a Broker
|
|
4358
|
+
* (excluding main account of nd broker).
|
|
4359
|
+
*
|
|
4360
|
+
* Status:
|
|
4361
|
+
* - PROCESSING: Processing
|
|
4362
|
+
* - WALLET_PROCESSING: Wallet Processing
|
|
4363
|
+
* - REVIEW: Under Review
|
|
4364
|
+
* - SUCCESS: Successful
|
|
4365
|
+
* - FAILURE: Failed
|
|
4366
|
+
*/
|
|
4367
|
+
getWithdrawal(params: {
|
|
4368
|
+
withdrawalId: string;
|
|
4369
|
+
}): Promise<APISuccessResponse<BrokerWithdrawalRecord>>
|
|
3851
4370
|
⋮----
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
| '
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
4371
|
+
/**
|
|
4372
|
+
* Get Broker Rebate
|
|
4373
|
+
*
|
|
4374
|
+
* This interface supports downloading Broker rebate orders.
|
|
4375
|
+
* Returns a URL to download a CSV file containing the rebate data.
|
|
4376
|
+
* The URL is valid for 1 day.
|
|
4377
|
+
* Maximum interval between begin and end dates is 6 months.
|
|
4378
|
+
*/
|
|
4379
|
+
getBrokerRebate(params: {
|
|
4380
|
+
begin: string;
|
|
4381
|
+
end: string;
|
|
4382
|
+
tradeType: '1' | '2';
|
|
4383
|
+
}): Promise<
|
|
4384
|
+
APISuccessResponse<{
|
|
4385
|
+
url: string;
|
|
4386
|
+
}>
|
|
4387
|
+
> {
|
|
4388
|
+
return this.getPrivate('api/v1/broker/nd/rebase/download', params);
|
|
4389
|
+
|
|
4390
|
+
================
|
|
4391
|
+
File: .eslintrc.cjs
|
|
4392
|
+
================
|
|
4393
|
+
// 'no-unused-vars': ['warn'],
|
|
4394
|
+
|
|
4395
|
+
================
|
|
4396
|
+
File: src/lib/BaseWSClient.ts
|
|
4397
|
+
================
|
|
4398
|
+
import EventEmitter from 'events';
|
|
4399
|
+
import WebSocket from 'isomorphic-ws';
|
|
3870
4400
|
⋮----
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
4401
|
+
import {
|
|
4402
|
+
WebsocketClientOptions,
|
|
4403
|
+
WSClientConfigurableOptions,
|
|
4404
|
+
} from '../types/websockets/client.js';
|
|
4405
|
+
import { WsOperation } from '../types/websockets/requests.js';
|
|
4406
|
+
import { WS_LOGGER_CATEGORY } from '../WebsocketClient.js';
|
|
4407
|
+
import { checkWebCryptoAPISupported } from './webCryptoAPI.js';
|
|
4408
|
+
import { DefaultLogger } from './websocket/logger.js';
|
|
4409
|
+
import {
|
|
4410
|
+
isMessageEvent,
|
|
4411
|
+
MessageEventLike,
|
|
4412
|
+
safeTerminateWs,
|
|
4413
|
+
WsTopicRequest,
|
|
4414
|
+
WsTopicRequestOrStringTopic,
|
|
4415
|
+
} from './websocket/websocket-util.js';
|
|
4416
|
+
import { WsStore } from './websocket/WsStore.js';
|
|
4417
|
+
import {
|
|
4418
|
+
WSConnectedResult,
|
|
4419
|
+
WsConnectionStateEnum,
|
|
4420
|
+
} from './websocket/WsStore.types.js';
|
|
3885
4421
|
⋮----
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
4422
|
+
interface WSClientEventMap<WsKey extends string> {
|
|
4423
|
+
/** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */
|
|
4424
|
+
open: (evt: { wsKey: WsKey; event: any }) => void;
|
|
4425
|
+
/** Reconnecting a dropped connection */
|
|
4426
|
+
reconnect: (evt: { wsKey: WsKey; event: any }) => void;
|
|
4427
|
+
/** Successfully reconnected a connection that dropped */
|
|
4428
|
+
reconnected: (evt: { wsKey: WsKey; event: any }) => void;
|
|
4429
|
+
/** Connection closed */
|
|
4430
|
+
close: (evt: { wsKey: WsKey; event: any }) => void;
|
|
4431
|
+
/** Received reply to websocket command (e.g. after subscribing to topics) */
|
|
4432
|
+
response: (response: any & { wsKey: WsKey }) => void;
|
|
4433
|
+
/** Received data for topic */
|
|
4434
|
+
update: (response: any & { wsKey: WsKey }) => void;
|
|
4435
|
+
/** Exception from ws client OR custom listeners (e.g. if you throw inside your event handler) */
|
|
4436
|
+
exception: (response: any & { wsKey: WsKey }) => void;
|
|
4437
|
+
error: (response: any & { wsKey: WsKey }) => void;
|
|
4438
|
+
/** Confirmation that a connection successfully authenticated */
|
|
4439
|
+
authenticated: (event: { wsKey: WsKey; event: any }) => void;
|
|
3899
4440
|
}
|
|
3900
4441
|
⋮----
|
|
3901
|
-
|
|
3902
|
-
password: string;
|
|
3903
|
-
remarks?: string;
|
|
3904
|
-
subName: string;
|
|
3905
|
-
access: string;
|
|
3906
|
-
}
|
|
4442
|
+
/** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */
|
|
3907
4443
|
⋮----
|
|
3908
|
-
|
|
3909
|
-
subName: string;
|
|
3910
|
-
passphrase: string;
|
|
3911
|
-
remark: string;
|
|
3912
|
-
permission?: string;
|
|
3913
|
-
ipWhitelist?: string;
|
|
3914
|
-
expire?: string;
|
|
3915
|
-
}
|
|
4444
|
+
/** Reconnecting a dropped connection */
|
|
3916
4445
|
⋮----
|
|
3917
|
-
|
|
3918
|
-
subName: string;
|
|
3919
|
-
apiKey: string;
|
|
3920
|
-
passphrase: string;
|
|
3921
|
-
permission?: string;
|
|
3922
|
-
ipWhitelist?: string;
|
|
3923
|
-
expire?: string;
|
|
3924
|
-
}
|
|
4446
|
+
/** Successfully reconnected a connection that dropped */
|
|
3925
4447
|
⋮----
|
|
3926
|
-
|
|
3927
|
-
apiKey: string;
|
|
3928
|
-
passphrase: string;
|
|
3929
|
-
subName: string;
|
|
3930
|
-
}
|
|
3931
|
-
|
|
3932
|
-
================
|
|
3933
|
-
File: src/types/request/spot-funding.ts
|
|
3934
|
-
================
|
|
3935
|
-
/**
|
|
3936
|
-
*
|
|
3937
|
-
***********
|
|
3938
|
-
* Funding
|
|
3939
|
-
***********
|
|
3940
|
-
*
|
|
3941
|
-
*/
|
|
4448
|
+
/** Connection closed */
|
|
3942
4449
|
⋮----
|
|
3943
|
-
|
|
3944
|
-
currency: string;
|
|
3945
|
-
chain?: string;
|
|
3946
|
-
to?: 'main' | 'trade';
|
|
3947
|
-
amount?: string;
|
|
3948
|
-
}
|
|
4450
|
+
/** Received reply to websocket command (e.g. after subscribing to topics) */
|
|
3949
4451
|
⋮----
|
|
3950
|
-
|
|
3951
|
-
quoteCurrency?: string;
|
|
3952
|
-
queryType?: 'MARGIN' | 'MARGIN_V2' | 'ALL';
|
|
3953
|
-
}
|
|
4452
|
+
/** Received data for topic */
|
|
3954
4453
|
⋮----
|
|
3955
|
-
|
|
3956
|
-
symbol?: string;
|
|
3957
|
-
quoteCurrency?: string;
|
|
3958
|
-
queryType?: 'ISOLATED' | 'ISOLATED_V2' | 'ALL';
|
|
3959
|
-
}
|
|
4454
|
+
/** Exception from ws client OR custom listeners (e.g. if you throw inside your event handler) */
|
|
3960
4455
|
⋮----
|
|
3961
|
-
/**
|
|
3962
|
-
*
|
|
3963
|
-
* Deposit
|
|
3964
|
-
*
|
|
3965
|
-
*/
|
|
4456
|
+
/** Confirmation that a connection successfully authenticated */
|
|
3966
4457
|
⋮----
|
|
3967
|
-
export interface
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
4458
|
+
export interface EmittableEvent<TEvent = any> {
|
|
4459
|
+
eventType:
|
|
4460
|
+
| 'response'
|
|
4461
|
+
| 'update'
|
|
4462
|
+
| 'exception'
|
|
4463
|
+
| 'authenticated'
|
|
4464
|
+
| 'connectionReady'; // tied to "requireConnectionReadyConfirmation"
|
|
4465
|
+
event: TEvent;
|
|
3974
4466
|
}
|
|
3975
4467
|
⋮----
|
|
3976
|
-
|
|
3977
|
-
*
|
|
3978
|
-
* Withdrawals
|
|
3979
|
-
*
|
|
3980
|
-
*/
|
|
4468
|
+
| 'connectionReady'; // tied to "requireConnectionReadyConfirmation"
|
|
3981
4469
|
⋮----
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
4470
|
+
// Type safety for on and emit handlers: https://stackoverflow.com/a/61609010/880837
|
|
4471
|
+
export interface BaseWebsocketClient<TWSKey extends string> {
|
|
4472
|
+
on<U extends keyof WSClientEventMap<TWSKey>>(
|
|
4473
|
+
event: U,
|
|
4474
|
+
listener: WSClientEventMap<TWSKey>[U],
|
|
4475
|
+
): this;
|
|
4476
|
+
|
|
4477
|
+
emit<U extends keyof WSClientEventMap<TWSKey>>(
|
|
4478
|
+
event: U,
|
|
4479
|
+
...args: Parameters<WSClientEventMap<TWSKey>[U]>
|
|
4480
|
+
): boolean;
|
|
3989
4481
|
}
|
|
3990
4482
|
⋮----
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
memo?: string;
|
|
3996
|
-
isInner?: boolean;
|
|
3997
|
-
remark?: string;
|
|
3998
|
-
chain?: string;
|
|
3999
|
-
feeDeductType?: 'INTERNAL' | 'EXTERNAL';
|
|
4000
|
-
}
|
|
4483
|
+
on<U extends keyof WSClientEventMap<TWSKey>>(
|
|
4484
|
+
event: U,
|
|
4485
|
+
listener: WSClientEventMap<TWSKey>[U],
|
|
4486
|
+
): this;
|
|
4001
4487
|
⋮----
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
memo?: string;
|
|
4007
|
-
isInner?: boolean;
|
|
4008
|
-
remark?: string;
|
|
4009
|
-
chain?: string;
|
|
4010
|
-
feeDeductType?: 'INTERNAL' | 'EXTERNAL';
|
|
4011
|
-
withdrawType: 'ADDRESS' | 'UID' | 'MAIL' | 'PHONE';
|
|
4012
|
-
}
|
|
4488
|
+
emit<U extends keyof WSClientEventMap<TWSKey>>(
|
|
4489
|
+
event: U,
|
|
4490
|
+
...args: Parameters<WSClientEventMap<TWSKey>[U]>
|
|
4491
|
+
): boolean;
|
|
4013
4492
|
⋮----
|
|
4014
4493
|
/**
|
|
4494
|
+
* Users can conveniently pass topics as strings or objects (object has topic name + optional params).
|
|
4015
4495
|
*
|
|
4016
|
-
*
|
|
4017
|
-
*
|
|
4496
|
+
* This method normalises topics into objects (object has topic name + optional params).
|
|
4018
4497
|
*/
|
|
4498
|
+
function getNormalisedTopicRequests(
|
|
4499
|
+
wsTopicRequests: WsTopicRequestOrStringTopic<string>[],
|
|
4500
|
+
): WsTopicRequest<string>[]
|
|
4019
4501
|
⋮----
|
|
4020
|
-
|
|
4021
|
-
currency: string;
|
|
4022
|
-
type:
|
|
4023
|
-
| 'MAIN'
|
|
4024
|
-
| 'TRADE'
|
|
4025
|
-
| 'TRADE_HF'
|
|
4026
|
-
| 'MARGIN'
|
|
4027
|
-
| 'ISOLATED'
|
|
4028
|
-
| 'OPTION'
|
|
4029
|
-
| 'MARGIN_V2'
|
|
4030
|
-
| 'ISOLATED_V2';
|
|
4031
|
-
tag?: string;
|
|
4032
|
-
}
|
|
4502
|
+
// passed as string, convert to object
|
|
4033
4503
|
⋮----
|
|
4034
|
-
|
|
4035
|
-
clientOid: string;
|
|
4036
|
-
currency?: string;
|
|
4037
|
-
amount: string;
|
|
4038
|
-
fromUserId?: string;
|
|
4039
|
-
fromAccountType:
|
|
4040
|
-
| 'MAIN'
|
|
4041
|
-
| 'TRADE'
|
|
4042
|
-
| 'CONTRACT'
|
|
4043
|
-
| 'MARGIN'
|
|
4044
|
-
| 'ISOLATED'
|
|
4045
|
-
| 'TRADE_HF'
|
|
4046
|
-
| 'MARGIN_V2'
|
|
4047
|
-
| 'ISOLATED_V2'
|
|
4048
|
-
| 'OPTION';
|
|
4049
|
-
fromAccountTag?: string;
|
|
4050
|
-
type: 'INTERNAL' | 'PARENT_TO_SUB' | 'SUB_TO_PARENT';
|
|
4051
|
-
toUserId?: string;
|
|
4052
|
-
toAccountType:
|
|
4053
|
-
| 'MAIN'
|
|
4054
|
-
| 'TRADE'
|
|
4055
|
-
| 'CONTRACT'
|
|
4056
|
-
| 'MARGIN'
|
|
4057
|
-
| 'ISOLATED'
|
|
4058
|
-
| 'TRADE_HF'
|
|
4059
|
-
| 'MARGIN_V2'
|
|
4060
|
-
| 'ISOLATED_V2'
|
|
4061
|
-
| 'OPTION';
|
|
4062
|
-
toAccountTag?: string;
|
|
4063
|
-
}
|
|
4504
|
+
// already a normalised object, thanks to user
|
|
4064
4505
|
⋮----
|
|
4065
|
-
|
|
4066
|
-
clientOid: string;
|
|
4067
|
-
currency: string;
|
|
4068
|
-
amount: string;
|
|
4069
|
-
direction: 'OUT' | 'IN';
|
|
4070
|
-
accountType?:
|
|
4071
|
-
| 'MAIN'
|
|
4072
|
-
| 'TRADE'
|
|
4073
|
-
| 'TRADE_HF'
|
|
4074
|
-
| 'MARGIN'
|
|
4075
|
-
| 'CONTRACT'
|
|
4076
|
-
| 'OPTION';
|
|
4077
|
-
subAccountType?:
|
|
4078
|
-
| 'MAIN'
|
|
4079
|
-
| 'TRADE'
|
|
4080
|
-
| 'TRADE_HF'
|
|
4081
|
-
| 'MARGIN'
|
|
4082
|
-
| 'CONTRACT'
|
|
4083
|
-
| 'OPTION';
|
|
4084
|
-
subUserId: string;
|
|
4085
|
-
}
|
|
4506
|
+
type WSTopic = string;
|
|
4086
4507
|
⋮----
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
from:
|
|
4091
|
-
| 'main'
|
|
4092
|
-
| 'trade'
|
|
4093
|
-
| 'trade_hf'
|
|
4094
|
-
| 'margin'
|
|
4095
|
-
| 'isolated'
|
|
4096
|
-
| 'margin_v2'
|
|
4097
|
-
| 'isolated_v2'
|
|
4098
|
-
| 'contract'
|
|
4099
|
-
| 'option';
|
|
4100
|
-
to:
|
|
4101
|
-
| 'main'
|
|
4102
|
-
| 'trade'
|
|
4103
|
-
| 'trade_hf'
|
|
4104
|
-
| 'margin'
|
|
4105
|
-
| 'isolated'
|
|
4106
|
-
| 'margin_v2'
|
|
4107
|
-
| 'isolated_v2'
|
|
4108
|
-
| 'contract'
|
|
4109
|
-
| 'option';
|
|
4110
|
-
amount: string;
|
|
4111
|
-
fromTag?: string;
|
|
4112
|
-
toTag?: string;
|
|
4113
|
-
}
|
|
4114
|
-
|
|
4115
|
-
================
|
|
4116
|
-
File: src/types/response/spot-account.ts
|
|
4117
|
-
================
|
|
4118
|
-
export interface SpotAccountSummary {
|
|
4119
|
-
level: number;
|
|
4120
|
-
subQuantity: number;
|
|
4121
|
-
spotSubQuantity: number;
|
|
4122
|
-
marginSubQuantity: number;
|
|
4123
|
-
futuresSubQuantity: number;
|
|
4124
|
-
optionSubQuantity: number;
|
|
4125
|
-
maxSubQuantity: number;
|
|
4126
|
-
maxDefaultSubQuantity: number;
|
|
4127
|
-
maxSpotSubQuantity: number;
|
|
4128
|
-
maxMarginSubQuantity: number;
|
|
4129
|
-
maxFuturesSubQuantity: number;
|
|
4130
|
-
maxOptionSubQuantity: number;
|
|
4131
|
-
}
|
|
4508
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
4509
|
+
export abstract class BaseWebsocketClient<
|
|
4510
|
+
TWSKey extends string,
|
|
4132
4511
|
⋮----
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
balance: string;
|
|
4138
|
-
available: string;
|
|
4139
|
-
holds: string;
|
|
4140
|
-
}
|
|
4512
|
+
constructor(
|
|
4513
|
+
options?: WSClientConfigurableOptions,
|
|
4514
|
+
logger?: typeof DefaultLogger,
|
|
4515
|
+
)
|
|
4141
4516
|
⋮----
|
|
4142
|
-
|
|
4143
|
-
currency: string;
|
|
4144
|
-
balance: string;
|
|
4145
|
-
available: string;
|
|
4146
|
-
holds: string;
|
|
4147
|
-
}
|
|
4517
|
+
// Requires a confirmation "response" from the ws connection before assuming it is ready
|
|
4148
4518
|
⋮----
|
|
4149
|
-
|
|
4150
|
-
id: string;
|
|
4151
|
-
currency: string;
|
|
4152
|
-
amount: string;
|
|
4153
|
-
fee: string;
|
|
4154
|
-
tax: string;
|
|
4155
|
-
balance: string;
|
|
4156
|
-
accountType: string; // 'TRADE_HF'
|
|
4157
|
-
bizType: string;
|
|
4158
|
-
direction: 'out' | 'in';
|
|
4159
|
-
createdAt: string;
|
|
4160
|
-
context: string;
|
|
4161
|
-
}
|
|
4519
|
+
// Automatically auth after opening a connection?
|
|
4162
4520
|
⋮----
|
|
4163
|
-
|
|
4521
|
+
// Automatically include auth/sign with every WS request
|
|
4164
4522
|
⋮----
|
|
4165
|
-
|
|
4166
|
-
currentPage: number;
|
|
4167
|
-
pageSize: number;
|
|
4168
|
-
totalNum: number;
|
|
4169
|
-
totalPage: number;
|
|
4170
|
-
items: SpotAccountTransaction[];
|
|
4171
|
-
}
|
|
4523
|
+
// Automatically re-auth WS API, if we were auth'd before and get reconnected
|
|
4172
4524
|
⋮----
|
|
4173
|
-
|
|
4174
|
-
id: string;
|
|
4175
|
-
currency: string;
|
|
4176
|
-
amount: string;
|
|
4177
|
-
fee: string;
|
|
4178
|
-
balance: string;
|
|
4179
|
-
accountType: 'MARGIN_V2' | 'ISOLATED_V2';
|
|
4180
|
-
bizType:
|
|
4181
|
-
| 'TRANSFER'
|
|
4182
|
-
| 'MARGIN_EXCHANGE'
|
|
4183
|
-
| 'ISOLATED_EXCHANGE'
|
|
4184
|
-
| 'LIQUIDATION'
|
|
4185
|
-
| 'ASSERT_RETURN';
|
|
4186
|
-
direction: 'out' | 'in';
|
|
4187
|
-
createdAt: string;
|
|
4188
|
-
tax: string;
|
|
4189
|
-
context: string;
|
|
4190
|
-
}
|
|
4525
|
+
// Check Web Crypto API support when credentials are provided and no custom sign function is used
|
|
4191
4526
|
⋮----
|
|
4192
|
-
|
|
4193
|
-
*
|
|
4194
|
-
* Sub-Account
|
|
4195
|
-
*
|
|
4196
|
-
*/
|
|
4527
|
+
protected abstract sendPingEvent(wsKey: TWSKey, ws: WebSocket): void;
|
|
4197
4528
|
⋮----
|
|
4198
|
-
|
|
4199
|
-
userId: string;
|
|
4200
|
-
uid: number;
|
|
4201
|
-
subName: string;
|
|
4202
|
-
status: number;
|
|
4203
|
-
type: number;
|
|
4204
|
-
access: string;
|
|
4205
|
-
createdAt: number;
|
|
4206
|
-
remarks: string;
|
|
4207
|
-
tradeTypes: string[];
|
|
4208
|
-
openedTradeTypes: string[];
|
|
4209
|
-
hostedStatus: null | string;
|
|
4210
|
-
}
|
|
4529
|
+
protected abstract sendPongEvent(wsKey: TWSKey, ws: WebSocket): void;
|
|
4211
4530
|
⋮----
|
|
4212
|
-
|
|
4213
|
-
currentPage: number;
|
|
4214
|
-
pageSize: number;
|
|
4215
|
-
totalNum: number;
|
|
4216
|
-
totalPage: number;
|
|
4217
|
-
items: SubAccountInfo[];
|
|
4218
|
-
}
|
|
4531
|
+
protected abstract isWsPong(data: any): boolean;
|
|
4219
4532
|
⋮----
|
|
4220
|
-
|
|
4221
|
-
userId: string;
|
|
4222
|
-
uid: number;
|
|
4223
|
-
subName: string;
|
|
4224
|
-
status: number;
|
|
4225
|
-
type: number;
|
|
4226
|
-
access: string;
|
|
4227
|
-
createdAt: number;
|
|
4228
|
-
remarks: string;
|
|
4229
|
-
tradeTypes: string[];
|
|
4230
|
-
openedTradeTypes: string[];
|
|
4231
|
-
hostedStatus: null | string;
|
|
4232
|
-
}
|
|
4533
|
+
protected abstract isWsPing(data: any): boolean;
|
|
4233
4534
|
⋮----
|
|
4234
|
-
|
|
4235
|
-
currentPage: number;
|
|
4236
|
-
pageSize: number;
|
|
4237
|
-
totalNum: number;
|
|
4238
|
-
totalPage: number;
|
|
4239
|
-
items: SubAccountItem[];
|
|
4240
|
-
}
|
|
4535
|
+
protected abstract getWsAuthRequestEvent(wsKey: TWSKey): Promise<object>;
|
|
4241
4536
|
⋮----
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
holds: string;
|
|
4247
|
-
baseCurrency: string;
|
|
4248
|
-
baseCurrencyPrice: string;
|
|
4249
|
-
baseAmount: string;
|
|
4250
|
-
}
|
|
4537
|
+
protected abstract isPrivateTopicRequest(
|
|
4538
|
+
request: WsTopicRequest<WSTopic>,
|
|
4539
|
+
wsKey: TWSKey,
|
|
4540
|
+
): boolean;
|
|
4251
4541
|
⋮----
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4542
|
+
/**
|
|
4543
|
+
* Returns a list of string events that can be individually sent upstream to complete subscribing/unsubscribing/etc to these topics
|
|
4544
|
+
*/
|
|
4545
|
+
protected abstract getWsOperationEventsForTopics(
|
|
4546
|
+
topics: WsTopicRequest<WSTopic>[],
|
|
4547
|
+
wsKey: TWSKey,
|
|
4548
|
+
operation: WsOperation,
|
|
4549
|
+
): Promise<string[]>;
|
|
4260
4550
|
⋮----
|
|
4261
|
-
|
|
4262
|
-
currentPage: number;
|
|
4263
|
-
pageSize: number;
|
|
4264
|
-
totalNum: number;
|
|
4265
|
-
totalPage: number;
|
|
4266
|
-
items: {
|
|
4267
|
-
subUserId: string;
|
|
4268
|
-
subName: string;
|
|
4269
|
-
mainAccounts: SubAccountBalance[];
|
|
4270
|
-
}[];
|
|
4271
|
-
}
|
|
4272
|
-
export interface SubAccountV2Details {
|
|
4273
|
-
currency?: string;
|
|
4274
|
-
balance?: string;
|
|
4275
|
-
available?: string;
|
|
4276
|
-
holds?: string;
|
|
4277
|
-
baseCurrency?: string;
|
|
4278
|
-
baseCurrencyPrice?: string;
|
|
4279
|
-
baseAmount?: string;
|
|
4280
|
-
tag?: string;
|
|
4281
|
-
}
|
|
4551
|
+
protected abstract getPrivateWSKeys(): TWSKey[];
|
|
4282
4552
|
⋮----
|
|
4283
|
-
|
|
4284
|
-
subUserId: string;
|
|
4285
|
-
subName: string;
|
|
4286
|
-
mainAccounts: SubAccountV2Details[]; // Funding Account
|
|
4287
|
-
tradeAccounts: SubAccountV2Details[]; // Spot Account
|
|
4288
|
-
marginAccounts: SubAccountV2Details[]; // Margin Account
|
|
4289
|
-
tradeHFAccounts: string[]; // Deprecated, only for old users
|
|
4290
|
-
}
|
|
4553
|
+
protected abstract getWsUrl(wsKey: TWSKey): Promise<string>;
|
|
4291
4554
|
⋮----
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
tradeHFAccounts: string[]; // Deprecated, only for old users
|
|
4555
|
+
protected abstract getMaxTopicsPerSubscribeEvent(
|
|
4556
|
+
wsKey: TWSKey,
|
|
4557
|
+
): number | null;
|
|
4296
4558
|
⋮----
|
|
4297
4559
|
/**
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
export interface SubAccountAPIInfo {
|
|
4305
|
-
subName: string;
|
|
4306
|
-
remark: string;
|
|
4307
|
-
apiKey: string;
|
|
4308
|
-
apiVersion: number;
|
|
4309
|
-
permission: string;
|
|
4310
|
-
ipWhitelist: string;
|
|
4311
|
-
createdAt: number;
|
|
4312
|
-
uid: number;
|
|
4313
|
-
isMaster: boolean;
|
|
4314
|
-
}
|
|
4560
|
+
* Abstraction called to sort ws events into emittable event types (response to a request, data update, etc)
|
|
4561
|
+
*/
|
|
4562
|
+
protected abstract resolveEmittableEvents(
|
|
4563
|
+
wsKey: TWSKey,
|
|
4564
|
+
event: MessageEventLike,
|
|
4565
|
+
): EmittableEvent[];
|
|
4315
4566
|
⋮----
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
apiSecret: string;
|
|
4321
|
-
apiVersion: number;
|
|
4322
|
-
passphrase: string;
|
|
4323
|
-
permission: string;
|
|
4324
|
-
createdAt: number;
|
|
4325
|
-
}
|
|
4567
|
+
/**
|
|
4568
|
+
* Request connection of all dependent (public & private) websockets, instead of waiting for automatic connection by library
|
|
4569
|
+
*/
|
|
4570
|
+
protected abstract connectAll(): Promise<(WSConnectedResult | undefined)[]>;
|
|
4326
4571
|
⋮----
|
|
4327
|
-
|
|
4328
|
-
apiKey: string;
|
|
4329
|
-
ipWhitelist: string;
|
|
4330
|
-
permission: string;
|
|
4331
|
-
subName: string;
|
|
4332
|
-
}
|
|
4572
|
+
protected isPrivateWsKey(wsKey: TWSKey): boolean
|
|
4333
4573
|
⋮----
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
apiKey: string;
|
|
4337
|
-
}
|
|
4338
|
-
|
|
4339
|
-
================
|
|
4340
|
-
File: src/BrokerClient.ts
|
|
4341
|
-
================
|
|
4342
|
-
import { BaseRestClient } from './lib/BaseRestClient.js';
|
|
4343
|
-
import { REST_CLIENT_TYPE_ENUM, RestClientType } from './lib/requestUtils.js';
|
|
4344
|
-
import {
|
|
4345
|
-
BrokerTransferRequest,
|
|
4346
|
-
CreateBrokerSubAccountApiRequest,
|
|
4347
|
-
DeleteBrokerSubAccountApiRequest,
|
|
4348
|
-
GetBrokerDepositListRequest,
|
|
4349
|
-
GetBrokerInfoRequest,
|
|
4350
|
-
GetBrokerSubAccountApisRequest,
|
|
4351
|
-
GetBrokerSubAccountsRequest,
|
|
4352
|
-
UpdateBrokerSubAccountApiRequest,
|
|
4353
|
-
} from './types/request/broker.types.js';
|
|
4354
|
-
import {
|
|
4355
|
-
BrokerDepositRecord,
|
|
4356
|
-
BrokerInfo,
|
|
4357
|
-
BrokerSubAccountApi,
|
|
4358
|
-
BrokerTransferHistory,
|
|
4359
|
-
BrokerWithdrawalRecord,
|
|
4360
|
-
CreateBrokerSubAccountApiResponse,
|
|
4361
|
-
CreateBrokerSubAccountResponse,
|
|
4362
|
-
GetBrokerSubAccountsResponse,
|
|
4363
|
-
} from './types/response/broker.types.js';
|
|
4364
|
-
import { APISuccessResponse } from './types/response/shared.types.js';
|
|
4574
|
+
/** Returns auto-incrementing request ID, used to track promise references for async requests */
|
|
4575
|
+
protected getNewRequestId(): string
|
|
4365
4576
|
⋮----
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4577
|
+
protected abstract sendWSAPIRequest(
|
|
4578
|
+
wsKey: TWSKey,
|
|
4579
|
+
channel: WSTopic,
|
|
4580
|
+
params?: any,
|
|
4581
|
+
): Promise<unknown>;
|
|
4370
4582
|
⋮----
|
|
4371
|
-
|
|
4583
|
+
protected abstract sendWSAPIRequest(
|
|
4584
|
+
wsKey: TWSKey,
|
|
4585
|
+
channel: WSTopic,
|
|
4586
|
+
params: any,
|
|
4587
|
+
): Promise<unknown>;
|
|
4372
4588
|
⋮----
|
|
4373
4589
|
/**
|
|
4374
|
-
*
|
|
4590
|
+
* Subscribe to one or more topics on a WS connection (identified by WS Key).
|
|
4375
4591
|
*
|
|
4376
|
-
*
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
): Promise<APISuccessResponse<BrokerInfo>>
|
|
4381
|
-
⋮----
|
|
4382
|
-
/**
|
|
4383
|
-
* Add SubAccount
|
|
4592
|
+
* - Topics are automatically cached
|
|
4593
|
+
* - Connections are automatically opened, if not yet connected
|
|
4594
|
+
* - Authentication is automatically handled
|
|
4595
|
+
* - Topics are automatically resubscribed to, if something happens to the connection, unless you call unsubsribeTopicsForWsKey(topics, key).
|
|
4384
4596
|
*
|
|
4385
|
-
*
|
|
4386
|
-
*
|
|
4387
|
-
* It is recommended to add a special identifier to prevent name duplication.
|
|
4597
|
+
* @param wsTopicRequests array of topics to subscribe to
|
|
4598
|
+
* @param wsKey ws key referring to the ws connection these topics should be subscribed on
|
|
4388
4599
|
*/
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4600
|
+
public subscribeTopicsForWsKey(
|
|
4601
|
+
wsTopicRequests: WsTopicRequestOrStringTopic<WSTopic>[],
|
|
4602
|
+
wsKey: TWSKey,
|
|
4603
|
+
)
|
|
4392
4604
|
⋮----
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
*/
|
|
4399
|
-
getSubAccounts(
|
|
4400
|
-
params: GetBrokerSubAccountsRequest,
|
|
4401
|
-
): Promise<APISuccessResponse<GetBrokerSubAccountsResponse>>
|
|
4605
|
+
// Store topics, so future automation (post-auth, post-reconnect) has everything needed to resubscribe automatically
|
|
4606
|
+
⋮----
|
|
4607
|
+
// start connection process if it hasn't yet begun. Topics are automatically subscribed to on-connect
|
|
4608
|
+
⋮----
|
|
4609
|
+
// Subscribe should happen automatically once connected, nothing to do here after topics are added to wsStore.
|
|
4402
4610
|
⋮----
|
|
4403
4611
|
/**
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
* Only General, Spot, and Futures permissions can be set.
|
|
4409
|
-
* Label must be between 4 and 32 characters.
|
|
4410
|
-
*/
|
|
4411
|
-
createSubAccountApi(
|
|
4412
|
-
params: CreateBrokerSubAccountApiRequest,
|
|
4413
|
-
): Promise<APISuccessResponse<CreateBrokerSubAccountApiResponse>>
|
|
4612
|
+
* Are we in the process of connection? Nothing to send yet.
|
|
4613
|
+
*/
|
|
4614
|
+
⋮----
|
|
4615
|
+
// We're connected. Check if auth is needed and if already authenticated
|
|
4414
4616
|
⋮----
|
|
4415
4617
|
/**
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4618
|
+
* If not authenticated yet and auth is required, don't request topics yet.
|
|
4619
|
+
*
|
|
4620
|
+
* Auth should already automatically be in progress, so no action needed from here. Topics will automatically subscribe post-auth success.
|
|
4621
|
+
*/
|
|
4622
|
+
⋮----
|
|
4623
|
+
// Finally, request subscription to topics if the connection is healthy and ready
|
|
4624
|
+
⋮----
|
|
4625
|
+
protected unsubscribeTopicsForWsKey(
|
|
4626
|
+
wsTopicRequests: WsTopicRequestOrStringTopic<string>[],
|
|
4627
|
+
wsKey: TWSKey,
|
|
4628
|
+
)
|
|
4629
|
+
⋮----
|
|
4630
|
+
// Store topics, so future automation (post-auth, post-reconnect) has everything needed to resubscribe automatically
|
|
4631
|
+
⋮----
|
|
4632
|
+
// If not connected, don't need to do anything.
|
|
4633
|
+
// Removing the topic from the store is enough to stop it from being resubscribed to on reconnect.
|
|
4634
|
+
⋮----
|
|
4635
|
+
// We're connected. Check if auth is needed and if already authenticated
|
|
4424
4636
|
⋮----
|
|
4425
4637
|
/**
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
* Label must be between 4 and 32 characters.
|
|
4432
|
-
*/
|
|
4433
|
-
updateSubAccountApi(
|
|
4434
|
-
params: UpdateBrokerSubAccountApiRequest,
|
|
4435
|
-
): Promise<APISuccessResponse<BrokerSubAccountApi>>
|
|
4638
|
+
* If not authenticated yet and auth is required, don't need to do anything.
|
|
4639
|
+
* We don't subscribe to topics until auth is complete anyway.
|
|
4640
|
+
*/
|
|
4641
|
+
⋮----
|
|
4642
|
+
// Finally, request subscription to topics if the connection is healthy and ready
|
|
4436
4643
|
⋮----
|
|
4437
4644
|
/**
|
|
4438
|
-
*
|
|
4439
|
-
*
|
|
4440
|
-
* This interface supports deleting Broker's sub-account APIKEY.
|
|
4645
|
+
* Splits topic requests into two groups, public & private topic requests
|
|
4441
4646
|
*/
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4647
|
+
private sortTopicRequestsIntoPublicPrivate(
|
|
4648
|
+
wsTopicRequests: WsTopicRequest<string>[],
|
|
4649
|
+
wsKey: TWSKey,
|
|
4650
|
+
):
|
|
4651
|
+
⋮----
|
|
4652
|
+
/** Get the WsStore that tracks websockets & topics */
|
|
4653
|
+
public getWsStore(): WsStore<TWSKey, WsTopicRequest<string>>
|
|
4654
|
+
⋮----
|
|
4655
|
+
public close(wsKey: TWSKey, force?: boolean)
|
|
4656
|
+
⋮----
|
|
4657
|
+
public closeAll(force?: boolean)
|
|
4658
|
+
⋮----
|
|
4659
|
+
public isConnected(wsKey: TWSKey): boolean
|
|
4445
4660
|
⋮----
|
|
4446
4661
|
/**
|
|
4447
|
-
*
|
|
4448
|
-
*
|
|
4449
|
-
* This endpoint supports fund transfer between Broker account and Broker sub-accounts.
|
|
4450
|
-
* Please be aware that withdrawal from sub-account is not directly supported.
|
|
4451
|
-
* Broker has to transfer funds from broker sub-account to broker account to initiate the withdrawals.
|
|
4452
|
-
*
|
|
4453
|
-
* Direction:
|
|
4454
|
-
* - OUT: Broker account is transferred to Broker sub-account
|
|
4455
|
-
* - IN: Broker sub-account is transferred to Broker account
|
|
4456
|
-
*
|
|
4457
|
-
* Account Types:
|
|
4458
|
-
* - MAIN: Funding account
|
|
4459
|
-
* - TRADE: Spot trading account
|
|
4662
|
+
* Request connection to a specific websocket, instead of waiting for automatic connection.
|
|
4460
4663
|
*/
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4664
|
+
public async connect(wsKey: TWSKey): Promise<WSConnectedResult | undefined>
|
|
4665
|
+
⋮----
|
|
4666
|
+
private connectToWsUrl(url: string, wsKey: TWSKey): WebSocket
|
|
4667
|
+
⋮----
|
|
4668
|
+
private parseWsError(context: string, error: any, wsKey: TWSKey)
|
|
4669
|
+
⋮----
|
|
4670
|
+
/** Get a signature, build the auth request and send it */
|
|
4671
|
+
private async sendAuthRequest(wsKey: TWSKey): Promise<void>
|
|
4672
|
+
⋮----
|
|
4673
|
+
private reconnectWithDelay(wsKey: TWSKey, connectionDelayMs: number)
|
|
4674
|
+
⋮----
|
|
4675
|
+
private ping(wsKey: TWSKey)
|
|
4676
|
+
⋮----
|
|
4677
|
+
private clearTimers(wsKey: TWSKey)
|
|
4678
|
+
⋮----
|
|
4679
|
+
// Send a ping at intervals
|
|
4680
|
+
private clearPingTimer(wsKey: TWSKey)
|
|
4681
|
+
⋮----
|
|
4682
|
+
// Expect a pong within a time limit
|
|
4683
|
+
private clearPongTimer(wsKey: TWSKey)
|
|
4684
|
+
⋮----
|
|
4685
|
+
// this.logger.trace(`Cleared pong timeout for "${wsKey}"`);
|
|
4686
|
+
⋮----
|
|
4687
|
+
// this.logger.trace(`No active pong timer for "${wsKey}"`);
|
|
4467
4688
|
⋮----
|
|
4468
4689
|
/**
|
|
4469
|
-
*
|
|
4470
|
-
*
|
|
4471
|
-
* This endpoint supports querying transfer records of the broker itself and its created sub-accounts.
|
|
4472
|
-
*
|
|
4473
|
-
* Account Types:
|
|
4474
|
-
* - MAIN: Funding account
|
|
4475
|
-
* - TRADE: Spot trading account
|
|
4476
|
-
* - CONTRACT: Contract account
|
|
4477
|
-
* - MARGIN: Margin account
|
|
4478
|
-
* - ISOLATED: Isolated margin account
|
|
4690
|
+
* Simply builds and sends subscribe events for a list of topics for a ws key
|
|
4479
4691
|
*
|
|
4480
|
-
*
|
|
4481
|
-
* - PROCESSING: Processing
|
|
4482
|
-
* - SUCCESS: Successful
|
|
4483
|
-
* - FAILURE: Failed
|
|
4692
|
+
* @private Use the `subscribe(topics)` or `subscribeTopicsForWsKey(topics, wsKey)` method to subscribe to topics. Send WS message to subscribe to topics.
|
|
4484
4693
|
*/
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4694
|
+
private async requestSubscribeTopics(
|
|
4695
|
+
wsKey: TWSKey,
|
|
4696
|
+
topics: WsTopicRequest<string>[],
|
|
4697
|
+
)
|
|
4698
|
+
⋮----
|
|
4699
|
+
// Automatically splits requests into smaller batches, if needed
|
|
4700
|
+
⋮----
|
|
4701
|
+
`Subscribing to ${topics.length} "${wsKey}" topics in ${subscribeWsMessages.length} batches.`, // Events: "${JSON.stringify(topics)}"
|
|
4702
|
+
⋮----
|
|
4703
|
+
// this.logger.trace(`Sending batch via message: "${wsMessage}"`);
|
|
4488
4704
|
⋮----
|
|
4489
4705
|
/**
|
|
4490
|
-
*
|
|
4491
|
-
*
|
|
4492
|
-
* This endpoint can obtain the deposit records of each sub-account under the ND Broker.
|
|
4493
|
-
* Default limit is 1000 records (max 1000).
|
|
4494
|
-
* Results are sorted in descending order by default.
|
|
4706
|
+
* Simply builds and sends unsubscribe events for a list of topics for a ws key
|
|
4495
4707
|
*
|
|
4496
|
-
*
|
|
4497
|
-
* - PROCESSING: Processing
|
|
4498
|
-
* - SUCCESS: Successful
|
|
4499
|
-
* - FAILURE: Failed
|
|
4708
|
+
* @private Use the `unsubscribe(topics)` method to unsubscribe from topics. Send WS message to unsubscribe from topics.
|
|
4500
4709
|
*/
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4710
|
+
private async requestUnsubscribeTopics(
|
|
4711
|
+
wsKey: TWSKey,
|
|
4712
|
+
wsTopicRequests: WsTopicRequest<string>[],
|
|
4713
|
+
)
|
|
4504
4714
|
⋮----
|
|
4505
4715
|
/**
|
|
4506
|
-
*
|
|
4507
|
-
*
|
|
4508
|
-
* This endpoint supports querying the deposit record of sub-accounts created by a Broker
|
|
4509
|
-
* (excluding main account of nd broker).
|
|
4510
|
-
*
|
|
4511
|
-
* Status:
|
|
4512
|
-
* - PROCESSING: Processing
|
|
4513
|
-
* - SUCCESS: Successful
|
|
4514
|
-
* - FAILURE: Failed
|
|
4716
|
+
* Try sending a string event on a WS connection (identified by the WS Key)
|
|
4515
4717
|
*/
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
}): Promise<APISuccessResponse<BrokerDepositRecord>>
|
|
4718
|
+
public tryWsSend(wsKey: TWSKey, wsMessage: string)
|
|
4719
|
+
⋮----
|
|
4720
|
+
private async onWsOpen(event: any, wsKey: TWSKey)
|
|
4520
4721
|
⋮----
|
|
4521
4722
|
/**
|
|
4522
|
-
*
|
|
4523
|
-
*
|
|
4524
|
-
*
|
|
4525
|
-
* (excluding main account of nd broker).
|
|
4723
|
+
* Called automatically once a connection is ready.
|
|
4724
|
+
* - Some exchanges are ready immediately after the connections open.
|
|
4725
|
+
* - Some exchanges send an event to confirm the connection is ready for us.
|
|
4526
4726
|
*
|
|
4527
|
-
*
|
|
4528
|
-
* - PROCESSING: Processing
|
|
4529
|
-
* - WALLET_PROCESSING: Wallet Processing
|
|
4530
|
-
* - REVIEW: Under Review
|
|
4531
|
-
* - SUCCESS: Successful
|
|
4532
|
-
* - FAILURE: Failed
|
|
4727
|
+
* This method is called to act when the connection is ready. Use `requireConnectionReadyConfirmation` to control how this is called.
|
|
4533
4728
|
*/
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4729
|
+
private async onWsReadyForEvents(wsKey: TWSKey)
|
|
4730
|
+
⋮----
|
|
4731
|
+
// Resolve & cleanup deferred "connection attempt in progress" promise
|
|
4732
|
+
⋮----
|
|
4733
|
+
// Remove before resolving, in case there's more requests queued
|
|
4734
|
+
⋮----
|
|
4735
|
+
// Some websockets require an auth packet to be sent after opening the connection
|
|
4736
|
+
⋮----
|
|
4737
|
+
// Reconnect to topics known before it connected
|
|
4738
|
+
⋮----
|
|
4739
|
+
// Request sub to public topics, if any
|
|
4740
|
+
⋮----
|
|
4741
|
+
// Request sub to private topics, if auth on connect isn't needed
|
|
4537
4742
|
⋮----
|
|
4538
4743
|
/**
|
|
4539
|
-
*
|
|
4744
|
+
* Handle subscription to private topics _after_ authentication successfully completes asynchronously.
|
|
4540
4745
|
*
|
|
4541
|
-
*
|
|
4542
|
-
* Returns a URL to download a CSV file containing the rebate data.
|
|
4543
|
-
* The URL is valid for 1 day.
|
|
4544
|
-
* Maximum interval between begin and end dates is 6 months.
|
|
4746
|
+
* Only used for exchanges that require auth before sending private topic subscription requests
|
|
4545
4747
|
*/
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4748
|
+
private onWsAuthenticated(
|
|
4749
|
+
wsKey: TWSKey,
|
|
4750
|
+
event: { isWSAPI?: boolean; WSAPIAuthChannel?: string },
|
|
4751
|
+
)
|
|
4752
|
+
⋮----
|
|
4753
|
+
private onWsMessage(event: unknown, wsKey: TWSKey, ws: WebSocket)
|
|
4754
|
+
⋮----
|
|
4755
|
+
// any message can clear the pong timer - wouldn't get a message if the ws wasn't working
|
|
4756
|
+
⋮----
|
|
4757
|
+
// console.log(`raw event: `, { data, dataType, emittableEvents });
|
|
4758
|
+
⋮----
|
|
4759
|
+
private onWsClose(event: unknown, wsKey: TWSKey)
|
|
4760
|
+
⋮----
|
|
4761
|
+
// clean up any pending promises for this connection
|
|
4762
|
+
⋮----
|
|
4763
|
+
// clean up any pending promises for this connection
|
|
4764
|
+
⋮----
|
|
4765
|
+
private getWs(wsKey: TWSKey)
|
|
4766
|
+
⋮----
|
|
4767
|
+
private setWsState(wsKey: TWSKey, state: WsConnectionStateEnum)
|
|
4768
|
+
⋮----
|
|
4769
|
+
/**
|
|
4770
|
+
* Promise-driven method to assert that a ws has successfully connected (will await until connection is open)
|
|
4771
|
+
*/
|
|
4772
|
+
protected async assertIsConnected(wsKey: TWSKey): Promise<unknown>
|
|
4773
|
+
⋮----
|
|
4774
|
+
// Already in progress? Await shared promise and retry
|
|
4775
|
+
⋮----
|
|
4776
|
+
// Start connection, it should automatically store/return a promise.
|
|
4561
4777
|
|
|
4562
4778
|
================
|
|
4563
4779
|
File: src/lib/requestUtils.ts
|
|
@@ -5298,6 +5514,7 @@ export interface HFMarginOrder {
|
|
|
5298
5514
|
active: boolean;
|
|
5299
5515
|
createdAt: number;
|
|
5300
5516
|
lastUpdatedAt: number;
|
|
5517
|
+
cancelReason?: number;
|
|
5301
5518
|
}
|
|
5302
5519
|
⋮----
|
|
5303
5520
|
/** @deprecated not used anymore **/
|
|
@@ -5670,6 +5887,186 @@ export interface LendingRedemption {
|
|
|
5670
5887
|
totalPage: number;
|
|
5671
5888
|
items: LendingOrder[];
|
|
5672
5889
|
}
|
|
5890
|
+
⋮----
|
|
5891
|
+
export interface BorrowInterestRateItem {
|
|
5892
|
+
currency: string; // Currency
|
|
5893
|
+
hourlyBorrowRate: string; // Hourly borrow rate
|
|
5894
|
+
annualizedBorrowRate: string; // Annualized borrow rate
|
|
5895
|
+
}
|
|
5896
|
+
⋮----
|
|
5897
|
+
currency: string; // Currency
|
|
5898
|
+
hourlyBorrowRate: string; // Hourly borrow rate
|
|
5899
|
+
annualizedBorrowRate: string; // Annualized borrow rate
|
|
5900
|
+
⋮----
|
|
5901
|
+
export interface BorrowInterestRate {
|
|
5902
|
+
vipLevel: number; // The VIP level (0-12)
|
|
5903
|
+
items: BorrowInterestRateItem[]; // Array of currency borrow rates
|
|
5904
|
+
}
|
|
5905
|
+
⋮----
|
|
5906
|
+
vipLevel: number; // The VIP level (0-12)
|
|
5907
|
+
items: BorrowInterestRateItem[]; // Array of currency borrow rates
|
|
5908
|
+
⋮----
|
|
5909
|
+
/**
|
|
5910
|
+
* Margin Stop Order Response Types
|
|
5911
|
+
*/
|
|
5912
|
+
export interface MarginStopOrderResponse {
|
|
5913
|
+
orderId: string; // The unique order ID generated by the trading system
|
|
5914
|
+
clientOid: string; // The user self-defined order ID
|
|
5915
|
+
}
|
|
5916
|
+
⋮----
|
|
5917
|
+
orderId: string; // The unique order ID generated by the trading system
|
|
5918
|
+
clientOid: string; // The user self-defined order ID
|
|
5919
|
+
⋮----
|
|
5920
|
+
export interface CancelMarginOrdersResponse {
|
|
5921
|
+
cancelledOrderIds: string[]; // Array of cancelled order IDs
|
|
5922
|
+
}
|
|
5923
|
+
⋮----
|
|
5924
|
+
cancelledOrderIds: string[]; // Array of cancelled order IDs
|
|
5925
|
+
⋮----
|
|
5926
|
+
export interface MarginStopOrderItem {
|
|
5927
|
+
id?: string; // Order ID
|
|
5928
|
+
symbol?: string; // Symbol name
|
|
5929
|
+
userId?: string; // User ID
|
|
5930
|
+
status?: 'NEW' | 'TRIGGERED'; // Order status
|
|
5931
|
+
type?: 'limit' | 'market'; // Order type
|
|
5932
|
+
side?: 'buy' | 'sell'; // Transaction direction
|
|
5933
|
+
price?: string; // Order price
|
|
5934
|
+
size?: string; // Order quantity
|
|
5935
|
+
funds?: string | null; // Order funds
|
|
5936
|
+
stp?: string | null; // Self Trade Prevention
|
|
5937
|
+
timeInForce?: 'GTC' | 'GTT' | 'IOC' | 'FOK'; // Time in force
|
|
5938
|
+
cancelAfter?: number; // Cancel after seconds
|
|
5939
|
+
postOnly?: boolean; // Post only
|
|
5940
|
+
hidden?: boolean; // Hidden order
|
|
5941
|
+
iceberg?: boolean; // Iceberg order
|
|
5942
|
+
visibleSize?: string | null; // Visible size for iceberg orders
|
|
5943
|
+
channel?: string; // Order source
|
|
5944
|
+
clientOid?: string; // Client order ID
|
|
5945
|
+
remark?: string | null; // Remarks
|
|
5946
|
+
tags?: string | null; // Tag order source
|
|
5947
|
+
relatedNo?: string | null; // Related number
|
|
5948
|
+
orderTime?: number; // Order time (nanoseconds)
|
|
5949
|
+
domainId?: string; // Domain ID
|
|
5950
|
+
tradeSource?: 'USER' | 'MARGIN_SYSTEM'; // Trade source
|
|
5951
|
+
tradeType?: 'TRADE' | 'MARGIN_TRADE' | 'MARGIN_ISOLATED_TRADE'; // Trade type
|
|
5952
|
+
feeCurrency?: string; // Fee currency
|
|
5953
|
+
takerFeeRate?: string; // Taker fee rate
|
|
5954
|
+
makerFeeRate?: string; // Maker fee rate
|
|
5955
|
+
createdAt?: number; // Order creation time
|
|
5956
|
+
stop?: 'loss' | 'entry'; // Stop order type
|
|
5957
|
+
stopTriggerTime?: number | null; // Stop trigger time
|
|
5958
|
+
stopPrice?: string; // Stop price
|
|
5959
|
+
limitPrice?: string | null; // Limit price
|
|
5960
|
+
pop?: string | null; // POP
|
|
5961
|
+
activateCondition?: string | null; // Activate condition
|
|
5962
|
+
}
|
|
5963
|
+
⋮----
|
|
5964
|
+
id?: string; // Order ID
|
|
5965
|
+
symbol?: string; // Symbol name
|
|
5966
|
+
userId?: string; // User ID
|
|
5967
|
+
status?: 'NEW' | 'TRIGGERED'; // Order status
|
|
5968
|
+
type?: 'limit' | 'market'; // Order type
|
|
5969
|
+
side?: 'buy' | 'sell'; // Transaction direction
|
|
5970
|
+
price?: string; // Order price
|
|
5971
|
+
size?: string; // Order quantity
|
|
5972
|
+
funds?: string | null; // Order funds
|
|
5973
|
+
stp?: string | null; // Self Trade Prevention
|
|
5974
|
+
timeInForce?: 'GTC' | 'GTT' | 'IOC' | 'FOK'; // Time in force
|
|
5975
|
+
cancelAfter?: number; // Cancel after seconds
|
|
5976
|
+
postOnly?: boolean; // Post only
|
|
5977
|
+
hidden?: boolean; // Hidden order
|
|
5978
|
+
iceberg?: boolean; // Iceberg order
|
|
5979
|
+
visibleSize?: string | null; // Visible size for iceberg orders
|
|
5980
|
+
channel?: string; // Order source
|
|
5981
|
+
clientOid?: string; // Client order ID
|
|
5982
|
+
remark?: string | null; // Remarks
|
|
5983
|
+
tags?: string | null; // Tag order source
|
|
5984
|
+
relatedNo?: string | null; // Related number
|
|
5985
|
+
orderTime?: number; // Order time (nanoseconds)
|
|
5986
|
+
domainId?: string; // Domain ID
|
|
5987
|
+
tradeSource?: 'USER' | 'MARGIN_SYSTEM'; // Trade source
|
|
5988
|
+
tradeType?: 'TRADE' | 'MARGIN_TRADE' | 'MARGIN_ISOLATED_TRADE'; // Trade type
|
|
5989
|
+
feeCurrency?: string; // Fee currency
|
|
5990
|
+
takerFeeRate?: string; // Taker fee rate
|
|
5991
|
+
makerFeeRate?: string; // Maker fee rate
|
|
5992
|
+
createdAt?: number; // Order creation time
|
|
5993
|
+
stop?: 'loss' | 'entry'; // Stop order type
|
|
5994
|
+
stopTriggerTime?: number | null; // Stop trigger time
|
|
5995
|
+
stopPrice?: string; // Stop price
|
|
5996
|
+
limitPrice?: string | null; // Limit price
|
|
5997
|
+
pop?: string | null; // POP
|
|
5998
|
+
activateCondition?: string | null; // Activate condition
|
|
5999
|
+
⋮----
|
|
6000
|
+
export interface MarginStopOrdersList {
|
|
6001
|
+
currentPage: number; // Current page
|
|
6002
|
+
pageSize: number; // Page size
|
|
6003
|
+
totalNum: number; // Total number of stop orders
|
|
6004
|
+
totalPage: number; // Total pages
|
|
6005
|
+
items: MarginStopOrderItem[]; // Array of stop orders
|
|
6006
|
+
}
|
|
6007
|
+
⋮----
|
|
6008
|
+
currentPage: number; // Current page
|
|
6009
|
+
pageSize: number; // Page size
|
|
6010
|
+
totalNum: number; // Total number of stop orders
|
|
6011
|
+
totalPage: number; // Total pages
|
|
6012
|
+
items: MarginStopOrderItem[]; // Array of stop orders
|
|
6013
|
+
⋮----
|
|
6014
|
+
/**
|
|
6015
|
+
* Margin OCO Order Response Types
|
|
6016
|
+
*/
|
|
6017
|
+
export interface MarginOcoOrderResponse {
|
|
6018
|
+
orderId: string; // The unique order ID generated by the trading system
|
|
6019
|
+
}
|
|
6020
|
+
⋮----
|
|
6021
|
+
orderId: string; // The unique order ID generated by the trading system
|
|
6022
|
+
⋮----
|
|
6023
|
+
export interface MarginOcoOrderItem {
|
|
6024
|
+
orderId: string; // Order ID
|
|
6025
|
+
symbol: string; // Symbol
|
|
6026
|
+
clientOid: string; // Client Order ID
|
|
6027
|
+
orderTime: number; // Order placement time (milliseconds)
|
|
6028
|
+
status: 'NEW' | 'DONE' | 'TRIGGERED' | 'CANCELLED'; // Order status
|
|
6029
|
+
}
|
|
6030
|
+
⋮----
|
|
6031
|
+
orderId: string; // Order ID
|
|
6032
|
+
symbol: string; // Symbol
|
|
6033
|
+
clientOid: string; // Client Order ID
|
|
6034
|
+
orderTime: number; // Order placement time (milliseconds)
|
|
6035
|
+
status: 'NEW' | 'DONE' | 'TRIGGERED' | 'CANCELLED'; // Order status
|
|
6036
|
+
⋮----
|
|
6037
|
+
export interface MarginOcoOrderSubOrder {
|
|
6038
|
+
id: string; // Sub-order ID
|
|
6039
|
+
symbol: string; // Symbol of the sub-order
|
|
6040
|
+
side: 'buy' | 'sell'; // Side of the sub-order
|
|
6041
|
+
price: string; // Price of the sub-order
|
|
6042
|
+
stopPrice: string; // Stop price of the sub-order
|
|
6043
|
+
size: string; // Size of the sub-order
|
|
6044
|
+
status: 'NEW' | 'DONE' | 'TRIGGERED' | 'CANCELLED'; // Status of the sub-order
|
|
6045
|
+
}
|
|
6046
|
+
⋮----
|
|
6047
|
+
id: string; // Sub-order ID
|
|
6048
|
+
symbol: string; // Symbol of the sub-order
|
|
6049
|
+
side: 'buy' | 'sell'; // Side of the sub-order
|
|
6050
|
+
price: string; // Price of the sub-order
|
|
6051
|
+
stopPrice: string; // Stop price of the sub-order
|
|
6052
|
+
size: string; // Size of the sub-order
|
|
6053
|
+
status: 'NEW' | 'DONE' | 'TRIGGERED' | 'CANCELLED'; // Status of the sub-order
|
|
6054
|
+
⋮----
|
|
6055
|
+
export interface MarginOcoOrderDetails {
|
|
6056
|
+
orderId: string; // Order ID
|
|
6057
|
+
symbol: string; // Symbol
|
|
6058
|
+
clientOid: string; // Client Order ID
|
|
6059
|
+
orderTime: number; // Order placement time (milliseconds)
|
|
6060
|
+
status: 'NEW' | 'DONE' | 'TRIGGERED' | 'CANCELLED'; // Order status
|
|
6061
|
+
orders: MarginOcoOrderSubOrder[]; // Sub-orders array
|
|
6062
|
+
}
|
|
6063
|
+
⋮----
|
|
6064
|
+
orderId: string; // Order ID
|
|
6065
|
+
symbol: string; // Symbol
|
|
6066
|
+
clientOid: string; // Client Order ID
|
|
6067
|
+
orderTime: number; // Order placement time (milliseconds)
|
|
6068
|
+
status: 'NEW' | 'DONE' | 'TRIGGERED' | 'CANCELLED'; // Order status
|
|
6069
|
+
orders: MarginOcoOrderSubOrder[]; // Sub-orders array
|
|
5673
6070
|
|
|
5674
6071
|
================
|
|
5675
6072
|
File: src/types/websockets/client.ts
|
|
@@ -5772,193 +6169,21 @@ export interface WebsocketClientOptions extends WSClientConfigurableOptions {
|
|
|
5772
6169
|
export type WsMarket = 'spot' | 'futures';
|
|
5773
6170
|
|
|
5774
6171
|
================
|
|
5775
|
-
File: src/
|
|
6172
|
+
File: src/types/response/spot-trading.ts
|
|
5776
6173
|
================
|
|
5777
|
-
|
|
5778
|
-
|
|
6174
|
+
/**
|
|
6175
|
+
*
|
|
6176
|
+
***********
|
|
6177
|
+
* Spot Trading
|
|
6178
|
+
***********
|
|
6179
|
+
*
|
|
6180
|
+
*/
|
|
5779
6181
|
⋮----
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
APIIDMainSign,
|
|
5786
|
-
getRestBaseUrl,
|
|
5787
|
-
REST_CLIENT_TYPE_ENUM,
|
|
5788
|
-
RestClientOptions,
|
|
5789
|
-
RestClientType,
|
|
5790
|
-
serializeParams,
|
|
5791
|
-
} from './requestUtils.js';
|
|
5792
|
-
import { checkWebCryptoAPISupported, signMessage } from './webCryptoAPI.js';
|
|
5793
|
-
⋮----
|
|
5794
|
-
interface SignedRequest<T extends object | undefined = {}> {
|
|
5795
|
-
originalParams: T;
|
|
5796
|
-
paramsWithSign?: T & { sign: string };
|
|
5797
|
-
serializedParams: string;
|
|
5798
|
-
sign: string;
|
|
5799
|
-
queryParamsWithSign: string;
|
|
5800
|
-
timestamp: number;
|
|
5801
|
-
recvWindow: number;
|
|
5802
|
-
}
|
|
5803
|
-
⋮----
|
|
5804
|
-
interface UnsignedRequest<T extends object | undefined = {}> {
|
|
5805
|
-
originalParams: T;
|
|
5806
|
-
paramsWithSign: T;
|
|
5807
|
-
}
|
|
5808
|
-
⋮----
|
|
5809
|
-
type SignMethod = 'kucoin';
|
|
5810
|
-
⋮----
|
|
5811
|
-
// request: {
|
|
5812
|
-
// url: response.config.url,
|
|
5813
|
-
// method: response.config.method,
|
|
5814
|
-
// data: response.config.data,
|
|
5815
|
-
// headers: response.config.headers,
|
|
5816
|
-
// },
|
|
5817
|
-
⋮----
|
|
5818
|
-
export abstract class BaseRestClient
|
|
5819
|
-
⋮----
|
|
5820
|
-
/** Defines the client type (affecting how requests & signatures behave) */
|
|
5821
|
-
abstract getClientType(): RestClientType;
|
|
5822
|
-
⋮----
|
|
5823
|
-
/**
|
|
5824
|
-
* Create an instance of the REST client. Pass API credentials in the object in the first parameter.
|
|
5825
|
-
* @param {RestClientOptions} [restClientOptions={}] options to configure REST API connectivity
|
|
5826
|
-
* @param {AxiosRequestConfig} [networkOptions={}] HTTP networking options for axios
|
|
5827
|
-
*/
|
|
5828
|
-
constructor(
|
|
5829
|
-
restClientOptions: RestClientOptions = {},
|
|
5830
|
-
networkOptions: AxiosRequestConfig = {},
|
|
5831
|
-
)
|
|
5832
|
-
⋮----
|
|
5833
|
-
/** Throw errors if any request params are empty */
|
|
5834
|
-
⋮----
|
|
5835
|
-
/** in ms == 5 minutes by default */
|
|
5836
|
-
⋮----
|
|
5837
|
-
/** inject custom rquest options based on axios specs - see axios docs for more guidance on AxiosRequestConfig: https://github.com/axios/axios#request-config */
|
|
5838
|
-
⋮----
|
|
5839
|
-
// If enabled, configure a https agent with keepAlive enabled
|
|
5840
|
-
⋮----
|
|
5841
|
-
// Extract existing https agent parameters, if provided, to prevent the keepAlive flag from overwriting an existing https agent completely
|
|
5842
|
-
⋮----
|
|
5843
|
-
// For more advanced configuration, raise an issue on GitHub or use the "networkOptions"
|
|
5844
|
-
// parameter to define a custom httpsAgent with the desired properties
|
|
5845
|
-
⋮----
|
|
5846
|
-
// Check Web Crypto API support when credentials are provided
|
|
5847
|
-
⋮----
|
|
5848
|
-
// Throw if one of the 3 values is missing, but at least one of them is set
|
|
5849
|
-
⋮----
|
|
5850
|
-
/**
|
|
5851
|
-
* Generates a timestamp for signing API requests.
|
|
5852
|
-
*
|
|
5853
|
-
* This method can be overridden or customized using `customTimestampFn`
|
|
5854
|
-
* to implement a custom timestamp synchronization mechanism.
|
|
5855
|
-
* If no custom function is provided, it defaults to the current system time.
|
|
5856
|
-
*/
|
|
5857
|
-
private getSignTimestampMs(): number
|
|
5858
|
-
⋮----
|
|
5859
|
-
get(endpoint: string, params?: any)
|
|
5860
|
-
⋮----
|
|
5861
|
-
post(endpoint: string, params?: any)
|
|
5862
|
-
⋮----
|
|
5863
|
-
getPrivate(endpoint: string, params?: any)
|
|
5864
|
-
⋮----
|
|
5865
|
-
postPrivate(endpoint: string, params?: any)
|
|
5866
|
-
⋮----
|
|
5867
|
-
deletePrivate(endpoint: string, params?: any)
|
|
5868
|
-
⋮----
|
|
5869
|
-
/**
|
|
5870
|
-
* @private Make a HTTP request to a specific endpoint. Private endpoint API calls are automatically signed.
|
|
5871
|
-
*/
|
|
5872
|
-
private async _call(
|
|
5873
|
-
method: Method,
|
|
5874
|
-
endpoint: string,
|
|
5875
|
-
params?: any,
|
|
5876
|
-
isPublicApi?: boolean,
|
|
5877
|
-
): Promise<any>
|
|
5878
|
-
⋮----
|
|
5879
|
-
// Sanity check to make sure it's only ever prefixed by one forward slash
|
|
5880
|
-
⋮----
|
|
5881
|
-
// Build a request and handle signature process
|
|
5882
|
-
⋮----
|
|
5883
|
-
// Dispatch request
|
|
5884
|
-
⋮----
|
|
5885
|
-
// Throw if API returns an error (e.g. insufficient balance)
|
|
5886
|
-
⋮----
|
|
5887
|
-
/**
|
|
5888
|
-
* @private generic handler to parse request exceptions
|
|
5889
|
-
*/
|
|
5890
|
-
parseException(e: any, requestParams: any): unknown
|
|
5891
|
-
⋮----
|
|
5892
|
-
// Something happened in setting up the request that triggered an error
|
|
5893
|
-
⋮----
|
|
5894
|
-
// request made but no response received
|
|
5895
|
-
⋮----
|
|
5896
|
-
// The request was made and the server responded with a status code
|
|
5897
|
-
// that falls out of the range of 2xx
|
|
5898
|
-
⋮----
|
|
5899
|
-
// console.error('err: ', response?.data);
|
|
5900
|
-
⋮----
|
|
5901
|
-
// Prevent credentials from leaking into error messages
|
|
5902
|
-
⋮----
|
|
5903
|
-
/**
|
|
5904
|
-
* @private sign request and set recv window
|
|
5905
|
-
*/
|
|
5906
|
-
private async signRequest<T extends object | undefined = {}>(
|
|
5907
|
-
data: T,
|
|
5908
|
-
endpoint: string,
|
|
5909
|
-
method: Method,
|
|
5910
|
-
signMethod: SignMethod,
|
|
5911
|
-
): Promise<SignedRequest<T>>
|
|
5912
|
-
⋮----
|
|
5913
|
-
private async prepareSignParams<TParams extends object | undefined>(
|
|
5914
|
-
method: Method,
|
|
5915
|
-
endpoint: string,
|
|
5916
|
-
signMethod: SignMethod,
|
|
5917
|
-
params?: TParams,
|
|
5918
|
-
isPublicApi?: true,
|
|
5919
|
-
): Promise<UnsignedRequest<TParams>>;
|
|
5920
|
-
⋮----
|
|
5921
|
-
private async prepareSignParams<TParams extends object | undefined>(
|
|
5922
|
-
method: Method,
|
|
5923
|
-
endpoint: string,
|
|
5924
|
-
signMethod: SignMethod,
|
|
5925
|
-
params?: TParams,
|
|
5926
|
-
isPublicApi?: false | undefined,
|
|
5927
|
-
): Promise<SignedRequest<TParams>>;
|
|
5928
|
-
⋮----
|
|
5929
|
-
private async prepareSignParams<TParams extends object | undefined>(
|
|
5930
|
-
method: Method,
|
|
5931
|
-
endpoint: string,
|
|
5932
|
-
signMethod: SignMethod,
|
|
5933
|
-
params?: TParams,
|
|
5934
|
-
isPublicApi?: boolean,
|
|
5935
|
-
)
|
|
5936
|
-
⋮----
|
|
5937
|
-
/** Returns an axios request object. Handles signing process automatically if this is a private API call */
|
|
5938
|
-
private async buildRequest(
|
|
5939
|
-
method: Method,
|
|
5940
|
-
endpoint: string,
|
|
5941
|
-
url: string,
|
|
5942
|
-
params?: any,
|
|
5943
|
-
isPublicApi?: boolean,
|
|
5944
|
-
): Promise<AxiosRequestConfig>
|
|
5945
|
-
|
|
5946
|
-
================
|
|
5947
|
-
File: src/types/response/spot-trading.ts
|
|
5948
|
-
================
|
|
5949
|
-
/**
|
|
5950
|
-
*
|
|
5951
|
-
***********
|
|
5952
|
-
* Spot Trading
|
|
5953
|
-
***********
|
|
5954
|
-
*
|
|
5955
|
-
*/
|
|
5956
|
-
⋮----
|
|
5957
|
-
/**
|
|
5958
|
-
*
|
|
5959
|
-
* Market data
|
|
5960
|
-
*
|
|
5961
|
-
*/
|
|
6182
|
+
/**
|
|
6183
|
+
*
|
|
6184
|
+
* Market data
|
|
6185
|
+
*
|
|
6186
|
+
*/
|
|
5962
6187
|
⋮----
|
|
5963
6188
|
interface Chain {
|
|
5964
6189
|
chainName: string;
|
|
@@ -6275,6 +6500,7 @@ export interface HFOrder {
|
|
|
6275
6500
|
tax: string;
|
|
6276
6501
|
createdAt: number;
|
|
6277
6502
|
lastUpdatedAt: number;
|
|
6503
|
+
cancelReason: number;
|
|
6278
6504
|
}
|
|
6279
6505
|
⋮----
|
|
6280
6506
|
/**
|
|
@@ -6697,75 +6923,247 @@ protected async getWsOperationEventsForTopics(
|
|
|
6697
6923
|
protected async getWsAuthRequestEvent(wsKey: WsKey): Promise<object>
|
|
6698
6924
|
|
|
6699
6925
|
================
|
|
6700
|
-
File: src/
|
|
6926
|
+
File: src/lib/BaseRestClient.ts
|
|
6701
6927
|
================
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
***********
|
|
6705
|
-
* Funding
|
|
6706
|
-
***********
|
|
6707
|
-
*
|
|
6708
|
-
*/
|
|
6709
|
-
⋮----
|
|
6710
|
-
export interface MarginAccountBalance {
|
|
6711
|
-
currency: string;
|
|
6712
|
-
totalBalance: string;
|
|
6713
|
-
availableBalance: string;
|
|
6714
|
-
holdBalance: string;
|
|
6715
|
-
liability: string;
|
|
6716
|
-
maxBorrowSize: string;
|
|
6717
|
-
}
|
|
6718
|
-
⋮----
|
|
6719
|
-
export interface MarginAccountDetail {
|
|
6720
|
-
currency: string;
|
|
6721
|
-
total: string;
|
|
6722
|
-
available: string;
|
|
6723
|
-
hold: string;
|
|
6724
|
-
liability: string;
|
|
6725
|
-
liabilityPrincipal: string;
|
|
6726
|
-
liabilityInterest: string;
|
|
6727
|
-
maxBorrowSize: string;
|
|
6728
|
-
borrowEnabled: boolean;
|
|
6729
|
-
transferInEnabled: boolean;
|
|
6730
|
-
}
|
|
6928
|
+
import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios';
|
|
6929
|
+
import https from 'https';
|
|
6731
6930
|
⋮----
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
}
|
|
6931
|
+
import { neverGuard } from './misc-util.js';
|
|
6932
|
+
import {
|
|
6933
|
+
APIIDFutures,
|
|
6934
|
+
APIIDFuturesSign,
|
|
6935
|
+
APIIDMain,
|
|
6936
|
+
APIIDMainSign,
|
|
6937
|
+
getRestBaseUrl,
|
|
6938
|
+
REST_CLIENT_TYPE_ENUM,
|
|
6939
|
+
RestClientOptions,
|
|
6940
|
+
RestClientType,
|
|
6941
|
+
serializeParams,
|
|
6942
|
+
} from './requestUtils.js';
|
|
6943
|
+
import { checkWebCryptoAPISupported, signMessage } from './webCryptoAPI.js';
|
|
6746
6944
|
⋮----
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
|
|
6945
|
+
interface SignedRequest<T extends object | undefined = {}> {
|
|
6946
|
+
originalParams: T;
|
|
6947
|
+
paramsWithSign?: T & { sign: string };
|
|
6948
|
+
serializedParams: string;
|
|
6949
|
+
sign: string;
|
|
6950
|
+
queryParamsWithSign: string;
|
|
6750
6951
|
timestamp: number;
|
|
6751
|
-
|
|
6952
|
+
recvWindow: number;
|
|
6752
6953
|
}
|
|
6753
6954
|
⋮----
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
*
|
|
6758
|
-
*/
|
|
6759
|
-
⋮----
|
|
6760
|
-
export interface DepositAddress {
|
|
6761
|
-
address: string;
|
|
6762
|
-
memo: string;
|
|
6763
|
-
chain: string;
|
|
6955
|
+
interface UnsignedRequest<T extends object | undefined = {}> {
|
|
6956
|
+
originalParams: T;
|
|
6957
|
+
paramsWithSign: T;
|
|
6764
6958
|
}
|
|
6765
6959
|
⋮----
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6960
|
+
type SignMethod = 'kucoin';
|
|
6961
|
+
⋮----
|
|
6962
|
+
// request: {
|
|
6963
|
+
// url: response.config.url,
|
|
6964
|
+
// method: response.config.method,
|
|
6965
|
+
// data: response.config.data,
|
|
6966
|
+
// headers: response.config.headers,
|
|
6967
|
+
// },
|
|
6968
|
+
⋮----
|
|
6969
|
+
export abstract class BaseRestClient
|
|
6970
|
+
⋮----
|
|
6971
|
+
/** Defines the client type (affecting how requests & signatures behave) */
|
|
6972
|
+
abstract getClientType(): RestClientType;
|
|
6973
|
+
⋮----
|
|
6974
|
+
/**
|
|
6975
|
+
* Create an instance of the REST client. Pass API credentials in the object in the first parameter.
|
|
6976
|
+
* @param {RestClientOptions} [restClientOptions={}] options to configure REST API connectivity
|
|
6977
|
+
* @param {AxiosRequestConfig} [networkOptions={}] HTTP networking options for axios
|
|
6978
|
+
*/
|
|
6979
|
+
constructor(
|
|
6980
|
+
restClientOptions: RestClientOptions = {},
|
|
6981
|
+
networkOptions: AxiosRequestConfig = {},
|
|
6982
|
+
)
|
|
6983
|
+
⋮----
|
|
6984
|
+
/** Throw errors if any request params are empty */
|
|
6985
|
+
⋮----
|
|
6986
|
+
/** in ms == 5 minutes by default */
|
|
6987
|
+
⋮----
|
|
6988
|
+
/** inject custom rquest options based on axios specs - see axios docs for more guidance on AxiosRequestConfig: https://github.com/axios/axios#request-config */
|
|
6989
|
+
⋮----
|
|
6990
|
+
// If enabled, configure a https agent with keepAlive enabled
|
|
6991
|
+
⋮----
|
|
6992
|
+
// Extract existing https agent parameters, if provided, to prevent the keepAlive flag from overwriting an existing https agent completely
|
|
6993
|
+
⋮----
|
|
6994
|
+
// For more advanced configuration, raise an issue on GitHub or use the "networkOptions"
|
|
6995
|
+
// parameter to define a custom httpsAgent with the desired properties
|
|
6996
|
+
⋮----
|
|
6997
|
+
// Check Web Crypto API support when credentials are provided
|
|
6998
|
+
⋮----
|
|
6999
|
+
// Throw if one of the 3 values is missing, but at least one of them is set
|
|
7000
|
+
⋮----
|
|
7001
|
+
/**
|
|
7002
|
+
* Generates a timestamp for signing API requests.
|
|
7003
|
+
*
|
|
7004
|
+
* This method can be overridden or customized using `customTimestampFn`
|
|
7005
|
+
* to implement a custom timestamp synchronization mechanism.
|
|
7006
|
+
* If no custom function is provided, it defaults to the current system time.
|
|
7007
|
+
*/
|
|
7008
|
+
private getSignTimestampMs(): number
|
|
7009
|
+
⋮----
|
|
7010
|
+
get(endpoint: string, params?: any)
|
|
7011
|
+
⋮----
|
|
7012
|
+
post(endpoint: string, params?: any)
|
|
7013
|
+
⋮----
|
|
7014
|
+
getPrivate(endpoint: string, params?: any)
|
|
7015
|
+
⋮----
|
|
7016
|
+
postPrivate(endpoint: string, params?: any)
|
|
7017
|
+
⋮----
|
|
7018
|
+
deletePrivate(endpoint: string, params?: any)
|
|
7019
|
+
⋮----
|
|
7020
|
+
/**
|
|
7021
|
+
* @private Make a HTTP request to a specific endpoint. Private endpoint API calls are automatically signed.
|
|
7022
|
+
*/
|
|
7023
|
+
private async _call(
|
|
7024
|
+
method: Method,
|
|
7025
|
+
endpoint: string,
|
|
7026
|
+
params?: any,
|
|
7027
|
+
isPublicApi?: boolean,
|
|
7028
|
+
): Promise<any>
|
|
7029
|
+
⋮----
|
|
7030
|
+
// Sanity check to make sure it's only ever prefixed by one forward slash
|
|
7031
|
+
⋮----
|
|
7032
|
+
// Build a request and handle signature process
|
|
7033
|
+
⋮----
|
|
7034
|
+
// Dispatch request
|
|
7035
|
+
⋮----
|
|
7036
|
+
// Throw if API returns an error (e.g. insufficient balance)
|
|
7037
|
+
⋮----
|
|
7038
|
+
/**
|
|
7039
|
+
* @private generic handler to parse request exceptions
|
|
7040
|
+
*/
|
|
7041
|
+
parseException(e: any, requestParams: any): unknown
|
|
7042
|
+
⋮----
|
|
7043
|
+
// Something happened in setting up the request that triggered an error
|
|
7044
|
+
⋮----
|
|
7045
|
+
// request made but no response received
|
|
7046
|
+
⋮----
|
|
7047
|
+
// The request was made and the server responded with a status code
|
|
7048
|
+
// that falls out of the range of 2xx
|
|
7049
|
+
⋮----
|
|
7050
|
+
// console.error('err: ', response?.data);
|
|
7051
|
+
⋮----
|
|
7052
|
+
// Prevent credentials from leaking into error messages
|
|
7053
|
+
⋮----
|
|
7054
|
+
/**
|
|
7055
|
+
* @private sign request and set recv window
|
|
7056
|
+
*/
|
|
7057
|
+
private async signRequest<T extends object | undefined = {}>(
|
|
7058
|
+
data: T,
|
|
7059
|
+
endpoint: string,
|
|
7060
|
+
method: Method,
|
|
7061
|
+
signMethod: SignMethod,
|
|
7062
|
+
): Promise<SignedRequest<T>>
|
|
7063
|
+
⋮----
|
|
7064
|
+
private async prepareSignParams<TParams extends object | undefined>(
|
|
7065
|
+
method: Method,
|
|
7066
|
+
endpoint: string,
|
|
7067
|
+
signMethod: SignMethod,
|
|
7068
|
+
params?: TParams,
|
|
7069
|
+
isPublicApi?: true,
|
|
7070
|
+
): Promise<UnsignedRequest<TParams>>;
|
|
7071
|
+
⋮----
|
|
7072
|
+
private async prepareSignParams<TParams extends object | undefined>(
|
|
7073
|
+
method: Method,
|
|
7074
|
+
endpoint: string,
|
|
7075
|
+
signMethod: SignMethod,
|
|
7076
|
+
params?: TParams,
|
|
7077
|
+
isPublicApi?: false | undefined,
|
|
7078
|
+
): Promise<SignedRequest<TParams>>;
|
|
7079
|
+
⋮----
|
|
7080
|
+
private async prepareSignParams<TParams extends object | undefined>(
|
|
7081
|
+
method: Method,
|
|
7082
|
+
endpoint: string,
|
|
7083
|
+
signMethod: SignMethod,
|
|
7084
|
+
params?: TParams,
|
|
7085
|
+
isPublicApi?: boolean,
|
|
7086
|
+
)
|
|
7087
|
+
⋮----
|
|
7088
|
+
/** Returns an axios request object. Handles signing process automatically if this is a private API call */
|
|
7089
|
+
private async buildRequest(
|
|
7090
|
+
method: Method,
|
|
7091
|
+
endpoint: string,
|
|
7092
|
+
url: string,
|
|
7093
|
+
params?: any,
|
|
7094
|
+
isPublicApi?: boolean,
|
|
7095
|
+
): Promise<AxiosRequestConfig>
|
|
7096
|
+
|
|
7097
|
+
================
|
|
7098
|
+
File: src/types/response/spot-funding.ts
|
|
7099
|
+
================
|
|
7100
|
+
/**
|
|
7101
|
+
*
|
|
7102
|
+
***********
|
|
7103
|
+
* Funding
|
|
7104
|
+
***********
|
|
7105
|
+
*
|
|
7106
|
+
*/
|
|
7107
|
+
⋮----
|
|
7108
|
+
export interface MarginAccountBalance {
|
|
7109
|
+
currency: string;
|
|
7110
|
+
totalBalance: string;
|
|
7111
|
+
availableBalance: string;
|
|
7112
|
+
holdBalance: string;
|
|
7113
|
+
liability: string;
|
|
7114
|
+
maxBorrowSize: string;
|
|
7115
|
+
}
|
|
7116
|
+
⋮----
|
|
7117
|
+
export interface MarginAccountDetail {
|
|
7118
|
+
currency: string;
|
|
7119
|
+
total: string;
|
|
7120
|
+
available: string;
|
|
7121
|
+
hold: string;
|
|
7122
|
+
liability: string;
|
|
7123
|
+
liabilityPrincipal: string;
|
|
7124
|
+
liabilityInterest: string;
|
|
7125
|
+
maxBorrowSize: string;
|
|
7126
|
+
borrowEnabled: boolean;
|
|
7127
|
+
transferInEnabled: boolean;
|
|
7128
|
+
}
|
|
7129
|
+
⋮----
|
|
7130
|
+
export interface MarginBalance {
|
|
7131
|
+
totalAssetOfQuoteCurrency: string;
|
|
7132
|
+
totalLiabilityOfQuoteCurrency: string;
|
|
7133
|
+
debtRatio: string;
|
|
7134
|
+
status: 'EFFECTIVE' | 'BANKRUPTCY' | 'LIQUIDATION' | 'REPAY' | 'BORROW';
|
|
7135
|
+
accounts: MarginAccountDetail[];
|
|
7136
|
+
}
|
|
7137
|
+
export interface IsolatedMarginAssetDetail {
|
|
7138
|
+
symbol: string;
|
|
7139
|
+
debtRatio: string;
|
|
7140
|
+
status: 'EFFECTIVE' | 'BANKRUPTCY' | 'LIQUIDATION' | 'REPAY' | 'BORROW';
|
|
7141
|
+
baseAsset: MarginAccountDetail;
|
|
7142
|
+
quoteAsset: MarginAccountDetail;
|
|
7143
|
+
}
|
|
7144
|
+
⋮----
|
|
7145
|
+
export interface IsolatedMarginBalance {
|
|
7146
|
+
totalAssetOfQuoteCurrency: string;
|
|
7147
|
+
totalLiabilityOfQuoteCurrency: string;
|
|
7148
|
+
timestamp: number;
|
|
7149
|
+
assets: IsolatedMarginAssetDetail[];
|
|
7150
|
+
}
|
|
7151
|
+
⋮----
|
|
7152
|
+
/**
|
|
7153
|
+
*
|
|
7154
|
+
* Deposit
|
|
7155
|
+
*
|
|
7156
|
+
*/
|
|
7157
|
+
⋮----
|
|
7158
|
+
export interface DepositAddress {
|
|
7159
|
+
address: string;
|
|
7160
|
+
memo: string;
|
|
7161
|
+
chain: string;
|
|
7162
|
+
}
|
|
7163
|
+
⋮----
|
|
7164
|
+
export type DepositAddressV2 = DepositAddress & {
|
|
7165
|
+
contractAddress: string;
|
|
7166
|
+
};
|
|
6769
7167
|
⋮----
|
|
6770
7168
|
export interface DepositAddressV3 {
|
|
6771
7169
|
address: string;
|
|
@@ -6888,435 +7286,61 @@ export interface WithdrawalQuotas {
|
|
|
6888
7286
|
remainAmount: string;
|
|
6889
7287
|
availableAmount: string;
|
|
6890
7288
|
withdrawMinFee: string;
|
|
6891
|
-
innerWithdrawMinFee: string;
|
|
6892
|
-
withdrawMinSize: string;
|
|
6893
|
-
isWithdrawEnabled: boolean;
|
|
6894
|
-
precision: number;
|
|
6895
|
-
chain: string;
|
|
6896
|
-
reason: string | null;
|
|
6897
|
-
lockedAmount: string;
|
|
6898
|
-
}
|
|
6899
|
-
⋮----
|
|
6900
|
-
export interface WithdrawalById {
|
|
6901
|
-
id: string;
|
|
6902
|
-
uid: number;
|
|
6903
|
-
currency: string;
|
|
6904
|
-
chainId: string;
|
|
6905
|
-
chainName: string;
|
|
6906
|
-
currencyName: string;
|
|
6907
|
-
status: string;
|
|
6908
|
-
failureReason: string;
|
|
6909
|
-
failureReasonMsg: string | null;
|
|
6910
|
-
address: string;
|
|
6911
|
-
memo: string;
|
|
6912
|
-
isInner: boolean;
|
|
6913
|
-
amount: string;
|
|
6914
|
-
fee: string;
|
|
6915
|
-
walletTxId: string | null;
|
|
6916
|
-
addressRemark: string | null;
|
|
6917
|
-
remark: string;
|
|
6918
|
-
createdAt: number;
|
|
6919
|
-
cancelType: string;
|
|
6920
|
-
taxes: string | null;
|
|
6921
|
-
taxDescription: string | null;
|
|
6922
|
-
returnStatus: string;
|
|
6923
|
-
returnAmount: string | null;
|
|
6924
|
-
returnCurrency: string;
|
|
6925
|
-
}
|
|
6926
|
-
⋮----
|
|
6927
|
-
/**
|
|
6928
|
-
*
|
|
6929
|
-
* Transfer
|
|
6930
|
-
*
|
|
6931
|
-
*/
|
|
6932
|
-
⋮----
|
|
6933
|
-
export interface TransferableFunds {
|
|
6934
|
-
currency: string; // Currency
|
|
6935
|
-
balance: string; // Total funds in an account.
|
|
6936
|
-
available: string; // Funds available to withdraw or trade.
|
|
6937
|
-
holds: string; // Funds on hold (not available for use).
|
|
6938
|
-
transferable: string; // Funds available to transfer.
|
|
6939
|
-
}
|
|
6940
|
-
⋮----
|
|
6941
|
-
currency: string; // Currency
|
|
6942
|
-
balance: string; // Total funds in an account.
|
|
6943
|
-
available: string; // Funds available to withdraw or trade.
|
|
6944
|
-
holds: string; // Funds on hold (not available for use).
|
|
6945
|
-
transferable: string; // Funds available to transfer.
|
|
6946
|
-
|
|
6947
|
-
================
|
|
6948
|
-
File: README.md
|
|
6949
|
-
================
|
|
6950
|
-
# Node.js & JavaScript SDK for Kucoin REST APIs & Websockets
|
|
6951
|
-
|
|
6952
|
-
<p align="center">
|
|
6953
|
-
<a href="https://www.npmjs.com/package/kucoin-api">
|
|
6954
|
-
<picture>
|
|
6955
|
-
<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">
|
|
6956
|
-
<img alt="SDK Logo" src="https://github.com/tiagosiebler/kucoin-api/blob/master/docs/images/logoBrightMode2.svg?raw=true#gh-light-mode-only">
|
|
6957
|
-
</picture>
|
|
6958
|
-
</a>
|
|
6959
|
-
</p>
|
|
6960
|
-
|
|
6961
|
-
[][1]
|
|
6962
|
-
[][1]
|
|
6963
|
-
[][1]
|
|
6964
|
-
[](https://github.com/tiagosiebler/kucoin-api/actions/workflows/e2etest.yml)
|
|
6965
|
-
[][1]
|
|
6966
|
-
[](https://t.me/nodetraders)
|
|
6967
|
-
|
|
6968
|
-
[1]: https://www.npmjs.com/package/kucoin-api
|
|
6969
|
-
|
|
6970
|
-
Updated & performant JavaScript & Node.js SDK for the Kucoin REST APIs and WebSockets:
|
|
6971
|
-
|
|
6972
|
-
- Professional, robust & performant Kucoin SDK with extensive production use in live trading environments.
|
|
6973
|
-
- Complete integration with all Kucoin REST APIs and WebSockets.
|
|
6974
|
-
- Dedicated REST clients for Spot, Futures, and Broker operations
|
|
6975
|
-
- Unified WebSocket client for all markets
|
|
6976
|
-
- Complete TypeScript support (with type declarations for most API requests & responses).
|
|
6977
|
-
- Strongly typed requests and responses.
|
|
6978
|
-
- Automated end-to-end tests ensuring reliability.
|
|
6979
|
-
- Actively maintained with a modern, promise-driven interface.
|
|
6980
|
-
- Robust WebSocket integration with configurable connection heartbeats & automatic reconnect then resubscribe workflows.
|
|
6981
|
-
- Event driven messaging.
|
|
6982
|
-
- Smart WebSocket persistence with automatic reconnection handling.
|
|
6983
|
-
- Emit `reconnected` event when dropped connection is restored.
|
|
6984
|
-
- Support for both public and private WebSocket streams.
|
|
6985
|
-
- Browser-friendly HMAC signature mechanism.
|
|
6986
|
-
- Automatically supports both ESM and CJS projects.
|
|
6987
|
-
- Heavy automated end-to-end testing with real API calls.
|
|
6988
|
-
- Proxy support via axios integration.
|
|
6989
|
-
- Active community support & collaboration in telegram: [Node.js Algo Traders](https://t.me/nodetraders).
|
|
6990
|
-
|
|
6991
|
-
## Table of Contents
|
|
6992
|
-
|
|
6993
|
-
- [Installation](#installation)
|
|
6994
|
-
- [Examples](#examples)
|
|
6995
|
-
- [Issues & Discussion](#issues--discussion)
|
|
6996
|
-
- [Related Projects](#related-projects)
|
|
6997
|
-
- [Documentation](#documentation)
|
|
6998
|
-
- [Structure](#structure)
|
|
6999
|
-
- [Usage](#usage)
|
|
7000
|
-
- [REST API Clients](#rest-api)
|
|
7001
|
-
- [Spot & Margin Trading](#spot--margin-trading)
|
|
7002
|
-
- [Futures Trading](#futures-trading)
|
|
7003
|
-
- [Broker Operations](#broker-operations)
|
|
7004
|
-
- [WebSocket Client](#websockets)
|
|
7005
|
-
- [Public WebSocket Streams](#public-websocket-streams)
|
|
7006
|
-
- [Private WebSocket Streams](#private-websocket-streams)
|
|
7007
|
-
- [Customise Logging](#customise-logging)
|
|
7008
|
-
- [LLMs & AI](#use-with-llms--ai)
|
|
7009
|
-
- [Used By](#used-by)
|
|
7010
|
-
- [Contributions & Thanks](#contributions--thanks)
|
|
7011
|
-
|
|
7012
|
-
## Installation
|
|
7013
|
-
|
|
7014
|
-
`npm install --save kucoin-api`
|
|
7015
|
-
|
|
7016
|
-
## Examples
|
|
7017
|
-
|
|
7018
|
-
Refer to the [examples](./examples) folder for implementation demos.
|
|
7019
|
-
|
|
7020
|
-
## Issues & Discussion
|
|
7021
|
-
|
|
7022
|
-
- Issues? Check the [issues tab](https://github.com/tiagosiebler/kucoin-api/issues).
|
|
7023
|
-
- Discuss & collaborate with other node devs? Join our [Node.js Algo Traders](https://t.me/nodetraders) engineering community on telegram.
|
|
7024
|
-
- Follow our announcement channel for real-time updates on [X/Twitter](https://x.com/sieblyio)
|
|
7025
|
-
|
|
7026
|
-
<!-- template_related_projects -->
|
|
7027
|
-
|
|
7028
|
-
## Related projects
|
|
7029
|
-
|
|
7030
|
-
Check out my related JavaScript/TypeScript/Node.js projects:
|
|
7031
|
-
|
|
7032
|
-
- Try my REST API & WebSocket SDKs:
|
|
7033
|
-
- [Bybit-api Node.js SDK](https://www.npmjs.com/package/bybit-api)
|
|
7034
|
-
- [Okx-api Node.js SDK](https://www.npmjs.com/package/okx-api)
|
|
7035
|
-
- [Binance Node.js SDK](https://www.npmjs.com/package/binance)
|
|
7036
|
-
- [Gateio-api Node.js SDK](https://www.npmjs.com/package/gateio-api)
|
|
7037
|
-
- [Bitget-api Node.js SDK](https://www.npmjs.com/package/bitget-api)
|
|
7038
|
-
- [Kucoin-api Node.js SDK](https://www.npmjs.com/package/kucoin-api)
|
|
7039
|
-
- [Coinbase-api Node.js SDK](https://www.npmjs.com/package/coinbase-api)
|
|
7040
|
-
- [Bitmart-api Node.js SDK](https://www.npmjs.com/package/bitmart-api)
|
|
7041
|
-
- Try my misc utilities:
|
|
7042
|
-
- [OrderBooks Node.js](https://www.npmjs.com/package/orderbooks)
|
|
7043
|
-
- [Crypto Exchange Account State Cache](https://www.npmjs.com/package/accountstate)
|
|
7044
|
-
- Check out my examples:
|
|
7045
|
-
- [awesome-crypto-examples Node.js](https://github.com/tiagosiebler/awesome-crypto-examples)
|
|
7046
|
-
<!-- template_related_projects_end -->
|
|
7047
|
-
|
|
7048
|
-
## Documentation
|
|
7049
|
-
|
|
7050
|
-
Most methods accept JS objects. These can be populated using parameters specified by Kucoin's API documentation, or check the type definition in each class within this repository.
|
|
7051
|
-
|
|
7052
|
-
### API Documentation Links
|
|
7053
|
-
|
|
7054
|
-
- [Kucoin API Documentation](https://www.kucoin.com/docs-new/introduction)
|
|
7055
|
-
|
|
7056
|
-
### SDK Documentation & Guides
|
|
7057
|
-
|
|
7058
|
-
- Node.js Quick Start Guides
|
|
7059
|
-
- [Spot Node.js Kucoin Quick Start Guide](./examples/kucoin-SPOT-examples-nodejs.md)
|
|
7060
|
-
- [Futures Node.js Kucoin Quick Start Guide](./examples/kucoin-FUTURES-examples-nodejs.md)
|
|
7061
|
-
- [Futures Node.js Kucoin Order Placement Guide](./examples/rest-futures-orders-guide.ts)
|
|
7062
|
-
- [REST Endpoint Function List](./docs/endpointFunctionList.md)
|
|
7063
|
-
|
|
7064
|
-
## Structure
|
|
7065
|
-
|
|
7066
|
-
This project uses typescript. Resources are stored in 2 key structures:
|
|
7067
|
-
|
|
7068
|
-
- [src](./src) - the whole connector written in typescript
|
|
7069
|
-
- [examples](./examples) - some implementation examples & demonstrations. Contributions are welcome!
|
|
7070
|
-
|
|
7071
|
-
---
|
|
7072
|
-
|
|
7073
|
-
# Usage
|
|
7074
|
-
|
|
7075
|
-
Create API credentials on Kucoin's website:
|
|
7076
|
-
|
|
7077
|
-
- [Kucoin API Key Management](https://www.kucoin.com/account/api)
|
|
7078
|
-
|
|
7079
|
-
## REST API
|
|
7080
|
-
|
|
7081
|
-
The SDK provides dedicated REST clients for different trading products:
|
|
7082
|
-
|
|
7083
|
-
- **SpotClient** - for spot trading and margin operations
|
|
7084
|
-
- **FuturesClient** - for futures trading operations
|
|
7085
|
-
- **BrokerClient** - for broker and sub-account management
|
|
7086
|
-
|
|
7087
|
-
### Spot & Margin Trading
|
|
7088
|
-
|
|
7089
|
-
To use Kucoin's Spot and Margin APIs, import (or require) the `SpotClient`:
|
|
7090
|
-
|
|
7091
|
-
```javascript
|
|
7092
|
-
const { SpotClient, FuturesClient } = require('kucoin-api');
|
|
7093
|
-
|
|
7094
|
-
const client = new SpotClient({
|
|
7095
|
-
apiKey: 'apiKeyHere',
|
|
7096
|
-
apiSecret: 'apiSecretHere',
|
|
7097
|
-
apiPassphrase: 'apiPassPhraseHere',
|
|
7098
|
-
});
|
|
7099
|
-
|
|
7100
|
-
try {
|
|
7101
|
-
const spotBuyResult = await client.submitHFOrder({
|
|
7102
|
-
clientOid: client.generateNewOrderID(),
|
|
7103
|
-
side: 'buy',
|
|
7104
|
-
type: 'market',
|
|
7105
|
-
symbol: 'BTC-USDT',
|
|
7106
|
-
size: '0.00001',
|
|
7107
|
-
});
|
|
7108
|
-
console.log('spotBuy ', JSON.stringify(spotBuyResult, null, 2));
|
|
7109
|
-
|
|
7110
|
-
const spotSellResult = await client.submitHFOrder({
|
|
7111
|
-
clientOid: client.generateNewOrderID(),
|
|
7112
|
-
side: 'sell',
|
|
7113
|
-
type: 'market',
|
|
7114
|
-
symbol: 'BTC-USDT',
|
|
7115
|
-
size: '0.00001',
|
|
7116
|
-
});
|
|
7117
|
-
console.log('spotSellResult ', JSON.stringify(spotSellResult, null, 2));
|
|
7118
|
-
} catch (e) {
|
|
7119
|
-
console.error(`Req error: `, e);
|
|
7120
|
-
}
|
|
7121
|
-
```
|
|
7122
|
-
|
|
7123
|
-
See [SpotClient](./src/SpotClient.ts) for further information, or the [examples](./examples/) for lots of usage examples.
|
|
7124
|
-
|
|
7125
|
-
### Futures Trading
|
|
7126
|
-
|
|
7127
|
-
Use the `FuturesClient` for futures trading operations. See [FuturesClient](./src/FuturesClient.ts) for complete API coverage.
|
|
7128
|
-
|
|
7129
|
-
### Broker Operations
|
|
7130
|
-
|
|
7131
|
-
Use the `BrokerClient` for broker and sub-account management operations. See [BrokerClient](./src/BrokerClient.ts) for complete API coverage.
|
|
7132
|
-
|
|
7133
|
-
## WebSockets
|
|
7134
|
-
|
|
7135
|
-
All WebSocket functionality is supported via the unified `WebsocketClient`. This client handles both spot and futures WebSocket streams with automatic connection management and reconnection.
|
|
7136
|
-
|
|
7137
|
-
Key WebSocket features:
|
|
7138
|
-
|
|
7139
|
-
- Event driven messaging
|
|
7140
|
-
- Smart WebSocket persistence with automatic reconnection
|
|
7141
|
-
- Heartbeat mechanisms to detect disconnections
|
|
7142
|
-
- Automatic resubscription after reconnection
|
|
7143
|
-
- Support for both public and private WebSocket streams
|
|
7144
|
-
- Unified client for spot and futures markets
|
|
7145
|
-
|
|
7146
|
-
### Public WebSocket Streams
|
|
7147
|
-
|
|
7148
|
-
For public market data, API credentials are not required:
|
|
7149
|
-
|
|
7150
|
-
All available WebSockets can be used via a shared `WebsocketClient`. The WebSocket client will automatically open/track/manage connections as needed. Each unique connection (one per server URL) is tracked using a WsKey (each WsKey is a string - see [WS_KEY_MAP](src/lib/websocket/websocket-util.ts) for a list of supported values).
|
|
7151
|
-
|
|
7152
|
-
Any subscribe/unsubscribe events will need to include a WsKey, so the WebSocket client understands which connection the event should be routed to. See examples below or in the [examples](./examples/) folder on GitHub.
|
|
7153
|
-
|
|
7154
|
-
Data events are emitted from the WebsocketClient via the `update` event, see example below:
|
|
7155
|
-
|
|
7156
|
-
```javascript
|
|
7157
|
-
const { WebsocketClient } = require('kucoin-api');
|
|
7158
|
-
|
|
7159
|
-
const client = new WebsocketClient();
|
|
7160
|
-
|
|
7161
|
-
client.on('open', (data) => {
|
|
7162
|
-
console.log('open: ', data?.wsKey);
|
|
7163
|
-
});
|
|
7164
|
-
|
|
7165
|
-
// Data received
|
|
7166
|
-
client.on('update', (data) => {
|
|
7167
|
-
console.info('data received: ', JSON.stringify(data));
|
|
7168
|
-
});
|
|
7169
|
-
|
|
7170
|
-
// Something happened, attempting to reconenct
|
|
7171
|
-
client.on('reconnect', (data) => {
|
|
7172
|
-
console.log('reconnect: ', data);
|
|
7173
|
-
});
|
|
7174
|
-
|
|
7175
|
-
// Reconnect successful
|
|
7176
|
-
client.on('reconnected', (data) => {
|
|
7177
|
-
console.log('reconnected: ', data);
|
|
7178
|
-
});
|
|
7179
|
-
|
|
7180
|
-
// Connection closed. If unexpected, expect reconnect -> reconnected.
|
|
7181
|
-
client.on('close', (data) => {
|
|
7182
|
-
console.error('close: ', data);
|
|
7183
|
-
});
|
|
7184
|
-
|
|
7185
|
-
// Reply to a request, e.g. "subscribe"/"unsubscribe"/"authenticate"
|
|
7186
|
-
client.on('response', (data) => {
|
|
7187
|
-
console.info('response: ', data);
|
|
7188
|
-
// throw new Error('res?');
|
|
7189
|
-
});
|
|
7190
|
-
|
|
7191
|
-
client.on('exception', (data) => {
|
|
7192
|
-
console.error('exception: ', {
|
|
7193
|
-
msg: data.msg,
|
|
7194
|
-
errno: data.errno,
|
|
7195
|
-
code: data.code,
|
|
7196
|
-
syscall: data.syscall,
|
|
7197
|
-
hostname: data.hostname,
|
|
7198
|
-
});
|
|
7199
|
-
});
|
|
7200
|
-
|
|
7201
|
-
try {
|
|
7202
|
-
// Optional: await a connection to be ready before subscribing (this is not necessary)
|
|
7203
|
-
// await client.connect('futuresPublicV1');
|
|
7204
|
-
|
|
7205
|
-
/**
|
|
7206
|
-
* Examples for public futures websocket topics (that don't require authentication).
|
|
7207
|
-
*
|
|
7208
|
-
* These should all subscribe via the "futuresPublicV1" wsKey. For detailed usage, refer to the ws-spot-public.ts example.
|
|
7209
|
-
*/
|
|
7210
|
-
client.subscribe(
|
|
7211
|
-
[
|
|
7212
|
-
'/contractMarket/tickerV2:XBTUSDM',
|
|
7213
|
-
'/contractMarket/ticker:XBTUSDM',
|
|
7214
|
-
'/contractMarket/level2:XBTUSDM',
|
|
7215
|
-
'/contractMarket/execution:XBTUSDM',
|
|
7216
|
-
'/contractMarket/level2Depth5:XBTUSDM',
|
|
7217
|
-
'/contractMarket/level2Depth50:XBTUSDM',
|
|
7218
|
-
'/contractMarket/limitCandle:XBTUSDTM_1hour',
|
|
7219
|
-
'/contract/instrument:XBTUSDM',
|
|
7220
|
-
'/contract/announcement',
|
|
7221
|
-
'/contractMarket/snapshot:XBTUSDM',
|
|
7222
|
-
],
|
|
7223
|
-
'futuresPublicV1',
|
|
7224
|
-
);
|
|
7225
|
-
} catch (e) {
|
|
7226
|
-
console.error(`Subscribe exception: `, e);
|
|
7227
|
-
}
|
|
7228
|
-
```
|
|
7229
|
-
|
|
7230
|
-
### Private WebSocket Streams
|
|
7231
|
-
|
|
7232
|
-
For private account data streams, API credentials are required. The WebsocketClient will automatically handle authentication when you provide API credentials.
|
|
7233
|
-
|
|
7234
|
-
See [WebsocketClient](./src/WebsocketClient.ts) for further information and make sure to check the [examples](./examples/) folder for much more detail, especially [ws-spot-public.ts](./examples/ws-spot-public.ts), which explains a lot of detail.
|
|
7235
|
-
|
|
7236
|
-
---
|
|
7237
|
-
|
|
7238
|
-
## Customise Logging
|
|
7239
|
-
|
|
7240
|
-
Pass a custom logger which supports the log methods `trace`, `info` and `error`, or override methods from the default logger as desired.
|
|
7241
|
-
|
|
7242
|
-
```javascript
|
|
7243
|
-
const { WebsocketClient, DefaultLogger } = require('kucoin-api');
|
|
7244
|
-
|
|
7245
|
-
// E.g. customise logging for only the trace level:
|
|
7246
|
-
const logger = {
|
|
7247
|
-
// Inherit existing logger methods, using an object spread
|
|
7248
|
-
...DefaultLogger,
|
|
7249
|
-
// Define a custom trace function to override only that function
|
|
7250
|
-
trace: (...params) => {
|
|
7251
|
-
if (
|
|
7252
|
-
[
|
|
7253
|
-
'Sending ping',
|
|
7254
|
-
// 'Sending upstream ws message: ',
|
|
7255
|
-
'Received pong',
|
|
7256
|
-
].includes(params[0])
|
|
7257
|
-
) {
|
|
7258
|
-
return;
|
|
7259
|
-
}
|
|
7260
|
-
console.log('trace', JSON.stringify(params, null, 2));
|
|
7261
|
-
},
|
|
7262
|
-
};
|
|
7263
|
-
|
|
7264
|
-
const ws = new WebsocketClient(
|
|
7265
|
-
{
|
|
7266
|
-
apiKey: 'apiKeyHere',
|
|
7267
|
-
apiSecret: 'apiSecretHere',
|
|
7268
|
-
apiPassphrase: 'apiPassPhraseHere',
|
|
7269
|
-
},
|
|
7270
|
-
logger,
|
|
7271
|
-
);
|
|
7272
|
-
```
|
|
7273
|
-
|
|
7274
|
-
## Use with LLMs & AI
|
|
7275
|
-
|
|
7276
|
-
This SDK includes a bundled `llms.txt` file in the root of the repository. If you're developing with LLMs, use the included `llms.txt` with your LLM - it will significantly improve the LLMs understanding of how to correctly use this SDK.
|
|
7277
|
-
|
|
7278
|
-
This file contains AI optimised structure of all the functions in this package, and their parameters for easier use with any learning models or artificial intelligence.
|
|
7279
|
-
|
|
7280
|
-
---
|
|
7281
|
-
|
|
7282
|
-
## Used By
|
|
7283
|
-
|
|
7284
|
-
[](https://github.com/tiagosiebler/kucoin-api/network/dependents)
|
|
7285
|
-
|
|
7286
|
-
---
|
|
7287
|
-
|
|
7288
|
-
<!-- template_contributions -->
|
|
7289
|
-
|
|
7290
|
-
### Contributions & Thanks
|
|
7291
|
-
|
|
7292
|
-
Have my projects helped you? Share the love, there are many ways you can show your thanks:
|
|
7293
|
-
|
|
7294
|
-
- Star & share my projects.
|
|
7295
|
-
- Are my projects useful? Sponsor me on Github and support my effort to maintain & improve them: https://github.com/sponsors/tiagosiebler
|
|
7296
|
-
- Have an interesting project? Get in touch & invite me to it.
|
|
7297
|
-
- Or buy me all the coffee:
|
|
7298
|
-
- ETH(ERC20): `0xA3Bda8BecaB4DCdA539Dc16F9C54a592553Be06C` <!-- metamask -->
|
|
7299
|
-
|
|
7300
|
-
<!---
|
|
7301
|
-
old ones:
|
|
7302
|
-
- BTC: `1C6GWZL1XW3jrjpPTS863XtZiXL1aTK7Jk`
|
|
7303
|
-
- BTC(SegWit): `bc1ql64wr9z3khp2gy7dqlmqw7cp6h0lcusz0zjtls`
|
|
7304
|
-
- ETH(ERC20): `0xe0bbbc805e0e83341fadc210d6202f4022e50992`
|
|
7305
|
-
- USDT(TRC20): `TA18VUywcNEM9ahh3TTWF3sFpt9rkLnnQa
|
|
7306
|
-
-->
|
|
7307
|
-
<!-- template_contributions_end -->
|
|
7308
|
-
|
|
7309
|
-
### Contributions & Pull Requests
|
|
7310
|
-
|
|
7311
|
-
Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.
|
|
7312
|
-
|
|
7313
|
-
<!-- template_star_history -->
|
|
7314
|
-
|
|
7315
|
-
## Star History
|
|
7316
|
-
|
|
7317
|
-
[](https://star-history.com/#tiagosiebler/bybit-api&tiagosiebler/okx-api&tiagosiebler/binance&tiagosiebler/bitget-api&tiagosiebler/bitmart-api&tiagosiebler/gateio-api&tiagosiebler/kucoin-api&tiagosiebler/coinbase-api&tiagosiebler/orderbooks&tiagosiebler/accountstate&tiagosiebler/awesome-crypto-examples&Date)
|
|
7318
|
-
|
|
7319
|
-
<!-- template_star_history_end -->
|
|
7289
|
+
innerWithdrawMinFee: string;
|
|
7290
|
+
withdrawMinSize: string;
|
|
7291
|
+
isWithdrawEnabled: boolean;
|
|
7292
|
+
precision: number;
|
|
7293
|
+
chain: string;
|
|
7294
|
+
reason: string | null;
|
|
7295
|
+
lockedAmount: string;
|
|
7296
|
+
}
|
|
7297
|
+
⋮----
|
|
7298
|
+
export interface WithdrawalById {
|
|
7299
|
+
id: string;
|
|
7300
|
+
uid: number;
|
|
7301
|
+
currency: string;
|
|
7302
|
+
chainId: string;
|
|
7303
|
+
chainName: string;
|
|
7304
|
+
currencyName: string;
|
|
7305
|
+
status: string;
|
|
7306
|
+
failureReason: string;
|
|
7307
|
+
failureReasonMsg: string | null;
|
|
7308
|
+
address: string;
|
|
7309
|
+
memo: string;
|
|
7310
|
+
isInner: boolean;
|
|
7311
|
+
amount: string;
|
|
7312
|
+
fee: string;
|
|
7313
|
+
walletTxId: string | null;
|
|
7314
|
+
addressRemark: string | null;
|
|
7315
|
+
remark: string;
|
|
7316
|
+
createdAt: number;
|
|
7317
|
+
cancelType: string;
|
|
7318
|
+
taxes: string | null;
|
|
7319
|
+
taxDescription: string | null;
|
|
7320
|
+
returnStatus: string;
|
|
7321
|
+
returnAmount: string | null;
|
|
7322
|
+
returnCurrency: string;
|
|
7323
|
+
}
|
|
7324
|
+
⋮----
|
|
7325
|
+
/**
|
|
7326
|
+
*
|
|
7327
|
+
* Transfer
|
|
7328
|
+
*
|
|
7329
|
+
*/
|
|
7330
|
+
⋮----
|
|
7331
|
+
export interface TransferableFunds {
|
|
7332
|
+
currency: string; // Currency
|
|
7333
|
+
balance: string; // Total funds in an account.
|
|
7334
|
+
available: string; // Funds available to withdraw or trade.
|
|
7335
|
+
holds: string; // Funds on hold (not available for use).
|
|
7336
|
+
transferable: string; // Funds available to transfer.
|
|
7337
|
+
}
|
|
7338
|
+
⋮----
|
|
7339
|
+
currency: string; // Currency
|
|
7340
|
+
balance: string; // Total funds in an account.
|
|
7341
|
+
available: string; // Funds available to withdraw or trade.
|
|
7342
|
+
holds: string; // Funds on hold (not available for use).
|
|
7343
|
+
transferable: string; // Funds available to transfer.
|
|
7320
7344
|
|
|
7321
7345
|
================
|
|
7322
7346
|
File: src/types/response/futures.types.ts
|
|
@@ -8199,6 +8223,380 @@ export interface CopyTradePosition {
|
|
|
8199
8223
|
settleCurrency: string;
|
|
8200
8224
|
}
|
|
8201
8225
|
|
|
8226
|
+
================
|
|
8227
|
+
File: README.md
|
|
8228
|
+
================
|
|
8229
|
+
# Node.js & JavaScript SDK for Kucoin REST APIs & Websockets
|
|
8230
|
+
|
|
8231
|
+
<p align="center">
|
|
8232
|
+
<a href="https://www.npmjs.com/package/kucoin-api">
|
|
8233
|
+
<picture>
|
|
8234
|
+
<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">
|
|
8235
|
+
<img alt="SDK Logo" src="https://github.com/tiagosiebler/kucoin-api/blob/master/docs/images/logoBrightMode2.svg?raw=true#gh-light-mode-only">
|
|
8236
|
+
</picture>
|
|
8237
|
+
</a>
|
|
8238
|
+
</p>
|
|
8239
|
+
|
|
8240
|
+
[][1]
|
|
8241
|
+
[][1]
|
|
8242
|
+
[][1]
|
|
8243
|
+
[](https://github.com/tiagosiebler/kucoin-api/actions/workflows/e2etest.yml)
|
|
8244
|
+
[][1]
|
|
8245
|
+
[](https://t.me/nodetraders)
|
|
8246
|
+
|
|
8247
|
+
[1]: https://www.npmjs.com/package/kucoin-api
|
|
8248
|
+
|
|
8249
|
+
Updated & performant JavaScript & Node.js SDK for the Kucoin REST APIs and WebSockets:
|
|
8250
|
+
|
|
8251
|
+
- Professional, robust & performant Kucoin SDK with extensive production use in live trading environments.
|
|
8252
|
+
- Complete integration with all Kucoin REST APIs and WebSockets.
|
|
8253
|
+
- Dedicated REST clients for Spot, Futures, and Broker operations
|
|
8254
|
+
- Unified WebSocket client for all markets
|
|
8255
|
+
- Complete TypeScript support (with type declarations for most API requests & responses).
|
|
8256
|
+
- Strongly typed requests and responses.
|
|
8257
|
+
- Automated end-to-end tests ensuring reliability.
|
|
8258
|
+
- Actively maintained with a modern, promise-driven interface.
|
|
8259
|
+
- Robust WebSocket integration with configurable connection heartbeats & automatic reconnect then resubscribe workflows.
|
|
8260
|
+
- Event driven messaging.
|
|
8261
|
+
- Smart WebSocket persistence with automatic reconnection handling.
|
|
8262
|
+
- Emit `reconnected` event when dropped connection is restored.
|
|
8263
|
+
- Support for both public and private WebSocket streams.
|
|
8264
|
+
- Browser-friendly HMAC signature mechanism.
|
|
8265
|
+
- Automatically supports both ESM and CJS projects.
|
|
8266
|
+
- Heavy automated end-to-end testing with real API calls.
|
|
8267
|
+
- Proxy support via axios integration.
|
|
8268
|
+
- Active community support & collaboration in telegram: [Node.js Algo Traders](https://t.me/nodetraders).
|
|
8269
|
+
|
|
8270
|
+
## Table of Contents
|
|
8271
|
+
|
|
8272
|
+
- [Installation](#installation)
|
|
8273
|
+
- [Examples](#examples)
|
|
8274
|
+
- [Issues & Discussion](#issues--discussion)
|
|
8275
|
+
- [Related Projects](#related-projects)
|
|
8276
|
+
- [Documentation](#documentation)
|
|
8277
|
+
- [Structure](#structure)
|
|
8278
|
+
- [Usage](#usage)
|
|
8279
|
+
- [REST API Clients](#rest-api)
|
|
8280
|
+
- [Spot & Margin Trading](#spot--margin-trading)
|
|
8281
|
+
- [Futures Trading](#futures-trading)
|
|
8282
|
+
- [Broker Operations](#broker-operations)
|
|
8283
|
+
- [WebSocket Client](#websockets)
|
|
8284
|
+
- [Public WebSocket Streams](#public-websocket-streams)
|
|
8285
|
+
- [Private WebSocket Streams](#private-websocket-streams)
|
|
8286
|
+
- [Customise Logging](#customise-logging)
|
|
8287
|
+
- [LLMs & AI](#use-with-llms--ai)
|
|
8288
|
+
- [Used By](#used-by)
|
|
8289
|
+
- [Contributions & Thanks](#contributions--thanks)
|
|
8290
|
+
|
|
8291
|
+
## Installation
|
|
8292
|
+
|
|
8293
|
+
`npm install --save kucoin-api`
|
|
8294
|
+
|
|
8295
|
+
## Examples
|
|
8296
|
+
|
|
8297
|
+
Refer to the [examples](./examples) folder for implementation demos.
|
|
8298
|
+
|
|
8299
|
+
## Issues & Discussion
|
|
8300
|
+
|
|
8301
|
+
- Issues? Check the [issues tab](https://github.com/tiagosiebler/kucoin-api/issues).
|
|
8302
|
+
- Discuss & collaborate with other node devs? Join our [Node.js Algo Traders](https://t.me/nodetraders) engineering community on telegram.
|
|
8303
|
+
- Follow our announcement channel for real-time updates on [X/Twitter](https://x.com/sieblyio)
|
|
8304
|
+
|
|
8305
|
+
<!-- template_related_projects -->
|
|
8306
|
+
|
|
8307
|
+
## Related projects
|
|
8308
|
+
|
|
8309
|
+
Check out my related JavaScript/TypeScript/Node.js projects:
|
|
8310
|
+
|
|
8311
|
+
- Try my REST API & WebSocket SDKs:
|
|
8312
|
+
- [Bybit-api Node.js SDK](https://www.npmjs.com/package/bybit-api)
|
|
8313
|
+
- [Okx-api Node.js SDK](https://www.npmjs.com/package/okx-api)
|
|
8314
|
+
- [Binance Node.js SDK](https://www.npmjs.com/package/binance)
|
|
8315
|
+
- [Gateio-api Node.js SDK](https://www.npmjs.com/package/gateio-api)
|
|
8316
|
+
- [Bitget-api Node.js SDK](https://www.npmjs.com/package/bitget-api)
|
|
8317
|
+
- [Kucoin-api Node.js SDK](https://www.npmjs.com/package/kucoin-api)
|
|
8318
|
+
- [Coinbase-api Node.js SDK](https://www.npmjs.com/package/coinbase-api)
|
|
8319
|
+
- [Bitmart-api Node.js SDK](https://www.npmjs.com/package/bitmart-api)
|
|
8320
|
+
- Try my misc utilities:
|
|
8321
|
+
- [OrderBooks Node.js](https://www.npmjs.com/package/orderbooks)
|
|
8322
|
+
- [Crypto Exchange Account State Cache](https://www.npmjs.com/package/accountstate)
|
|
8323
|
+
- Check out my examples:
|
|
8324
|
+
- [awesome-crypto-examples Node.js](https://github.com/tiagosiebler/awesome-crypto-examples)
|
|
8325
|
+
<!-- template_related_projects_end -->
|
|
8326
|
+
|
|
8327
|
+
## Documentation
|
|
8328
|
+
|
|
8329
|
+
Most methods accept JS objects. These can be populated using parameters specified by Kucoin's API documentation, or check the type definition in each class within this repository.
|
|
8330
|
+
|
|
8331
|
+
### API Documentation Links
|
|
8332
|
+
|
|
8333
|
+
- [Kucoin API Documentation](https://www.kucoin.com/docs-new/introduction)
|
|
8334
|
+
|
|
8335
|
+
### SDK Documentation & Guides
|
|
8336
|
+
|
|
8337
|
+
- Node.js Quick Start Guides
|
|
8338
|
+
- [Spot Node.js Kucoin Quick Start Guide](./examples/kucoin-SPOT-examples-nodejs.md)
|
|
8339
|
+
- [Futures Node.js Kucoin Quick Start Guide](./examples/kucoin-FUTURES-examples-nodejs.md)
|
|
8340
|
+
- [Futures Node.js Kucoin Order Placement Guide](./examples/rest-futures-orders-guide.ts)
|
|
8341
|
+
- [REST Endpoint Function List](./docs/endpointFunctionList.md)
|
|
8342
|
+
|
|
8343
|
+
## Structure
|
|
8344
|
+
|
|
8345
|
+
This project uses typescript. Resources are stored in 2 key structures:
|
|
8346
|
+
|
|
8347
|
+
- [src](./src) - the whole connector written in typescript
|
|
8348
|
+
- [examples](./examples) - some implementation examples & demonstrations. Contributions are welcome!
|
|
8349
|
+
|
|
8350
|
+
---
|
|
8351
|
+
|
|
8352
|
+
# Usage
|
|
8353
|
+
|
|
8354
|
+
Create API credentials on Kucoin's website:
|
|
8355
|
+
|
|
8356
|
+
- [Kucoin API Key Management](https://www.kucoin.com/account/api)
|
|
8357
|
+
|
|
8358
|
+
## REST API
|
|
8359
|
+
|
|
8360
|
+
The SDK provides dedicated REST clients for different trading products:
|
|
8361
|
+
|
|
8362
|
+
- **SpotClient** - for spot trading and margin operations
|
|
8363
|
+
- **FuturesClient** - for futures trading operations
|
|
8364
|
+
- **BrokerClient** - for broker and sub-account management
|
|
8365
|
+
|
|
8366
|
+
### Spot & Margin Trading
|
|
8367
|
+
|
|
8368
|
+
To use Kucoin's Spot and Margin APIs, import (or require) the `SpotClient`:
|
|
8369
|
+
|
|
8370
|
+
```javascript
|
|
8371
|
+
const { SpotClient, FuturesClient } = require('kucoin-api');
|
|
8372
|
+
|
|
8373
|
+
const client = new SpotClient({
|
|
8374
|
+
apiKey: 'apiKeyHere',
|
|
8375
|
+
apiSecret: 'apiSecretHere',
|
|
8376
|
+
apiPassphrase: 'apiPassPhraseHere',
|
|
8377
|
+
});
|
|
8378
|
+
|
|
8379
|
+
try {
|
|
8380
|
+
const spotBuyResult = await client.submitHFOrder({
|
|
8381
|
+
clientOid: client.generateNewOrderID(),
|
|
8382
|
+
side: 'buy',
|
|
8383
|
+
type: 'market',
|
|
8384
|
+
symbol: 'BTC-USDT',
|
|
8385
|
+
size: '0.00001',
|
|
8386
|
+
});
|
|
8387
|
+
console.log('spotBuy ', JSON.stringify(spotBuyResult, null, 2));
|
|
8388
|
+
|
|
8389
|
+
const spotSellResult = await client.submitHFOrder({
|
|
8390
|
+
clientOid: client.generateNewOrderID(),
|
|
8391
|
+
side: 'sell',
|
|
8392
|
+
type: 'market',
|
|
8393
|
+
symbol: 'BTC-USDT',
|
|
8394
|
+
size: '0.00001',
|
|
8395
|
+
});
|
|
8396
|
+
console.log('spotSellResult ', JSON.stringify(spotSellResult, null, 2));
|
|
8397
|
+
} catch (e) {
|
|
8398
|
+
console.error(`Req error: `, e);
|
|
8399
|
+
}
|
|
8400
|
+
```
|
|
8401
|
+
|
|
8402
|
+
See [SpotClient](./src/SpotClient.ts) for further information, or the [examples](./examples/) for lots of usage examples.
|
|
8403
|
+
|
|
8404
|
+
### Futures Trading
|
|
8405
|
+
|
|
8406
|
+
Use the `FuturesClient` for futures trading operations. See [FuturesClient](./src/FuturesClient.ts) for complete API coverage.
|
|
8407
|
+
|
|
8408
|
+
### Broker Operations
|
|
8409
|
+
|
|
8410
|
+
Use the `BrokerClient` for broker and sub-account management operations. See [BrokerClient](./src/BrokerClient.ts) for complete API coverage.
|
|
8411
|
+
|
|
8412
|
+
## WebSockets
|
|
8413
|
+
|
|
8414
|
+
All WebSocket functionality is supported via the unified `WebsocketClient`. This client handles both spot and futures WebSocket streams with automatic connection management and reconnection.
|
|
8415
|
+
|
|
8416
|
+
Key WebSocket features:
|
|
8417
|
+
|
|
8418
|
+
- Event driven messaging
|
|
8419
|
+
- Smart WebSocket persistence with automatic reconnection
|
|
8420
|
+
- Heartbeat mechanisms to detect disconnections
|
|
8421
|
+
- Automatic resubscription after reconnection
|
|
8422
|
+
- Support for both public and private WebSocket streams
|
|
8423
|
+
- Unified client for spot and futures markets
|
|
8424
|
+
|
|
8425
|
+
### Public WebSocket Streams
|
|
8426
|
+
|
|
8427
|
+
For public market data, API credentials are not required:
|
|
8428
|
+
|
|
8429
|
+
All available WebSockets can be used via a shared `WebsocketClient`. The WebSocket client will automatically open/track/manage connections as needed. Each unique connection (one per server URL) is tracked using a WsKey (each WsKey is a string - see [WS_KEY_MAP](src/lib/websocket/websocket-util.ts) for a list of supported values).
|
|
8430
|
+
|
|
8431
|
+
Any subscribe/unsubscribe events will need to include a WsKey, so the WebSocket client understands which connection the event should be routed to. See examples below or in the [examples](./examples/) folder on GitHub.
|
|
8432
|
+
|
|
8433
|
+
Data events are emitted from the WebsocketClient via the `update` event, see example below:
|
|
8434
|
+
|
|
8435
|
+
```javascript
|
|
8436
|
+
const { WebsocketClient } = require('kucoin-api');
|
|
8437
|
+
|
|
8438
|
+
const client = new WebsocketClient();
|
|
8439
|
+
|
|
8440
|
+
client.on('open', (data) => {
|
|
8441
|
+
console.log('open: ', data?.wsKey);
|
|
8442
|
+
});
|
|
8443
|
+
|
|
8444
|
+
// Data received
|
|
8445
|
+
client.on('update', (data) => {
|
|
8446
|
+
console.info('data received: ', JSON.stringify(data));
|
|
8447
|
+
});
|
|
8448
|
+
|
|
8449
|
+
// Something happened, attempting to reconenct
|
|
8450
|
+
client.on('reconnect', (data) => {
|
|
8451
|
+
console.log('reconnect: ', data);
|
|
8452
|
+
});
|
|
8453
|
+
|
|
8454
|
+
// Reconnect successful
|
|
8455
|
+
client.on('reconnected', (data) => {
|
|
8456
|
+
console.log('reconnected: ', data);
|
|
8457
|
+
});
|
|
8458
|
+
|
|
8459
|
+
// Connection closed. If unexpected, expect reconnect -> reconnected.
|
|
8460
|
+
client.on('close', (data) => {
|
|
8461
|
+
console.error('close: ', data);
|
|
8462
|
+
});
|
|
8463
|
+
|
|
8464
|
+
// Reply to a request, e.g. "subscribe"/"unsubscribe"/"authenticate"
|
|
8465
|
+
client.on('response', (data) => {
|
|
8466
|
+
console.info('response: ', data);
|
|
8467
|
+
// throw new Error('res?');
|
|
8468
|
+
});
|
|
8469
|
+
|
|
8470
|
+
client.on('exception', (data) => {
|
|
8471
|
+
console.error('exception: ', {
|
|
8472
|
+
msg: data.msg,
|
|
8473
|
+
errno: data.errno,
|
|
8474
|
+
code: data.code,
|
|
8475
|
+
syscall: data.syscall,
|
|
8476
|
+
hostname: data.hostname,
|
|
8477
|
+
});
|
|
8478
|
+
});
|
|
8479
|
+
|
|
8480
|
+
try {
|
|
8481
|
+
// Optional: await a connection to be ready before subscribing (this is not necessary)
|
|
8482
|
+
// await client.connect('futuresPublicV1');
|
|
8483
|
+
|
|
8484
|
+
/**
|
|
8485
|
+
* Examples for public futures websocket topics (that don't require authentication).
|
|
8486
|
+
*
|
|
8487
|
+
* These should all subscribe via the "futuresPublicV1" wsKey. For detailed usage, refer to the ws-spot-public.ts example.
|
|
8488
|
+
*/
|
|
8489
|
+
client.subscribe(
|
|
8490
|
+
[
|
|
8491
|
+
'/contractMarket/tickerV2:XBTUSDM',
|
|
8492
|
+
'/contractMarket/ticker:XBTUSDM',
|
|
8493
|
+
'/contractMarket/level2:XBTUSDM',
|
|
8494
|
+
'/contractMarket/execution:XBTUSDM',
|
|
8495
|
+
'/contractMarket/level2Depth5:XBTUSDM',
|
|
8496
|
+
'/contractMarket/level2Depth50:XBTUSDM',
|
|
8497
|
+
'/contractMarket/limitCandle:XBTUSDTM_1hour',
|
|
8498
|
+
'/contract/instrument:XBTUSDM',
|
|
8499
|
+
'/contract/announcement',
|
|
8500
|
+
'/contractMarket/snapshot:XBTUSDM',
|
|
8501
|
+
],
|
|
8502
|
+
'futuresPublicV1',
|
|
8503
|
+
);
|
|
8504
|
+
} catch (e) {
|
|
8505
|
+
console.error(`Subscribe exception: `, e);
|
|
8506
|
+
}
|
|
8507
|
+
```
|
|
8508
|
+
|
|
8509
|
+
### Private WebSocket Streams
|
|
8510
|
+
|
|
8511
|
+
For private account data streams, API credentials are required. The WebsocketClient will automatically handle authentication when you provide API credentials.
|
|
8512
|
+
|
|
8513
|
+
See [WebsocketClient](./src/WebsocketClient.ts) for further information and make sure to check the [examples](./examples/) folder for much more detail, especially [ws-spot-public.ts](./examples/ws-spot-public.ts), which explains a lot of detail.
|
|
8514
|
+
|
|
8515
|
+
---
|
|
8516
|
+
|
|
8517
|
+
## Customise Logging
|
|
8518
|
+
|
|
8519
|
+
Pass a custom logger which supports the log methods `trace`, `info` and `error`, or override methods from the default logger as desired.
|
|
8520
|
+
|
|
8521
|
+
```javascript
|
|
8522
|
+
const { WebsocketClient, DefaultLogger } = require('kucoin-api');
|
|
8523
|
+
|
|
8524
|
+
// E.g. customise logging for only the trace level:
|
|
8525
|
+
const logger = {
|
|
8526
|
+
// Inherit existing logger methods, using an object spread
|
|
8527
|
+
...DefaultLogger,
|
|
8528
|
+
// Define a custom trace function to override only that function
|
|
8529
|
+
trace: (...params) => {
|
|
8530
|
+
if (
|
|
8531
|
+
[
|
|
8532
|
+
'Sending ping',
|
|
8533
|
+
// 'Sending upstream ws message: ',
|
|
8534
|
+
'Received pong',
|
|
8535
|
+
].includes(params[0])
|
|
8536
|
+
) {
|
|
8537
|
+
return;
|
|
8538
|
+
}
|
|
8539
|
+
console.log('trace', JSON.stringify(params, null, 2));
|
|
8540
|
+
},
|
|
8541
|
+
};
|
|
8542
|
+
|
|
8543
|
+
const ws = new WebsocketClient(
|
|
8544
|
+
{
|
|
8545
|
+
apiKey: 'apiKeyHere',
|
|
8546
|
+
apiSecret: 'apiSecretHere',
|
|
8547
|
+
apiPassphrase: 'apiPassPhraseHere',
|
|
8548
|
+
},
|
|
8549
|
+
logger,
|
|
8550
|
+
);
|
|
8551
|
+
```
|
|
8552
|
+
|
|
8553
|
+
## Use with LLMs & AI
|
|
8554
|
+
|
|
8555
|
+
This SDK includes a bundled `llms.txt` file in the root of the repository. If you're developing with LLMs, use the included `llms.txt` with your LLM - it will significantly improve the LLMs understanding of how to correctly use this SDK.
|
|
8556
|
+
|
|
8557
|
+
This file contains AI optimised structure of all the functions in this package, and their parameters for easier use with any learning models or artificial intelligence.
|
|
8558
|
+
|
|
8559
|
+
---
|
|
8560
|
+
|
|
8561
|
+
## Used By
|
|
8562
|
+
|
|
8563
|
+
[](https://github.com/tiagosiebler/kucoin-api/network/dependents)
|
|
8564
|
+
|
|
8565
|
+
---
|
|
8566
|
+
|
|
8567
|
+
<!-- template_contributions -->
|
|
8568
|
+
|
|
8569
|
+
### Contributions & Thanks
|
|
8570
|
+
|
|
8571
|
+
Have my projects helped you? Share the love, there are many ways you can show your thanks:
|
|
8572
|
+
|
|
8573
|
+
- Star & share my projects.
|
|
8574
|
+
- Are my projects useful? Sponsor me on Github and support my effort to maintain & improve them: https://github.com/sponsors/tiagosiebler
|
|
8575
|
+
- Have an interesting project? Get in touch & invite me to it.
|
|
8576
|
+
- Or buy me all the coffee:
|
|
8577
|
+
- ETH(ERC20): `0xA3Bda8BecaB4DCdA539Dc16F9C54a592553Be06C` <!-- metamask -->
|
|
8578
|
+
|
|
8579
|
+
<!---
|
|
8580
|
+
old ones:
|
|
8581
|
+
- BTC: `1C6GWZL1XW3jrjpPTS863XtZiXL1aTK7Jk`
|
|
8582
|
+
- BTC(SegWit): `bc1ql64wr9z3khp2gy7dqlmqw7cp6h0lcusz0zjtls`
|
|
8583
|
+
- ETH(ERC20): `0xe0bbbc805e0e83341fadc210d6202f4022e50992`
|
|
8584
|
+
- USDT(TRC20): `TA18VUywcNEM9ahh3TTWF3sFpt9rkLnnQa
|
|
8585
|
+
-->
|
|
8586
|
+
<!-- template_contributions_end -->
|
|
8587
|
+
|
|
8588
|
+
### Contributions & Pull Requests
|
|
8589
|
+
|
|
8590
|
+
Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.
|
|
8591
|
+
|
|
8592
|
+
<!-- template_star_history -->
|
|
8593
|
+
|
|
8594
|
+
## Star History
|
|
8595
|
+
|
|
8596
|
+
[](https://star-history.com/#tiagosiebler/bybit-api&tiagosiebler/okx-api&tiagosiebler/binance&tiagosiebler/bitget-api&tiagosiebler/bitmart-api&tiagosiebler/gateio-api&tiagosiebler/kucoin-api&tiagosiebler/coinbase-api&tiagosiebler/orderbooks&tiagosiebler/accountstate&tiagosiebler/awesome-crypto-examples&Date)
|
|
8597
|
+
|
|
8598
|
+
<!-- template_star_history_end -->
|
|
8599
|
+
|
|
8202
8600
|
================
|
|
8203
8601
|
File: src/FuturesClient.ts
|
|
8204
8602
|
================
|
|
@@ -9080,6 +9478,7 @@ import {
|
|
|
9080
9478
|
GetAffiliateCommissionRequest,
|
|
9081
9479
|
GetAffiliateInviteesRequest,
|
|
9082
9480
|
GetAffiliateTradeHistoryRequest,
|
|
9481
|
+
GetAffiliateTransactionRequest,
|
|
9083
9482
|
} from './types/request/spot-affiliate.js';
|
|
9084
9483
|
import {
|
|
9085
9484
|
AddConvertLimitOrderRequest,
|
|
@@ -9116,10 +9515,21 @@ import {
|
|
|
9116
9515
|
SubmitWithdrawV3Request,
|
|
9117
9516
|
} from './types/request/spot-funding.js';
|
|
9118
9517
|
import {
|
|
9518
|
+
BatchCancelMarginOcoOrdersRequest,
|
|
9519
|
+
BatchCancelMarginStopOrdersRequest,
|
|
9520
|
+
CancelMarginOcoOrderByClientOidRequest,
|
|
9521
|
+
CancelMarginOcoOrderByOrderIdRequest,
|
|
9522
|
+
CancelMarginStopOrderByClientOidRequest,
|
|
9523
|
+
GetBorrowInterestRateRequest,
|
|
9119
9524
|
GetHFMarginFilledRequest,
|
|
9120
9525
|
getHFMarginFillsRequest,
|
|
9121
9526
|
GetLendingRedemptionOrdersV3Request,
|
|
9122
9527
|
GetLendingSubscriptionOrdersV3Request,
|
|
9528
|
+
GetMarginOcoOrderByClientOidRequest,
|
|
9529
|
+
GetMarginOcoOrderDetailByOrderIdRequest,
|
|
9530
|
+
GetMarginStopOrderByClientOidRequest,
|
|
9531
|
+
GetMarginStopOrderByOrderIdRequest,
|
|
9532
|
+
GetMarginStopOrdersListRequest,
|
|
9123
9533
|
HFMarginRequestOrder,
|
|
9124
9534
|
InitiateLendingRedemptionV3Request,
|
|
9125
9535
|
InitiateLendingSubscriptionV3Request,
|
|
@@ -9130,7 +9540,9 @@ import {
|
|
|
9130
9540
|
MarginRiskLimitRequest,
|
|
9131
9541
|
ModifyLendingSubscriptionOrdersV3Request,
|
|
9132
9542
|
SubmitHFMarginOrderRequest,
|
|
9543
|
+
SubmitMarginOcoOrderRequest,
|
|
9133
9544
|
SubmitMarginOrderRequest,
|
|
9545
|
+
SubmitMarginStopOrderRequest,
|
|
9134
9546
|
} from './types/request/spot-margin-trading.js';
|
|
9135
9547
|
import { GetAnnouncementsRequest } from './types/request/spot-misc.js';
|
|
9136
9548
|
import {
|
|
@@ -9176,6 +9588,7 @@ import {
|
|
|
9176
9588
|
AffiliateCommissionItem,
|
|
9177
9589
|
AffiliateInvitees,
|
|
9178
9590
|
AffiliateTradeHistory,
|
|
9591
|
+
AffiliateTransaction,
|
|
9179
9592
|
} from './types/response/spot-affiliate.js';
|
|
9180
9593
|
import {
|
|
9181
9594
|
ConvertCurrencies,
|
|
@@ -9216,6 +9629,8 @@ import {
|
|
|
9216
9629
|
Withdrawals,
|
|
9217
9630
|
} from './types/response/spot-funding.js';
|
|
9218
9631
|
import {
|
|
9632
|
+
BorrowInterestRate,
|
|
9633
|
+
CancelMarginOrdersResponse,
|
|
9219
9634
|
HFMarginOrder,
|
|
9220
9635
|
HFMarginTransactionRecord,
|
|
9221
9636
|
IsolatedMarginAccountInfo,
|
|
@@ -9228,9 +9643,15 @@ import {
|
|
|
9228
9643
|
MarginInterestRecords,
|
|
9229
9644
|
MarginLevTokenInfo,
|
|
9230
9645
|
MarginMarkPrice,
|
|
9646
|
+
MarginOcoOrderDetails,
|
|
9647
|
+
MarginOcoOrderItem,
|
|
9648
|
+
MarginOcoOrderResponse,
|
|
9231
9649
|
MarginOrderV3,
|
|
9232
9650
|
MarginRepayHistoryV3,
|
|
9233
9651
|
MarginRiskLimit,
|
|
9652
|
+
MarginStopOrderItem,
|
|
9653
|
+
MarginStopOrderResponse,
|
|
9654
|
+
MarginStopOrdersList,
|
|
9234
9655
|
MarginSubmitOrderV3Response,
|
|
9235
9656
|
SingleIsolatedMarginAccountInfo,
|
|
9236
9657
|
SubmitMarginOrderResponse,
|
|
@@ -10484,12 +10905,138 @@ getHFMarginOrderByClientOid(params: {
|
|
|
10484
10905
|
symbol: string;
|
|
10485
10906
|
}): Promise<APISuccessResponse<HFMarginOrder>>
|
|
10486
10907
|
⋮----
|
|
10908
|
+
/**
|
|
10909
|
+
* Add Margin Stop Order
|
|
10910
|
+
*
|
|
10911
|
+
* Place stop order to the margin trading system. The maximum untriggered stop orders for a single trading pair in one account is 20.
|
|
10912
|
+
*/
|
|
10913
|
+
addMarginStopOrder(
|
|
10914
|
+
params: SubmitMarginStopOrderRequest,
|
|
10915
|
+
): Promise<APISuccessResponse<MarginStopOrderResponse>>
|
|
10916
|
+
⋮----
|
|
10917
|
+
/**
|
|
10918
|
+
* Cancel Margin Stop Order By OrderId
|
|
10919
|
+
*
|
|
10920
|
+
* Request via this endpoint the cancellation of a single stop order previously placed.
|
|
10921
|
+
*/
|
|
10922
|
+
cancelMarginStopOrderByOrderId(params: {
|
|
10923
|
+
orderId: string;
|
|
10924
|
+
}): Promise<APISuccessResponse<CancelMarginOrdersResponse>>
|
|
10925
|
+
⋮----
|
|
10926
|
+
/**
|
|
10927
|
+
* Cancel Margin Stop Order By ClientOid
|
|
10928
|
+
*
|
|
10929
|
+
* This endpoint can be used to cancel a stop order by clientOid.
|
|
10930
|
+
*/
|
|
10931
|
+
cancelMarginStopOrderByClientOid(
|
|
10932
|
+
params: CancelMarginStopOrderByClientOidRequest,
|
|
10933
|
+
): Promise<APISuccessResponse<CancelMarginOrdersResponse>>
|
|
10934
|
+
⋮----
|
|
10935
|
+
/**
|
|
10936
|
+
* Batch Cancel Margin Stop Orders
|
|
10937
|
+
*
|
|
10938
|
+
* Request via this interface to cancel a batch of stop orders.
|
|
10939
|
+
*/
|
|
10940
|
+
batchCancelMarginStopOrder(
|
|
10941
|
+
params: BatchCancelMarginStopOrdersRequest,
|
|
10942
|
+
): Promise<APISuccessResponse<CancelMarginOrdersResponse>>
|
|
10943
|
+
⋮----
|
|
10944
|
+
/**
|
|
10945
|
+
* Get Margin Stop Orders List
|
|
10946
|
+
*
|
|
10947
|
+
* Request via this endpoint to get your current untriggered stop order list.
|
|
10948
|
+
*/
|
|
10949
|
+
getMarginStopOrdersList(
|
|
10950
|
+
params?: GetMarginStopOrdersListRequest,
|
|
10951
|
+
): Promise<APISuccessResponse<MarginStopOrdersList>>
|
|
10952
|
+
⋮----
|
|
10953
|
+
/**
|
|
10954
|
+
* Get Margin Stop Order By OrderId
|
|
10955
|
+
*
|
|
10956
|
+
* Request via this interface to get a stop order information via the order ID.
|
|
10957
|
+
*/
|
|
10958
|
+
getMarginStopOrderByOrderId(
|
|
10959
|
+
params: GetMarginStopOrderByOrderIdRequest,
|
|
10960
|
+
): Promise<APISuccessResponse<MarginStopOrderItem>>
|
|
10961
|
+
⋮----
|
|
10962
|
+
/**
|
|
10963
|
+
* Get Margin Stop Order By ClientOid
|
|
10964
|
+
*
|
|
10965
|
+
* Request via this interface to get a stop order information via the clientOid.
|
|
10966
|
+
*/
|
|
10967
|
+
getMarginStopOrderByClientOid(
|
|
10968
|
+
params: GetMarginStopOrderByClientOidRequest,
|
|
10969
|
+
): Promise<APISuccessResponse<MarginStopOrderItem>>
|
|
10970
|
+
⋮----
|
|
10971
|
+
/**
|
|
10972
|
+
* Add Margin OCO Order
|
|
10973
|
+
*
|
|
10974
|
+
* Place OCO order to the Margin trading system
|
|
10975
|
+
*/
|
|
10976
|
+
addMarginOcoOrder(
|
|
10977
|
+
params: SubmitMarginOcoOrderRequest,
|
|
10978
|
+
): Promise<APISuccessResponse<MarginOcoOrderResponse>>
|
|
10979
|
+
⋮----
|
|
10980
|
+
/**
|
|
10981
|
+
* Cancel Margin OCO Order By OrderId
|
|
10982
|
+
*
|
|
10983
|
+
* Request via this endpoint the cancellation of a single OCO order previously placed.
|
|
10984
|
+
*/
|
|
10985
|
+
cancelMarginOcoOrderByOrderId(
|
|
10986
|
+
params: CancelMarginOcoOrderByOrderIdRequest,
|
|
10987
|
+
): Promise<APISuccessResponse<CancelMarginOrdersResponse>>
|
|
10988
|
+
⋮----
|
|
10989
|
+
/**
|
|
10990
|
+
* Cancel Margin OCO Order By ClientOid
|
|
10991
|
+
*
|
|
10992
|
+
* Request via this interface to cancel a stop order via the clientOid.
|
|
10993
|
+
*/
|
|
10994
|
+
cancelMarginOcoOrderByClientOid(
|
|
10995
|
+
params: CancelMarginOcoOrderByClientOidRequest,
|
|
10996
|
+
): Promise<APISuccessResponse<CancelMarginOrdersResponse>>
|
|
10997
|
+
⋮----
|
|
10998
|
+
/**
|
|
10999
|
+
* Batch Cancel Margin OCO Orders
|
|
11000
|
+
*
|
|
11001
|
+
* This interface can batch cancel OCO orders through orderIds.
|
|
11002
|
+
*/
|
|
11003
|
+
batchCancelMarginOcoOrders(
|
|
11004
|
+
params?: BatchCancelMarginOcoOrdersRequest,
|
|
11005
|
+
): Promise<APISuccessResponse<CancelMarginOrdersResponse>>
|
|
11006
|
+
⋮----
|
|
11007
|
+
/**
|
|
11008
|
+
* Get Margin OCO Order By ClientOid
|
|
11009
|
+
*
|
|
11010
|
+
* Request via this interface to get a oco order information via the client order ID.
|
|
11011
|
+
*/
|
|
11012
|
+
getMarginOcoOrderByClientOid(
|
|
11013
|
+
params: GetMarginOcoOrderByClientOidRequest,
|
|
11014
|
+
): Promise<APISuccessResponse<MarginOcoOrderItem>>
|
|
11015
|
+
⋮----
|
|
11016
|
+
/**
|
|
11017
|
+
* Get Margin OCO Order Detail By OrderId
|
|
11018
|
+
*
|
|
11019
|
+
* Request via this interface to get a oco order detail via the order ID.
|
|
11020
|
+
*/
|
|
11021
|
+
getMarginOcoOrderDetailByOrderId(
|
|
11022
|
+
params: GetMarginOcoOrderDetailByOrderIdRequest,
|
|
11023
|
+
): Promise<APISuccessResponse<MarginOcoOrderDetails>>
|
|
11024
|
+
⋮----
|
|
10487
11025
|
/**
|
|
10488
11026
|
*
|
|
10489
11027
|
* REST - MARGIN TRADING - Debit
|
|
10490
11028
|
*
|
|
10491
11029
|
*/
|
|
10492
11030
|
⋮----
|
|
11031
|
+
/**
|
|
11032
|
+
* Get Borrow Interest Rate
|
|
11033
|
+
*
|
|
11034
|
+
* Query the borrowing interest rate through this interface.
|
|
11035
|
+
*/
|
|
11036
|
+
getBorrowInterestRate(
|
|
11037
|
+
params?: GetBorrowInterestRateRequest,
|
|
11038
|
+
): Promise<APISuccessResponse<BorrowInterestRate>>
|
|
11039
|
+
⋮----
|
|
10493
11040
|
/**
|
|
10494
11041
|
* Borrow
|
|
10495
11042
|
*
|
|
@@ -10924,13 +11471,13 @@ getOtcLoanAccounts(): Promise<APISuccessResponse<OtcLoanAccount[]>>
|
|
|
10924
11471
|
getAffiliateUserRebateInfo(): Promise<APISuccessResponse<any>>
|
|
10925
11472
|
⋮----
|
|
10926
11473
|
/**
|
|
10927
|
-
* Get
|
|
11474
|
+
* Get Invited
|
|
10928
11475
|
*
|
|
10929
|
-
*
|
|
11476
|
+
* Affiliate user invited information can be obtained at this endpoint.
|
|
10930
11477
|
*/
|
|
10931
|
-
|
|
10932
|
-
params
|
|
10933
|
-
): Promise<APISuccessResponse<
|
|
11478
|
+
getAffiliateInvitees(
|
|
11479
|
+
params?: GetAffiliateInviteesRequest,
|
|
11480
|
+
): Promise<APISuccessResponse<AffiliateInvitees>>
|
|
10934
11481
|
⋮----
|
|
10935
11482
|
/**
|
|
10936
11483
|
* Get Commission
|
|
@@ -10942,13 +11489,22 @@ getAffiliateCommission(
|
|
|
10942
11489
|
): Promise<APISuccessResponse<AffiliateCommissionItem[]>>
|
|
10943
11490
|
⋮----
|
|
10944
11491
|
/**
|
|
10945
|
-
* Get
|
|
11492
|
+
* Get Trade History
|
|
10946
11493
|
*
|
|
10947
|
-
*
|
|
11494
|
+
* Trade history information can be obtained at this endpoint.
|
|
10948
11495
|
*/
|
|
10949
|
-
|
|
10950
|
-
params
|
|
10951
|
-
): Promise<APISuccessResponse<
|
|
11496
|
+
getAffiliateTradeHistory(
|
|
11497
|
+
params: GetAffiliateTradeHistoryRequest,
|
|
11498
|
+
): Promise<APISuccessResponse<AffiliateTradeHistory>>
|
|
11499
|
+
⋮----
|
|
11500
|
+
/**
|
|
11501
|
+
* Get Transaction
|
|
11502
|
+
*
|
|
11503
|
+
* Transaction information can be obtained at this endpoint.
|
|
11504
|
+
*/
|
|
11505
|
+
getAffiliateTransaction(
|
|
11506
|
+
params: GetAffiliateTransactionRequest,
|
|
11507
|
+
): Promise<APISuccessResponse<AffiliateTransaction>>
|
|
10952
11508
|
⋮----
|
|
10953
11509
|
/**
|
|
10954
11510
|
*
|
|
@@ -11273,7 +11829,7 @@ File: package.json
|
|
|
11273
11829
|
================
|
|
11274
11830
|
{
|
|
11275
11831
|
"name": "kucoin-api",
|
|
11276
|
-
"version": "2.1.
|
|
11832
|
+
"version": "2.1.22",
|
|
11277
11833
|
"description": "Complete & robust Node.js SDK for Kucoin's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
|
|
11278
11834
|
"scripts": {
|
|
11279
11835
|
"clean": "rm -rf dist",
|
|
@@ -11361,6 +11917,7 @@ File: package.json
|
|
|
11361
11917
|
|
|
11362
11918
|
|
|
11363
11919
|
|
|
11920
|
+
|
|
11364
11921
|
================================================================
|
|
11365
11922
|
End of Codebase
|
|
11366
11923
|
================================================================
|