ccxt 4.4.31 → 4.4.33

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 (111) hide show
  1. package/README.md +9 -3
  2. package/dist/ccxt.browser.min.js +4 -4
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/base/Exchange.js +89 -0
  5. package/dist/cjs/src/binance.js +154 -0
  6. package/dist/cjs/src/bitvavo.js +0 -4
  7. package/dist/cjs/src/bybit.js +138 -6
  8. package/dist/cjs/src/cex.js +4 -3
  9. package/dist/cjs/src/coinbase.js +2 -22
  10. package/dist/cjs/src/coinbaseexchange.js +2 -1
  11. package/dist/cjs/src/coincatch.js +3 -3
  12. package/dist/cjs/src/coinex.js +2 -1
  13. package/dist/cjs/src/deribit.js +2 -2
  14. package/dist/cjs/src/gate.js +19 -3
  15. package/dist/cjs/src/hitbtc.js +3 -3
  16. package/dist/cjs/src/htx.js +1 -1
  17. package/dist/cjs/src/hyperliquid.js +14 -2
  18. package/dist/cjs/src/indodax.js +1 -1
  19. package/dist/cjs/src/kraken.js +5 -2
  20. package/dist/cjs/src/krakenfutures.js +2 -0
  21. package/dist/cjs/src/kucoin.js +5 -3
  22. package/dist/cjs/src/kucoinfutures.js +99 -28
  23. package/dist/cjs/src/lbank.js +1 -0
  24. package/dist/cjs/src/okx.js +94 -3
  25. package/dist/cjs/src/phemex.js +31 -30
  26. package/dist/cjs/src/pro/binance.js +8 -8
  27. package/dist/cjs/src/pro/bitget.js +4 -4
  28. package/dist/cjs/src/pro/bitmart.js +2 -2
  29. package/dist/cjs/src/pro/bitmex.js +2 -2
  30. package/dist/cjs/src/pro/bitvavo.js +46 -48
  31. package/dist/cjs/src/pro/blofin.js +2 -2
  32. package/dist/cjs/src/pro/bybit.js +2 -2
  33. package/dist/cjs/src/pro/coincatch.js +1 -1
  34. package/dist/cjs/src/pro/cryptocom.js +4 -4
  35. package/dist/cjs/src/pro/gate.js +4 -4
  36. package/dist/cjs/src/pro/hashkey.js +3 -3
  37. package/dist/cjs/src/pro/mexc.js +1 -2
  38. package/dist/cjs/src/pro/okx.js +11 -1
  39. package/dist/cjs/src/wavesexchange.js +1 -0
  40. package/dist/cjs/src/woofipro.js +2 -2
  41. package/js/ccxt.d.ts +1 -1
  42. package/js/ccxt.js +1 -1
  43. package/js/src/abstract/coinbaseexchange.d.ts +1 -0
  44. package/js/src/abstract/kraken.d.ts +1 -0
  45. package/js/src/base/Exchange.d.ts +3 -0
  46. package/js/src/base/Exchange.js +89 -0
  47. package/js/src/binance.d.ts +1 -0
  48. package/js/src/binance.js +154 -0
  49. package/js/src/bitvavo.js +0 -4
  50. package/js/src/bybit.js +139 -7
  51. package/js/src/cex.d.ts +1 -1
  52. package/js/src/cex.js +5 -4
  53. package/js/src/coinbase.js +2 -22
  54. package/js/src/coinbaseexchange.js +2 -1
  55. package/js/src/coincatch.d.ts +1 -1
  56. package/js/src/coincatch.js +3 -3
  57. package/js/src/coinex.d.ts +1 -1
  58. package/js/src/coinex.js +2 -1
  59. package/js/src/deribit.d.ts +2 -2
  60. package/js/src/deribit.js +2 -2
  61. package/js/src/gate.d.ts +3 -1
  62. package/js/src/gate.js +19 -3
  63. package/js/src/hitbtc.d.ts +3 -3
  64. package/js/src/hitbtc.js +3 -3
  65. package/js/src/htx.d.ts +1 -1
  66. package/js/src/htx.js +1 -1
  67. package/js/src/hyperliquid.d.ts +2 -1
  68. package/js/src/hyperliquid.js +14 -2
  69. package/js/src/indodax.js +1 -1
  70. package/js/src/kraken.d.ts +4 -2
  71. package/js/src/kraken.js +5 -2
  72. package/js/src/krakenfutures.d.ts +2 -0
  73. package/js/src/krakenfutures.js +2 -0
  74. package/js/src/kucoin.d.ts +3 -3
  75. package/js/src/kucoin.js +5 -3
  76. package/js/src/kucoinfutures.d.ts +9 -5
  77. package/js/src/kucoinfutures.js +99 -28
  78. package/js/src/lbank.js +1 -0
  79. package/js/src/okx.d.ts +2 -2
  80. package/js/src/okx.js +94 -3
  81. package/js/src/phemex.d.ts +4 -0
  82. package/js/src/phemex.js +31 -30
  83. package/js/src/pro/binance.d.ts +8 -8
  84. package/js/src/pro/binance.js +8 -8
  85. package/js/src/pro/bitget.d.ts +3 -3
  86. package/js/src/pro/bitget.js +4 -4
  87. package/js/src/pro/bitmart.d.ts +2 -2
  88. package/js/src/pro/bitmart.js +2 -2
  89. package/js/src/pro/bitmex.d.ts +2 -2
  90. package/js/src/pro/bitmex.js +2 -2
  91. package/js/src/pro/bitvavo.d.ts +1 -1
  92. package/js/src/pro/bitvavo.js +46 -48
  93. package/js/src/pro/blofin.d.ts +2 -2
  94. package/js/src/pro/blofin.js +2 -2
  95. package/js/src/pro/bybit.d.ts +2 -2
  96. package/js/src/pro/bybit.js +2 -2
  97. package/js/src/pro/coincatch.d.ts +1 -1
  98. package/js/src/pro/coincatch.js +1 -1
  99. package/js/src/pro/cryptocom.d.ts +4 -4
  100. package/js/src/pro/cryptocom.js +4 -4
  101. package/js/src/pro/gate.d.ts +4 -4
  102. package/js/src/pro/gate.js +4 -4
  103. package/js/src/pro/hashkey.d.ts +3 -3
  104. package/js/src/pro/hashkey.js +3 -3
  105. package/js/src/pro/mexc.js +1 -2
  106. package/js/src/pro/okx.js +11 -1
  107. package/js/src/wavesexchange.d.ts +1 -0
  108. package/js/src/wavesexchange.js +1 -0
  109. package/js/src/woofipro.d.ts +2 -2
  110. package/js/src/woofipro.js +2 -2
  111. package/package.json +1 -1
