okx-api 0.0.1 → 0.0.2

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.
Files changed (65) hide show
  1. package/README.md +26 -168
  2. package/lib/index.d.ts +2 -1
  3. package/lib/index.js +17 -13
  4. package/lib/index.js.map +1 -1
  5. package/lib/rest-client.d.ts +315 -0
  6. package/lib/rest-client.js +635 -0
  7. package/lib/rest-client.js.map +1 -0
  8. package/lib/types/rest/index.d.ts +3 -0
  9. package/lib/types/rest/index.js +20 -0
  10. package/lib/types/rest/index.js.map +1 -0
  11. package/lib/types/rest/request/index.d.ts +4 -0
  12. package/lib/types/rest/request/index.js +21 -0
  13. package/lib/types/rest/request/index.js.map +1 -0
  14. package/lib/types/rest/request/private-account.d.ts +16 -0
  15. package/lib/types/rest/request/private-account.js +3 -0
  16. package/lib/types/rest/request/private-account.js.map +1 -0
  17. package/lib/types/rest/request/private-block-trading.d.ts +60 -0
  18. package/lib/types/rest/request/private-block-trading.js +3 -0
  19. package/lib/types/rest/request/private-block-trading.js.map +1 -0
  20. package/lib/types/rest/request/private-trade.d.ts +111 -0
  21. package/lib/types/rest/request/private-trade.js +3 -0
  22. package/lib/types/rest/request/private-trade.js.map +1 -0
  23. package/lib/types/rest/request/shared.d.ts +7 -0
  24. package/lib/types/rest/request/shared.js +3 -0
  25. package/lib/types/rest/request/shared.js.map +1 -0
  26. package/lib/types/rest/response/index.d.ts +6 -0
  27. package/lib/types/rest/response/index.js +23 -0
  28. package/lib/types/rest/response/index.js.map +1 -0
  29. package/lib/types/rest/response/private-account.d.ts +213 -0
  30. package/lib/types/rest/response/private-account.js +3 -0
  31. package/lib/types/rest/response/private-account.js.map +1 -0
  32. package/lib/types/rest/response/private-block-trading.d.ts +89 -0
  33. package/lib/types/rest/response/private-block-trading.js +3 -0
  34. package/lib/types/rest/response/private-block-trading.js.map +1 -0
  35. package/lib/types/rest/response/private-funding.d.ts +67 -0
  36. package/lib/types/rest/response/private-funding.js +3 -0
  37. package/lib/types/rest/response/private-funding.js.map +1 -0
  38. package/lib/types/rest/response/private-subaccount.d.ts +56 -0
  39. package/lib/types/rest/response/private-subaccount.js +3 -0
  40. package/lib/types/rest/response/private-subaccount.js.map +1 -0
  41. package/lib/types/rest/response/private-trade.d.ts +235 -0
  42. package/lib/types/rest/response/private-trade.js +3 -0
  43. package/lib/types/rest/response/private-trade.js.map +1 -0
  44. package/lib/types/rest/response/public-data.d.ts +70 -0
  45. package/lib/types/rest/response/public-data.js +3 -0
  46. package/lib/types/rest/response/public-data.js.map +1 -0
  47. package/lib/types/rest/shared.d.ts +36 -0
  48. package/lib/types/rest/shared.js +3 -0
  49. package/lib/types/rest/shared.js.map +1 -0
  50. package/lib/util/BaseRestClient.d.ts +35 -0
  51. package/lib/util/BaseRestClient.js +204 -0
  52. package/lib/util/BaseRestClient.js.map +1 -0
  53. package/lib/util/browser-support.d.ts +1 -0
  54. package/lib/util/browser-support.js +24 -0
  55. package/lib/util/browser-support.js.map +1 -0
  56. package/lib/util/node-support.d.ts +1 -0
  57. package/lib/util/node-support.js +9 -0
  58. package/lib/util/node-support.js.map +1 -0
  59. package/lib/util/requestUtils.d.ts +17 -0
  60. package/lib/util/requestUtils.js +52 -0
  61. package/lib/util/requestUtils.js.map +1 -0
  62. package/lib/util/typeGuards.d.ts +2 -0
  63. package/lib/util/typeGuards.js +14 -0
  64. package/lib/util/typeGuards.js.map +1 -0
  65. package/package.json +8 -8
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.MISSING_CREDENTIALS_ERROR = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const node_support_1 = require("./node-support");
18
+ const requestUtils_1 = require("./requestUtils");
19
+ const typeGuards_1 = require("./typeGuards");
20
+ // axios.interceptors.request.use((request) => {
21
+ // console.log(new Date(), 'Starting Request', JSON.stringify(request, null, 2));
22
+ // return request;
23
+ // });
24
+ // axios.interceptors.response.use((response) => {
25
+ // // console.log(new Date(), 'Response:', JSON.stringify(response, null, 2));
26
+ // console.log(
27
+ // new Date(),
28
+ // 'Response:',
29
+ // JSON.stringify(
30
+ // {
31
+ // data: response.data,
32
+ // headers: response.headers,
33
+ // },
34
+ // null,
35
+ // 2
36
+ // )
37
+ // );
38
+ // return response;
39
+ // });
40
+ exports.MISSING_CREDENTIALS_ERROR = 'Private endpoints require api and secret to be provided in the REST client constructor';
41
+ class BaseRestClient {
42
+ constructor(credentials, baseUrl, options = {}, requestOptions = {}, environment) {
43
+ this.environment = environment;
44
+ this.options = Object.assign({
45
+ // if true, we'll throw errors if any params are undefined
46
+ strict_param_validation: false }, options);
47
+ this.baseUrl = baseUrl;
48
+ // Allow empty object
49
+ if (credentials &&
50
+ (!credentials.apiKey ||
51
+ !credentials.apiSecret ||
52
+ !credentials.apiPassphrase)) {
53
+ throw new Error('API Key, Secret AND Passphrase are ALL required for private enpoints');
54
+ }
55
+ this.globalRequestOptions = Object.assign({
56
+ // in ms == 5 minutes by default
57
+ timeout: 1000 * 60 * 5, headers: {} }, requestOptions);
58
+ // Note: `x-simulated-trading: 1` needs to be added to the header of the Demo Trading request.
59
+ if (environment === 'demo') {
60
+ this.globalRequestOptions.headers['x-simulated-trading'] = 1;
61
+ }
62
+ this.globalRequestOptions.headers['Content-Type'] = 'application/json';
63
+ this.globalRequestOptions.headers['Accept'] = 'application/json';
64
+ this.apiKey = credentials === null || credentials === void 0 ? void 0 : credentials.apiKey;
65
+ this.apiSecret = credentials === null || credentials === void 0 ? void 0 : credentials.apiSecret;
66
+ this.apiPassphrase = credentials === null || credentials === void 0 ? void 0 : credentials.apiPassphrase;
67
+ }
68
+ // private isDemoTrading(): boolean {
69
+ // return this.environment === 'demo';
70
+ // }
71
+ get(endpoint, params) {
72
+ return this._call('GET', endpoint, params, true);
73
+ }
74
+ post(endpoint, params) {
75
+ return this._call('POST', endpoint, params, true);
76
+ }
77
+ getPrivate(endpoint, params) {
78
+ return this._call('GET', endpoint, params, false);
79
+ }
80
+ postPrivate(endpoint, params) {
81
+ return this._call('POST', endpoint, Array.isArray(params)
82
+ ? params.map((p) => (Object.assign(Object.assign({}, p), { [requestUtils_1.programKey]: requestUtils_1.programId })))
83
+ : Object.assign(Object.assign({}, params), { [requestUtils_1.programKey]: requestUtils_1.programId }), false);
84
+ }
85
+ deletePrivate(endpoint, params) {
86
+ return this._call('DELETE', endpoint, params, false);
87
+ }
88
+ /**
89
+ * Make a HTTP request to a specific endpoint. Private endpoints are automatically signed.
90
+ */
91
+ _call(method, endpoint, params, isPublicApi) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ const options = Object.assign(Object.assign({}, this.globalRequestOptions), { url: [this.baseUrl, endpoint].join(endpoint.startsWith('/') ? '' : '/'), method: method, json: true });
94
+ // Delete any params without value
95
+ for (const key in params) {
96
+ if (typeof params[key] === 'undefined') {
97
+ delete params[key];
98
+ }
99
+ }
100
+ const tsISO = new Date().toISOString();
101
+ const signResult = yield this.signRequest(isPublicApi, tsISO, method, endpoint, params);
102
+ if (!isPublicApi) {
103
+ options.headers['OK-ACCESS-KEY'] = this.apiKey;
104
+ options.headers['OK-ACCESS-SIGN'] = signResult.sign;
105
+ options.headers['OK-ACCESS-TIMESTAMP'] = tsISO;
106
+ options.headers['OK-ACCESS-PASSPHRASE'] = this.apiPassphrase;
107
+ }
108
+ if (method === 'GET') {
109
+ options.params = signResult.requestBody;
110
+ }
111
+ else {
112
+ options.data = signResult.requestBody;
113
+ }
114
+ // console.log(new Date(), 'request: ', {
115
+ // url: options.url,
116
+ // method,
117
+ // params: signResult.requestBody,
118
+ // sign: signResult.sign,
119
+ // });
120
+ return (0, axios_1.default)(options)
121
+ .then((response) => {
122
+ var _a;
123
+ // Check this is an API response without an error code.
124
+ // If so, resolve the nested data property, else throw the full response body
125
+ if ((0, typeGuards_1.isRawAPIResponse)(response.data) &&
126
+ response.status == 200 &&
127
+ ((_a = response.data) === null || _a === void 0 ? void 0 : _a.code) === '0') {
128
+ return response.data.data;
129
+ }
130
+ // console.log('request: ', JSON.stringify(options, null, 2));
131
+ // console.log(
132
+ // 'bad response: ',
133
+ // JSON.stringify(
134
+ // {
135
+ // data: response.data,
136
+ // headers: response.headers,
137
+ // },
138
+ // null,
139
+ // 2
140
+ // )
141
+ // );
142
+ // Also throw if API returned error code
143
+ // This API error thrown by the exchange will be post-processed by the exception parser
144
+ throw { response };
145
+ })
146
+ .catch((e) => this.parseException(e));
147
+ });
148
+ }
149
+ /**
150
+ * Sign request
151
+ */
152
+ signRequest(isPublicApi, tsISO, method, endpoint, params) {
153
+ return __awaiter(this, void 0, void 0, function* () {
154
+ const res = {
155
+ requestBody: params,
156
+ method,
157
+ endpoint,
158
+ sign: '',
159
+ };
160
+ if (isPublicApi) {
161
+ return res;
162
+ }
163
+ if (!this.apiKey || !this.apiSecret || !this.apiPassphrase) {
164
+ throw new Error(exports.MISSING_CREDENTIALS_ERROR);
165
+ }
166
+ const serializedParams = (0, requestUtils_1.serializeParams)(params, method, this.options.strict_param_validation);
167
+ const message = tsISO + method + endpoint + serializedParams;
168
+ // console.log(new Date(), `Sign params: `, {
169
+ // message,
170
+ // secret: this.apiSecret,
171
+ // });
172
+ return Object.assign(Object.assign({}, res), { sign: (0, node_support_1.signMessage)(message, this.apiSecret) });
173
+ });
174
+ }
175
+ /**
176
+ * Generic handler to parse request exceptions
177
+ */
178
+ parseException(e) {
179
+ if (this.options.parse_exceptions === false) {
180
+ throw e;
181
+ }
182
+ // Something happened in setting up the request that triggered an Error
183
+ if (!e.response) {
184
+ if (!e.request) {
185
+ throw e.message;
186
+ }
187
+ // request made but no response received
188
+ throw e;
189
+ }
190
+ // The request was made and the server responded with a status code
191
+ // that falls out of the range of 2xx
192
+ const response = e.response;
193
+ throw response.data;
194
+ // throw {
195
+ // status: response.status,
196
+ // statusText: response.statusText,
197
+ // data: response.data,
198
+ // headers: response.headers,
199
+ // requestOptions: this.options,
200
+ // };
201
+ }
202
+ }
203
+ exports.default = BaseRestClient;
204
+ //# sourceMappingURL=BaseRestClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseRestClient.js","sourceRoot":"","sources":["../../src/util/BaseRestClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAyE;AAEzE,iDAA6C;AAE7C,iDAMwB;AACxB,6CAAgD;AAEhD,gDAAgD;AAChD,mFAAmF;AACnF,oBAAoB;AACpB,MAAM;AAEN,kDAAkD;AAClD,gFAAgF;AAChF,iBAAiB;AACjB,kBAAkB;AAClB,mBAAmB;AACnB,sBAAsB;AACtB,UAAU;AACV,+BAA+B;AAC/B,qCAAqC;AACrC,WAAW;AACX,cAAc;AACd,UAAU;AACV,QAAQ;AACR,OAAO;AACP,qBAAqB;AACrB,MAAM;AAEO,QAAA,yBAAyB,GACpC,wFAAwF,CAAC;AAe3F,MAA8B,cAAc;IAU1C,YACE,WAA8C,EAC9C,OAAe,EACf,UAA6B,EAAE,EAC/B,iBAAqC,EAAE,EACvC,WAA2B;QAE3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAE/B,IAAI,CAAC,OAAO;YACV,0DAA0D;YAC1D,uBAAuB,EAAE,KAAK,IAC3B,OAAO,CACX,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,qBAA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mE;QACnE,qCAAqC;QACrC,MAAM,QAAQ,GAAkB,CAAC,CAAC,QAAQ,CAAC;QAC3C,MAAM,QAAQ,CAAC,IAAI,CAAC;QACpB,UAAU;QACV,6BAA6B;QAC7B,qCAAqC;QACrC,yBAAyB;QACzB,+BAA+B;QAC/B,kCAAkC;QAClC,KAAK;IACP,CAAC;CACF;AAvPD,iCAuPC"}
@@ -0,0 +1 @@
1
+ export declare function signMessage(message: string, secret: string): Promise<string>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.signMessage = void 0;
13
+ function signMessage(message, secret) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const encoder = new TextEncoder();
16
+ const key = yield window.crypto.subtle.importKey('raw', encoder.encode(secret), { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign']);
17
+ const signature = yield window.crypto.subtle.sign('HMAC', key, encoder.encode(message));
18
+ return Array.prototype.map
19
+ .call(new Uint8Array(signature), (x) => ('00' + x.toString(16)).slice(-2))
20
+ .join('');
21
+ });
22
+ }
23
+ exports.signMessage = signMessage;
24
+ //# sourceMappingURL=browser-support.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-support.js","sourceRoot":"","sources":["../../src/util/browser-support.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,SAAsB,WAAW,CAC/B,OAAe,EACf,MAAc;;QAEd,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAC9C,KAAK,EACL,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EACtB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAC3C,KAAK,EACL,CAAC,MAAM,CAAC,CACT,CAAC;QAEF,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAC/C,MAAM,EACN,GAAG,EACH,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CACxB,CAAC;QAEF,OAAO,KAAK,CAAC,SAAS,CAAC,GAAG;aACvB,IAAI,CAAC,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC,CAAM,EAAE,EAAE,CAC1C,CAAC,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAClC;aACA,IAAI,CAAC,EAAE,CAAC,CAAC;IACd,CAAC;CAAA;AAxBD,kCAwBC"}
@@ -0,0 +1 @@
1
+ export declare function signMessage(message: string, secret: string): string;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.signMessage = void 0;
4
+ const crypto_1 = require("crypto");
5
+ function signMessage(message, secret) {
6
+ return (0, crypto_1.createHmac)('sha256', secret).update(message).digest('base64');
7
+ }
8
+ exports.signMessage = signMessage;
9
+ //# sourceMappingURL=node-support.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-support.js","sourceRoot":"","sources":["../../src/util/node-support.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AAEpC,SAAgB,WAAW,CAAC,OAAe,EAAE,MAAc;IACzD,OAAO,IAAA,mBAAU,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACvE,CAAC;AAFD,kCAEC"}
@@ -0,0 +1,17 @@
1
+ import { Method } from 'axios';
2
+ export interface RestClientOptions {
3
+ strict_param_validation?: boolean;
4
+ baseUrl?: string;
5
+ parse_exceptions?: boolean;
6
+ }
7
+ export declare function serializeParams(params: object | undefined, method: Method, strict_validation?: boolean): string;
8
+ export declare const programKey = "tag";
9
+ export declare const programId = "159881cb7207BCDE";
10
+ /**
11
+ * - live: production,
12
+ * - aws: aws subdomain,
13
+ * - demo: demo environment
14
+ */
15
+ export declare type OKXEnvironment = 'live' | 'aws' | 'demo';
16
+ export declare function getRestBaseUrl(environment: OKXEnvironment, restClientOptions: RestClientOptions): string;
17
+ export declare function isWsPong(response: any): any;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWsPong = exports.getRestBaseUrl = exports.programId = exports.programKey = exports.serializeParams = void 0;
4
+ function serializeParams(params, method, strict_validation = false) {
5
+ if (!params) {
6
+ return '';
7
+ }
8
+ if (method !== 'GET') {
9
+ return JSON.stringify(params);
10
+ }
11
+ // Original order should be preserved, no sorting allowed here or sign will fail
12
+ return ('?' +
13
+ Object.keys(params)
14
+ .map((key) => {
15
+ const value = params[key];
16
+ if (strict_validation === true && typeof value === 'undefined') {
17
+ throw new Error('Failed to sign API request due to undefined parameter');
18
+ }
19
+ return `${key}=${value}`;
20
+ })
21
+ .join('&'));
22
+ }
23
+ exports.serializeParams = serializeParams;
24
+ exports.programKey = 'tag';
25
+ exports.programId = '159881cb7207BCDE';
26
+ function getRestBaseUrl(environment, restClientOptions) {
27
+ if (restClientOptions.baseUrl) {
28
+ return restClientOptions.baseUrl;
29
+ }
30
+ switch (environment) {
31
+ default:
32
+ case 'demo':
33
+ case 'live': {
34
+ return 'https://www.okx.com';
35
+ }
36
+ case 'aws': {
37
+ return 'https://aws.okex.com';
38
+ }
39
+ }
40
+ }
41
+ exports.getRestBaseUrl = getRestBaseUrl;
42
+ function isWsPong(response) {
43
+ if (response.pong || response.ping) {
44
+ return true;
45
+ }
46
+ return (response.request &&
47
+ response.request.op === 'ping' &&
48
+ response.ret_msg === 'pong' &&
49
+ response.success === true);
50
+ }
51
+ exports.isWsPong = isWsPong;
52
+ //# sourceMappingURL=requestUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestUtils.js","sourceRoot":"","sources":["../../src/util/requestUtils.ts"],"names":[],"mappings":";;;AAcA,SAAgB,eAAe,CAC7B,MAA0B,EAC1B,MAAc,EACd,iBAAiB,GAAG,KAAK;IAEzB,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAC;KACX;IAED,IAAI,MAAM,KAAK,KAAK,EAAE;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;KAC/B;IAED,gFAAgF;IAChF,OAAO,CACL,GAAG;QACH,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;aAChB,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YACX,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC1B,IAAI,iBAAiB,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;gBAC9D,MAAM,IAAI,KAAK,CACb,uDAAuD,CACxD,CAAC;aACH;YACD,OAAO,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;QAC3B,CAAC,CAAC;aACD,IAAI,CAAC,GAAG,CAAC,CACb,CAAC;AACJ,CAAC;AA5BD,0CA4BC;AACY,QAAA,UAAU,GAAG,KAAK,CAAC;AACnB,QAAA,SAAS,GAAG,kBAAkB,CAAC;AAS5C,SAAgB,cAAc,CAC5B,WAA2B,EAC3B,iBAAoC;IAEpC,IAAI,iBAAiB,CAAC,OAAO,EAAE;QAC7B,OAAO,iBAAiB,CAAC,OAAO,CAAC;KAClC;IAED,QAAQ,WAAW,EAAE;QACnB,QAAQ;QACR,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM,CAAC,CAAC;YACX,OAAO,qBAAqB,CAAC;SAC9B;QACD,KAAK,KAAK,CAAC,CAAC;YACV,OAAO,sBAAsB,CAAC;SAC/B;KACF;AACH,CAAC;AAlBD,wCAkBC;AAED,SAAgB,QAAQ,CAAC,QAAa;IACpC,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,EAAE;QAClC,OAAO,IAAI,CAAC;KACb;IACD,OAAO,CACL,QAAQ,CAAC,OAAO;QAChB,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,MAAM;QAC9B,QAAQ,CAAC,OAAO,KAAK,MAAM;QAC3B,QAAQ,CAAC,OAAO,KAAK,IAAI,CAC1B,CAAC;AACJ,CAAC;AAVD,4BAUC"}
@@ -0,0 +1,2 @@
1
+ import { APIResponse } from '../types/rest';
2
+ export declare function isRawAPIResponse(response: unknown): response is APIResponse<unknown>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRawAPIResponse = void 0;
4
+ function isRawAPIResponse(response) {
5
+ if (typeof response !== 'object' || !response) {
6
+ return false;
7
+ }
8
+ if ('code' in response && 'msg' in response && 'data' in response) {
9
+ return true;
10
+ }
11
+ return false;
12
+ }
13
+ exports.isRawAPIResponse = isRawAPIResponse;
14
+ //# sourceMappingURL=typeGuards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeGuards.js","sourceRoot":"","sources":["../../src/util/typeGuards.ts"],"names":[],"mappings":";;;AAEA,SAAgB,gBAAgB,CAC9B,QAAiB;IAEjB,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,QAAQ,EAAE;QAC7C,OAAO,KAAK,CAAC;KACd;IAED,IAAI,MAAM,IAAI,QAAQ,IAAI,KAAK,IAAI,QAAQ,IAAI,MAAM,IAAI,QAAQ,EAAE;QACjE,OAAO,IAAI,CAAC;KACb;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAZD,4CAYC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "okx-api",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "EARLY BETA. Node.js connector for OKX REST APIs and WebSockets, with TypeScript & integration tests.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -27,14 +27,14 @@
27
27
  "ws": "^7.4.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@types/jest": "^26.0.23",
30
+ "@types/jest": "^28.1.4",
31
31
  "@types/node": "^14.14.7",
32
- "eslint": "^7.10.0",
33
- "jest": "^27.0.4",
34
- "source-map-loader": "^2.0.0",
35
- "ts-jest": "^27.0.3",
36
- "ts-loader": "^8.0.11",
37
- "typescript": "^4.0.5",
32
+ "eslint": "^8.19.0",
33
+ "jest": "^28.1.2",
34
+ "source-map-loader": "^4.0.0",
35
+ "ts-jest": "^28.0.5",
36
+ "ts-loader": "^9.3.1",
37
+ "typescript": "^4.7.4",
38
38
  "webpack": "^5.4.0",
39
39
  "webpack-bundle-analyzer": "^4.1.0",
40
40
  "webpack-cli": "^4.2.0"