ccxt 4.1.73 → 4.1.75

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 (53) hide show
  1. package/README.md +6 -8
  2. package/dist/ccxt.browser.js +1108 -1455
  3. package/dist/ccxt.browser.min.js +3 -3
  4. package/dist/cjs/ccxt.js +1 -4
  5. package/dist/cjs/src/base/Exchange.js +31 -4
  6. package/dist/cjs/src/base/ws/Client.js +11 -14
  7. package/dist/cjs/src/bigone.js +38 -9
  8. package/dist/cjs/src/bingx.js +57 -18
  9. package/dist/cjs/src/bitmart.js +33 -11
  10. package/dist/cjs/src/bybit.js +30 -7
  11. package/dist/cjs/src/cex.js +61 -3
  12. package/dist/cjs/src/exmo.js +34 -31
  13. package/dist/cjs/src/gate.js +1 -0
  14. package/dist/cjs/src/gemini.js +21 -19
  15. package/dist/cjs/src/kraken.js +156 -11
  16. package/dist/cjs/src/okx.js +45 -2
  17. package/dist/cjs/src/poloniex.js +27 -25
  18. package/dist/cjs/src/pro/binance.js +60 -8
  19. package/dist/cjs/src/pro/cex.js +317 -10
  20. package/dist/cjs/src/pro/coinbasepro.js +1 -1
  21. package/js/ccxt.d.ts +2 -5
  22. package/js/ccxt.js +2 -4
  23. package/js/src/abstract/kraken.d.ts +2 -0
  24. package/js/src/base/Exchange.d.ts +2 -0
  25. package/js/src/base/Exchange.js +31 -4
  26. package/js/src/base/ws/Client.js +11 -14
  27. package/js/src/bigone.d.ts +1 -0
  28. package/js/src/bigone.js +38 -9
  29. package/js/src/bingx.d.ts +3 -0
  30. package/js/src/bingx.js +58 -19
  31. package/js/src/bitmart.d.ts +1 -0
  32. package/js/src/bitmart.js +33 -11
  33. package/js/src/bybit.d.ts +1 -0
  34. package/js/src/bybit.js +30 -7
  35. package/js/src/cex.d.ts +1 -0
  36. package/js/src/cex.js +61 -3
  37. package/js/src/exmo.d.ts +1 -1
  38. package/js/src/exmo.js +34 -31
  39. package/js/src/gate.js +1 -0
  40. package/js/src/gemini.js +21 -19
  41. package/js/src/kraken.d.ts +2 -0
  42. package/js/src/kraken.js +156 -11
  43. package/js/src/okx.d.ts +2 -0
  44. package/js/src/okx.js +45 -2
  45. package/js/src/poloniex.js +27 -25
  46. package/js/src/pro/binance.d.ts +1 -0
  47. package/js/src/pro/binance.js +61 -9
  48. package/js/src/pro/cex.d.ts +11 -2
  49. package/js/src/pro/cex.js +318 -11
  50. package/js/src/pro/coinbasepro.js +1 -1
  51. package/package.json +1 -1
  52. package/js/src/abstract/tidex.d.ts +0 -28
  53. package/js/src/abstract/tidex.js +0 -11
package/js/ccxt.js CHANGED
@@ -38,7 +38,7 @@ import * as errors from './src/base/errors.js';
38
38
  import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.1.73';
41
+ const version = '4.1.75';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -130,7 +130,6 @@ import phemex from './src/phemex.js';
130
130
  import poloniex from './src/poloniex.js';
131
131
  import poloniexfutures from './src/poloniexfutures.js';
132
132
  import probit from './src/probit.js';
133
- import tidex from './src/tidex.js';
134
133
  import timex from './src/timex.js';
135
134
  import tokocrypto from './src/tokocrypto.js';
136
135
  import upbit from './src/upbit.js';