@@ -1226,8 +1226,8 @@ export default class kucoinfutures extends kucoin {
1226
1226
  * @description fetches historical positions
1227
1227
  * @see https://www.kucoin.com/docs/rest/futures-trading/positions/get-positions-history
1228
1228
  * @param {string[]} [symbols] list of unified market symbols
1229
- * @param since
1230
- * @param limit
1229
+ * @param {int} [since] the earliest time in ms to fetch position history for
1230
+ * @param {int} [limit] the maximum number of entries to retrieve
1231
1231
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1232
1232
  * @param {int} [params.until] closing end time
1233
1233
  * @param {int} [params.pageId] page id
@@ -1429,7 +1429,7 @@ export default class kucoinfutures extends kucoin {
1429
1429
  * @method
1430
1430
  * @name kucoinfutures#createOrder
1431
1431
  * @description Create an order on the exchange
1432
- * @see https://docs.kucoin.com/futures/#place-an-order
1432
+ * @see https://www.kucoin.com/docs/rest/futures-trading/orders/place-order
1433
1433
  * @see https://www.kucoin.com/docs/rest/futures-trading/orders/place-take-profit-and-stop-loss-order#http-request
1434
1434
  * @param {string} symbol Unified CCXT market symbol
1435
1435
  * @param {string} type 'limit' or 'market'
@@ -1445,8 +1445,9 @@ export default class kucoinfutures extends kucoin {
1445
1445
  * @param {bool} [params.reduceOnly] A mark to reduce the position size only. Set to false by default. Need to set the position size when reduceOnly is true.
1446
1446
  * @param {string} [params.timeInForce] GTC, GTT, IOC, or FOK, default is GTC, limit orders only
1447
1447
  * @param {string} [params.postOnly] Post only flag, invalid when timeInForce is IOC or FOK
1448
+ * @param {float} [params.cost] the cost of the order in units of USDT
1448
1449
  * ----------------- Exchange Specific Parameters -----------------
1449
- * @param {float} [params.leverage] Leverage size of the order
1450
+ * @param {float} [params.leverage] Leverage size of the order (mandatory param in request, default is 1)
1450
1451
  * @param {string} [params.clientOid] client order id, defaults to uuid if not passed
1451
1452
  * @param {string} [params.remark] remark for the order, length cannot exceed 100 utf8 characters
1452
1453
  * @param {string} [params.stop] 'up' or 'down', the direction the stopPrice is triggered from, requires stopPrice. down: Triggers when the price reaches or goes below the stopPrice. up: Triggers when the price reaches or goes above the stopPrice.
@@ -1540,18 +1541,24 @@ export default class kucoinfutures extends kucoin {
1540
1541
  // required param, cannot be used twice
1541
1542
  const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId', this.uuid());
1542
1543
  params = this.omit(params, ['clientOid', 'clientOrderId']);
1543
- if (amount < 1) {
1544
- throw new InvalidOrder(this.id + ' createOrder() minimum contract order amount is 1');
1545
- }
1546
- const preciseAmount = parseInt(this.amountToPrecision(symbol, amount));
1547
1544
  const request = {
1548
1545
  'clientOid': clientOrderId,
1549
1546
  'side': side,
1550
1547
  'symbol': market['id'],
1551
1548
  'type': type,
1552
- 'size': preciseAmount,
1553
1549
  'leverage': 1,
1554
1550
  };
1551
+ const cost = this.safeString(params, 'cost');
1552
+ params = this.omit(params, 'cost');
1553
+ if (cost !== undefined) {
1554
+ request['valueQty'] = this.costToPrecision(symbol, cost);
1555
+ }
1556
+ else {
1557
+ if (amount < 1) {
1558
+ throw new InvalidOrder(this.id + ' createOrder() minimum contract order amount is 1');
1559
+ }
1560
+ request['size'] = parseInt(this.amountToPrecision(symbol, amount));
1561
+ }
1555
1562
  const [triggerPrice, stopLossPrice, takeProfitPrice] = this.handleTriggerPrices(params);
1556
1563
  const stopLoss = this.safeDict(params, 'stopLoss');
1557
1564
  const takeProfit = this.safeDict(params, 'takeProfit');
@@ -2426,6 +2433,8 @@ export default class kucoinfutures extends kucoin {
2426
2433
  * @method
2427
2434
  * @name kucoinfutures#transfer
2428
2435
  * @description transfer currency internally between wallets on the same account
2436
+ * @see https://www.kucoin.com/docs/rest/funding/transfer/transfer-to-main-or-trade-account
2437
+ * @see https://www.kucoin.com/docs/rest/funding/transfer/transfer-to-futures-account
2429
2438
  * @param {string} code unified currency code
2430
2439
  * @param {float} amount amount to transfer
2431
2440
  * @param {string} fromAccount account to transfer from
@@ -2434,9 +2443,6 @@ export default class kucoinfutures extends kucoin {
2434
2443
  * @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
2435
2444
  */
2436
2445
  async transfer(code, amount, fromAccount, toAccount, params = {}) {
2437
- if ((toAccount !== 'main' && toAccount !== 'funding') || (fromAccount !== 'futures' && fromAccount !== 'future' && fromAccount !== 'contract')) {
2438
- throw new BadRequest(this.id + ' transfer() only supports transfers from contract(future) account to main(funding) account');
2439
- }
2440
2446
  await this.loadMarkets();
2441
2447
  const currency = this.currency(code);
2442
2448
  const amountToPrecision = this.currencyToPrecision(code, amount);
@@ -2444,38 +2450,95 @@ export default class kucoinfutures extends kucoin {
2444
2450
  'currency': this.safeString(currency, 'id'),
2445
2451
  'amount': amountToPrecision,
2446
2452
  };
2447
- // transfer from usdm futures wallet to spot wallet
2448
- const response = await this.futuresPrivatePostTransferOut(this.extend(request, params));
2449
- //
2450
- // {
2451
- // "code": "200000",
2452
- // "data": {
2453
- // "applyId": "5bffb63303aa675e8bbe18f9" // Transfer-out request ID
2454
- // }
2455
- // }
2456
- //
2457
- const data = this.safeValue(response, 'data');
2453
+ const toAccountString = this.parseTransferType(toAccount);
2454
+ let response = undefined;
2455
+ if (toAccountString === 'TRADE' || toAccountString === 'MAIN') {
2456
+ request['recAccountType'] = toAccountString;
2457
+ response = await this.futuresPrivatePostTransferOut(this.extend(request, params));
2458
+ //
2459
+ // {
2460
+ // "code": "200000",
2461
+ // "data": {
2462
+ // "applyId": "6738754373ceee00011ec3f8",
2463
+ // "bizNo": "6738754373ceee00011ec3f7",
2464
+ // "payAccountType": "CONTRACT",
2465
+ // "payTag": "DEFAULT",
2466
+ // "remark": "",
2467
+ // "recAccountType": "MAIN",
2468
+ // "recTag": "DEFAULT",
2469
+ // "recRemark": "",
2470
+ // "recSystem": "KUCOIN",
2471
+ // "status": "PROCESSING",
2472
+ // "currency": "USDT",
2473
+ // "amount": "5",
2474
+ // "fee": "0",
2475
+ // "sn": 1519769124846692,
2476
+ // "reason": "",
2477
+ // "createdAt": 1731753283000,
2478
+ // "updatedAt": 1731753283000
2479
+ // }
2480
+ // }
2481
+ //
2482
+ }
2483
+ else if (toAccount === 'future' || toAccount === 'swap' || toAccount === 'contract') {
2484
+ request['payAccountType'] = this.parseTransferType(fromAccount);
2485
+ response = await this.futuresPrivatePostTransferIn(this.extend(request, params));
2486
+ //
2487
+ // {
2488
+ // "code": "200000",
2489
+ // "data": {
2490
+ // "applyId": "5bffb63303aa675e8bbe18f9" // Transfer-out request ID
2491
+ // }
2492
+ // }
2493
+ //
2494
+ }
2495
+ else {
2496
+ throw new BadRequest(this.id + ' transfer() only supports transfers between future/swap, spot and funding accounts');
2497
+ }
2498
+ const data = this.safeDict(response, 'data', {});
2458
2499
  return this.extend(this.parseTransfer(data, currency), {
2459
2500
  'amount': this.parseNumber(amountToPrecision),
2460
- 'fromAccount': 'future',
2461
- 'toAccount': 'spot',
2501
+ 'fromAccount': fromAccount,
2502
+ 'toAccount': toAccount,
2462
2503
  });
2463
2504
  }
2464
2505
  parseTransfer(transfer, currency = undefined) {
2465
2506
  //
2466
- // transfer
2507
+ // transfer to spot or funding account
2467
2508
  //
2468
2509
  // {
2469
2510
  // "applyId": "5bffb63303aa675e8bbe18f9" // Transfer-out request ID
2470
2511
  // }
2471
2512
  //
2513
+ // transfer to future account
2514
+ //
2515
+ // {
2516
+ // "applyId": "6738754373ceee00011ec3f8",
2517
+ // "bizNo": "6738754373ceee00011ec3f7",
2518
+ // "payAccountType": "CONTRACT",
2519
+ // "payTag": "DEFAULT",
2520
+ // "remark": "",
2521
+ // "recAccountType": "MAIN",
2522
+ // "recTag": "DEFAULT",
2523
+ // "recRemark": "",
2524
+ // "recSystem": "KUCOIN",
2525
+ // "status": "PROCESSING",
2526
+ // "currency": "USDT",
2527
+ // "amount": "5",
2528
+ // "fee": "0",
2529
+ // "sn": 1519769124846692,
2530
+ // "reason": "",
2531
+ // "createdAt": 1731753283000,
2532
+ // "updatedAt": 1731753283000
2533
+ // }
2534
+ //
2472
2535
  const timestamp = this.safeInteger(transfer, 'updatedAt');
2473
2536
  return {
2474
2537
  'id': this.safeString(transfer, 'applyId'),
2475
2538
  'timestamp': timestamp,
2476
2539
  'datetime': this.iso8601(timestamp),
2477
2540
  'currency': this.safeCurrencyCode(undefined, currency),
2478
- 'amount': undefined,
2541
+ 'amount': this.safeNumber(transfer, 'amount'),
2479
2542
  'fromAccount': undefined,
2480
2543
  'toAccount': undefined,
2481
2544
  'status': this.safeString(transfer, 'status'),
@@ -2488,6 +2551,13 @@ export default class kucoinfutures extends kucoin {
2488
2551
  };
2489
2552
  return this.safeString(statuses, status, status);
2490
2553
  }
2554
+ parseTransferType(transferType) {
2555
+ const transferTypes = {
2556
+ 'spot': 'TRADE',
2557
+ 'funding': 'MAIN',
2558
+ };
2559
+ return this.safeStringUpper(transferTypes, transferType, transferType);
2560
+ }
2491
2561
  /**
2492
2562
  * @method
2493
2563
  * @name kucoinfutures#fetchMyTrades
@@ -2889,6 +2959,7 @@ export default class kucoinfutures extends kucoin {
2889
2959
  /**
2890
2960
  * @ignore
2891
2961
  * @method
2962
+ * @name kucoinfutures#parseMarketLeverageTiers
2892
2963
  * @param {object} info Exchange market response for 1 market
2893
2964
  * @param {object} market CCXT market
2894
2965
  */
@@ -3130,7 +3201,7 @@ export default class kucoinfutures extends kucoin {
3130
3201
  }
3131
3202
  /**
3132
3203
  * @method
3133
- * @name kucoin#fetchLeverage
3204
+ * @name kucoinfutures#fetchLeverage
3134
3205
  * @description fetch the set leverage for a market
3135
3206
  * @see https://www.kucoin.com/docs/rest/futures-trading/positions/get-cross-margin-leverage
3136
3207
  * @param {string} symbol unified market symbol
package/js/src/lbank.js CHANGED
@@ -212,6 +212,7 @@ export default class lbank extends Exchange {
212
212
  },
213
213
  },
214
214
  'commonCurrencies': {
215
+ 'HIT': 'Hiver',
215
216
  'VET_ERC20': 'VEN',
216
217
  'PNT': 'Penta',
217
218
  },
package/js/src/okx.d.ts CHANGED
@@ -1042,8 +1042,8 @@ export default class okx extends Exchange {
1042
1042
  * @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-bills-details-last-3-months
1043
1043
  * @param {string} [symbol] not used by okx fetchMarginAdjustmentHistory
1044
1044
  * @param {string} [type] "add" or "reduce"
1045
- * @param since
1046
- * @param limit
1045
+ * @param {int} [since] the earliest time in ms to fetch margin adjustment history for
1046
+ * @param {int} [limit] the maximum number of entries to retrieve
1047
1047
  * @param {object} params extra parameters specific to the exchange api endpoint
1048
1048
  * @param {boolean} [params.auto] true if fetching auto margin increases
1049
1049
  * @returns {object[]} a list of [margin structures]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
package/js/src/okx.js CHANGED
@@ -1176,6 +1176,97 @@ export default class okx extends Exchange {
1176
1176
  },
1177
1177
  'brokerId': 'e847386590ce4dBC',
1178
1178
  },
1179
+ 'features': {
1180
+ // https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
1181
+ 'default': {
1182
+ 'sandbox': true,
1183
+ 'createOrder': {
1184
+ 'triggerPrice': true,
1185
+ 'triggerPriceType': {
1186
+ 'last': true,
1187
+ 'mark': true,
1188
+ 'index': true,
1189
+ },
1190
+ 'triggerDirection': false,
1191
+ 'stopLossPrice': true,
1192
+ 'takeProfitPrice': true,
1193
+ 'marginMode': true,
1194
+ 'attachedStopLossTakeProfit': {
1195
+ 'triggerPriceType': {
1196
+ 'last': true,
1197
+ 'mark': true,
1198
+ 'index': true,
1199
+ },
1200
+ 'limitPrice': true,
1201
+ },
1202
+ 'timeInForce': {
1203
+ 'GTC': true,
1204
+ 'IOC': true,
1205
+ 'FOK': true,
1206
+ 'PO': true,
1207
+ 'GTD': false,
1208
+ },
1209
+ 'hedged': true,
1210
+ // even though the below params not unified yet, it's useful metadata for users to know that exchange supports them
1211
+ 'selfTradePrevention': true,
1212
+ 'trailing': true,
1213
+ 'twap': true,
1214
+ 'iceberg': true,
1215
+ 'oco': true,
1216
+ },
1217
+ 'createOrders': {
1218
+ 'max': 20,
1219
+ },
1220
+ 'fetchMyTrades': {
1221
+ 'daysBack': 90,
1222
+ 'limit': 100,
1223
+ 'untilDays': 10000,
1224
+ },
1225
+ 'fetchOrder': {
1226
+ 'marginMode': false,
1227
+ 'trigger': true,
1228
+ 'trailing': true,
1229
+ },
1230
+ 'fetchOpenOrders': {
1231
+ 'limit': 100,
1232
+ 'marginMode': false,
1233
+ 'trigger': true,
1234
+ 'trailing': true,
1235
+ },
1236
+ 'fetchOrders': undefined,
1237
+ 'fetchClosedOrders': {
1238
+ 'limit': 100,
1239
+ 'daysBackClosed': 90,
1240
+ 'daysBackCanceled': 1 / 12,
1241
+ 'untilDays': undefined,
1242
+ 'marginMode': false,
1243
+ 'trigger': true,
1244
+ 'trailing': true,
1245
+ },
1246
+ 'fetchOHLCV': {
1247
+ 'limit': 300,
1248
+ },
1249
+ },
1250
+ 'spot': {
1251
+ 'extends': 'default',
1252
+ },
1253
+ 'swap': {
1254
+ 'linear': {
1255
+ 'extends': 'default',
1256
+ },
1257
+ 'inverse': {
1258
+ 'extends': 'default',
1259
+ },
1260
+ },
1261
+ 'future': {
1262
+ 'linear': {
1263
+ 'extends': 'default',
1264
+ },
1265
+ 'inverse': {
1266
+ 'extends': 'default',
1267
+ },
1268
+ },
1269
+ },
1179
1270
  'commonCurrencies': {
1180
1271
  // the exchange refers to ERC20 version of Aeternity (AEToken)
1181
1272
  'AE': 'AET',
@@ -3221,7 +3312,7 @@ export default class okx extends Exchange {
3221
3312
  request['newPx'] = this.priceToPrecision(symbol, price);
3222
3313
  }
3223
3314
  }
3224
- params = this.omit(params, ['clOrdId', 'clientOrderId', 'takeProfitPrice', 'stopLossPrice', 'stopLoss', 'takeProfit']);
3315
+ params = this.omit(params, ['clOrdId', 'clientOrderId', 'takeProfitPrice', 'stopLossPrice', 'stopLoss', 'takeProfit', 'postOnly']);
3225
3316
  return this.extend(request, params);
3226
3317
  }
3227
3318
  /**
@@ -8332,8 +8423,8 @@ export default class okx extends Exchange {
8332
8423
  * @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-bills-details-last-3-months
8333
8424
  * @param {string} [symbol] not used by okx fetchMarginAdjustmentHistory
8334
8425
  * @param {string} [type] "add" or "reduce"
8335
- * @param since
8336
- * @param limit
8426
+ * @param {int} [since] the earliest time in ms to fetch margin adjustment history for
8427
+ * @param {int} [limit] the maximum number of entries to retrieve
8337
8428
  * @param {object} params extra parameters specific to the exchange api endpoint
8338
8429
  * @param {boolean} [params.auto] true if fetching auto margin increases
8339
8430
  * @returns {object[]} a list of [margin structures]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
@@ -334,6 +334,7 @@ export default class phemex extends Exchange {
334
334
  * @method
335
335
  * @name phemex#setMarginMode
336
336
  * @description set margin mode to 'cross' or 'isolated'
337
+ * @see https://phemex-docs.github.io/#set-leverage
337
338
  * @param {string} marginMode 'cross' or 'isolated'
338
339
  * @param {string} symbol unified market symbol
339
340
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -385,6 +386,8 @@ export default class phemex extends Exchange {
385
386
  * @method
386
387
  * @name phemex#transfer
387
388
  * @description transfer currency internally between wallets on the same account
389
+ * @see https://phemex-docs.github.io/#transfer-between-spot-and-futures
390
+ * @see https://phemex-docs.github.io/#universal-transfer-main-account-only-transfer-between-sub-to-main-main-to-sub-or-sub-to-sub
388
391
  * @param {string} code unified currency code
389
392
  * @param {float} amount amount to transfer
390
393
  * @param {string} fromAccount account to transfer from
@@ -398,6 +401,7 @@ export default class phemex extends Exchange {
398
401
  * @method
399
402
  * @name phemex#fetchTransfers
400
403
  * @description fetch a history of internal transfers made on an account
404
+ * @see https://phemex-docs.github.io/#query-transfer-history
401
405
  * @param {string} code unified currency code of the currency transferred
402
406
  * @param {int} [since] the earliest time in ms to fetch transfers for
403
407
  * @param {int} [limit] the maximum number of transfers structures to retrieve
package/js/src/phemex.js CHANGED
@@ -491,6 +491,13 @@ export default class phemex extends Exchange {
491
491
  'transfer': {
492
492
  'fillResponseFromRequest': true,
493
493
  },
494
+ 'triggerPriceTypesMap': {
495
+ 'last': 'ByLastPrice',
496
+ 'mark': 'ByMarkPrice',
497
+ 'index': 'ByIndexPrice',
498
+ 'ask': 'ByAskPrice',
499
+ 'bid': 'ByBidPrice',
500
+ },
494
501
  },
495
502
  });
496
503
  }
@@ -506,7 +513,7 @@ export default class phemex extends Exchange {
506
513
  parseSwapMarket(market) {
507
514
  //
508
515
  // {
509
- // "symbol":"BTCUSD",
516
+ // "symbol":"BTCUSD", //
510
517
  // "code":"1",
511
518
  // "type":"Perpetual",
512
519
  // "displaySymbol":"BTC / USD",
@@ -514,7 +521,7 @@ export default class phemex extends Exchange {
514
521
  // "markSymbol":".MBTC",
515
522
  // "fundingRateSymbol":".BTCFR",
516
523
  // "fundingRate8hSymbol":".BTCFR8H",
517
- // "contractUnderlyingAssets":"USD",
524
+ // "contractUnderlyingAssets":"USD", // or eg. `1000 SHIB`
518
525
  // "settleCurrency":"BTC",
519
526
  // "quoteCurrency":"USD",
520
527
  // "contractSize":"1 USD",
@@ -557,7 +564,8 @@ export default class phemex extends Exchange {
557
564
  const baseId = this.safeString2(market, 'baseCurrency', 'contractUnderlyingAssets');
558
565
  const quoteId = this.safeString(market, 'quoteCurrency');
559
566
  const settleId = this.safeString(market, 'settleCurrency');
560
- const base = this.safeCurrencyCode(baseId);
567
+ let base = this.safeCurrencyCode(baseId);
568
+ base = base.replace(' ', ''); // replace space for junction codes, eg. `1000 SHIB`
561
569
  const quote = this.safeCurrencyCode(quoteId);
562
570
  const settle = this.safeCurrencyCode(settleId);
563
571
  let inverse = false;
@@ -2140,6 +2148,7 @@ export default class phemex extends Exchange {
2140
2148
  'PartiallyFilled': 'open',
2141
2149
  'Filled': 'closed',
2142
2150
  'Canceled': 'canceled',
2151
+ 'Suspended': 'canceled',
2143
2152
  '1': 'open',
2144
2153
  '2': 'canceled',
2145
2154
  '3': 'closed',
@@ -2636,7 +2645,7 @@ export default class phemex extends Exchange {
2636
2645
  if (stopLossDefined) {
2637
2646
  const stopLossTriggerPrice = this.safeValue2(stopLoss, 'triggerPrice', 'stopPrice');
2638
2647
  if (stopLossTriggerPrice === undefined) {
2639
- throw new InvalidOrder(this.id + ' createOrder() requires a trigger price in params["stopLoss"]["triggerPrice"], or params["stopLoss"]["stopPrice"] for a stop loss order');
2648
+ throw new InvalidOrder(this.id + ' createOrder() requires a trigger price in params["stopLoss"]["triggerPrice"] for a stop loss order');
2640
2649
  }
2641
2650
  if (market['settle'] === 'USDT') {
2642
2651
  request['stopLossRp'] = this.priceToPrecision(symbol, stopLossTriggerPrice);
@@ -2646,23 +2655,17 @@ export default class phemex extends Exchange {
2646
2655
  }
2647
2656
  const stopLossTriggerPriceType = this.safeString2(stopLoss, 'triggerPriceType', 'slTrigger');
2648
2657
  if (stopLossTriggerPriceType !== undefined) {
2649
- if (market['settle'] === 'USDT') {
2650
- if ((stopLossTriggerPriceType !== 'ByMarkPrice') && (stopLossTriggerPriceType !== 'ByLastPrice') && (stopLossTriggerPriceType !== 'ByIndexPrice') && (stopLossTriggerPriceType !== 'ByAskPrice') && (stopLossTriggerPriceType !== 'ByBidPrice') && (stopLossTriggerPriceType !== 'ByMarkPriceLimit') && (stopLossTriggerPriceType !== 'ByLastPriceLimit')) {
2651
- throw new InvalidOrder(this.id + ' createOrder() take profit trigger price type must be one of "ByMarkPrice", "ByIndexPrice", "ByAskPrice", "ByBidPrice", "ByMarkPriceLimit", "ByLastPriceLimit" or "ByLastPrice"');
2652
- }
2653
- }
2654
- else {
2655
- if ((stopLossTriggerPriceType !== 'ByMarkPrice') && (stopLossTriggerPriceType !== 'ByLastPrice')) {
2656
- throw new InvalidOrder(this.id + ' createOrder() take profit trigger price type must be one of "ByMarkPrice", or "ByLastPrice"');
2657
- }
2658
- }
2659
- request['slTrigger'] = stopLossTriggerPriceType;
2658
+ request['slTrigger'] = this.safeString(this.options['triggerPriceTypesMap'], stopLossTriggerPriceType, stopLossTriggerPriceType);
2659
+ }
2660
+ const slLimitPrice = this.safeString(stopLoss, 'price');
2661
+ if (slLimitPrice !== undefined) {
2662
+ request['slPxRp'] = this.priceToPrecision(symbol, slLimitPrice);
2660
2663
  }
2661
2664
  }
2662
2665
  if (takeProfitDefined) {
2663
2666
  const takeProfitTriggerPrice = this.safeValue2(takeProfit, 'triggerPrice', 'stopPrice');
2664
2667
  if (takeProfitTriggerPrice === undefined) {
2665
- throw new InvalidOrder(this.id + ' createOrder() requires a trigger price in params["takeProfit"]["triggerPrice"], or params["takeProfit"]["stopPrice"] for a take profit order');
2668
+ throw new InvalidOrder(this.id + ' createOrder() requires a trigger price in params["takeProfit"]["triggerPrice"] for a take profit order');
2666
2669
  }
2667
2670
  if (market['settle'] === 'USDT') {
2668
2671
  request['takeProfitRp'] = this.priceToPrecision(symbol, takeProfitTriggerPrice);
@@ -2670,19 +2673,13 @@ export default class phemex extends Exchange {
2670
2673
  else {
2671
2674
  request['takeProfitEp'] = this.toEp(takeProfitTriggerPrice, market);
2672
2675
  }
2673
- const takeProfitTriggerPriceType = this.safeString2(stopLoss, 'triggerPriceType', 'tpTrigger');
2676
+ const takeProfitTriggerPriceType = this.safeString2(takeProfit, 'triggerPriceType', 'tpTrigger');
2674
2677
  if (takeProfitTriggerPriceType !== undefined) {
2675
- if (market['settle'] === 'USDT') {
2676
- if ((takeProfitTriggerPriceType !== 'ByMarkPrice') && (takeProfitTriggerPriceType !== 'ByLastPrice') && (takeProfitTriggerPriceType !== 'ByIndexPrice') && (takeProfitTriggerPriceType !== 'ByAskPrice') && (takeProfitTriggerPriceType !== 'ByBidPrice') && (takeProfitTriggerPriceType !== 'ByMarkPriceLimit') && (takeProfitTriggerPriceType !== 'ByLastPriceLimit')) {
2677
- throw new InvalidOrder(this.id + ' createOrder() take profit trigger price type must be one of "ByMarkPrice", "ByIndexPrice", "ByAskPrice", "ByBidPrice", "ByMarkPriceLimit", "ByLastPriceLimit" or "ByLastPrice"');
2678
- }
2679
- }
2680
- else {
2681
- if ((takeProfitTriggerPriceType !== 'ByMarkPrice') && (takeProfitTriggerPriceType !== 'ByLastPrice')) {
2682
- throw new InvalidOrder(this.id + ' createOrder() take profit trigger price type must be one of "ByMarkPrice", or "ByLastPrice"');
2683
- }
2684
- }
2685
- request['tpTrigger'] = takeProfitTriggerPriceType;
2678
+ request['tpTrigger'] = this.safeString(this.options['triggerPriceTypesMap'], takeProfitTriggerPriceType, takeProfitTriggerPriceType);
2679
+ }
2680
+ const tpLimitPrice = this.safeString(takeProfit, 'price');
2681
+ if (tpLimitPrice !== undefined) {
2682
+ request['tpPxRp'] = this.priceToPrecision(symbol, tpLimitPrice);
2686
2683
  }
2687
2684
  }
2688
2685
  }
@@ -2858,7 +2855,7 @@ export default class phemex extends Exchange {
2858
2855
  request['baseQtyEV'] = this.toEv(amount, market);
2859
2856
  }
2860
2857
  }
2861
- const stopPrice = this.safeString2(params, 'stopPx', 'stopPrice');
2858
+ const stopPrice = this.safeStringN(params, ['triggerPrice', 'stopPx', 'stopPrice']);
2862
2859
  if (stopPrice !== undefined) {
2863
2860
  if (isUSDTSettled) {
2864
2861
  request['stopPxRp'] = this.priceToPrecision(symbol, stopPrice);
@@ -2867,7 +2864,7 @@ export default class phemex extends Exchange {
2867
2864
  request['stopPxEp'] = this.toEp(stopPrice, market);
2868
2865
  }
2869
2866
  }
2870
- params = this.omit(params, ['stopPx', 'stopPrice']);
2867
+ params = this.omit(params, ['triggerPrice', 'stopPx', 'stopPrice']);
2871
2868
  let response = undefined;
2872
2869
  if (isUSDTSettled) {
2873
2870
  const posSide = this.safeString(params, 'posSide');
@@ -4211,6 +4208,7 @@ export default class phemex extends Exchange {
4211
4208
  * @method
4212
4209
  * @name phemex#setMarginMode
4213
4210
  * @description set margin mode to 'cross' or 'isolated'
4211
+ * @see https://phemex-docs.github.io/#set-leverage
4214
4212
  * @param {string} marginMode 'cross' or 'isolated'
4215
4213
  * @param {string} symbol unified market symbol
4216
4214
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -4501,6 +4499,8 @@ export default class phemex extends Exchange {
4501
4499
  * @method
4502
4500
  * @name phemex#transfer
4503
4501
  * @description transfer currency internally between wallets on the same account
4502
+ * @see https://phemex-docs.github.io/#transfer-between-spot-and-futures
4503
+ * @see https://phemex-docs.github.io/#universal-transfer-main-account-only-transfer-between-sub-to-main-main-to-sub-or-sub-to-sub
4504
4504
  * @param {string} code unified currency code
4505
4505
  * @param {float} amount amount to transfer
4506
4506
  * @param {string} fromAccount account to transfer from
@@ -4588,6 +4588,7 @@ export default class phemex extends Exchange {
4588
4588
  * @method
4589
4589
  * @name phemex#fetchTransfers
4590
4590
  * @description fetch a history of internal transfers made on an account
4591
+ * @see https://phemex-docs.github.io/#query-transfer-history
4591
4592
  * @param {string} code unified currency code of the currency transferred
4592
4593
  * @param {int} [since] the earliest time in ms to fetch transfers for
4593
4594
  * @param {int} [limit] the maximum number of transfers structures to retrieve
@@ -167,7 +167,7 @@ export default class binance extends binanceRest {
167
167
  * @description watch the public liquidations of a trading pair
168
168
  * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/All-Market-Liquidation-Order-Streams
169
169
  * @see https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/All-Market-Liquidation-Order-Streams
170
- * @param {string[]} symbols
170
+ * @param {string[]} symbols list of unified market symbols
171
171
  * @param {int} [since] the earliest time in ms to fetch liquidations for
172
172
  * @param {int} [limit] the maximum number of liquidation structures to retrieve
173
173
  * @param {object} [params] exchange specific parameters for the bitmex api endpoint
@@ -195,7 +195,7 @@ export default class binance extends binanceRest {
195
195
  * @description watch the private liquidations of a trading pair
196
196
  * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/user-data-streams/Event-Order-Update
197
197
  * @see https://developers.binance.com/docs/derivatives/coin-margined-futures/user-data-streams/Event-Order-Update
198
- * @param symbols
198
+ * @param {string[]} symbols list of unified market symbols
199
199
  * @param {int} [since] the earliest time in ms to fetch liquidations for
200
200
  * @param {int} [limit] the maximum number of liquidation structures to retrieve
201
201
  * @param {object} [params] exchange specific parameters for the bitmex api endpoint
@@ -636,7 +636,7 @@ export default class binance extends binanceRest {
636
636
  * @see https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api#cancel-order-trade
637
637
  * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Cancel-Order
638
638
  * @param {string} id order id
639
- * @param {string} symbol unified market symbol, default is undefined
639
+ * @param {string} [symbol] unified market symbol, default is undefined
640
640
  * @param {object} [params] extra parameters specific to the exchange API endpoint
641
641
  * @param {string|undefined} [params.cancelRestrictions] Supported values: ONLY_NEW - Cancel will succeed if the order status is NEW. ONLY_PARTIALLY_FILLED - Cancel will succeed if order status is PARTIALLY_FILLED.
642
642
  * @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -647,7 +647,7 @@ export default class binance extends binanceRest {
647
647
  * @name binance#cancelAllOrdersWs
648
648
  * @description cancel all open orders in a market
649
649
  * @see https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api#cancel-open-orders-trade
650
- * @param {string} symbol unified market symbol of the market to cancel orders in
650
+ * @param {string} [symbol] unified market symbol of the market to cancel orders in
651
651
  * @param {object} [params] extra parameters specific to the exchange API endpoint
652
652
  * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
653
653
  */
@@ -659,8 +659,8 @@ export default class binance extends binanceRest {
659
659
  * @see https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api#query-order-user_data
660
660
  * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Query-Order
661
661
  * @param {string} id order id
662
- * @param {string} symbol unified symbol of the market the order was made in
663
- * @param {object} params extra parameters specific to the exchange API endpoint
662
+ * @param {string} [symbol] unified symbol of the market the order was made in
663
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
664
664
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
665
665
  */
666
666
  fetchOrderWs(id: string, symbol?: Str, params?: {}): Promise<Order>;
@@ -727,8 +727,8 @@ export default class binance extends binanceRest {
727
727
  * @name binance#watchPositions
728
728
  * @description watch all open positions
729
729
  * @param {string[]|undefined} symbols list of unified market symbols
730
- * @param since
731
- * @param limit
730
+ * @param {number} [since] since timestamp
731
+ * @param {number} [limit] limit
732
732
  * @param {object} params extra parameters specific to the exchange API endpoint
733
733
  * @param {boolean} [params.portfolioMargin] set to true if you would like to watch positions in a portfolio margin account
734
734
  * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}