kucoin-api 2.4.1 → 2.5.0
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/README.md +37 -0
- package/dist/cjs/FuturesClient.d.ts +1 -3
- package/dist/cjs/FuturesClient.js +0 -4
- package/dist/cjs/FuturesClient.js.map +1 -1
- package/dist/cjs/SpotClient.d.ts +1 -3
- package/dist/cjs/SpotClient.js +0 -4
- package/dist/cjs/SpotClient.js.map +1 -1
- package/dist/cjs/UnifiedAPIClient.d.ts +1 -3
- package/dist/cjs/UnifiedAPIClient.js +0 -4
- package/dist/cjs/UnifiedAPIClient.js.map +1 -1
- package/dist/cjs/WebsocketClient.js +1 -1
- package/dist/cjs/WebsocketClient.js.map +1 -1
- package/dist/cjs/lib/BaseRestClient.js +8 -0
- package/dist/cjs/lib/BaseRestClient.js.map +1 -1
- package/dist/cjs/lib/requestUtils.d.ts +22 -6
- package/dist/cjs/lib/requestUtils.js +39 -9
- package/dist/cjs/lib/requestUtils.js.map +1 -1
- package/dist/cjs/types/websockets/ws-general.d.ts +14 -1
- package/dist/mjs/FuturesClient.d.ts +1 -3
- package/dist/mjs/FuturesClient.js +1 -5
- package/dist/mjs/FuturesClient.js.map +1 -1
- package/dist/mjs/SpotClient.d.ts +1 -3
- package/dist/mjs/SpotClient.js +1 -5
- package/dist/mjs/SpotClient.js.map +1 -1
- package/dist/mjs/UnifiedAPIClient.d.ts +1 -3
- package/dist/mjs/UnifiedAPIClient.js +1 -5
- package/dist/mjs/UnifiedAPIClient.js.map +1 -1
- package/dist/mjs/WebsocketClient.js +1 -1
- package/dist/mjs/WebsocketClient.js.map +1 -1
- package/dist/mjs/lib/BaseRestClient.js +8 -0
- package/dist/mjs/lib/BaseRestClient.js.map +1 -1
- package/dist/mjs/lib/requestUtils.d.ts +22 -6
- package/dist/mjs/lib/requestUtils.js +39 -9
- package/dist/mjs/lib/requestUtils.js.map +1 -1
- package/dist/mjs/types/websockets/ws-general.d.ts +14 -1
- package/package.json +1 -1
|
@@ -2,16 +2,19 @@
|
|
|
2
2
|
* Used to switch how authentication/requests work under the hood
|
|
3
3
|
*/
|
|
4
4
|
export declare const REST_CLIENT_TYPE_ENUM: {
|
|
5
|
-
/** Spot & Margin */
|
|
5
|
+
/** Global & AU: Spot & Margin */
|
|
6
6
|
readonly main: "main";
|
|
7
|
-
/** Futures */
|
|
7
|
+
/** Global & AU: Futures */
|
|
8
8
|
readonly futures: "futures";
|
|
9
|
-
/** Broker */
|
|
9
|
+
/** Global: Broker */
|
|
10
10
|
readonly broker: "broker";
|
|
11
|
-
/** Unified Trading Account */
|
|
11
|
+
/** Global: Unified Trading Account */
|
|
12
12
|
readonly unifiedTradingAccount: "unifiedTradingAccount";
|
|
13
|
+
/** Dedicated EU: main (Spot & Margin). No futures at this time. */
|
|
14
|
+
readonly mainEU: "mainEU";
|
|
13
15
|
};
|
|
14
16
|
export type RestClientType = (typeof REST_CLIENT_TYPE_ENUM)[keyof typeof REST_CLIENT_TYPE_ENUM];
|
|
17
|
+
export type APIRegion = 'global' | 'EU' | 'AU';
|
|
15
18
|
export interface RestClientOptions {
|
|
16
19
|
/** Your API key */
|
|
17
20
|
apiKey?: string;
|
|
@@ -26,10 +29,23 @@ export interface RestClientOptions {
|
|
|
26
29
|
apiAccessToken?: string;
|
|
27
30
|
/** The API key version. Defaults to "2" right now. You can see this in your API management page */
|
|
28
31
|
apiKeyVersion?: number | string;
|
|
32
|
+
/**
|
|
33
|
+
* The API region you would like to work with:
|
|
34
|
+
* - Global (default)
|
|
35
|
+
* - API Docs: https://www.kucoin.com/docs-new/introduction
|
|
36
|
+
* - EU:
|
|
37
|
+
* - API Docs: https://www.kucoin.com/en-eu/docs-new/introduction/eu
|
|
38
|
+
* - Behaves the same as global, but keep in mind that futures may not be available at this time for EU users.
|
|
39
|
+
* - AU:
|
|
40
|
+
* - API Docs: https://www.kucoin.com/en-au/docs-new/introduction/au
|
|
41
|
+
* - Ensures regional market data is retrieved (e.g. correct trading pairs, correct tickers, etc).
|
|
42
|
+
* - Also ensures requests for AU users include the required extra header (X-SITE-TYPE: australia).
|
|
43
|
+
*/
|
|
44
|
+
apiRegion?: APIRegion;
|
|
29
45
|
/** Default: false. If true, we'll throw errors if any params are undefined */
|
|
30
46
|
strictParamValidation?: boolean;
|
|
31
47
|
/**
|
|
32
|
-
* Optionally override API protocol + domain
|
|
48
|
+
* Optionally override API protocol + domain. This will override any domain influence from the apiRegion parameter.
|
|
33
49
|
* e.g baseUrl: 'https://api.kucoin.com'
|
|
34
50
|
**/
|
|
35
51
|
baseUrl?: string;
|
|
@@ -58,4 +74,4 @@ export declare const APIIDMain = "NODESDK";
|
|
|
58
74
|
export declare const APIIDMainSign = "d28f5b4a-179d-4fcb-9c00-c8319c0bb82c";
|
|
59
75
|
export declare const APIIDFutures = "NODESDKFUTURES";
|
|
60
76
|
export declare const APIIDFuturesSign = "7f7fb0d6-e600-4ef4-8fe3-41e6aea9af84";
|
|
61
|
-
export declare function getRestBaseUrl(useTestnet: boolean,
|
|
77
|
+
export declare function getRestBaseUrl(useTestnet: boolean, restOptions: RestClientOptions, restClientType: RestClientType): string;
|
|
@@ -1,18 +1,23 @@
|
|
|
1
|
+
import { neverGuard } from './misc-util.js';
|
|
1
2
|
/**
|
|
2
3
|
* Used to switch how authentication/requests work under the hood
|
|
3
4
|
*/
|
|
4
5
|
export const REST_CLIENT_TYPE_ENUM = {
|
|
5
|
-
/** Spot & Margin */
|
|
6
|
+
/** Global & AU: Spot & Margin */
|
|
6
7
|
main: 'main',
|
|
7
|
-
/** Futures */
|
|
8
|
+
/** Global & AU: Futures */
|
|
8
9
|
futures: 'futures',
|
|
9
|
-
/** Broker */
|
|
10
|
+
/** Global: Broker */
|
|
10
11
|
broker: 'broker',
|
|
11
|
-
/** Unified Trading Account */
|
|
12
|
+
/** Global: Unified Trading Account */
|
|
12
13
|
unifiedTradingAccount: 'unifiedTradingAccount',
|
|
14
|
+
/** Dedicated EU: main (Spot & Margin). No futures at this time. */
|
|
15
|
+
mainEU: 'mainEU',
|
|
13
16
|
};
|
|
14
17
|
const kucoinURLMap = {
|
|
15
18
|
[REST_CLIENT_TYPE_ENUM.main]: 'https://api.kucoin.com',
|
|
19
|
+
// https://www.kucoin.com/en-eu/docs-new/introduction/eu
|
|
20
|
+
[REST_CLIENT_TYPE_ENUM.mainEU]: 'https://api.kucoin.eu',
|
|
16
21
|
[REST_CLIENT_TYPE_ENUM.futures]: 'https://api-futures.kucoin.com',
|
|
17
22
|
[REST_CLIENT_TYPE_ENUM.broker]: 'https://api-broker.kucoin.com',
|
|
18
23
|
[REST_CLIENT_TYPE_ENUM.unifiedTradingAccount]: 'https://api.kucoin.com',
|
|
@@ -39,14 +44,39 @@ export const APIIDMain = 'NODESDK';
|
|
|
39
44
|
export const APIIDMainSign = 'd28f5b4a-179d-4fcb-9c00-c8319c0bb82c';
|
|
40
45
|
export const APIIDFutures = 'NODESDKFUTURES';
|
|
41
46
|
export const APIIDFuturesSign = '7f7fb0d6-e600-4ef4-8fe3-41e6aea9af84';
|
|
42
|
-
export function getRestBaseUrl(useTestnet,
|
|
47
|
+
export function getRestBaseUrl(useTestnet, restOptions, restClientType) {
|
|
48
|
+
let resolvedClientType = restClientType;
|
|
49
|
+
if (restOptions.baseUrl) {
|
|
50
|
+
return restOptions.baseUrl;
|
|
51
|
+
}
|
|
52
|
+
// Override to EU URL for EU regional users
|
|
53
|
+
if (restOptions.apiRegion === 'EU') {
|
|
54
|
+
switch (restClientType) {
|
|
55
|
+
case REST_CLIENT_TYPE_ENUM.main:
|
|
56
|
+
case REST_CLIENT_TYPE_ENUM.mainEU: {
|
|
57
|
+
resolvedClientType = REST_CLIENT_TYPE_ENUM.mainEU;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case REST_CLIENT_TYPE_ENUM.futures: {
|
|
61
|
+
console.warn('Futures market is not available for EU users at this time. API requests may not function as expected');
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case REST_CLIENT_TYPE_ENUM.broker: {
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case REST_CLIENT_TYPE_ENUM.unifiedTradingAccount: {
|
|
68
|
+
resolvedClientType = REST_CLIENT_TYPE_ENUM.mainEU;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
default: {
|
|
72
|
+
throw neverGuard(restClientType, `Unhandled REST Client Type "${restClientType}"`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
43
76
|
const exchangeBaseUrls = {
|
|
44
|
-
livenet: kucoinURLMap[
|
|
77
|
+
livenet: kucoinURLMap[resolvedClientType],
|
|
45
78
|
testnet: 'https://noTestnet',
|
|
46
79
|
};
|
|
47
|
-
if (restInverseOptions.baseUrl) {
|
|
48
|
-
return restInverseOptions.baseUrl;
|
|
49
|
-
}
|
|
50
80
|
if (useTestnet) {
|
|
51
81
|
return exchangeBaseUrls.testnet;
|
|
52
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestUtils.js","sourceRoot":"","sources":["../../../src/lib/requestUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,
|
|
1
|
+
{"version":3,"file":"requestUtils.js","sourceRoot":"","sources":["../../../src/lib/requestUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,iCAAiC;IACjC,IAAI,EAAE,MAAM;IACZ,2BAA2B;IAC3B,OAAO,EAAE,SAAS;IAClB,qBAAqB;IACrB,MAAM,EAAE,QAAQ;IAChB,sCAAsC;IACtC,qBAAqB,EAAE,uBAAuB;IAC9C,mEAAmE;IACnE,MAAM,EAAE,QAAQ;CACR,CAAC;AAKX,MAAM,YAAY,GAAmC;IACnD,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE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equestArgs } from 'http';
|
|
3
3
|
import WebSocket from 'isomorphic-ws';
|
|
4
|
-
import { RestClientOptions } from '../../lib/requestUtils.js';
|
|
4
|
+
import { APIRegion, RestClientOptions } from '../../lib/requestUtils.js';
|
|
5
5
|
/** General configuration for the WebsocketClient */
|
|
6
6
|
export interface WSClientConfigurableOptions {
|
|
7
7
|
/** Your API key */
|
|
@@ -10,6 +10,19 @@ export interface WSClientConfigurableOptions {
|
|
|
10
10
|
apiSecret?: string;
|
|
11
11
|
/** Your API passphrase (can be anything) that you included when creating this API key */
|
|
12
12
|
apiPassphrase?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The API region you would like to work with:
|
|
15
|
+
* - Global (default)
|
|
16
|
+
* - API Docs: https://www.kucoin.com/docs-new/introduction
|
|
17
|
+
* - EU:
|
|
18
|
+
* - API Docs: https://www.kucoin.com/en-eu/docs-new/introduction/eu
|
|
19
|
+
* - Behaves the same as global, but keep in mind that futures may not be available at this time for EU users.
|
|
20
|
+
* - AU:
|
|
21
|
+
* - API Docs: https://www.kucoin.com/en-au/docs-new/introduction/au
|
|
22
|
+
* - Ensures regional market data is retrieved (e.g. correct trading pairs, correct tickers, etc).
|
|
23
|
+
* - Also ensures requests for AU users include the required extra header (X-SITE-TYPE: australia).
|
|
24
|
+
*/
|
|
25
|
+
apiRegion?: APIRegion;
|
|
13
26
|
/** Define a recv window when preparing a private websocket signature. This is in milliseconds, so 5000 == 5 seconds */
|
|
14
27
|
recvWindow?: number;
|
|
15
28
|
/** How often to check if the connection is alive */
|
package/package.json
CHANGED