okx-api 0.0.2 → 0.0.4
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 +22 -10
- package/lib/constants/funding.d.ts +139 -0
- package/lib/constants/funding.js +143 -0
- package/lib/constants/funding.js.map +1 -0
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/index.js +18 -0
- package/lib/constants/index.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/rest-client.d.ts +134 -47
- package/lib/rest-client.js +124 -18
- package/lib/rest-client.js.map +1 -1
- package/lib/types/rest/request/account.d.ts +32 -0
- package/lib/types/rest/request/{private-trade.js → account.js} +1 -1
- package/lib/types/rest/request/account.js.map +1 -0
- package/lib/types/rest/request/{private-block-trading.d.ts → block-trading.d.ts} +5 -5
- package/lib/types/rest/request/{private-account.js → block-trading.js} +1 -1
- package/lib/types/rest/request/block-trading.js.map +1 -0
- package/lib/types/rest/request/convert.d.ts +19 -0
- package/lib/types/rest/request/{private-block-trading.js → convert.js} +1 -1
- package/lib/types/rest/request/convert.js.map +1 -0
- package/lib/types/rest/request/funding.d.ts +21 -0
- package/lib/types/rest/request/funding.js +3 -0
- package/lib/types/rest/request/funding.js.map +1 -0
- package/lib/types/rest/request/grid-trading.d.ts +30 -0
- package/lib/types/rest/request/grid-trading.js +3 -0
- package/lib/types/rest/request/grid-trading.js.map +1 -0
- package/lib/types/rest/request/index.d.ts +7 -3
- package/lib/types/rest/request/index.js +7 -3
- package/lib/types/rest/request/index.js.map +1 -1
- package/lib/types/rest/request/subaccount.d.ts +12 -0
- package/lib/types/rest/request/subaccount.js +3 -0
- package/lib/types/rest/request/subaccount.js.map +1 -0
- package/lib/types/rest/request/{private-trade.d.ts → trade.d.ts} +3 -1
- package/lib/types/rest/request/trade.js +3 -0
- package/lib/types/rest/request/trade.js.map +1 -0
- package/lib/types/rest/response/private-funding.d.ts +2 -1
- package/lib/types/rest/shared.d.ts +5 -1
- package/lib/util/BaseRestClient.d.ts +1 -2
- package/lib/util/BaseRestClient.js +5 -5
- package/lib/util/BaseRestClient.js.map +1 -1
- package/lib/util/requestUtils.js +11 -11
- package/lib/util/requestUtils.js.map +1 -1
- package/package.json +2 -2
- package/lib/types/rest/request/private-account.d.ts +0 -16
- package/lib/types/rest/request/private-account.js.map +0 -1
- package/lib/types/rest/request/private-block-trading.js.map +0 -1
- package/lib/types/rest/request/private-trade.js.map +0 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { InstrumentType } from '../shared';
|
|
2
|
+
export interface SetLeverageRequest {
|
|
3
|
+
instId?: string;
|
|
4
|
+
ccy?: string;
|
|
5
|
+
lever: string;
|
|
6
|
+
mgnMode: 'isolated' | 'cross';
|
|
7
|
+
posSide?: 'long' | 'short';
|
|
8
|
+
}
|
|
9
|
+
export interface ChangePositionMarginRequest {
|
|
10
|
+
instId: string;
|
|
11
|
+
posSide: 'long' | 'short' | 'net';
|
|
12
|
+
type: 'add' | 'reduce';
|
|
13
|
+
amt: string;
|
|
14
|
+
ccy?: string;
|
|
15
|
+
auto?: boolean;
|
|
16
|
+
loanTrans?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface GetPositionsParams {
|
|
19
|
+
instType?: InstrumentType;
|
|
20
|
+
instId?: string;
|
|
21
|
+
posId?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface GetHistoricPositionParams {
|
|
24
|
+
instType?: InstrumentType;
|
|
25
|
+
instId?: string;
|
|
26
|
+
mgnMode?: string;
|
|
27
|
+
type?: string;
|
|
28
|
+
posId?: string;
|
|
29
|
+
after?: string;
|
|
30
|
+
before?: string;
|
|
31
|
+
limit?: string;
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../src/types/rest/request/account.ts"],"names":[],"mappings":""}
|
|
@@ -10,8 +10,8 @@ export interface CancelBlockRFQRequest {
|
|
|
10
10
|
clRfqId?: string;
|
|
11
11
|
}
|
|
12
12
|
export interface CancelMultipleBlockRFQRequest {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
rfqIds?: string[];
|
|
14
|
+
clRfqIds?: string[];
|
|
15
15
|
}
|
|
16
16
|
export interface ExecuteBlockQuoteRequest {
|
|
17
17
|
rfqId: string;
|
|
@@ -20,7 +20,7 @@ export interface ExecuteBlockQuoteRequest {
|
|
|
20
20
|
export interface CreateBlockQuoteRequest {
|
|
21
21
|
rfqId: string;
|
|
22
22
|
clQuoteId?: string;
|
|
23
|
-
quoteSide:
|
|
23
|
+
quoteSide: OrderSide;
|
|
24
24
|
anonymous?: boolean;
|
|
25
25
|
expiresIn?: string;
|
|
26
26
|
legs: CreateBlockQuoteLeg[];
|
|
@@ -37,8 +37,8 @@ export interface CancelBlockQuoteRequest {
|
|
|
37
37
|
clQuoteId?: string;
|
|
38
38
|
}
|
|
39
39
|
export interface CancelMultipleBlockQuoteRequest {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
quoteIds?: string[];
|
|
41
|
+
clQuoteIds?: string[];
|
|
42
42
|
}
|
|
43
43
|
export interface GetBlockRFQSParams {
|
|
44
44
|
rfqId?: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-trading.js","sourceRoot":"","sources":["../../../../src/types/rest/request/block-trading.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ConvertQuoteEstimateRequest {
|
|
2
|
+
baseCcy: string;
|
|
3
|
+
quoteCcy: string;
|
|
4
|
+
side: string;
|
|
5
|
+
rfqSz: string;
|
|
6
|
+
rfqSzCcy: string;
|
|
7
|
+
clTReqId?: string;
|
|
8
|
+
tag?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ConvertTradeRequest {
|
|
11
|
+
quoteId: string;
|
|
12
|
+
baseCcy: string;
|
|
13
|
+
quoteCcy: string;
|
|
14
|
+
side: string;
|
|
15
|
+
sz: string;
|
|
16
|
+
szCcy: string;
|
|
17
|
+
clTReqId?: string;
|
|
18
|
+
tag?: string;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../../../src/types/rest/request/convert.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface FundsTransferRequest {
|
|
2
|
+
ccy: string;
|
|
3
|
+
amt: string;
|
|
4
|
+
from: '6' | '18';
|
|
5
|
+
to: '6' | '16';
|
|
6
|
+
subAcct?: string;
|
|
7
|
+
type?: '0' | '1' | '2' | '3' | '4';
|
|
8
|
+
loanTrans?: boolean;
|
|
9
|
+
clientId?: string;
|
|
10
|
+
omitPosRisk?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface WithdrawRequest {
|
|
13
|
+
ccy: string;
|
|
14
|
+
amt: string;
|
|
15
|
+
dest: '3' | '4';
|
|
16
|
+
toAddr: string;
|
|
17
|
+
fee: string;
|
|
18
|
+
chain?: string;
|
|
19
|
+
areaCode?: string;
|
|
20
|
+
clientId?: string;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"funding.js","sourceRoot":"","sources":["../../../../src/types/rest/request/funding.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare type GridAlgoOrderType = 'grid' | 'contract_grid' | 'moon_grid';
|
|
2
|
+
export interface GetGridAlgoOrdersRequest {
|
|
3
|
+
algoOrdType: GridAlgoOrderType;
|
|
4
|
+
algoId?: string;
|
|
5
|
+
instId?: string;
|
|
6
|
+
instType?: 'SPOT' | 'MARGIN' | 'SWAP' | 'FUTURES';
|
|
7
|
+
after?: string;
|
|
8
|
+
before?: string;
|
|
9
|
+
limit?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface GridAlgoOrderRequest {
|
|
12
|
+
instId: string;
|
|
13
|
+
algoOrdType: GridAlgoOrderType;
|
|
14
|
+
maxPx: string;
|
|
15
|
+
minPx: string;
|
|
16
|
+
gridNum: string;
|
|
17
|
+
runType: '1' | '2';
|
|
18
|
+
quoteSz?: string;
|
|
19
|
+
baseSz?: string;
|
|
20
|
+
sz?: string;
|
|
21
|
+
direction?: 'long' | 'short' | 'neutral';
|
|
22
|
+
lever?: string;
|
|
23
|
+
basePos?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface StopGridAlgoOrderRequest {
|
|
26
|
+
algoId: string;
|
|
27
|
+
instId: string;
|
|
28
|
+
algoOrdType: GridAlgoOrderType;
|
|
29
|
+
stopType: '1' | '2';
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid-trading.js","sourceRoot":"","sources":["../../../../src/types/rest/request/grid-trading.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
export * from './account';
|
|
2
|
+
export * from './convert';
|
|
3
|
+
export * from './funding';
|
|
1
4
|
export * from './shared';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
+
export * from './subaccount';
|
|
6
|
+
export * from './trade';
|
|
7
|
+
export * from './block-trading';
|
|
8
|
+
export * from './grid-trading';
|
|
@@ -14,8 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./account"), exports);
|
|
18
|
+
__exportStar(require("./convert"), exports);
|
|
19
|
+
__exportStar(require("./funding"), exports);
|
|
17
20
|
__exportStar(require("./shared"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
__exportStar(require("./
|
|
21
|
+
__exportStar(require("./subaccount"), exports);
|
|
22
|
+
__exportStar(require("./trade"), exports);
|
|
23
|
+
__exportStar(require("./block-trading"), exports);
|
|
24
|
+
__exportStar(require("./grid-trading"), exports);
|
|
21
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/types/rest/request/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/types/rest/request/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B;AAC1B,4CAA0B;AAC1B,2CAAyB;AACzB,+CAA6B;AAC7B,0CAAwB;AACxB,kDAAgC;AAChC,iDAA+B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare type AccountType = '6' | '18';
|
|
2
|
+
export interface SubAccountTransferRequest {
|
|
3
|
+
ccy: string;
|
|
4
|
+
amt: string;
|
|
5
|
+
from: AccountType;
|
|
6
|
+
to: AccountType;
|
|
7
|
+
fromSubAccount: string;
|
|
8
|
+
toSubAccount: string;
|
|
9
|
+
loanTrans?: boolean;
|
|
10
|
+
omitPosRisk?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subaccount.js","sourceRoot":"","sources":["../../../../src/types/rest/request/subaccount.ts"],"names":[],"mappings":""}
|
|
@@ -103,9 +103,11 @@ export interface OrderRequest {
|
|
|
103
103
|
side: OrderSide;
|
|
104
104
|
posSide?: PositionSide;
|
|
105
105
|
ordType: OrderType;
|
|
106
|
+
/** Quantity to buy or sell */
|
|
106
107
|
sz: numberInString;
|
|
107
108
|
px?: string;
|
|
108
109
|
reduceOnly?: boolean;
|
|
109
|
-
|
|
110
|
+
/** A spot buy on BTC-USDT with "base_ccy" would mean the QTY (sz) is in USDT */
|
|
111
|
+
tgtCcy?: 'base_ccy' | 'quote_ccy';
|
|
110
112
|
banAmend?: boolean;
|
|
111
113
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trade.js","sourceRoot":"","sources":["../../../../src/types/rest/request/trade.ts"],"names":[],"mappings":""}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ASSET_BILL_TYPE } from '../../../constants';
|
|
1
2
|
export interface FundingCurrency {
|
|
2
3
|
canDep: boolean;
|
|
3
4
|
canInternal: boolean;
|
|
@@ -62,6 +63,6 @@ export interface AssetBillDetails {
|
|
|
62
63
|
clientId: string;
|
|
63
64
|
balChg: string;
|
|
64
65
|
bal: string;
|
|
65
|
-
type:
|
|
66
|
+
type: `${ASSET_BILL_TYPE}`;
|
|
66
67
|
ts: string;
|
|
67
68
|
}
|
|
@@ -7,7 +7,6 @@ export interface APIResponse<T> {
|
|
|
7
7
|
export declare type AlgoOrderType = 'conditional' | 'oco' | 'trigger' | 'move_order_stop' | 'iceberg' | 'twap';
|
|
8
8
|
export declare type AlgoState = 'effective' | 'canceled' | 'order_failed';
|
|
9
9
|
export declare type ContractGridDirection = 'long' | 'short' | 'neutral';
|
|
10
|
-
export declare type GridAlgoOrderType = 'grid' | 'contract_grid';
|
|
11
10
|
export declare type GridAlgoSubOrderType = 'live' | 'filled';
|
|
12
11
|
export declare type InstrumentType = 'SPOT' | 'MARGIN' | 'SWAP' | 'FUTURES' | 'OPTION';
|
|
13
12
|
export declare type MarginMode = 'cross' | 'isolated';
|
|
@@ -34,3 +33,8 @@ export declare type TradeMode = 'cross' | 'isolated' | 'cash';
|
|
|
34
33
|
export interface TimestampObject {
|
|
35
34
|
ts: numberInString;
|
|
36
35
|
}
|
|
36
|
+
export interface Pagination {
|
|
37
|
+
after?: string;
|
|
38
|
+
before?: string;
|
|
39
|
+
limit?: string;
|
|
40
|
+
}
|
|
@@ -4,7 +4,7 @@ export declare const MISSING_CREDENTIALS_ERROR = "Private endpoints require api
|
|
|
4
4
|
export interface APICredentials {
|
|
5
5
|
apiKey: string;
|
|
6
6
|
apiSecret: string;
|
|
7
|
-
|
|
7
|
+
apiPass: string;
|
|
8
8
|
}
|
|
9
9
|
export default abstract class BaseRestClient {
|
|
10
10
|
private options;
|
|
@@ -13,7 +13,6 @@ export default abstract class BaseRestClient {
|
|
|
13
13
|
private apiKey;
|
|
14
14
|
private apiSecret;
|
|
15
15
|
private apiPassphrase;
|
|
16
|
-
private environment;
|
|
17
16
|
constructor(credentials: APICredentials | undefined | null, baseUrl: string, options: RestClientOptions | undefined, requestOptions: AxiosRequestConfig | undefined, environment: OKXEnvironment);
|
|
18
17
|
get(endpoint: string, params?: any): Promise<any>;
|
|
19
18
|
post(endpoint: string, params?: any): Promise<any>;
|
|
@@ -39,17 +39,16 @@ const typeGuards_1 = require("./typeGuards");
|
|
|
39
39
|
// });
|
|
40
40
|
exports.MISSING_CREDENTIALS_ERROR = 'Private endpoints require api and secret to be provided in the REST client constructor';
|
|
41
41
|
class BaseRestClient {
|
|
42
|
+
// private environment: OKXEnvironment;
|
|
42
43
|
constructor(credentials, baseUrl, options = {}, requestOptions = {}, environment) {
|
|
43
|
-
this.environment = environment;
|
|
44
|
+
// this.environment = environment;
|
|
44
45
|
this.options = Object.assign({
|
|
45
46
|
// if true, we'll throw errors if any params are undefined
|
|
46
47
|
strict_param_validation: false }, options);
|
|
47
48
|
this.baseUrl = baseUrl;
|
|
48
49
|
// Allow empty object
|
|
49
50
|
if (credentials &&
|
|
50
|
-
(!credentials.apiKey ||
|
|
51
|
-
!credentials.apiSecret ||
|
|
52
|
-
!credentials.apiPassphrase)) {
|
|
51
|
+
(!credentials.apiKey || !credentials.apiSecret || !credentials.apiPass)) {
|
|
53
52
|
throw new Error('API Key, Secret AND Passphrase are ALL required for private enpoints');
|
|
54
53
|
}
|
|
55
54
|
this.globalRequestOptions = Object.assign({
|
|
@@ -63,7 +62,7 @@ class BaseRestClient {
|
|
|
63
62
|
this.globalRequestOptions.headers['Accept'] = 'application/json';
|
|
64
63
|
this.apiKey = credentials === null || credentials === void 0 ? void 0 : credentials.apiKey;
|
|
65
64
|
this.apiSecret = credentials === null || credentials === void 0 ? void 0 : credentials.apiSecret;
|
|
66
|
-
this.apiPassphrase = credentials === null || credentials === void 0 ? void 0 : credentials.
|
|
65
|
+
this.apiPassphrase = credentials === null || credentials === void 0 ? void 0 : credentials.apiPass;
|
|
67
66
|
}
|
|
68
67
|
// private isDemoTrading(): boolean {
|
|
69
68
|
// return this.environment === 'demo';
|
|
@@ -116,6 +115,7 @@ class BaseRestClient {
|
|
|
116
115
|
// method,
|
|
117
116
|
// params: signResult.requestBody,
|
|
118
117
|
// sign: signResult.sign,
|
|
118
|
+
// options,
|
|
119
119
|
// });
|
|
120
120
|
return (0, axios_1.default)(options)
|
|
121
121
|
.then((response) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseRestClient.js","sourceRoot":"","sources":["../../src/util/BaseRestClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAyE;AAEzE,iDAA6C;
|
|
1
|
+
{"version":3,"file":"BaseRestClient.js","sourceRoot":"","sources":["../../src/util/BaseRestClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAyE;AAEzE,iDAA6C;AAC7C,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;IAQ1C,uCAAuC;IAEvC,YACE,WAA8C,EAC9C,OAAe,EACf,UAA6B,EAAE,EAC/B,iBAAqC,EAAE,EACvC,WA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IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE;YACf,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE;gBACd,MAAM,CAAC,CAAC,OAAO,CAAC;aACjB;YAED,wCAAwC;YACxC,MAAM,CAAC,CAAC;SACT;QAED,mEAAmE;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;AAtPD,iCAsPC"}
|
package/lib/util/requestUtils.js
CHANGED
|
@@ -8,17 +8,17 @@ function serializeParams(params, method, strict_validation = false) {
|
|
|
8
8
|
if (method !== 'GET') {
|
|
9
9
|
return JSON.stringify(params);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
const queryString = Object.keys(params)
|
|
12
|
+
.map((key) => {
|
|
13
|
+
const value = params[key];
|
|
14
|
+
if (strict_validation === true && typeof value === 'undefined') {
|
|
15
|
+
throw new Error('Failed to sign API request due to undefined parameter');
|
|
16
|
+
}
|
|
17
|
+
return `${key}=${value}`;
|
|
18
|
+
})
|
|
19
|
+
.join('&');
|
|
20
|
+
// Prevent trailing `?` if no params are provided
|
|
21
|
+
return queryString ? '?' + queryString : queryString;
|
|
22
22
|
}
|
|
23
23
|
exports.serializeParams = serializeParams;
|
|
24
24
|
exports.programKey = 'tag';
|
|
@@ -1 +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,KA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R,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"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "okx-api",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "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",
|
|
7
7
|
"files": [
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { InstrumentType } from '../shared';
|
|
2
|
-
export interface GetPositionsParams {
|
|
3
|
-
instType?: InstrumentType;
|
|
4
|
-
instId?: string;
|
|
5
|
-
posId?: string;
|
|
6
|
-
}
|
|
7
|
-
export interface GetHistoricPositionParams {
|
|
8
|
-
instType?: InstrumentType;
|
|
9
|
-
instId?: string;
|
|
10
|
-
mgnMode?: string;
|
|
11
|
-
type?: string;
|
|
12
|
-
posId?: string;
|
|
13
|
-
after?: string;
|
|
14
|
-
before?: string;
|
|
15
|
-
limit?: string;
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"private-account.js","sourceRoot":"","sources":["../../../../src/types/rest/request/private-account.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"private-block-trading.js","sourceRoot":"","sources":["../../../../src/types/rest/request/private-block-trading.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"private-trade.js","sourceRoot":"","sources":["../../../../src/types/rest/request/private-trade.ts"],"names":[],"mappings":""}
|