@@ -290,7 +289,6 @@ const exchanges = {
290
289
  'poloniex': poloniex,
291
290
  'poloniexfutures': poloniexfutures,
292
291
  'probit': probit,
293
- 'tidex': tidex,
294
292
  'timex': timex,
295
293
  'tokocrypto': tokocrypto,
296
294
  'upbit': upbit,
@@ -374,6 +372,6 @@ pro.exchanges = Object.keys(pro);
374
372
  pro['Exchange'] = Exchange; // now the same for rest and ts
375
373
  //-----------------------------------------------------------------------------
376
374
  const ccxt = Object.assign({ version, Exchange, Precise, 'exchanges': Object.keys(exchanges), 'pro': pro }, exchanges, functions, errors);
377
- export { version, Exchange, exchanges, pro, Precise, functions, errors, BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange, ace, alpaca, ascendex, bequant, bigone, binance, binancecoinm, binanceus, binanceusdm, bingx, bit2c, bitbank, bitbay, bitbns, bitcoincom, bitfinex, bitfinex2, bitflyer, bitforex, bitget, bithumb, bitmart, bitmex, bitopro, bitpanda, bitrue, bitso, bitstamp, bittrex, bitvavo, bl3p, blockchaincom, btcalpha, btcbox, btcmarkets, btcturk, bybit, cex, coinbase, coinbaseprime, coinbasepro, coincheck, coinex, coinlist, coinmate, coinone, coinsph, coinspot, cryptocom, currencycom, delta, deribit, digifinex, exmo, fmfwio, gate, gateio, gemini, hitbtc, hitbtc3, hollaex, htx, huobi, huobijp, idex, independentreserve, indodax, kraken, krakenfutures, kucoin, kucoinfutures, kuna, latoken, lbank, luno, lykke, mercado, mexc, ndax, novadax, oceanex, okcoin, okx, p2b, paymium, phemex, poloniex, poloniexfutures, probit, tidex, timex, tokocrypto, upbit, wavesexchange, wazirx, whitebit, woo, yobit, zaif, zonda, };
375
+ export { version, Exchange, exchanges, pro, Precise, functions, errors, BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange, ace, alpaca, ascendex, bequant, bigone, binance, binancecoinm, binanceus, binanceusdm, bingx, bit2c, bitbank, bitbay, bitbns, bitcoincom, bitfinex, bitfinex2, bitflyer, bitforex, bitget, bithumb, bitmart, bitmex, bitopro, bitpanda, bitrue, bitso, bitstamp, bittrex, bitvavo, bl3p, blockchaincom, btcalpha, btcbox, btcmarkets, btcturk, bybit, cex, coinbase, coinbaseprime, coinbasepro, coincheck, coinex, coinlist, coinmate, coinone, coinsph, coinspot, cryptocom, currencycom, delta, deribit, digifinex, exmo, fmfwio, gate, gateio, gemini, hitbtc, hitbtc3, hollaex, htx, huobi, huobijp, idex, independentreserve, indodax, kraken, krakenfutures, kucoin, kucoinfutures, kuna, latoken, lbank, luno, lykke, mercado, mexc, ndax, novadax, oceanex, okcoin, okx, p2b, paymium, phemex, poloniex, poloniexfutures, probit, timex, tokocrypto, upbit, wavesexchange, wazirx, whitebit, woo, yobit, zaif, zonda, };
378
376
  export default ccxt;
379
377
  //-----------------------------------------------------------------------------
@@ -42,6 +42,8 @@ interface Exchange {
42
42
  privatePostWithdraw(params?: {}): Promise<implicitReturnType>;
43
43
  privatePostWithdrawCancel(params?: {}): Promise<implicitReturnType>;
44
44
  privatePostWithdrawInfo(params?: {}): Promise<implicitReturnType>;
45
+ privatePostWithdrawMethods(params?: {}): Promise<implicitReturnType>;
46
+ privatePostWithdrawAddresses(params?: {}): Promise<implicitReturnType>;
45
47
  privatePostWithdrawStatus(params?: {}): Promise<implicitReturnType>;
46
48
  privatePostWalletTransfer(params?: {}): Promise<implicitReturnType>;
47
49
  privatePostCreateSubaccount(params?: {}): Promise<implicitReturnType>;
@@ -296,6 +296,7 @@ export default class Exchange {
296
296
  createMarketOrder: boolean;
297
297
  createOrder: boolean;
298
298
  createMarketBuyOrderWithCost: any;
299
+ createMarketOrderWithCost: any;
299
300
  createMarketSellOrderWithCost: any;
300
301
  createOrders: any;
301
302
  createPostOnlyOrder: any;
@@ -759,6 +760,7 @@ export default class Exchange {
759
760
  fetchOrderStatus(id: string, symbol?: string, params?: {}): Promise<string>;
760
761
  fetchUnifiedOrder(order: any, params?: {}): Promise<Order>;
761
762
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<Order>;
763
+ createMarketOrderWithCost(symbol: string, side: OrderSide, cost: any, params?: {}): Promise<Order>;
762
764
  createMarketBuyOrderWithCost(symbol: string, cost: any, params?: {}): Promise<Order>;
763
765
  createMarketSellOrderWithCost(symbol: string, cost: any, params?: {}): Promise<Order>;
764
766
  createOrders(orders: OrderRequest[], params?: {}): Promise<Order[]>;
@@ -354,6 +354,7 @@ export default class Exchange {
354
354
  'createMarketOrder': true,
355
355
  'createOrder': true,
356
356
  'createMarketBuyOrderWithCost': undefined,
357
+ 'createMarketOrderWithCost': undefined,
357
358
  'createMarketSellOrderWithCost': undefined,
358
359
  'createOrders': undefined,
359
360
  'createPostOnlyOrder': undefined,
@@ -3556,28 +3557,50 @@ export default class Exchange {
3556
3557
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
3557
3558
  throw new NotSupported(this.id + ' createOrder() is not supported yet');
3558
3559
  }
3560
+ async createMarketOrderWithCost(symbol, side, cost, params = {}) {
3561
+ /**
3562
+ * @method
3563
+ * @name createMarketOrderWithCost
3564
+ * @description create a market order by providing the symbol, side and cost
3565
+ * @param {string} symbol unified symbol of the market to create an order in
3566
+ * @param {string} side 'buy' or 'sell'
3567
+ * @param {float} cost how much you want to trade in units of the quote currency
3568
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3569
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3570
+ */
3571
+ if (this.options['createMarketOrderWithCost'] || (this.options['createMarketBuyOrderWithCost'] && this.options['createMarketSellOrderWithCost'])) {
3572
+ return await this.createOrder(symbol, 'market', side, cost, 1, params);
3573
+ }
3574
+ throw new NotSupported(this.id + ' createMarketOrderWithCost() is not supported yet');
3575
+ }
3559
3576
  async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
3560
3577
  /**
3561
3578
  * @method
3562
- * @name createMarketBuyWithCost
3579
+ * @name createMarketBuyOrderWithCost
3563
3580
  * @description create a market buy order by providing the symbol and cost
3564
3581
  * @param {string} symbol unified symbol of the market to create an order in
3565
3582
  * @param {float} cost how much you want to trade in units of the quote currency
3566
3583
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3567
3584
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3568
3585
  */
3586
+ if (this.options['createMarketBuyOrderRequiresPrice'] || this.options['createMarketBuyOrderWithCost']) {
3587
+ return await this.createOrder(symbol, 'market', 'buy', cost, 1, params);
3588
+ }
3569
3589
  throw new NotSupported(this.id + ' createMarketBuyOrderWithCost() is not supported yet');
3570
3590
  }
3571
3591
  async createMarketSellOrderWithCost(symbol, cost, params = {}) {
3572
3592
  /**
3573
3593
  * @method
3574
3594
  * @name createMarketSellOrderWithCost
3575
- * @description create a market buy order by providing the symbol and cost
3595
+ * @description create a market sell order by providing the symbol and cost
3576
3596
  * @param {string} symbol unified symbol of the market to create an order in
3577
3597
  * @param {float} cost how much you want to trade in units of the quote currency
3578
3598
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3579
3599
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3580
3600
  */
3601
+ if (this.options['createMarketSellOrderRequiresPrice'] || this.options['createMarketSellOrderWithCost']) {
3602
+ return await this.createOrder(symbol, 'market', 'sell', cost, 1, params);
3603
+ }
3581
3604
  throw new NotSupported(this.id + ' createMarketSellOrderWithCost() is not supported yet');
3582
3605
  }
3583
3606
  async createOrders(orders, params = {}) {
@@ -4662,6 +4685,10 @@ export default class Exchange {
4662
4685
  if (cursorValue === undefined) {
4663
4686
  break;
4664
4687
  }
4688
+ const lastTimestamp = this.safeInteger(last, 'timestamp');
4689
+ if (lastTimestamp !== undefined && lastTimestamp < since) {
4690
+ break;
4691
+ }
4665
4692
  }
4666
4693
  catch (e) {
4667
4694
  errors += 1;
@@ -4714,10 +4741,10 @@ export default class Exchange {
4714
4741
  const first = this.safeValue(result, 0);
4715
4742
  if (first !== undefined) {
4716
4743
  if ('timestamp' in first) {
4717
- return this.sortBy(result, 'timestamp');
4744
+ return this.sortBy(result, 'timestamp', true);
4718
4745
  }
4719
4746
  if ('id' in first) {
4720
- return this.sortBy(result, 'id');
4747
+ return this.sortBy(result, 'id', true);
4721
4748
  }
4722
4749
  }
4723
4750
  return result;
@@ -250,23 +250,20 @@ export default class Client {
250
250
  // MessageEvent {isTrusted: true, data: "{"e":"depthUpdate","E":1581358737706,"s":"ETHBTC",…"0.06200000"]],"a":[["0.02261300","0.00000000"]]}", origin: "wss://stream.binance.com:9443", lastEventId: "", source: null, …}
251
251
  let message = messageEvent.data;
252
252
  let arrayBuffer;
253
- if (this.gunzip || this.inflate) {
254
- if (typeof message === 'string') {
255
- arrayBuffer = utf8.decode(message);
256
- }
257
- else {
253
+ if (typeof message !== 'string') {
254
+ if (this.gunzip || this.inflate) {
258
255
  arrayBuffer = new Uint8Array(message.buffer.slice(message.byteOffset, message.byteOffset + message.byteLength));
256
+ if (this.gunzip) {
257
+ arrayBuffer = gunzipSync(arrayBuffer);
258
+ }
259
+ else if (this.inflate) {
260
+ arrayBuffer = inflateSync(arrayBuffer);
261
+ }
262
+ message = utf8.encode(arrayBuffer);
259
263
  }
260
- if (this.gunzip) {
261
- arrayBuffer = gunzipSync(arrayBuffer);
262
- }
263
- else if (this.inflate) {
264
- arrayBuffer = inflateSync(arrayBuffer);
264
+ else {
265
+ message = message.toString();
265
266
  }
266
- message = utf8.encode(arrayBuffer);
267
- }
268
- if (typeof message !== 'string') {
269
- message = message.toString();
270
267
  }
271
268
  try {
272
269
  if (isJsonEncodedObject(message)) {
@@ -22,6 +22,7 @@ export default class bigone extends Exchange {
22
22
  fetchBalance(params?: {}): Promise<Balances>;
23
23
  parseType(type: string): string;
24
24
  parseOrder(order: any, market?: Market): Order;
25
+ createMarketBuyOrderWithCost(symbol: string, cost: any, params?: {}): Promise<Order>;
25
26
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<Order>;
26
27
  cancelOrder(id: string, symbol?: Str, params?: {}): Promise<Order>;
27
28
  cancelAllOrders(symbol?: Str, params?: {}): Promise<any>;
package/js/src/bigone.js CHANGED
@@ -33,6 +33,8 @@ export default class bigone extends Exchange {
33
33
  'option': undefined,
34
34
  'cancelAllOrders': true,
35
35
  'cancelOrder': true,
36
+ 'createMarketBuyOrderWithCost': true,
37
+ 'createMarketSellOrderWithCost': false,
36
38
  'createOrder': true,
37
39
  'createPostOnlyOrder': true,
38
40
  'createStopLimitOrder': true,
@@ -1155,6 +1157,20 @@ export default class bigone extends Exchange {
1155
1157
  'trades': undefined,
1156
1158
  }, market);
1157
1159
  }
1160
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
1161
+ /**
1162
+ * @method
1163
+ * @name bigone#createMarketBuyOrderWithCost
1164
+ * @see https://open.big.one/docs/spot_orders.html#create-order
1165
+ * @description create a market buy order by providing the symbol and cost
1166
+ * @param {string} symbol unified symbol of the market to create an order in
1167
+ * @param {float} cost how much you want to trade in units of the quote currency
1168
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1169
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1170
+ */
1171
+ params['createMarketBuyOrderRequiresPrice'] = false;
1172
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
1173
+ }
1158
1174
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1159
1175
  /**
1160
1176
  * @method
@@ -1182,7 +1198,7 @@ export default class bigone extends Exchange {
1182
1198
  const requestSide = isBuy ? 'BID' : 'ASK';
1183
1199
  let uppercaseType = type.toUpperCase();
1184
1200
  const isLimit = uppercaseType === 'LIMIT';
1185
- const exchangeSpecificParam = this.safeValue(params, 'post_only');
1201
+ const exchangeSpecificParam = this.safeValue(params, 'post_only', false);
1186
1202
  let postOnly = undefined;
1187
1203
  [postOnly, params] = this.handlePostOnly((uppercaseType === 'MARKET'), exchangeSpecificParam, params);
1188
1204
  const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'stop_price']);
@@ -1206,21 +1222,34 @@ export default class bigone extends Exchange {
1206
1222
  request['post_only'] = true;
1207
1223
  }
1208
1224
  }
1225
+ request['amount'] = this.amountToPrecision(symbol, amount);
1209
1226
  }
1210
1227
  else {
1211
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice');
1212
- if (createMarketBuyOrderRequiresPrice && (side === 'buy')) {
1213
- if (price === undefined) {
1214
- throw new InvalidOrder(this.id + ' createOrder() requires price argument for market buy orders on spot markets to calculate the total amount to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option to false and pass in the cost to spend into the amount parameter');
1228
+ if (isBuy) {
1229
+ let createMarketBuyOrderRequiresPrice = true;
1230
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
1231
+ const cost = this.safeNumber(params, 'cost');
1232
+ params = this.omit(params, 'cost');
1233
+ if (createMarketBuyOrderRequiresPrice) {
1234
+ if ((price === undefined) && (cost === undefined)) {
1235
+ throw new InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument');
1236
+ }
1237
+ else {
1238
+ const amountString = this.numberToString(amount);
1239
+ const priceString = this.numberToString(price);
1240
+ const quoteAmount = this.parseToNumeric(Precise.stringMul(amountString, priceString));
1241
+ const costRequest = (cost !== undefined) ? cost : quoteAmount;
1242
+ request['amount'] = this.costToPrecision(symbol, costRequest);
1243
+ }
1215
1244
  }
1216
1245
  else {
1217
- const amountString = this.numberToString(amount);
1218
- const priceString = this.numberToString(price);
1219
- amount = this.parseNumber(Precise.stringMul(amountString, priceString));
1246
+ request['amount'] = this.costToPrecision(symbol, amount);
1220
1247
  }
1221
1248
  }
1249
+ else {
1250
+ request['amount'] = this.amountToPrecision(symbol, amount);
1251
+ }
1222
1252
  }
1223
- request['amount'] = this.amountToPrecision(symbol, amount);
1224
1253
  if (triggerPrice !== undefined) {
1225
1254
  request['stop_price'] = this.priceToPrecision(symbol, triggerPrice);
1226
1255
  request['operator'] = isBuy ? 'GTE' : 'LTE';
package/js/src/bingx.d.ts CHANGED
@@ -61,6 +61,9 @@ export default class bingx extends Exchange {
61
61
  parseBalance(response: any): Balances;
62
62
  fetchPositions(symbols?: Strings, params?: {}): Promise<import("./base/types.js").Position[]>;
63
63
  parsePosition(position: any, market?: Market): import("./base/types.js").Position;
64
+ createMarketOrderWithCost(symbol: string, side: OrderSide, cost: any, params?: {}): Promise<Order>;
65
+ createMarketBuyOrderWithCost(symbol: string, cost: any, params?: {}): Promise<Order>;
66
+ createMarketSellOrderWithCost(symbol: string, cost: any, params?: {}): Promise<Order>;
64
67
  createOrderRequest(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): any;
65
68
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<Order>;
66
69
  createOrders(orders: OrderRequest[], params?: {}): Promise<Order[]>;
package/js/src/bingx.js CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import Exchange from './abstract/bingx.js';
9
- import { AuthenticationError, ExchangeNotAvailable, PermissionDenied, ExchangeError, InsufficientFunds, BadRequest, OrderNotFound, DDoSProtection, BadSymbol, InvalidOrder, ArgumentsRequired } from './base/errors.js';
9
+ import { AuthenticationError, ExchangeNotAvailable, PermissionDenied, ExchangeError, InsufficientFunds, BadRequest, OrderNotFound, DDoSProtection, BadSymbol, ArgumentsRequired } from './base/errors.js';
10
10
  import { Precise } from './base/Precise.js';
11
11
  import { sha256 } from './static_dependencies/noble-hashes/sha256.js';
12
12
  import { DECIMAL_PLACES } from './base/functions/number.js';
@@ -32,6 +32,9 @@ export default class bingx extends Exchange {
32
32
  'cancelAllOrders': true,
33
33
  'cancelOrder': true,
34
34
  'cancelOrders': true,
35
+ 'createMarketBuyOrderWithCost': true,
36
+ 'createMarketOrderWithCost': true,
37
+ 'createMarketSellOrderWithCost': true,
35
38
  'createOrder': true,
36
39
  'createOrders': true,
37
40
  'fetchBalance': true,
@@ -1624,6 +1627,46 @@ export default class bingx extends Exchange {
1624
1627
  'takeProfitPrice': undefined,
1625
1628
  });
1626
1629
  }
1630
+ async createMarketOrderWithCost(symbol, side, cost, params = {}) {
1631
+ /**
1632
+ * @method
1633
+ * @name bingx#createMarketOrderWithCost
1634
+ * @description create a market order by providing the symbol, side and cost
1635
+ * @param {string} symbol unified symbol of the market to create an order in
1636
+ * @param {string} side 'buy' or 'sell'
1637
+ * @param {float} cost how much you want to trade in units of the quote currency
1638
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1639
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1640
+ */
1641
+ params['quoteOrderQty'] = cost;
1642
+ return await this.createOrder(symbol, 'market', side, cost, undefined, params);
1643
+ }
1644
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
1645
+ /**
1646
+ * @method
1647
+ * @name bingx#createMarketBuyOrderWithCost
1648
+ * @description create a market buy order by providing the symbol and cost
1649
+ * @param {string} symbol unified symbol of the market to create an order in
1650
+ * @param {float} cost how much you want to trade in units of the quote currency
1651
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1652
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1653
+ */
1654
+ params['quoteOrderQty'] = cost;
1655
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
1656
+ }
1657
+ async createMarketSellOrderWithCost(symbol, cost, params = {}) {
1658
+ /**
1659
+ * @method
1660
+ * @name bingx#createMarketSellOrderWithCost
1661
+ * @description create a market sell order by providing the symbol and cost
1662
+ * @param {string} symbol unified symbol of the market to create an order in
1663
+ * @param {float} cost how much you want to trade in units of the quote currency
1664
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1665
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1666
+ */
1667
+ params['quoteOrderQty'] = cost;
1668
+ return await this.createOrder(symbol, 'market', 'sell', cost, undefined, params);
1669
+ }
1627
1670
  createOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
1628
1671
  /**
1629
1672
  * @method
@@ -1659,26 +1702,21 @@ export default class bingx extends Exchange {
1659
1702
  if (postOnly || (timeInForce === 'POC')) {
1660
1703
  request['timeInForce'] = 'POC';
1661
1704
  }
1662
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
1663
- if (isMarketOrder && (side === 'buy')) {
1664
- if (createMarketBuyOrderRequiresPrice) {
1665
- if (price === undefined) {
1666
- throw new InvalidOrder(this.id + ' createOrder() requires price argument for market buy orders on spot markets to calculate the total amount to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option to false and pass in the cost to spend into the amount parameter');
1667
- }
1668
- else {
1669
- const amountString = this.numberToString(amount);
1670
- const priceString = this.numberToString(price);
1671
- const cost = this.parseNumber(Precise.stringMul(amountString, priceString));
1672
- request['quoteOrderQty'] = this.parseToNumeric(this.priceToPrecision(symbol, cost));
1673
- }
1705
+ const cost = this.safeNumber2(params, 'cost', 'quoteOrderQty');
1706
+ params = this.omit(params, 'cost');
1707
+ if (cost !== undefined) {
1708
+ request['quoteOrderQty'] = this.parseToNumeric(this.costToPrecision(symbol, cost));
1709
+ }
1710
+ else {
1711
+ if (market['spot'] && isMarketOrder && (price !== undefined)) {
1712
+ // keep the legacy behavior, to avoid breaking the old spot-market-buying code
1713
+ const calculatedCost = Precise.stringMul(this.numberToString(amount), this.numberToString(price));
1714
+ request['quoteOrderQty'] = this.parseToNumeric(calculatedCost);
1674
1715
  }
1675
1716
  else {
1676
- request['quoteOrderQty'] = this.parseToNumeric(this.priceToPrecision(symbol, amount));
1717
+ request['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, amount));
1677
1718
  }
1678
1719
  }
1679
- else {
1680
- request['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, amount));
1681
- }
1682
1720
  if (!isMarketOrder) {
1683
1721
  request['price'] = this.parseToNumeric(this.priceToPrecision(symbol, price));
1684
1722
  }
@@ -1753,8 +1791,8 @@ export default class bingx extends Exchange {
1753
1791
  * @method
1754
1792
  * @name bingx#createOrder
1755
1793
  * @description create a trade order
1756
- * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Create%20an%20Order
1757
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Trade%20order
1794
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Create%20an%20Order
1795
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Trade%20order
1758
1796
  * @param {string} symbol unified symbol of the market to create an order in
1759
1797
  * @param {string} type 'market' or 'limit'
1760
1798
  * @param {string} side 'buy' or 'sell'
@@ -1767,6 +1805,7 @@ export default class bingx extends Exchange {
1767
1805
  * @param {float} [params.triggerPrice] *swap only* triggerPrice at which the attached take profit / stop loss order will be triggered
1768
1806
  * @param {float} [params.stopLossPrice] *swap only* stop loss trigger price
1769
1807
  * @param {float} [params.takeProfitPrice] *swap only* take profit trigger price
1808
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount
1770
1809
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1771
1810
  */
1772
1811
  await this.loadMarkets();
@@ -75,6 +75,7 @@ export default class bitmart extends Exchange {
75
75
  parseOrder(order: any, market?: Market): Order;
76
76
  parseOrderSide(side: any): string;
77
77
  parseOrderStatusByType(type: any, status: any): string;
78
+ createMarketBuyOrderWithCost(symbol: string, cost: any, params?: {}): Promise<Order>;
78
79
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<Order>;
79
80
  createSwapOrderRequest(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): any;
80
81
  createSpotOrderRequest(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): any;
package/js/src/bitmart.js CHANGED
@@ -39,6 +39,9 @@ export default class bitmart extends Exchange {
39
39
  'cancelAllOrders': true,
40
40
  'cancelOrder': true,
41
41
  'cancelOrders': false,
42
+ 'createMarketBuyOrderWithCost': true,
43
+ 'createMarketOrderWithCost': false,
44
+ 'createMarketSellOrderWithCost': false,
42
45
  'createOrder': true,
43
46
  'createPostOnlyOrder': true,
44
47
  'createStopLimitOrder': false,
@@ -2164,12 +2167,31 @@ export default class bitmart extends Exchange {
2164
2167
  const statuses = this.safeValue(statusesByType, type, {});
2165
2168
  return this.safeString(statuses, status, status);
2166
2169
  }
2170
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
2171
+ /**
2172
+ * @method
2173
+ * @name bitmart#createMarketBuyOrderWithCost
2174
+ * @description create a market buy order by providing the symbol and cost
2175
+ * @see https://developer-pro.bitmart.com/en/spot/#new-order-v2-signed
2176
+ * @param {string} symbol unified symbol of the market to create an order in
2177
+ * @param {float} cost how much you want to trade in units of the quote currency
2178
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2179
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2180
+ */
2181
+ await this.loadMarkets();
2182
+ const market = this.market(symbol);
2183
+ if (!market['spot']) {
2184
+ throw new NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
2185
+ }
2186
+ params['createMarketBuyOrderRequiresPrice'] = false;
2187
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
2188
+ }
2167
2189
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
2168
2190
  /**
2169
2191
  * @method
2170
2192
  * @name bitmart#createOrder
2171
2193
  * @description create a trade order
2172
- * @see https://developer-pro.bitmart.com/en/spot/#place-spot-order
2194
+ * @see https://developer-pro.bitmart.com/en/spot/#new-order-v2-signed
2173
2195
  * @see https://developer-pro.bitmart.com/en/spot/#place-margin-order
2174
2196
  * @see https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2175
2197
  * @param {string} symbol unified symbol of the market to create an order in
@@ -2346,18 +2368,18 @@ export default class bitmart extends Exchange {
2346
2368
  else if (isMarketOrder) {
2347
2369
  // for market buy it requires the amount of quote currency to spend
2348
2370
  if (side === 'buy') {
2349
- let notional = this.safeNumber(params, 'notional');
2350
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
2371
+ let notional = this.safeNumber2(params, 'cost', 'notional');
2372
+ params = this.omit(params, 'cost');
2373
+ let createMarketBuyOrderRequiresPrice = true;
2374
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
2351
2375
  if (createMarketBuyOrderRequiresPrice) {
2352
- if (price !== undefined) {
2353
- if (notional === undefined) {
2354
- const amountString = this.numberToString(amount);
2355
- const priceString = this.numberToString(price);
2356
- notional = this.parseNumber(Precise.stringMul(amountString, priceString));
2357
- }
2376
+ if ((price === undefined) && (notional === undefined)) {
2377
+ throw new InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument or in the "notional" extra parameter (the exchange-specific behaviour)');
2358
2378
  }
2359
- else if (notional === undefined) {
2360
- throw new InvalidOrder(this.id + " createOrder () requires the price argument with market buy orders to calculate total order cost (amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options['createMarketBuyOrderRequiresPrice'] = false and supply the total cost value in the 'amount' argument or in the 'notional' extra parameter (the exchange-specific behaviour)");
2379
+ else {
2380
+ const amountString = this.numberToString(amount);
2381
+ const priceString = this.numberToString(price);
2382
+ notional = this.parseNumber(Precise.stringMul(amountString, priceString));
2361
2383
  }
2362
2384
  }
2363
2385
  else {
package/js/src/bybit.d.ts CHANGED
@@ -58,6 +58,7 @@ export default class bybit extends Exchange {
58
58
  parseTimeInForce(timeInForce: any): string;
59
59
  parseOrder(order: any, market?: Market): Order;
60
60
  fetchOrder(id: string, symbol?: Str, params?: {}): Promise<Order>;
61
+ createMarketBuyOrderWithCost(symbol: string, cost: any, params?: {}): Promise<Order>;
61
62
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<Order>;
62
63
  createOrderRequest(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): any;
63
64
  createOrders(orders: OrderRequest[], params?: {}): Promise<Order[]>;
package/js/src/bybit.js CHANGED
@@ -38,6 +38,8 @@ export default class bybit extends Exchange {
38
38
  'borrowCrossMargin': true,
39
39
  'cancelAllOrders': true,
40
40
  'cancelOrder': true,
41
+ 'createMarketBuyOrderWithCost': true,
42
+ 'createMarketSellOrderWithCost': false,
41
43
  'createOrder': true,
42
44
  'createOrders': true,
43
45
  'createPostOnlyOrder': true,
@@ -3449,6 +3451,25 @@ export default class bybit extends Exchange {
3449
3451
  }
3450
3452
  return this.safeValue(result, 0);
3451
3453
  }
3454
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
3455
+ /**
3456
+ * @method
3457
+ * @name bybit#createMarketBuyOrderWithCost
3458
+ * @see https://bybit-exchange.github.io/docs/v5/order/create-order
3459
+ * @description create a market buy order by providing the symbol and cost
3460
+ * @param {string} symbol unified symbol of the market to create an order in
3461
+ * @param {float} cost how much you want to trade in units of the quote currency
3462
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3463
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3464
+ */
3465
+ await this.loadMarkets();
3466
+ const market = this.market(symbol);
3467
+ if (!market['spot']) {
3468
+ throw new NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
3469
+ }
3470
+ params['createMarketBuyOrderRequiresPrice'] = false;
3471
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
3472
+ }
3452
3473
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
3453
3474
  /**
3454
3475
  * @method
@@ -3549,18 +3570,20 @@ export default class bybit extends Exchange {
3549
3570
  }
3550
3571
  if (market['spot'] && (type === 'market') && (side === 'buy')) {
3551
3572
  // for market buy it requires the amount of quote currency to spend
3552
- if (this.options['createMarketBuyOrderRequiresPrice']) {
3553
- const cost = this.safeNumber(params, 'cost');
3554
- params = this.omit(params, 'cost');
3555
- if (price === undefined && cost === undefined) {
3556
- throw new InvalidOrder(this.id + ' createOrder() requires the price argument with market buy orders to calculate total order cost (amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options["createMarketBuyOrderRequiresPrice"] = false to supply the cost in the amount argument (the exchange-specific behaviour)');
3573
+ let createMarketBuyOrderRequiresPrice = true;
3574
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
3575
+ const cost = this.safeNumber(params, 'cost');
3576
+ params = this.omit(params, 'cost');
3577
+ if (createMarketBuyOrderRequiresPrice) {
3578
+ if ((price === undefined) && (cost === undefined)) {
3579
+ throw new InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument');
3557
3580
  }
3558
3581
  else {
3559
3582
  const amountString = this.numberToString(amount);
3560
3583
  const priceString = this.numberToString(price);
3561
3584
  const quoteAmount = Precise.stringMul(amountString, priceString);
3562
- amount = (cost !== undefined) ? cost : this.parseNumber(quoteAmount);
3563
- request['qty'] = this.costToPrecision(symbol, amount);
3585
+ const costRequest = (cost !== undefined) ? cost : quoteAmount;
3586
+ request['qty'] = this.costToPrecision(symbol, costRequest);
3564
3587
  }
3565
3588
  }
3566
3589
  else {
package/js/src/cex.d.ts CHANGED
@@ -22,6 +22,7 @@ export default class cex extends Exchange {
22
22
  fetchTradingFees(params?: {}): Promise<{}>;
23
23
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<Order>;
24
24
  cancelOrder(id: string, symbol?: Str, params?: {}): Promise<any>;
25
+ cancelAllOrders(symbol?: string, params?: {}): Promise<any>;
25
26
  parseOrder(order: any, market?: Market): Order;
26
27
  fetchOpenOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
27
28
  fetchClosedOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;