ccxt 4.0.87 → 4.0.89

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
@@ -180,7 +180,7 @@ var woo$1 = require('./src/pro/woo.js');
180
180
 
181
181
  //-----------------------------------------------------------------------------
182
182
  // this is updated by vss.js when building
183
- const version = '4.0.87';
183
+ const version = '4.0.89';
184
184
  Exchange["default"].ccxtVersion = version;
185
185
  const exchanges = {
186
186
  'ace': ace,
@@ -106,6 +106,7 @@ class binance extends binance$1 {
106
106
  'fetchTransactionFees': true,
107
107
  'fetchTransactions': false,
108
108
  'fetchTransfers': true,
109
+ 'fetchUnderlyingAssets': false,
109
110
  'fetchVolatilityHistory': false,
110
111
  'fetchWithdrawal': false,
111
112
  'fetchWithdrawals': true,
@@ -693,7 +693,7 @@ class bingx extends bingx$1 {
693
693
  'symbol': market['id'],
694
694
  };
695
695
  if (limit !== undefined) {
696
- request['limit'] = limit;
696
+ request['limit'] = Math.min(limit, 100); // avoid API exception "limit should less than 100"
697
697
  }
698
698
  let response = undefined;
699
699
  let marketType = undefined;
@@ -87,6 +87,7 @@ class bybit extends bybit$1 {
87
87
  'fetchTradingFees': true,
88
88
  'fetchTransactions': false,
89
89
  'fetchTransfers': true,
90
+ 'fetchUnderlyingAssets': false,
90
91
  'fetchVolatilityHistory': true,
91
92
  'fetchWithdrawals': true,
92
93
  'setLeverage': true,
@@ -83,6 +83,7 @@ class cryptocom extends cryptocom$1 {
83
83
  'fetchTransactionFees': false,
84
84
  'fetchTransactions': false,
85
85
  'fetchTransfers': true,
86
+ 'fetchUnderlyingAssets': false,
86
87
  'fetchVolatilityHistory': false,
87
88
  'fetchWithdrawals': true,
88
89
  'reduceMargin': false,
@@ -70,6 +70,7 @@ class delta extends delta$1 {
70
70
  'fetchTrades': true,
71
71
  'fetchTransfer': undefined,
72
72
  'fetchTransfers': undefined,
73
+ 'fetchUnderlyingAssets': false,
73
74
  'fetchVolatilityHistory': false,
74
75
  'fetchWithdrawal': undefined,
75
76
  'fetchWithdrawals': undefined,
@@ -83,6 +83,7 @@ class deribit extends deribit$1 {
83
83
  'fetchTransactions': false,
84
84
  'fetchTransfer': false,
85
85
  'fetchTransfers': true,
86
+ 'fetchUnderlyingAssets': false,
86
87
  'fetchVolatilityHistory': true,
87
88
  'fetchWithdrawal': false,
88
89
  'fetchWithdrawals': true,
@@ -1173,17 +1173,16 @@ class exmo extends exmo$1 {
1173
1173
  // "commission_percent": "0.2"
1174
1174
  // }
1175
1175
  //
1176
- // margin
1176
+ // fetchMyTrades (margin)
1177
1177
  //
1178
1178
  // {
1179
- // "is_maker": false,
1180
- // "order_id": "123",
1181
- // "pair": "BTC_USD",
1182
- // "price": "54122.25",
1183
- // "quantity": "0.00069994",
1184
- // "trade_dt": "1619069561718824428",
1185
- // "trade_id": "692842802860135010",
1186
- // "type": "sell"
1179
+ // "trade_id": "692861757015952517",
1180
+ // "trade_dt": "1693951853197811824",
1181
+ // "trade_type": "buy",
1182
+ // "pair": "ADA_USDT",
1183
+ // "quantity": "1.96607879",
1184
+ // "price": "0.2568",
1185
+ // "amount": "0.50488903"
1187
1186
  // }
1188
1187
  //
1189
1188
  const timestamp = this.safeTimestamp(trade, 'date');
@@ -1192,7 +1191,7 @@ class exmo extends exmo$1 {
1192
1191
  const priceString = this.safeString(trade, 'price');
1193
1192
  const amountString = this.safeString(trade, 'quantity');
1194
1193
  const costString = this.safeString(trade, 'amount');
1195
- const side = this.safeString(trade, 'type');
1194
+ const side = this.safeString2(trade, 'type', 'trade_type');
1196
1195
  const type = undefined;
1197
1196
  const marketId = this.safeString(trade, 'pair');
1198
1197
  market = this.safeMarket(marketId, market, '_');
@@ -1281,38 +1280,91 @@ class exmo extends exmo$1 {
1281
1280
  * @method
1282
1281
  * @name exmo#fetchMyTrades
1283
1282
  * @description fetch all trades made by the user
1284
- * @param {string} symbol unified market symbol
1283
+ * @see https://documenter.getpostman.com/view/10287440/SzYXWKPi#b8d8d9af-4f46-46a1-939b-ad261d79f452 // spot
1284
+ * @see https://documenter.getpostman.com/view/10287440/SzYXWKPi#f4b1aaf8-399f-403b-ab5e-4926d967a106 // margin
1285
+ * @param {string} symbol a symbol is required but it can be a single string, or a non-empty array
1285
1286
  * @param {int} [since] the earliest time in ms to fetch trades for
1286
- * @param {int} [limit] the maximum number of trades structures to retrieve
1287
+ * @param {int} [limit] *required for margin orders* the maximum number of trades structures to retrieve
1287
1288
  * @param {object} [params] extra parameters specific to the exmo api endpoint
1289
+ *
1290
+ * EXCHANGE SPECIFIC PARAMETERS
1291
+ * @param {int} [params.offset] last deal offset, default = 0
1288
1292
  * @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#trade-structure}
1289
1293
  */
1290
- // a symbol is required but it can be a single string, or a non-empty array
1291
- if (symbol === undefined) {
1292
- throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument (a single symbol or an array)');
1294
+ this.checkRequiredSymbol('fetchMyTrades', symbol);
1295
+ let marginMode = undefined;
1296
+ [marginMode, params] = this.handleMarginModeAndParams('fetchMyTrades', params);
1297
+ if (marginMode === 'cross') {
1298
+ throw new errors.BadRequest(this.id + 'only isolated margin is supported');
1293
1299
  }
1294
1300
  await this.loadMarkets();
1295
- let pair = undefined;
1296
- let market = undefined;
1297
- if (Array.isArray(symbol)) {
1298
- const numSymbols = symbol.length;
1299
- if (numSymbols < 1) {
1300
- throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires a non-empty symbol array');
1301
- }
1302
- const marketIds = this.marketIds(symbol);
1303
- pair = marketIds.join(',');
1301
+ const market = this.market(symbol);
1302
+ const pair = market['id'];
1303
+ const isSpot = marginMode !== 'isolated';
1304
+ if (limit === undefined) {
1305
+ limit = 100;
1306
+ }
1307
+ const request = {};
1308
+ if (isSpot) {
1309
+ request['pair'] = pair;
1304
1310
  }
1305
1311
  else {
1306
- market = this.market(symbol);
1307
- pair = market['id'];
1312
+ request['pair_name'] = pair;
1308
1313
  }
1309
- const request = {
1310
- 'pair': pair,
1311
- };
1312
1314
  if (limit !== undefined) {
1313
1315
  request['limit'] = limit;
1314
1316
  }
1315
- const response = await this.privatePostUserTrades(this.extend(request, params));
1317
+ const offset = this.safeInteger(params, 'offset', 0);
1318
+ request['offset'] = offset;
1319
+ let response = undefined;
1320
+ if (isSpot) {
1321
+ response = await this.privatePostUserTrades(this.extend(request, params));
1322
+ //
1323
+ // {
1324
+ // "BTC_USD": [
1325
+ // {
1326
+ // "trade_id": 20056872,
1327
+ // "client_id": 100500,
1328
+ // "date": 1435488248,
1329
+ // "type": "buy",
1330
+ // "pair": "BTC_USD",
1331
+ // "quantity": "1",
1332
+ // "price": "100",
1333
+ // "amount": "100",
1334
+ // "order_id": 7,
1335
+ // "parent_order_id": 117684023830293,
1336
+ // "exec_type": "taker",
1337
+ // "commission_amount": "0.02",
1338
+ // "commission_currency": "BTC",
1339
+ // "commission_percent": "0.2"
1340
+ // }
1341
+ // ],
1342
+ // ...
1343
+ // }
1344
+ //
1345
+ }
1346
+ else {
1347
+ const responseFromExchange = await this.privatePostMarginTrades(this.extend(request, params));
1348
+ //
1349
+ // {
1350
+ // "trades": {
1351
+ // "ADA_USDT": [
1352
+ // {
1353
+ // "trade_id": "692861757015952517",
1354
+ // "trade_dt": "1693951853197811824",
1355
+ // "trade_type": "buy",
1356
+ // "pair": "ADA_USDT",
1357
+ // "quantity": "1.96607879",
1358
+ // "price": "0.2568",
1359
+ // "amount": "0.50488903"
1360
+ // },
1361
+ // ]
1362
+ // ...
1363
+ // }
1364
+ // }
1365
+ //
1366
+ response = this.safeValue(responseFromExchange, 'trades');
1367
+ }
1316
1368
  let result = [];
1317
1369
  const marketIdsInner = Object.keys(response);
1318
1370
  for (let i = 0; i < marketIdsInner.length; i++) {
@@ -130,6 +130,7 @@ class gate extends gate$1 {
130
130
  'fetchTradingFee': true,
131
131
  'fetchTradingFees': true,
132
132
  'fetchTransactionFees': true,
133
+ 'fetchUnderlyingAssets': true,
133
134
  'fetchVolatilityHistory': false,
134
135
  'fetchWithdrawals': true,
135
136
  'reduceMargin': true,
@@ -6222,6 +6223,44 @@ class gate extends gate$1 {
6222
6223
  request['dual_mode'] = hedged;
6223
6224
  return await this.privateFuturesPostSettleDualMode(this.extend(request, query));
6224
6225
  }
6226
+ async fetchUnderlyingAssets(params = {}) {
6227
+ /**
6228
+ * @method
6229
+ * @name gate#fetchUnderlyingAssets
6230
+ * @description fetches the market ids of underlying assets for a specific contract market type
6231
+ * @param {object} [params] exchange specific params
6232
+ * @param {string} [params.type] the contract market type, 'option', 'swap' or 'future', the default is 'option'
6233
+ * @returns {object[]} a list of [underlying assets]{@link https://github.com/ccxt/ccxt/wiki/Manual#underlying-assets-structure}
6234
+ */
6235
+ await this.loadMarkets();
6236
+ let marketType = undefined;
6237
+ [marketType, params] = this.handleMarketTypeAndParams('fetchUnderlyingAssets', undefined, params);
6238
+ if ((marketType === undefined) || (marketType === 'spot')) {
6239
+ marketType = 'option';
6240
+ }
6241
+ if (marketType !== 'option') {
6242
+ throw new errors.NotSupported(this.id + ' fetchUnderlyingAssets() supports option markets only');
6243
+ }
6244
+ const response = await this.publicOptionsGetUnderlyings(params);
6245
+ //
6246
+ // [
6247
+ // {
6248
+ // "index_time": "1646915796",
6249
+ // "name": "BTC_USDT",
6250
+ // "index_price": "39142.73"
6251
+ // }
6252
+ // ]
6253
+ //
6254
+ const underlyings = [];
6255
+ for (let i = 0; i < response.length; i++) {
6256
+ const underlying = response[i];
6257
+ const name = this.safeString(underlying, 'name');
6258
+ if (name !== undefined) {
6259
+ underlyings.push(name);
6260
+ }
6261
+ }
6262
+ return underlyings;
6263
+ }
6225
6264
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
6226
6265
  if (response === undefined) {
6227
6266
  return undefined;
@@ -107,6 +107,7 @@ class okx extends okx$1 {
107
107
  'fetchTransactions': false,
108
108
  'fetchTransfer': true,
109
109
  'fetchTransfers': true,
110
+ 'fetchUnderlyingAssets': true,
110
111
  'fetchVolatilityHistory': false,
111
112
  'fetchWithdrawal': true,
112
113
  'fetchWithdrawals': true,
@@ -6700,6 +6701,44 @@ class okx extends okx$1 {
6700
6701
  }
6701
6702
  return result;
6702
6703
  }
6704
+ async fetchUnderlyingAssets(params = {}) {
6705
+ /**
6706
+ * @method
6707
+ * @name okx#fetchUnderlyingAssets
6708
+ * @description fetches the market ids of underlying assets for a specific contract market type
6709
+ * @see https://www.okx.com/docs-v5/en/#public-data-rest-api-get-underlying
6710
+ * @param {object} [params] exchange specific params
6711
+ * @param {string} [params.type] the contract market type, 'option', 'swap' or 'future', the default is 'option'
6712
+ * @returns {object[]} a list of [underlying assets]{@link https://github.com/ccxt/ccxt/wiki/Manual#underlying-assets-structure}
6713
+ */
6714
+ await this.loadMarkets();
6715
+ let marketType = undefined;
6716
+ [marketType, params] = this.handleMarketTypeAndParams('fetchUnderlyingAssets', undefined, params);
6717
+ if ((marketType === undefined) || (marketType === 'spot')) {
6718
+ marketType = 'option';
6719
+ }
6720
+ if ((marketType !== 'option') && (marketType !== 'swap') && (marketType !== 'future')) {
6721
+ throw new errors.NotSupported(this.id + ' fetchUnderlyingAssets() supports contract markets only');
6722
+ }
6723
+ const request = {
6724
+ 'instType': this.convertToInstrumentType(marketType),
6725
+ };
6726
+ const response = await this.publicGetPublicUnderlying(this.extend(request, params));
6727
+ //
6728
+ // {
6729
+ // "code": "0",
6730
+ // "data": [
6731
+ // [
6732
+ // "BTC-USD",
6733
+ // "ETH-USD"
6734
+ // ]
6735
+ // ],
6736
+ // "msg": ""
6737
+ // }
6738
+ //
6739
+ const underlyings = this.safeValue(response, 'data', []);
6740
+ return underlyings[0];
6741
+ }
6703
6742
  handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
6704
6743
  if (!response) {
6705
6744
  return undefined; // fallback to default error handler
@@ -704,7 +704,7 @@ class bybit extends bybit$1 {
704
704
  if (this.newUpdates) {
705
705
  limit = trades.getLimit(symbol, limit);
706
706
  }
707
- return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
707
+ return this.filterBySymbolSinceLimit(trades, symbol, since, limit, true);
708
708
  }
709
709
  handleMyTrades(client, message) {
710
710
  //
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 } 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 } from './src/base/errors.js';
7
- declare const version = "4.0.86";
7
+ declare const version = "4.0.88";
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 } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.0.87';
41
+ const version = '4.0.89';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
package/js/src/binance.js CHANGED
@@ -109,6 +109,7 @@ export default class binance extends Exchange {
109
109
  'fetchTransactionFees': true,
110
110
  'fetchTransactions': false,
111
111
  'fetchTransfers': true,
112
+ 'fetchUnderlyingAssets': false,
112
113
  'fetchVolatilityHistory': false,
113
114
  'fetchWithdrawal': false,
114
115
  'fetchWithdrawals': true,
package/js/src/bingx.js CHANGED
@@ -696,7 +696,7 @@ export default class bingx extends Exchange {
696
696
  'symbol': market['id'],
697
697
  };
698
698
  if (limit !== undefined) {
699
- request['limit'] = limit;
699
+ request['limit'] = Math.min(limit, 100); // avoid API exception "limit should less than 100"
700
700
  }
701
701
  let response = undefined;
702
702
  let marketType = undefined;
package/js/src/bybit.js CHANGED
@@ -90,6 +90,7 @@ export default class bybit extends Exchange {
90
90
  'fetchTradingFees': true,
91
91
  'fetchTransactions': false,
92
92
  'fetchTransfers': true,
93
+ 'fetchUnderlyingAssets': false,
93
94
  'fetchVolatilityHistory': true,
94
95
  'fetchWithdrawals': true,
95
96
  'setLeverage': true,
@@ -86,6 +86,7 @@ export default class cryptocom extends Exchange {
86
86
  'fetchTransactionFees': false,
87
87
  'fetchTransactions': false,
88
88
  'fetchTransfers': true,
89
+ 'fetchUnderlyingAssets': false,
89
90
  'fetchVolatilityHistory': false,
90
91
  'fetchWithdrawals': true,
91
92
  'reduceMargin': false,
package/js/src/delta.js CHANGED
@@ -73,6 +73,7 @@ export default class delta extends Exchange {
73
73
  'fetchTrades': true,
74
74
  'fetchTransfer': undefined,
75
75
  'fetchTransfers': undefined,
76
+ 'fetchUnderlyingAssets': false,
76
77
  'fetchVolatilityHistory': false,
77
78
  'fetchWithdrawal': undefined,
78
79
  'fetchWithdrawals': undefined,
package/js/src/deribit.js CHANGED
@@ -86,6 +86,7 @@ export default class deribit extends Exchange {
86
86
  'fetchTransactions': false,
87
87
  'fetchTransfer': false,
88
88
  'fetchTransfers': true,
89
+ 'fetchUnderlyingAssets': false,
89
90
  'fetchVolatilityHistory': true,
90
91
  'fetchWithdrawal': false,
91
92
  'fetchWithdrawals': true,
package/js/src/exmo.js CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import Exchange from './abstract/exmo.js';
9
- import { ArgumentsRequired, ExchangeError, OrderNotFound, AuthenticationError, InsufficientFunds, InvalidOrder, InvalidNonce, OnMaintenance, RateLimitExceeded, BadRequest, PermissionDenied } from './base/errors.js';
9
+ import { ExchangeError, OrderNotFound, AuthenticationError, InsufficientFunds, InvalidOrder, InvalidNonce, OnMaintenance, RateLimitExceeded, BadRequest, PermissionDenied } from './base/errors.js';
10
10
  import { Precise } from './base/Precise.js';
11
11
  import { TICK_SIZE } from './base/functions/number.js';
12
12
  import { sha512 } from './static_dependencies/noble-hashes/sha512.js';
@@ -1176,17 +1176,16 @@ export default class exmo extends Exchange {
1176
1176
  // "commission_percent": "0.2"
1177
1177
  // }
1178
1178
  //
1179
- // margin
1179
+ // fetchMyTrades (margin)
1180
1180
  //
1181
1181
  // {
1182
- // "is_maker": false,
1183
- // "order_id": "123",
1184
- // "pair": "BTC_USD",
1185
- // "price": "54122.25",
1186
- // "quantity": "0.00069994",
1187
- // "trade_dt": "1619069561718824428",
1188
- // "trade_id": "692842802860135010",
1189
- // "type": "sell"
1182
+ // "trade_id": "692861757015952517",
1183
+ // "trade_dt": "1693951853197811824",
1184
+ // "trade_type": "buy",
1185
+ // "pair": "ADA_USDT",
1186
+ // "quantity": "1.96607879",
1187
+ // "price": "0.2568",
1188
+ // "amount": "0.50488903"
1190
1189
  // }
1191
1190
  //
1192
1191
  const timestamp = this.safeTimestamp(trade, 'date');
@@ -1195,7 +1194,7 @@ export default class exmo extends Exchange {
1195
1194
  const priceString = this.safeString(trade, 'price');
1196
1195
  const amountString = this.safeString(trade, 'quantity');
1197
1196
  const costString = this.safeString(trade, 'amount');
1198
- const side = this.safeString(trade, 'type');
1197
+ const side = this.safeString2(trade, 'type', 'trade_type');
1199
1198
  const type = undefined;
1200
1199
  const marketId = this.safeString(trade, 'pair');
1201
1200
  market = this.safeMarket(marketId, market, '_');
@@ -1284,38 +1283,91 @@ export default class exmo extends Exchange {
1284
1283
  * @method
1285
1284
  * @name exmo#fetchMyTrades
1286
1285
  * @description fetch all trades made by the user
1287
- * @param {string} symbol unified market symbol
1286
+ * @see https://documenter.getpostman.com/view/10287440/SzYXWKPi#b8d8d9af-4f46-46a1-939b-ad261d79f452 // spot
1287
+ * @see https://documenter.getpostman.com/view/10287440/SzYXWKPi#f4b1aaf8-399f-403b-ab5e-4926d967a106 // margin
1288
+ * @param {string} symbol a symbol is required but it can be a single string, or a non-empty array
1288
1289
  * @param {int} [since] the earliest time in ms to fetch trades for
1289
- * @param {int} [limit] the maximum number of trades structures to retrieve
1290
+ * @param {int} [limit] *required for margin orders* the maximum number of trades structures to retrieve
1290
1291
  * @param {object} [params] extra parameters specific to the exmo api endpoint
1292
+ *
1293
+ * EXCHANGE SPECIFIC PARAMETERS
1294
+ * @param {int} [params.offset] last deal offset, default = 0
1291
1295
  * @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#trade-structure}
1292
1296
  */
1293
- // a symbol is required but it can be a single string, or a non-empty array
1294
- if (symbol === undefined) {
1295
- throw new ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument (a single symbol or an array)');
1297
+ this.checkRequiredSymbol('fetchMyTrades', symbol);
1298
+ let marginMode = undefined;
1299
+ [marginMode, params] = this.handleMarginModeAndParams('fetchMyTrades', params);
1300
+ if (marginMode === 'cross') {
1301
+ throw new BadRequest(this.id + 'only isolated margin is supported');
1296
1302
  }
1297
1303
  await this.loadMarkets();
1298
- let pair = undefined;
1299
- let market = undefined;
1300
- if (Array.isArray(symbol)) {
1301
- const numSymbols = symbol.length;
1302
- if (numSymbols < 1) {
1303
- throw new ArgumentsRequired(this.id + ' fetchMyTrades() requires a non-empty symbol array');
1304
- }
1305
- const marketIds = this.marketIds(symbol);
1306
- pair = marketIds.join(',');
1304
+ const market = this.market(symbol);
1305
+ const pair = market['id'];
1306
+ const isSpot = marginMode !== 'isolated';
1307
+ if (limit === undefined) {
1308
+ limit = 100;
1309
+ }
1310
+ const request = {};
1311
+ if (isSpot) {
1312
+ request['pair'] = pair;
1307
1313
  }
1308
1314
  else {
1309
- market = this.market(symbol);
1310
- pair = market['id'];
1315
+ request['pair_name'] = pair;
1311
1316
  }
1312
- const request = {
1313
- 'pair': pair,
1314
- };
1315
1317
  if (limit !== undefined) {
1316
1318
  request['limit'] = limit;
1317
1319
  }
1318
- const response = await this.privatePostUserTrades(this.extend(request, params));
1320
+ const offset = this.safeInteger(params, 'offset', 0);
1321
+ request['offset'] = offset;
1322
+ let response = undefined;
1323
+ if (isSpot) {
1324
+ response = await this.privatePostUserTrades(this.extend(request, params));
1325
+ //
1326
+ // {
1327
+ // "BTC_USD": [
1328
+ // {
1329
+ // "trade_id": 20056872,
1330
+ // "client_id": 100500,
1331
+ // "date": 1435488248,
1332
+ // "type": "buy",
1333
+ // "pair": "BTC_USD",
1334
+ // "quantity": "1",
1335
+ // "price": "100",
1336
+ // "amount": "100",
1337
+ // "order_id": 7,
1338
+ // "parent_order_id": 117684023830293,
1339
+ // "exec_type": "taker",
1340
+ // "commission_amount": "0.02",
1341
+ // "commission_currency": "BTC",
1342
+ // "commission_percent": "0.2"
1343
+ // }
1344
+ // ],
1345
+ // ...
1346
+ // }
1347
+ //
1348
+ }
1349
+ else {
1350
+ const responseFromExchange = await this.privatePostMarginTrades(this.extend(request, params));
1351
+ //
1352
+ // {
1353
+ // "trades": {
1354
+ // "ADA_USDT": [
1355
+ // {
1356
+ // "trade_id": "692861757015952517",
1357
+ // "trade_dt": "1693951853197811824",
1358
+ // "trade_type": "buy",
1359
+ // "pair": "ADA_USDT",
1360
+ // "quantity": "1.96607879",
1361
+ // "price": "0.2568",
1362
+ // "amount": "0.50488903"
1363
+ // },
1364
+ // ]
1365
+ // ...
1366
+ // }
1367
+ // }
1368
+ //
1369
+ response = this.safeValue(responseFromExchange, 'trades');
1370
+ }
1319
1371
  let result = [];
1320
1372
  const marketIdsInner = Object.keys(response);
1321
1373
  for (let i = 0; i < marketIdsInner.length; i++) {
package/js/src/gate.d.ts CHANGED
@@ -410,5 +410,6 @@ export default class gate extends Exchange {
410
410
  };
411
411
  parseLedgerEntryType(type: any): string;
412
412
  setPositionMode(hedged: any, symbol?: any, params?: {}): Promise<any>;
413
+ fetchUnderlyingAssets(params?: {}): Promise<any[]>;
413
414
  handleErrors(code: any, reason: any, url: any, method: any, headers: any, body: any, response: any, requestHeaders: any, requestBody: any): any;
414
415
  }
package/js/src/gate.js CHANGED
@@ -133,6 +133,7 @@ export default class gate extends Exchange {
133
133
  'fetchTradingFee': true,
134
134
  'fetchTradingFees': true,
135
135
  'fetchTransactionFees': true,
136
+ 'fetchUnderlyingAssets': true,
136
137
  'fetchVolatilityHistory': false,
137
138
  'fetchWithdrawals': true,
138
139
  'reduceMargin': true,
@@ -6225,6 +6226,44 @@ export default class gate extends Exchange {
6225
6226
  request['dual_mode'] = hedged;
6226
6227
  return await this.privateFuturesPostSettleDualMode(this.extend(request, query));
6227
6228
  }
6229
+ async fetchUnderlyingAssets(params = {}) {
6230
+ /**
6231
+ * @method
6232
+ * @name gate#fetchUnderlyingAssets
6233
+ * @description fetches the market ids of underlying assets for a specific contract market type
6234
+ * @param {object} [params] exchange specific params
6235
+ * @param {string} [params.type] the contract market type, 'option', 'swap' or 'future', the default is 'option'
6236
+ * @returns {object[]} a list of [underlying assets]{@link https://github.com/ccxt/ccxt/wiki/Manual#underlying-assets-structure}
6237
+ */
6238
+ await this.loadMarkets();
6239
+ let marketType = undefined;
6240
+ [marketType, params] = this.handleMarketTypeAndParams('fetchUnderlyingAssets', undefined, params);
6241
+ if ((marketType === undefined) || (marketType === 'spot')) {
6242
+ marketType = 'option';
6243
+ }
6244
+ if (marketType !== 'option') {
6245
+ throw new NotSupported(this.id + ' fetchUnderlyingAssets() supports option markets only');
6246
+ }
6247
+ const response = await this.publicOptionsGetUnderlyings(params);
6248
+ //
6249
+ // [
6250
+ // {
6251
+ // "index_time": "1646915796",
6252
+ // "name": "BTC_USDT",
6253
+ // "index_price": "39142.73"
6254
+ // }
6255
+ // ]
6256
+ //
6257
+ const underlyings = [];
6258
+ for (let i = 0; i < response.length; i++) {
6259
+ const underlying = response[i];
6260
+ const name = this.safeString(underlying, 'name');
6261
+ if (name !== undefined) {
6262
+ underlyings.push(name);
6263
+ }
6264
+ }
6265
+ return underlyings;
6266
+ }
6228
6267
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
6229
6268
  if (response === undefined) {
6230
6269
  return undefined;
package/js/src/okx.d.ts CHANGED
@@ -432,5 +432,6 @@ export default class okx extends Exchange {
432
432
  datetime: any;
433
433
  };
434
434
  parseSettlements(settlements: any, market: any): any[];
435
+ fetchUnderlyingAssets(params?: {}): Promise<any>;
435
436
  handleErrors(httpCode: any, reason: any, url: any, method: any, headers: any, body: any, response: any, requestHeaders: any, requestBody: any): any;
436
437
  }