ccxt 4.1.48 → 4.1.49

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/dist/cjs/ccxt.js CHANGED
@@ -183,7 +183,7 @@ var woo$1 = require('./src/pro/woo.js');
183
183
 
184
184
  //-----------------------------------------------------------------------------
185
185
  // this is updated by vss.js when building
186
- const version = '4.1.48';
186
+ const version = '4.1.49';
187
187
  Exchange["default"].ccxtVersion = version;
188
188
  const exchanges = {
189
189
  'ace': ace,
@@ -283,6 +283,7 @@ class coinex extends coinex$1 {
283
283
  },
284
284
  },
285
285
  'options': {
286
+ 'brokerId': 'x-167673045',
286
287
  'createMarketBuyOrderRequiresPrice': true,
287
288
  'defaultType': 'spot',
288
289
  'defaultSubType': 'linear',
@@ -302,6 +303,26 @@ class coinex extends coinex$1 {
302
303
  'ACM': 'Actinium',
303
304
  },
304
305
  'precisionMode': number.TICK_SIZE,
306
+ 'exceptions': {
307
+ 'exact': {
308
+ // https://github.com/coinexcom/coinex_exchange_api/wiki/013error_code
309
+ '23': errors.PermissionDenied,
310
+ '24': errors.AuthenticationError,
311
+ '25': errors.AuthenticationError,
312
+ '34': errors.AuthenticationError,
313
+ '35': errors.ExchangeNotAvailable,
314
+ '36': errors.RequestTimeout,
315
+ '213': errors.RateLimitExceeded,
316
+ '107': errors.InsufficientFunds,
317
+ '600': errors.OrderNotFound,
318
+ '601': errors.InvalidOrder,
319
+ '602': errors.InvalidOrder,
320
+ '606': errors.InvalidOrder,
321
+ },
322
+ 'broad': {
323
+ 'ip not allow visit': errors.PermissionDenied,
324
+ },
325
+ },
305
326
  });
306
327
  }
