ccxt 4.3.8 → 4.3.10
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 +3 -3
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/src/base/Exchange.js +3 -3
- package/dist/cjs/src/bingx.js +21 -11
- package/dist/cjs/src/bitget.js +1 -1
- package/dist/cjs/src/coinex.js +689 -426
- package/dist/cjs/src/coinmetro.js +31 -31
- package/dist/cjs/src/kucoinfutures.js +159 -11
- package/dist/cjs/src/okx.js +58 -1
- package/js/ccxt.d.ts +1 -1
- package/js/ccxt.js +1 -1
- package/js/src/abstract/bingx.d.ts +1 -1
- package/js/src/abstract/coinmetro.d.ts +1 -0
- package/js/src/abstract/kucoinfutures.d.ts +2 -0
- package/js/src/base/Exchange.js +3 -3
- package/js/src/base/types.d.ts +2 -0
- package/js/src/bingx.js +21 -11
- package/js/src/bitget.js +1 -1
- package/js/src/coinex.js +689 -426
- package/js/src/coinmetro.d.ts +1 -1
- package/js/src/coinmetro.js +31 -31
- package/js/src/kucoinfutures.d.ts +3 -1
- package/js/src/kucoinfutures.js +159 -11
- package/js/src/okx.d.ts +4 -0
- package/js/src/okx.js +58 -1
- package/package.json +8 -7
package/js/src/coinmetro.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export default class coinmetro extends Exchange {
|
|
|
28
28
|
fetchBidsAsks(symbols?: Strings, params?: {}): Promise<import("./base/types.js").Dictionary<Ticker>>;
|
|
29
29
|
parseTicker(ticker: any, market?: Market): Ticker;
|
|
30
30
|
fetchBalance(params?: {}): Promise<Balances>;
|
|
31
|
-
parseBalance(
|
|
31
|
+
parseBalance(balances: any): Balances;
|
|
32
32
|
fetchLedger(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<any>;
|
|
33
33
|
parseLedgerEntry(item: any, currency?: Currency): {
|
|
34
34
|
id: string;
|
package/js/src/coinmetro.js
CHANGED
|
@@ -164,6 +164,7 @@ export default class coinmetro extends Exchange {
|
|
|
164
164
|
'private': {
|
|
165
165
|
'get': {
|
|
166
166
|
'users/balances': 1,
|
|
167
|
+
'users/wallets': 1,
|
|
167
168
|
'users/wallets/history/{since}': 1.67,
|
|
168
169
|
'exchange/orders/status/{orderID}': 1,
|
|
169
170
|
'exchange/orders/active': 1,
|
|
@@ -944,49 +945,48 @@ export default class coinmetro extends Exchange {
|
|
|
944
945
|
* @method
|
|
945
946
|
* @name coinmetro#fetchBalance
|
|
946
947
|
* @description query for balance and get the amount of funds available for trading or funds locked in orders
|
|
947
|
-
* @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#
|
|
948
|
+
* @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#741a1dcc-7307-40d0-acca-28d003d1506a
|
|
948
949
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
949
950
|
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
|
|
950
951
|
*/
|
|
951
952
|
await this.loadMarkets();
|
|
952
|
-
const response = await this.
|
|
953
|
-
|
|
953
|
+
const response = await this.privateGetUsersWallets(params);
|
|
954
|
+
const list = this.safeList(response, 'list', []);
|
|
955
|
+
return this.parseBalance(list);
|
|
954
956
|
}
|
|
955
|
-
parseBalance(
|
|
957
|
+
parseBalance(balances) {
|
|
956
958
|
//
|
|
957
|
-
//
|
|
958
|
-
//
|
|
959
|
-
// "
|
|
960
|
-
// "
|
|
961
|
-
// "
|
|
962
|
-
//
|
|
963
|
-
//
|
|
964
|
-
// "
|
|
965
|
-
// "
|
|
966
|
-
// "
|
|
967
|
-
//
|
|
968
|
-
//
|
|
969
|
-
// "
|
|
970
|
-
// "
|
|
959
|
+
// [
|
|
960
|
+
// {
|
|
961
|
+
// "xcmLocks": [],
|
|
962
|
+
// "xcmLockAmounts": [],
|
|
963
|
+
// "refList": [],
|
|
964
|
+
// "balanceHistory": [],
|
|
965
|
+
// "_id": "5fecd3c998e75c2e4d63f7c3",
|
|
966
|
+
// "currency": "BTC",
|
|
967
|
+
// "label": "BTC",
|
|
968
|
+
// "userId": "5fecd3c97fbfed1521db23bd",
|
|
969
|
+
// "__v": 0,
|
|
970
|
+
// "balance": 0.5,
|
|
971
|
+
// "createdAt": "2020-12-30T19:23:53.646Z",
|
|
972
|
+
// "disabled": false,
|
|
973
|
+
// "updatedAt": "2020-12-30T19:23:53.653Z",
|
|
974
|
+
// "reserved": 0,
|
|
975
|
+
// "id": "5fecd3c998e75c2e4d63f7c3"
|
|
971
976
|
// },
|
|
972
|
-
//
|
|
973
|
-
//
|
|
974
|
-
// "EUR": 0,
|
|
975
|
-
// "BTC": 0
|
|
976
|
-
// }
|
|
977
|
-
// }
|
|
977
|
+
// ...
|
|
978
|
+
// ]
|
|
978
979
|
//
|
|
979
980
|
const result = {
|
|
980
|
-
'info':
|
|
981
|
+
'info': balances,
|
|
981
982
|
};
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
const currencyId = currencyIds[i];
|
|
983
|
+
for (let i = 0; i < balances.length; i++) {
|
|
984
|
+
const balanceEntry = this.safeDict(balances, i, {});
|
|
985
|
+
const currencyId = this.safeString(balanceEntry, 'currency');
|
|
986
986
|
const code = this.safeCurrencyCode(currencyId);
|
|
987
987
|
const account = this.account();
|
|
988
|
-
|
|
989
|
-
account['
|
|
988
|
+
account['total'] = this.safeString(balanceEntry, 'balance');
|
|
989
|
+
account['used'] = this.safeString(balanceEntry, 'reserved');
|
|
990
990
|
result[code] = account;
|
|
991
991
|
}
|
|
992
992
|
return this.safeBalance(result);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import kucoin from './abstract/kucoinfutures.js';
|
|
2
|
-
import type { TransferEntry, Int, OrderSide, OrderType, OHLCV, Order, Trade, OrderRequest, FundingHistory, Balances, Str, Ticker, Tickers, OrderBook, Transaction, Strings, Market, Currency, Num, MarginModification } from './base/types.js';
|
|
2
|
+
import type { TransferEntry, Int, OrderSide, OrderType, OHLCV, Order, Trade, OrderRequest, FundingHistory, Balances, Str, Ticker, Tickers, OrderBook, Transaction, Strings, Market, Currency, Num, MarginModification, TradingFeeInterface } from './base/types.js';
|
|
3
3
|
/**
|
|
4
4
|
* @class kucoinfutures
|
|
5
5
|
* @augments Exchange
|
|
@@ -31,6 +31,7 @@ export default class kucoinfutures extends kucoin {
|
|
|
31
31
|
fetchFundingHistory(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<FundingHistory[]>;
|
|
32
32
|
fetchPosition(symbol: string, params?: {}): Promise<import("./base/types.js").Position>;
|
|
33
33
|
fetchPositions(symbols?: Strings, params?: {}): Promise<import("./base/types.js").Position[]>;
|
|
34
|
+
fetchPositionsHistory(symbols?: Strings, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").Position[]>;
|
|
34
35
|
parsePosition(position: any, market?: Market): import("./base/types.js").Position;
|
|
35
36
|
createOrder(symbol: string, type: OrderType, side: OrderSide, amount: number, price?: Num, params?: {}): Promise<Order>;
|
|
36
37
|
createOrders(orders: OrderRequest[], params?: {}): Promise<Order[]>;
|
|
@@ -94,4 +95,5 @@ export default class kucoinfutures extends kucoin {
|
|
|
94
95
|
datetime: string;
|
|
95
96
|
};
|
|
96
97
|
closePosition(symbol: string, side?: OrderSide, params?: {}): Promise<Order>;
|
|
98
|
+
fetchTradingFee(symbol: string, params?: {}): Promise<TradingFeeInterface>;
|
|
97
99
|
}
|
package/js/src/kucoinfutures.js
CHANGED
|
@@ -84,13 +84,14 @@ export default class kucoinfutures extends kucoin {
|
|
|
84
84
|
'fetchPositionHistory': false,
|
|
85
85
|
'fetchPositionMode': false,
|
|
86
86
|
'fetchPositions': true,
|
|
87
|
-
'fetchPositionsHistory':
|
|
87
|
+
'fetchPositionsHistory': true,
|
|
88
88
|
'fetchPremiumIndexOHLCV': false,
|
|
89
89
|
'fetchStatus': true,
|
|
90
90
|
'fetchTicker': true,
|
|
91
91
|
'fetchTickers': true,
|
|
92
92
|
'fetchTime': true,
|
|
93
93
|
'fetchTrades': true,
|
|
94
|
+
'fetchTradingFee': true,
|
|
94
95
|
'fetchTransactionFee': false,
|
|
95
96
|
'fetchWithdrawals': true,
|
|
96
97
|
'setLeverage': false,
|
|
@@ -167,6 +168,8 @@ export default class kucoinfutures extends kucoin {
|
|
|
167
168
|
'funding-history': 4.44,
|
|
168
169
|
'sub/api-key': 1,
|
|
169
170
|
'trade-statistics': 1,
|
|
171
|
+
'trade-fees': 1,
|
|
172
|
+
'history-positions': 1,
|
|
170
173
|
},
|
|
171
174
|
'post': {
|
|
172
175
|
'withdrawals': 1,
|
|
@@ -1140,6 +1143,76 @@ export default class kucoinfutures extends kucoin {
|
|
|
1140
1143
|
const data = this.safeList(response, 'data');
|
|
1141
1144
|
return this.parsePositions(data, symbols);
|
|
1142
1145
|
}
|
|
1146
|
+
async fetchPositionsHistory(symbols = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1147
|
+
/**
|
|
1148
|
+
* @method
|
|
1149
|
+
* @name kucoinfutures#fetchPositionsHistory
|
|
1150
|
+
* @description fetches historical positions
|
|
1151
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/positions/get-positions-history
|
|
1152
|
+
* @param {string[]} [symbols] list of unified market symbols
|
|
1153
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1154
|
+
* @param {int} [params.until] closing end time
|
|
1155
|
+
* @param {int} [params.pageId] page id
|
|
1156
|
+
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
|
|
1157
|
+
*/
|
|
1158
|
+
await this.loadMarkets();
|
|
1159
|
+
if (limit === undefined) {
|
|
1160
|
+
limit = 200;
|
|
1161
|
+
}
|
|
1162
|
+
const request = {
|
|
1163
|
+
'limit': limit,
|
|
1164
|
+
};
|
|
1165
|
+
if (since !== undefined) {
|
|
1166
|
+
request['from'] = since;
|
|
1167
|
+
}
|
|
1168
|
+
const until = this.safeInteger(params, 'until');
|
|
1169
|
+
if (until !== undefined) {
|
|
1170
|
+
params = this.omit(params, 'until');
|
|
1171
|
+
request['to'] = until;
|
|
1172
|
+
}
|
|
1173
|
+
const response = await this.futuresPrivateGetHistoryPositions(this.extend(request, params));
|
|
1174
|
+
//
|
|
1175
|
+
// {
|
|
1176
|
+
// "success": true,
|
|
1177
|
+
// "code": "200",
|
|
1178
|
+
// "msg": "success",
|
|
1179
|
+
// "retry": false,
|
|
1180
|
+
// "data": {
|
|
1181
|
+
// "currentPage": 1,
|
|
1182
|
+
// "pageSize": 10,
|
|
1183
|
+
// "totalNum": 25,
|
|
1184
|
+
// "totalPage": 3,
|
|
1185
|
+
// "items": [
|
|
1186
|
+
// {
|
|
1187
|
+
// "closeId": "300000000000000030",
|
|
1188
|
+
// "positionId": "300000000000000009",
|
|
1189
|
+
// "uid": 99996908309485,
|
|
1190
|
+
// "userId": "6527d4fc8c7f3d0001f40f5f",
|
|
1191
|
+
// "symbol": "XBTUSDM",
|
|
1192
|
+
// "settleCurrency": "XBT",
|
|
1193
|
+
// "leverage": "0.0",
|
|
1194
|
+
// "type": "LIQUID_LONG",
|
|
1195
|
+
// "side": null,
|
|
1196
|
+
// "closeSize": null,
|
|
1197
|
+
// "pnl": "-1.0000003793999999",
|
|
1198
|
+
// "realisedGrossCost": "0.9993849748999999",
|
|
1199
|
+
// "withdrawPnl": "0.0",
|
|
1200
|
+
// "roe": null,
|
|
1201
|
+
// "tradeFee": "0.0006154045",
|
|
1202
|
+
// "fundingFee": "0.0",
|
|
1203
|
+
// "openTime": 1713785751181,
|
|
1204
|
+
// "closeTime": 1713785752784,
|
|
1205
|
+
// "openPrice": null,
|
|
1206
|
+
// "closePrice": null
|
|
1207
|
+
// }
|
|
1208
|
+
// ]
|
|
1209
|
+
// }
|
|
1210
|
+
// }
|
|
1211
|
+
//
|
|
1212
|
+
const data = this.safeDict(response, 'data');
|
|
1213
|
+
const items = this.safeList(data, 'items', []);
|
|
1214
|
+
return this.parsePositions(items, symbols);
|
|
1215
|
+
}
|
|
1143
1216
|
parsePosition(position, market = undefined) {
|
|
1144
1217
|
//
|
|
1145
1218
|
// {
|
|
@@ -1186,17 +1259,51 @@ export default class kucoinfutures extends kucoin {
|
|
|
1186
1259
|
// }
|
|
1187
1260
|
// ]
|
|
1188
1261
|
// }
|
|
1262
|
+
// position history
|
|
1263
|
+
// {
|
|
1264
|
+
// "closeId": "300000000000000030",
|
|
1265
|
+
// "positionId": "300000000000000009",
|
|
1266
|
+
// "uid": 99996908309485,
|
|
1267
|
+
// "userId": "6527d4fc8c7f3d0001f40f5f",
|
|
1268
|
+
// "symbol": "XBTUSDM",
|
|
1269
|
+
// "settleCurrency": "XBT",
|
|
1270
|
+
// "leverage": "0.0",
|
|
1271
|
+
// "type": "LIQUID_LONG",
|
|
1272
|
+
// "side": null,
|
|
1273
|
+
// "closeSize": null,
|
|
1274
|
+
// "pnl": "-1.0000003793999999",
|
|
1275
|
+
// "realisedGrossCost": "0.9993849748999999",
|
|
1276
|
+
// "withdrawPnl": "0.0",
|
|
1277
|
+
// "roe": null,
|
|
1278
|
+
// "tradeFee": "0.0006154045",
|
|
1279
|
+
// "fundingFee": "0.0",
|
|
1280
|
+
// "openTime": 1713785751181,
|
|
1281
|
+
// "closeTime": 1713785752784,
|
|
1282
|
+
// "openPrice": null,
|
|
1283
|
+
// "closePrice": null
|
|
1284
|
+
// }
|
|
1189
1285
|
//
|
|
1190
1286
|
const symbol = this.safeString(position, 'symbol');
|
|
1191
1287
|
market = this.safeMarket(symbol, market);
|
|
1192
1288
|
const timestamp = this.safeInteger(position, 'currentTimestamp');
|
|
1193
1289
|
const size = this.safeString(position, 'currentQty');
|
|
1194
1290
|
let side = undefined;
|
|
1195
|
-
|
|
1196
|
-
|
|
1291
|
+
const type = this.safeStringLower(position, 'type');
|
|
1292
|
+
if (size !== undefined) {
|
|
1293
|
+
if (Precise.stringGt(size, '0')) {
|
|
1294
|
+
side = 'long';
|
|
1295
|
+
}
|
|
1296
|
+
else if (Precise.stringLt(size, '0')) {
|
|
1297
|
+
side = 'short';
|
|
1298
|
+
}
|
|
1197
1299
|
}
|
|
1198
|
-
else if (
|
|
1199
|
-
|
|
1300
|
+
else if (type !== undefined) {
|
|
1301
|
+
if (type.indexOf('long') > -1) {
|
|
1302
|
+
side = 'long';
|
|
1303
|
+
}
|
|
1304
|
+
else {
|
|
1305
|
+
side = 'short';
|
|
1306
|
+
}
|
|
1200
1307
|
}
|
|
1201
1308
|
const notional = Precise.stringAbs(this.safeString(position, 'posCost'));
|
|
1202
1309
|
const initialMargin = this.safeString(position, 'posInit');
|
|
@@ -1205,25 +1312,28 @@ export default class kucoinfutures extends kucoin {
|
|
|
1205
1312
|
const unrealisedPnl = this.safeString(position, 'unrealisedPnl');
|
|
1206
1313
|
const crossMode = this.safeValue(position, 'crossMode');
|
|
1207
1314
|
// currently crossMode is always set to false and only isolated positions are supported
|
|
1208
|
-
|
|
1315
|
+
let marginMode = undefined;
|
|
1316
|
+
if (crossMode !== undefined) {
|
|
1317
|
+
marginMode = crossMode ? 'cross' : 'isolated';
|
|
1318
|
+
}
|
|
1209
1319
|
return this.safePosition({
|
|
1210
1320
|
'info': position,
|
|
1211
|
-
'id': this.
|
|
1321
|
+
'id': this.safeString2(position, 'id', 'positionId'),
|
|
1212
1322
|
'symbol': this.safeString(market, 'symbol'),
|
|
1213
1323
|
'timestamp': timestamp,
|
|
1214
1324
|
'datetime': this.iso8601(timestamp),
|
|
1215
|
-
'lastUpdateTimestamp':
|
|
1325
|
+
'lastUpdateTimestamp': this.safeInteger(position, 'closeTime'),
|
|
1216
1326
|
'initialMargin': this.parseNumber(initialMargin),
|
|
1217
1327
|
'initialMarginPercentage': this.parseNumber(initialMarginPercentage),
|
|
1218
1328
|
'maintenanceMargin': this.safeNumber(position, 'posMaint'),
|
|
1219
1329
|
'maintenanceMarginPercentage': this.safeNumber(position, 'maintMarginReq'),
|
|
1220
|
-
'entryPrice': this.
|
|
1330
|
+
'entryPrice': this.safeNumber2(position, 'avgEntryPrice', 'openPrice'),
|
|
1221
1331
|
'notional': this.parseNumber(notional),
|
|
1222
|
-
'leverage': this.
|
|
1332
|
+
'leverage': this.safeNumber2(position, 'realLeverage', 'leverage'),
|
|
1223
1333
|
'unrealizedPnl': this.parseNumber(unrealisedPnl),
|
|
1224
1334
|
'contracts': this.parseNumber(Precise.stringAbs(size)),
|
|
1225
1335
|
'contractSize': this.safeValue(market, 'contractSize'),
|
|
1226
|
-
'realizedPnl': this.
|
|
1336
|
+
'realizedPnl': this.safeNumber2(position, 'realisedPnl', 'pnl'),
|
|
1227
1337
|
'marginRatio': undefined,
|
|
1228
1338
|
'liquidationPrice': this.safeNumber(position, 'liquidationPrice'),
|
|
1229
1339
|
'markPrice': this.safeNumber(position, 'markPrice'),
|
|
@@ -2704,4 +2814,42 @@ export default class kucoinfutures extends kucoin {
|
|
|
2704
2814
|
}
|
|
2705
2815
|
return this.parseOrder(response, market);
|
|
2706
2816
|
}
|
|
2817
|
+
async fetchTradingFee(symbol, params = {}) {
|
|
2818
|
+
/**
|
|
2819
|
+
* @method
|
|
2820
|
+
* @name kucoinfutures#fetchTradingFee
|
|
2821
|
+
* @description fetch the trading fees for a market
|
|
2822
|
+
* @see https://www.kucoin.com/docs/rest/funding/trade-fee/trading-pair-actual-fee-futures
|
|
2823
|
+
* @param {string} symbol unified market symbol
|
|
2824
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2825
|
+
* @returns {object} a [fee structure]{@link https://docs.ccxt.com/#/?id=fee-structure}
|
|
2826
|
+
*/
|
|
2827
|
+
await this.loadMarkets();
|
|
2828
|
+
const market = this.market(symbol);
|
|
2829
|
+
const request = {
|
|
2830
|
+
'symbols': market['id'],
|
|
2831
|
+
};
|
|
2832
|
+
const response = await this.privateGetTradeFees(this.extend(request, params));
|
|
2833
|
+
//
|
|
2834
|
+
// {
|
|
2835
|
+
// "code": "200000",
|
|
2836
|
+
// "data": {
|
|
2837
|
+
// "symbol": "XBTUSDTM",
|
|
2838
|
+
// "takerFeeRate": "0.0006",
|
|
2839
|
+
// "makerFeeRate": "0.0002"
|
|
2840
|
+
// }
|
|
2841
|
+
// }
|
|
2842
|
+
//
|
|
2843
|
+
const data = this.safeList(response, 'data', []);
|
|
2844
|
+
const first = this.safeDict(data, 0);
|
|
2845
|
+
const marketId = this.safeString(first, 'symbol');
|
|
2846
|
+
return {
|
|
2847
|
+
'info': response,
|
|
2848
|
+
'symbol': this.safeSymbol(marketId, market),
|
|
2849
|
+
'maker': this.safeNumber(first, 'makerFeeRate'),
|
|
2850
|
+
'taker': this.safeNumber(first, 'takerFeeRate'),
|
|
2851
|
+
'percentage': true,
|
|
2852
|
+
'tierBased': true,
|
|
2853
|
+
};
|
|
2854
|
+
}
|
|
2707
2855
|
}
|
package/js/src/okx.d.ts
CHANGED
|
@@ -171,6 +171,10 @@ export default class okx extends Exchange {
|
|
|
171
171
|
}>;
|
|
172
172
|
fetchFundingHistory(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<FundingHistory[]>;
|
|
173
173
|
setLeverage(leverage: Int, symbol?: Str, params?: {}): Promise<any>;
|
|
174
|
+
fetchPositionMode(symbol?: Str, params?: {}): Promise<{
|
|
175
|
+
info: any;
|
|
176
|
+
hedged: boolean;
|
|
177
|
+
}>;
|
|
174
178
|
setPositionMode(hedged: boolean, symbol?: Str, params?: {}): Promise<any>;
|
|
175
179
|
setMarginMode(marginMode: string, symbol?: Str, params?: {}): Promise<any>;
|
|
176
180
|
fetchCrossBorrowRates(params?: {}): Promise<any>;
|
package/js/src/okx.js
CHANGED
|
@@ -2632,6 +2632,8 @@ export default class okx extends Exchange {
|
|
|
2632
2632
|
const takeProfitDefined = (takeProfit !== undefined);
|
|
2633
2633
|
const trailingPercent = this.safeString2(params, 'trailingPercent', 'callbackRatio');
|
|
2634
2634
|
const isTrailingPercentOrder = trailingPercent !== undefined;
|
|
2635
|
+
const trigger = (triggerPrice !== undefined) || (type === 'trigger');
|
|
2636
|
+
const isReduceOnly = this.safeValue(params, 'reduceOnly', false);
|
|
2635
2637
|
const defaultMarginMode = this.safeString2(this.options, 'defaultMarginMode', 'marginMode', 'cross');
|
|
2636
2638
|
let marginMode = this.safeString2(params, 'marginMode', 'tdMode'); // cross or isolated, tdMode not ommited so as to be extended into the request
|
|
2637
2639
|
let margin = false;
|
|
@@ -2658,6 +2660,25 @@ export default class okx extends Exchange {
|
|
|
2658
2660
|
if (positionSide !== undefined) {
|
|
2659
2661
|
request['posSide'] = positionSide;
|
|
2660
2662
|
}
|
|
2663
|
+
else {
|
|
2664
|
+
let hedged = undefined;
|
|
2665
|
+
[hedged, params] = this.handleOptionAndParams(params, 'createOrder', 'hedged');
|
|
2666
|
+
if (hedged) {
|
|
2667
|
+
const isBuy = (side === 'buy');
|
|
2668
|
+
const isProtective = (takeProfitPrice !== undefined) || (stopLossPrice !== undefined) || isReduceOnly;
|
|
2669
|
+
if (isProtective) {
|
|
2670
|
+
// in case of protective orders, the posSide should be opposite of position side
|
|
2671
|
+
// reduceOnly is emulated and not natively supported by the exchange
|
|
2672
|
+
request['posSide'] = isBuy ? 'short' : 'long';
|
|
2673
|
+
if (isReduceOnly) {
|
|
2674
|
+
params = this.omit(params, 'reduceOnly');
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
else {
|
|
2678
|
+
request['posSide'] = isBuy ? 'long' : 'short';
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2661
2682
|
}
|
|
2662
2683
|
request['tdMode'] = marginMode;
|
|
2663
2684
|
}
|
|
@@ -2667,7 +2688,6 @@ export default class okx extends Exchange {
|
|
|
2667
2688
|
params = this.omit(params, ['currency', 'ccy', 'marginMode', 'timeInForce', 'stopPrice', 'triggerPrice', 'clientOrderId', 'stopLossPrice', 'takeProfitPrice', 'slOrdPx', 'tpOrdPx', 'margin', 'stopLoss', 'takeProfit', 'trailingPercent']);
|
|
2668
2689
|
const ioc = (timeInForce === 'IOC') || (type === 'ioc');
|
|
2669
2690
|
const fok = (timeInForce === 'FOK') || (type === 'fok');
|
|
2670
|
-
const trigger = (triggerPrice !== undefined) || (type === 'trigger');
|
|
2671
2691
|
const conditional = (stopLossPrice !== undefined) || (takeProfitPrice !== undefined) || (type === 'conditional');
|
|
2672
2692
|
const marketIOC = (isMarketOrder && ioc) || (type === 'optimal_limit_ioc');
|
|
2673
2693
|
const defaultTgtCcy = this.safeString(this.options, 'tgtCcy', 'base_ccy');
|
|
@@ -2877,6 +2897,7 @@ export default class okx extends Exchange {
|
|
|
2877
2897
|
* @param {string} [params.positionSide] if position mode is one-way: set to 'net', if position mode is hedge-mode: set to 'long' or 'short'
|
|
2878
2898
|
* @param {string} [params.trailingPercent] the percent to trail away from the current market price
|
|
2879
2899
|
* @param {string} [params.tpOrdKind] 'condition' or 'limit', the default is 'condition'
|
|
2900
|
+
* @param {string} [params.hedged] true/false, to automatically set exchange-specific params needed when trading in hedge mode
|
|
2880
2901
|
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
2881
2902
|
*/
|
|
2882
2903
|
await this.loadMarkets();
|
|
@@ -6264,6 +6285,42 @@ export default class okx extends Exchange {
|
|
|
6264
6285
|
//
|
|
6265
6286
|
return response;
|
|
6266
6287
|
}
|
|
6288
|
+
async fetchPositionMode(symbol = undefined, params = {}) {
|
|
6289
|
+
/**
|
|
6290
|
+
* @method
|
|
6291
|
+
* @name okx#fetchPositionMode
|
|
6292
|
+
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-account-configuration
|
|
6293
|
+
* @description fetchs the position mode, hedged or one way, hedged for binance is set identically for all linear markets or all inverse markets
|
|
6294
|
+
* @param {string} symbol unified symbol of the market to fetch the order book for
|
|
6295
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
6296
|
+
* @param {string} [param.accountId] if you have multiple accounts, you must specify the account id to fetch the position mode
|
|
6297
|
+
* @returns {object} an object detailing whether the market is in hedged or one-way mode
|
|
6298
|
+
*/
|
|
6299
|
+
const accounts = await this.fetchAccounts();
|
|
6300
|
+
const length = accounts.length;
|
|
6301
|
+
let selectedAccount = undefined;
|
|
6302
|
+
if (length > 1) {
|
|
6303
|
+
const accountId = this.safeString(params, 'accountId');
|
|
6304
|
+
if (accountId === undefined) {
|
|
6305
|
+
const accountIds = this.getListFromObjectValues(accounts, 'id');
|
|
6306
|
+
throw new ExchangeError(this.id + ' fetchPositionMode() can not detect position mode, because you have multiple accounts. Set params["accountId"] to desired id from: ' + accountIds.join(', '));
|
|
6307
|
+
}
|
|
6308
|
+
else {
|
|
6309
|
+
const accountsById = this.indexBy(accounts, 'id');
|
|
6310
|
+
selectedAccount = this.safeDict(accountsById, accountId);
|
|
6311
|
+
}
|
|
6312
|
+
}
|
|
6313
|
+
else {
|
|
6314
|
+
selectedAccount = accounts[0];
|
|
6315
|
+
}
|
|
6316
|
+
const mainAccount = selectedAccount['info'];
|
|
6317
|
+
const posMode = this.safeString(mainAccount, 'posMode'); // long_short_mode, net_mode
|
|
6318
|
+
const isHedged = posMode === 'long_short_mode';
|
|
6319
|
+
return {
|
|
6320
|
+
'info': mainAccount,
|
|
6321
|
+
'hedged': isHedged,
|
|
6322
|
+
};
|
|
6323
|
+
}
|
|
6267
6324
|
async setPositionMode(hedged, symbol = undefined, params = {}) {
|
|
6268
6325
|
/**
|
|
6269
6326
|
* @method
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ccxt",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.10",
|
|
4
4
|
"description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
|
|
5
5
|
"unpkg": "dist/ccxt.browser.js",
|
|
6
6
|
"type": "module",
|
|
@@ -30,8 +30,9 @@
|
|
|
30
30
|
"coverage-js": "npm run instrument && npm run nyc-coverage && rm -rf jsInstrumented",
|
|
31
31
|
"docker": "docker-compose run --rm ccxt",
|
|
32
32
|
"fixTSBug": "node build/fixTSBug",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
33
|
+
"transpileCsSingle": "tsx build/csharpTranspiler.ts",
|
|
34
|
+
"transpileCS": "tsx build/csharpTranspiler.ts --multi",
|
|
35
|
+
"transpileCSWs": "tsx build/csharpTranspiler.ts --ws",
|
|
35
36
|
"buildCS": "dotnet build cs/ccxt.sln",
|
|
36
37
|
"buildCSRelease": "dotnet build cs --configuration Release",
|
|
37
38
|
"csharp": "npm run transpileCS && npm run transpileCSWs && npm run buildCS",
|
|
@@ -74,7 +75,7 @@
|
|
|
74
75
|
"cli.js": "node ./examples/js/cli.js",
|
|
75
76
|
"cli.py": "python3 ./examples/py/cli.py",
|
|
76
77
|
"cli.php": "php ./examples/php/cli.php",
|
|
77
|
-
"cli.ts": "
|
|
78
|
+
"cli.ts": "tsx examples/ts/cli.ts",
|
|
78
79
|
"cli.cs": "dotnet run --project \"./cs/cli/cli.csproj\"",
|
|
79
80
|
"export-exchanges": "node build/export-exchanges",
|
|
80
81
|
"capabilities": "node ./examples/js/exchange-capabilities.js",
|
|
@@ -121,7 +122,7 @@
|
|
|
121
122
|
"copy-python-keys": "node build/copy keys.json python/keys.json",
|
|
122
123
|
"copy-python-readme": "node build/copy README.md python/README.md",
|
|
123
124
|
"postinstall": "node postinstall.js",
|
|
124
|
-
"validate-types": "
|
|
125
|
+
"validate-types": "tsx build/validate-types.ts",
|
|
125
126
|
"response-js": "node js/src/test/test.js --responseTests",
|
|
126
127
|
"request-js": "node js/src/test/test.js --requestTests",
|
|
127
128
|
"request-py": "python3 python/ccxt/test/test_async.py --requestTests",
|
|
@@ -138,7 +139,7 @@
|
|
|
138
139
|
"id-tests-php": "php php/test/test_async.php --idTests",
|
|
139
140
|
"id-tests-cs": "dotnet run --project cs/tests/tests.csproj --idTests",
|
|
140
141
|
"id-tests": "npm run id-tests-js && npm run id-tests-py && npm run id-tests-php && npm run id-tests-cs",
|
|
141
|
-
"benchmark": "
|
|
142
|
+
"benchmark": "tsx examples/ts/benchmark.ts"
|
|
142
143
|
},
|
|
143
144
|
"types": "./js/ccxt.d.ts",
|
|
144
145
|
"devDependencies": {
|
|
@@ -168,7 +169,7 @@
|
|
|
168
169
|
"rollup-plugin-execute": "1.1.1",
|
|
169
170
|
"terser-webpack-plugin": "^5.3.9",
|
|
170
171
|
"ts-loader": "^9.4.2",
|
|
171
|
-
"
|
|
172
|
+
"tsx": "^4.7.2",
|
|
172
173
|
"typescript": "4.7.4",
|
|
173
174
|
"webpack": "^5.76.2",
|
|
174
175
|
"webpack-cli": "^5.0.1"
|