307
328
  async fetchCurrencies(params = {}) {
@@ -1539,6 +1560,7 @@ class coinex extends coinex$1 {
1539
1560
  // "status": "done",
1540
1561
  // "taker_fee_rate": "0.0005",
1541
1562
  // "type": "sell",
1563
+ // "client_id": "",
1542
1564
  // }
1543
1565
  //
1544
1566
  // Spot and Margin createOrder, cancelOrder, fetchOrder
@@ -1566,6 +1588,7 @@ class coinex extends coinex$1 {
1566
1588
  // "stock_fee":"0",
1567
1589
  // "taker_fee_rate":"0.002",
1568
1590
  // "type":"buy"
1591
+ // "client_id": "",
1569
1592
  // }
1570
1593
  //
1571
1594
  // Swap createOrder, cancelOrder, fetchOrder
@@ -1781,9 +1804,13 @@ class coinex extends coinex$1 {
1781
1804
  else {
1782
1805
  type = rawType;
1783
1806
  }
1807
+ let clientOrderId = this.safeString(order, 'client_id');
1808
+ if (clientOrderId === '') {
1809
+ clientOrderId = undefined;
1810
+ }
1784
1811
  return this.safeOrder({
1785
1812
  'id': this.safeString2(order, 'id', 'order_id'),
1786
- 'clientOrderId': undefined,
1813
+ 'clientOrderId': clientOrderId,
1787
1814
  'datetime': this.iso8601(timestamp),
1788
1815
  'timestamp': timestamp,
1789
1816
  'lastTradeTimestamp': this.safeTimestamp(order, 'update_time'),
@@ -1840,6 +1867,7 @@ class coinex extends coinex$1 {
1840
1867
  await this.loadMarkets();
1841
1868
  const market = this.market(symbol);
1842
1869
  const swap = market['swap'];
1870
+ const clientOrderId = this.safeString2(params, 'client_id', 'clientOrderId');
1843
1871
  const stopPrice = this.safeValue2(params, 'stopPrice', 'triggerPrice');
1844
1872
  const stopLossPrice = this.safeValue(params, 'stopLossPrice');
1845
1873
  const takeProfitPrice = this.safeValue(params, 'takeProfitPrice');
@@ -1861,6 +1889,14 @@ class coinex extends coinex$1 {
1861
1889
  const request = {
1862
1890
  'market': market['id'],
1863
1891
  };
1892
+ if (clientOrderId === undefined) {
1893
+ const defaultId = 'x-167673045';
1894
+ const brokerId = this.safeString(this.options, 'brokerId', defaultId);
1895
+ request['client_id'] = brokerId + '-' + this.uuid16();
1896
+ }
1897
+ else {
1898
+ request['client_id'] = clientOrderId;
1899
+ }
1864
1900
  if (swap) {
1865
1901
  if (stopLossPrice || takeProfitPrice) {
1866
1902
  request['stop_type'] = this.safeInteger(params, 'stop_type', 1); // 1: triggered by the latest transaction, 2: mark price, 3: index price
@@ -4762,6 +4798,32 @@ class coinex extends coinex$1 {
4762
4798
  let url = this.urls['api'][api] + '/' + this.version + '/' + path;
4763
4799
  let query = this.omit(params, this.extractParams(path));
4764
4800
  const nonce = this.nonce().toString();
4801
+ if (method === 'POST') {
4802
+ const parts = path.split('/');
4803
+ const firstPart = this.safeString(parts, 0, '');
4804
+ const numParts = parts.length;
4805
+ const lastPart = this.safeString(parts, numParts - 1, '');
4806
+ const lastWords = lastPart.split('_');
4807
+ const numWords = lastWords.length;
4808
+ const lastWord = this.safeString(lastWords, numWords - 1, '');
4809
+ if ((firstPart === 'order') && (lastWord === 'limit' || lastWord === 'market')) {
4810
+ // inject in implicit API calls
4811
+ // POST /order/limit - Place limit orders
4812
+ // POST /order/market - Place market orders
4813
+ // POST /order/stop/limit - Place stop limit orders
4814
+ // POST /order/stop/market - Place stop market orders
4815
+ // POST /perpetual/v1/order/put_limit - Place limit orders
4816
+ // POST /perpetual/v1/order/put_market - Place market orders
4817
+ // POST /perpetual/v1/order/put_stop_limit - Place stop limit orders
4818
+ // POST /perpetual/v1/order/put_stop_market - Place stop market orders
4819
+ const clientOrderId = this.safeString(params, 'client_id');
4820
+ if (clientOrderId === undefined) {
4821
+ const defaultId = 'x-167673045';
4822
+ const brokerId = this.safeValue(this.options, 'brokerId', defaultId);
4823
+ query['client_id'] = brokerId + '_' + this.uuid16();
4824
+ }
4825
+ }
4826
+ }
4765
4827
  if (api === 'perpetualPrivate' || url === 'https://api.coinex.com/perpetual/v1/market/user_deals') {
4766
4828
  this.checkRequiredCredentials();
4767
4829
  query = this.extend({
@@ -4818,23 +4880,10 @@ class coinex extends coinex$1 {
4818
4880
  const data = this.safeValue(response, 'data');
4819
4881
  const message = this.safeString(response, 'message');
4820
4882
  if ((code !== '0') || ((message !== 'Success') && (message !== 'Succeeded') && (message !== 'Ok') && !data)) {
4821
- const responseCodes = {
4822
- // https://github.com/coinexcom/coinex_exchange_api/wiki/013error_code
4823
- '23': errors.PermissionDenied,
4824
- '24': errors.AuthenticationError,
4825
- '25': errors.AuthenticationError,
4826
- '34': errors.AuthenticationError,
4827
- '35': errors.ExchangeNotAvailable,
4828
- '36': errors.RequestTimeout,
4829
- '213': errors.RateLimitExceeded,
4830
- '107': errors.InsufficientFunds,
4831
- '600': errors.OrderNotFound,
4832
- '601': errors.InvalidOrder,
4833
- '602': errors.InvalidOrder,
4834
- '606': errors.InvalidOrder,
4835
- };
4836
- const ErrorClass = this.safeValue(responseCodes, code, errors.ExchangeError);
4837
- throw new ErrorClass(response['message']);
4883
+ const feedback = this.id + ' ' + message;
4884
+ this.throwBroadlyMatchedException(this.exceptions['broad'], message, feedback);
4885
+ this.throwExactlyMatchedException(this.exceptions['exact'], code, feedback);
4886
+ throw new errors.ExchangeError(feedback);
4838
4887
  }
4839
4888
  return undefined;
4840
4889
  }
@@ -130,8 +130,8 @@ class mexc extends mexc$1 {
130
130
  },
131
131
  'www': 'https://www.mexc.com/',
132
132
  'doc': [
133
- 'https://mxcdevelop.github.io/apidocs/spot_v3_en/',
134
- 'https://mxcdevelop.github.io/APIDoc/', // v1 & v2 : soon to be deprecated
133
+ 'https://mexcdevelop.github.io/apidocs/spot_v3_en/',
134
+ 'https://mexcdevelop.github.io/APIDoc/', // v1 & v2 : soon to be deprecated
135
135
  ],
136
136
  'fees': [
137
137
  'https://www.mexc.com/fee',
@@ -883,7 +883,7 @@ class mexc extends mexc$1 {
883
883
  * @method
884
884
  * @name mexc3#fetchCurrencies
885
885
  * @description fetches all available currencies on an exchange
886
- * @see https://mxcdevelop.github.io/apidocs/spot_v3_en/#query-the-currency-information
886
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#query-the-currency-information
887
887
  * @param {object} [params] extra parameters specific to the mexc3 api endpoint
888
888
  * @returns {object} an associative dictionary of currencies
889
889
  */
@@ -1283,8 +1283,8 @@ class mexc extends mexc$1 {
1283
1283
  /**
1284
1284
  * @method
1285
1285
  * @name mexc3#fetchOrderBook
1286
- * @see https://mxcdevelop.github.io/apidocs/spot_v3_en/#order-book
1287
- * @see https://mxcdevelop.github.io/apidocs/contract_v1_en/#get-the-contract-s-depth-information
1286
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#order-book
1287
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-contract-s-depth-information
1288
1288
  * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
1289
1289
  * @param {string} symbol unified symbol of the market to fetch the order book for
1290
1290
  * @param {int} [limit] the maximum amount of order book entries to return
@@ -3531,9 +3531,9 @@ class mexc extends mexc$1 {
3531
3531
  * @method
3532
3532
  * @name mexc3#fetchBalance
3533
3533
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
3534
- * @see https://mxcdevelop.github.io/apidocs/spot_v3_en/#account-information
3535
- * @see https://mxcdevelop.github.io/apidocs/contract_v1_en/#get-all-informations-of-user-39-s-asset
3536
- * @see https://mxcdevelop.github.io/apidocs/spot_v3_en/#isolated-account
3534
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#account-information
3535
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-informations-of-user-39-s-asset
3536
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#isolated-account
3537
3537
  * @param {object} [params] extra parameters specific to the mexc3 api endpoint
3538
3538
  * @param {string} [params.symbols] // required for margin, market id's separated by commas
3539
3539
  * @returns {object} a [balance structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#balance-structure}
@@ -4230,7 +4230,7 @@ class mexc extends mexc$1 {
4230
4230
  * @method
4231
4231
  * @name mexc3#fetchDepositAddressesByNetwork
4232
4232
  * @description fetch a dictionary of addresses for a currency, indexed by network
4233
- * @see https://mxcdevelop.github.io/apidocs/spot_v3_en/#deposit-address-supporting-network
4233
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#deposit-address-supporting-network
4234
4234
  * @param {string} code unified currency code of the currency for the deposit address
4235
4235
  * @param {object} [params] extra parameters specific to the mexc3 api endpoint
4236
4236
  * @returns {object} a dictionary of [address structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#address-structure} indexed by the network
@@ -4269,7 +4269,7 @@ class mexc extends mexc$1 {
4269
4269
  /**
4270
4270
  * @method
4271
4271
  * @name mexc3#createDepositAddress
4272
- * @see https://mxcdevelop.github.io/apidocs/spot_v3_en/#generate-deposit-address-supporting-network
4272
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#generate-deposit-address-supporting-network
4273
4273
  * @description create a currency deposit address
4274
4274
  * @param {string} code unified currency code of the currency for the deposit address
4275
4275
  * @param {object} [params] extra parameters specific to the mexc3 api endpoint
@@ -4310,7 +4310,7 @@ class mexc extends mexc$1 {
4310
4310
  * @method
4311
4311
  * @name mexc3#fetchDepositAddress
4312
4312
  * @description fetch the deposit address for a currency associated with this account
4313
- * @see https://mxcdevelop.github.io/apidocs/spot_v3_en/#deposit-address-supporting-network
4313
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#deposit-address-supporting-network
4314
4314
  * @param {string} code unified currency code
4315
4315
  * @param {object} [params] extra parameters specific to the mexc3 api endpoint
4316
4316
  * @returns {object} an [address structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#address-structure}
@@ -4338,7 +4338,7 @@ class mexc extends mexc$1 {
4338
4338
  * @method
4339
4339
  * @name mexc3#fetchDeposits
4340
4340
  * @description fetch all deposits made to an account
4341
- * @see https://mxcdevelop.github.io/apidocs/spot_v3_en/#deposit-history-supporting-network
4341
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#deposit-history-supporting-network
4342
4342
  * @param {string} code unified currency code
4343
4343
  * @param {int} [since] the earliest time in ms to fetch deposits for
4344
4344
  * @param {int} [limit] the maximum number of deposits structures to retrieve
@@ -4398,7 +4398,7 @@ class mexc extends mexc$1 {
4398
4398
  * @method
4399
4399
  * @name mexc3#fetchWithdrawals
4400
4400
  * @description fetch all withdrawals made from an account
4401
- * @see https://mxcdevelop.github.io/apidocs/spot_v3_en/#withdraw-history-supporting-network
4401
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#withdraw-history-supporting-network
4402
4402
  * @param {string} code unified currency code
4403
4403
  * @param {int} [since] the earliest time in ms to fetch withdrawals for
4404
4404
  * @param {int} [limit] the maximum number of withdrawals structures to retrieve
@@ -4817,7 +4817,7 @@ class mexc extends mexc$1 {
4817
4817
  * @method
4818
4818
  * @name mexc3#transfer
4819
4819
  * @description transfer currency internally between wallets on the same account
4820
- * @see https://mxcdevelop.github.io/apidocs/spot_v3_en/#user-universal-transfer
4820
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#user-universal-transfer
4821
4821
  * @param {string} code unified currency code
4822
4822
  * @param {float} amount amount to transfer
4823
4823
  * @param {string} fromAccount account to transfer from
@@ -4950,7 +4950,7 @@ class mexc extends mexc$1 {
4950
4950
  * @method
4951
4951
  * @name mexc3#withdraw
4952
4952
  * @description make a withdrawal
4953
- * @see https://mxcdevelop.github.io/apidocs/spot_v3_en/#withdraw
4953
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#withdraw
4954
4954
  * @param {string} code unified currency code
4955
4955
  * @param {float} amount the amount to withdraw
4956
4956
  * @param {string} address the address to withdraw to
@@ -4960,7 +4960,7 @@ class mexc extends mexc$1 {
4960
4960
  */
4961
4961
  [tag, params] = this.handleWithdrawTagAndParams(tag, params);
4962
4962
  const networks = this.safeValue(this.options, 'networks', {});
4963
- let network = this.safeStringUpper2(params, 'network', 'chain'); // this line allows the user to specify either ERC20 or ETH
4963
+ let network = this.safeString2(params, 'network', 'chain'); // this line allows the user to specify either ERC20 or ETH
4964
4964
  network = this.safeString(networks, network, network); // handle ETH > ERC-20 alias
4965
4965
  this.checkAddress(address);
4966
4966
  await this.loadMarkets();
@@ -4975,7 +4975,7 @@ class mexc extends mexc$1 {
4975
4975
  }
4976
4976
  if (network !== undefined) {
4977
4977
  request['network'] = network;
4978
- params = this.omit(params, 'network');
4978
+ params = this.omit(params, ['network', 'chain']);
4979
4979
  }
4980
4980
  const response = await this.spotPrivatePostCapitalWithdrawApply(this.extend(request, params));
4981
4981
  //
@@ -5018,7 +5018,7 @@ class mexc extends mexc$1 {
5018
5018
  * @method
5019
5019
  * @name mexc3#borrowMargin
5020
5020
  * @description create a loan to borrow margin
5021
- * @see https://mxcdevelop.github.io/apidocs/spot_v3_en/#loan
5021
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#loan
5022
5022
  * @param {string} code unified currency code of the currency to borrow
5023
5023
  * @param {float} amount the amount to borrow
5024
5024
  * @param {string} symbol unified market symbol
@@ -5051,7 +5051,7 @@ class mexc extends mexc$1 {
5051
5051
  * @method
5052
5052
  * @name mexc3#repayMargin
5053
5053
  * @description repay borrowed margin and interest
5054
- * @see https://mxcdevelop.github.io/apidocs/spot_v3_en/#repayment
5054
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#repayment
5055
5055
  * @param {string} code unified currency code of the currency to repay
5056
5056
  * @param {float} amount the amount to repay
5057
5057
  * @param {string} symbol unified market symbol
@@ -5090,7 +5090,7 @@ class mexc extends mexc$1 {
5090
5090
  * @method
5091
5091
  * @name mexc3#fetchTransactionFees
5092
5092
  * @description fetch deposit and withdrawal fees
5093
- * @see https://mxcdevelop.github.io/apidocs/spot_v3_en/#query-the-currency-information
5093
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#query-the-currency-information
5094
5094
  * @param {string[]|undefined} codes returns fees for all currencies if undefined
5095
5095
  * @param {object} [params] extra parameters specific to the mexc3 api endpoint
5096
5096
  * @returns {object[]} a list of [fee structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#fee-structure}
@@ -5188,7 +5188,7 @@ class mexc extends mexc$1 {
5188
5188
  * @method
5189
5189
  * @name mexc3#fetchDepositWithdrawFees
5190
5190
  * @description fetch deposit and withdrawal fees
5191
- * @see https://mxcdevelop.github.io/apidocs/spot_v3_en/#query-the-currency-information
5191
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#query-the-currency-information
5192
5192
  * @param {string[]|undefined} codes returns fees for all currencies if undefined
5193
5193
  * @param {object} [params] extra parameters specific to the mexc3 api endpoint
5194
5194
  * @returns {object[]} a list of [fee structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#fee-structure}
package/js/ccxt.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as functions from './src/base/functions.js';
4
4
  import * as errors from './src/base/errors.js';
5
5
  import { Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory, MarginMode } from './src/base/types.js';
6
6
  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';
7
- declare const version = "4.1.47";
7
+ declare const version = "4.1.48";
8
8
  import ace from './src/ace.js';
9
9
  import alpaca from './src/alpaca.js';
10
10
  import ascendex from './src/ascendex.js';
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.48';
41
+ const version = '4.1.49';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -5,7 +5,7 @@
5
5
  // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
6
 
7
7
  // -------------------------------------------------------------------------------
8
- import { Exchange as _Exchange } from '../base/Exchange.js';
9
- class Exchange extends _Exchange {
8
+ import _htx from '../htx.js';
9
+ class htx extends _htx {
10
10
  }
11
- export default Exchange;
11
+ export default htx;
package/js/src/coinex.js CHANGED
@@ -286,6 +286,7 @@ export default class coinex extends Exchange {
286
286
  },
287
287
  },
288
288
  'options': {
289
+ 'brokerId': 'x-167673045',
289
290
  'createMarketBuyOrderRequiresPrice': true,
290
291
  'defaultType': 'spot',
291
292
  'defaultSubType': 'linear',
@@ -305,6 +306,26 @@ export default class coinex extends Exchange {
305
306
  'ACM': 'Actinium',
306
307
  },
307
308
  'precisionMode': TICK_SIZE,
309
+ 'exceptions': {
310
+ 'exact': {
311
+ // https://github.com/coinexcom/coinex_exchange_api/wiki/013error_code
312
+ '23': PermissionDenied,
313
+ '24': AuthenticationError,
314
+ '25': AuthenticationError,
315
+ '34': AuthenticationError,
316
+ '35': ExchangeNotAvailable,
317
+ '36': RequestTimeout,
318
+ '213': RateLimitExceeded,
319
+ '107': InsufficientFunds,
320
+ '600': OrderNotFound,
321
+ '601': InvalidOrder,
322
+ '602': InvalidOrder,
323
+ '606': InvalidOrder,
324
+ },
325
+ 'broad': {
326
+ 'ip not allow visit': PermissionDenied,
327
+ },
328
+ },
308
329
  });
309
330
  }
310
331
  async fetchCurrencies(params = {}) {
@@ -1542,6 +1563,7 @@ export default class coinex extends Exchange {
1542
1563
  // "status": "done",
1543
1564
  // "taker_fee_rate": "0.0005",
1544
1565
  // "type": "sell",
1566
+ // "client_id": "",
1545
1567
  // }
1546
1568
  //
1547
1569
  // Spot and Margin createOrder, cancelOrder, fetchOrder
@@ -1569,6 +1591,7 @@ export default class coinex extends Exchange {
1569
1591
  // "stock_fee":"0",
1570
1592
  // "taker_fee_rate":"0.002",
1571
1593
  // "type":"buy"
1594
+ // "client_id": "",
1572
1595
  // }
1573
1596
  //
1574
1597
  // Swap createOrder, cancelOrder, fetchOrder
@@ -1784,9 +1807,13 @@ export default class coinex extends Exchange {
1784
1807
  else {
1785
1808
  type = rawType;
1786
1809
  }
1810
+ let clientOrderId = this.safeString(order, 'client_id');
1811
+ if (clientOrderId === '') {
1812
+ clientOrderId = undefined;
1813
+ }
1787
1814
  return this.safeOrder({
1788
1815
  'id': this.safeString2(order, 'id', 'order_id'),
1789
- 'clientOrderId': undefined,
1816
+ 'clientOrderId': clientOrderId,
1790
1817
  'datetime': this.iso8601(timestamp),
1791
1818
  'timestamp': timestamp,
1792
1819
  'lastTradeTimestamp': this.safeTimestamp(order, 'update_time'),
@@ -1843,6 +1870,7 @@ export default class coinex extends Exchange {
1843
1870
  await this.loadMarkets();
1844
1871
  const market = this.market(symbol);
1845
1872
  const swap = market['swap'];
1873
+ const clientOrderId = this.safeString2(params, 'client_id', 'clientOrderId');
1846
1874
  const stopPrice = this.safeValue2(params, 'stopPrice', 'triggerPrice');
1847
1875
  const stopLossPrice = this.safeValue(params, 'stopLossPrice');
1848
1876
  const takeProfitPrice = this.safeValue(params, 'takeProfitPrice');
@@ -1864,6 +1892,14 @@ export default class coinex extends Exchange {
1864
1892
  const request = {
1865
1893
  'market': market['id'],
1866
1894
  };
1895
+ if (clientOrderId === undefined) {
1896
+ const defaultId = 'x-167673045';
1897
+ const brokerId = this.safeString(this.options, 'brokerId', defaultId);
1898
+ request['client_id'] = brokerId + '-' + this.uuid16();
1899
+ }
1900
+ else {
1901
+ request['client_id'] = clientOrderId;
1902
+ }
1867
1903
  if (swap) {
1868
1904
  if (stopLossPrice || takeProfitPrice) {
1869
1905
  request['stop_type'] = this.safeInteger(params, 'stop_type', 1); // 1: triggered by the latest transaction, 2: mark price, 3: index price
@@ -4765,6 +4801,32 @@ export default class coinex extends Exchange {
4765
4801
  let url = this.urls['api'][api] + '/' + this.version + '/' + path;
4766
4802
  let query = this.omit(params, this.extractParams(path));
4767
4803
  const nonce = this.nonce().toString();
4804
+ if (method === 'POST') {
4805
+ const parts = path.split('/');
4806
+ const firstPart = this.safeString(parts, 0, '');
4807
+ const numParts = parts.length;
4808
+ const lastPart = this.safeString(parts, numParts - 1, '');
4809
+ const lastWords = lastPart.split('_');
4810
+ const numWords = lastWords.length;
4811
+ const lastWord = this.safeString(lastWords, numWords - 1, '');
4812
+ if ((firstPart === 'order') && (lastWord === 'limit' || lastWord === 'market')) {
4813
+ // inject in implicit API calls
4814
+ // POST /order/limit - Place limit orders
4815
+ // POST /order/market - Place market orders
4816
+ // POST /order/stop/limit - Place stop limit orders
4817
+ // POST /order/stop/market - Place stop market orders
4818
+ // POST /perpetual/v1/order/put_limit - Place limit orders
4819
+ // POST /perpetual/v1/order/put_market - Place market orders
4820
+ // POST /perpetual/v1/order/put_stop_limit - Place stop limit orders
4821
+ // POST /perpetual/v1/order/put_stop_market - Place stop market orders
4822
+ const clientOrderId = this.safeString(params, 'client_id');
4823
+ if (clientOrderId === undefined) {
4824
+ const defaultId = 'x-167673045';
4825
+ const brokerId = this.safeValue(this.options, 'brokerId', defaultId);
4826
+ query['client_id'] = brokerId + '_' + this.uuid16();
4827
+ }
4828
+ }
4829
+ }
4768
4830
  if (api === 'perpetualPrivate' || url === 'https://api.coinex.com/perpetual/v1/market/user_deals') {
4769
4831
  this.checkRequiredCredentials();
4770
4832
  query = this.extend({
@@ -4821,23 +4883,10 @@ export default class coinex extends Exchange {
4821
4883
  const data = this.safeValue(response, 'data');
4822
4884
  const message = this.safeString(response, 'message');
4823
4885
  if ((code !== '0') || ((message !== 'Success') && (message !== 'Succeeded') && (message !== 'Ok') && !data)) {
4824
- const responseCodes = {
4825
- // https://github.com/coinexcom/coinex_exchange_api/wiki/013error_code
4826
- '23': PermissionDenied,
4827
- '24': AuthenticationError,
4828
- '25': AuthenticationError,
4829
- '34': AuthenticationError,
4830
- '35': ExchangeNotAvailable,
4831
- '36': RequestTimeout,
4832
- '213': RateLimitExceeded,
4833
- '107': InsufficientFunds,
4834
- '600': OrderNotFound,
4835
- '601': InvalidOrder,
4836
- '602': InvalidOrder,
4837
- '606': InvalidOrder,
4838
- };
4839
- const ErrorClass = this.safeValue(responseCodes, code, ExchangeError);
4840
- throw new ErrorClass(response['message']);
4886
+ const feedback = this.id + ' ' + message;
4887
+ this.throwBroadlyMatchedException(this.exceptions['broad'], message, feedback);
4888
+ this.throwExactlyMatchedException(this.exceptions['exact'], code, feedback);
4889
+ throw new ExchangeError(feedback);
4841
4890
  }
4842
4891
  return undefined;
4843
4892
  }