ccxt 4.2.1 → 4.2.2

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/js/src/bingx.js CHANGED
@@ -120,6 +120,7 @@ export default class bingx extends Exchange {
120
120
  'trade/query': 3,
121
121
  'trade/openOrders': 3,
122
122
  'trade/historyOrders': 3,
123
+ 'user/commissionRate': 3,
123
124
  'account/balance': 3,
124
125
  },
125
126
  'post': {
@@ -127,6 +128,7 @@ export default class bingx extends Exchange {
127
128
  'trade/cancel': 3,
128
129
  'trade/batchOrders': 3,
129
130
  'trade/cancelOrders': 3,
131
+ 'trade/cancelOpenOrders': 3,
130
132
  },
131
133
  },
132
134
  },
@@ -1317,22 +1319,30 @@ export default class bingx extends Exchange {
1317
1319
  // }
1318
1320
  //
1319
1321
  const marketId = this.safeString(ticker, 'symbol');
1320
- // const change = this.safeString (ticker, 'priceChange'); // this is not ccxt's change because it does high-low instead of last-open
1321
1322
  const lastQty = this.safeString(ticker, 'lastQty');
1322
1323
  // in spot markets, lastQty is not present
1323
1324
  // it's (bad, but) the only way we can check the tickers origin
1324
1325
  const type = (lastQty === undefined) ? 'spot' : 'swap';
1325
- const symbol = this.safeSymbol(marketId, market, undefined, type);
1326
+ market = this.safeMarket(marketId, market, undefined, type);
1327
+ const symbol = market['symbol'];
1326
1328
  const open = this.safeString(ticker, 'openPrice');
1327
1329
  const high = this.safeString(ticker, 'highPrice');
1328
1330
  const low = this.safeString(ticker, 'lowPrice');
1329
1331
  const close = this.safeString(ticker, 'lastPrice');
1330
1332
  const quoteVolume = this.safeString(ticker, 'quoteVolume');
1331
1333
  const baseVolume = this.safeString(ticker, 'volume');
1334
+ let percentage = undefined;
1335
+ let change = undefined;
1336
+ if (market['swap']) {
1337
+ // right now only swap uses the 24h change, spot will be added soon
1338
+ percentage = this.safeString(ticker, 'priceChangePercent');
1339
+ change = this.safeString(ticker, 'priceChange');
1340
+ }
1332
1341
  // let percentage = this.safeString (ticker, 'priceChangePercent');
1333
1342
  // if (percentage !== undefined) {
1334
1343
  // percentage = percentage.replace ('%', '');
1335
1344
  // } similarly to change, it's not ccxt's percentage because it does priceChange/open, and priceChange is high-low
1345
+ // const change = this.safeString (ticker, 'priceChange'); // this is not ccxt's change because it does high-low instead of last-open
1336
1346
  const ts = this.safeInteger(ticker, 'closeTime');
1337
1347
  const datetime = this.iso8601(ts);
1338
1348
  const bid = this.safeString(ticker, 'bidPrice');
@@ -1354,8 +1364,8 @@ export default class bingx extends Exchange {
1354
1364
  'close': close,
1355
1365
  'last': undefined,
1356
1366
  'previousClose': undefined,
1357
- 'change': undefined,
1358
- 'percentage': undefined,
1367
+ 'change': change,
1368
+ 'percentage': percentage,
1359
1369
  'average': undefined,
1360
1370
  'baseVolume': baseVolume,
1361
1371
  'quoteVolume': quoteVolume,
@@ -2206,6 +2216,7 @@ export default class bingx extends Exchange {
2206
2216
  * @method
2207
2217
  * @name bingx#cancelAllOrders
2208
2218
  * @description cancel all open orders
2219
+ * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Cancel%20orders%20by%20symbol
2209
2220
  * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Cancel%20All%20Orders
2210
2221
  * @param {string} [symbol] unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
2211
2222
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -2216,42 +2227,70 @@ export default class bingx extends Exchange {
2216
2227
  }
2217
2228
  await this.loadMarkets();
2218
2229
  const market = this.market(symbol);
2219
- if (market['type'] !== 'swap') {
2220
- throw new BadRequest(this.id + ' cancelAllOrders is only supported for swap markets.');
2221
- }
2222
2230
  const request = {
2223
2231
  'symbol': market['id'],
2224
2232
  };
2225
- const response = await this.swapV2PrivateDeleteTradeAllOpenOrders(this.extend(request, params));
2226
- //
2227
- // {
2228
- // "code": 0,
2229
- // "msg": "",
2230
- // "data": {
2231
- // "success": [
2232
- // {
2233
- // "symbol": "LINK-USDT",
2234
- // "orderId": 1597783835095859200,
2235
- // "side": "BUY",
2236
- // "positionSide": "LONG",
2237
- // "type": "TRIGGER_LIMIT",
2238
- // "origQty": "5.0",
2239
- // "price": "9.0000",
2240
- // "executedQty": "0.0",
2241
- // "avgPrice": "0.0000",
2242
- // "cumQuote": "0",
2243
- // "stopPrice": "9.5000",
2244
- // "profit": "",
2245
- // "commission": "",
2246
- // "status": "NEW",
2247
- // "time": 1669776326000,
2248
- // "updateTime": 1669776326000
2249
- // }
2250
- // ],
2251
- // "failed": null
2252
- // }
2253
- // }
2254
- //
2233
+ let response = undefined;
2234
+ if (market['spot']) {
2235
+ response = await this.spotV1PrivatePostTradeCancelOpenOrders(this.extend(request, params));
2236
+ //
2237
+ // {
2238
+ // "code": 0,
2239
+ // "msg": "",
2240
+ // "debugMsg": "",
2241
+ // "data": {
2242
+ // "orders": [{
2243
+ // "symbol": "ADA-USDT",
2244
+ // "orderId": 1740659971369992192,
2245
+ // "transactTime": 1703840651730,
2246
+ // "price": 5,
2247
+ // "stopPrice": 0,
2248
+ // "origQty": 10,
2249
+ // "executedQty": 0,
2250
+ // "cummulativeQuoteQty": 0,
2251
+ // "status": "CANCELED",
2252
+ // "type": "LIMIT",
2253
+ // "side": "SELL"
2254
+ // }]
2255
+ // }
2256
+ // }
2257
+ //
2258
+ }
2259
+ else if (market['swap']) {
2260
+ response = await this.swapV2PrivateDeleteTradeAllOpenOrders(this.extend(request, params));
2261
+ //
2262
+ // {
2263
+ // "code": 0,
2264
+ // "msg": "",
2265
+ // "data": {
2266
+ // "success": [
2267
+ // {
2268
+ // "symbol": "LINK-USDT",
2269
+ // "orderId": 1597783835095859200,
2270
+ // "side": "BUY",
2271
+ // "positionSide": "LONG",
2272
+ // "type": "TRIGGER_LIMIT",
2273
+ // "origQty": "5.0",
2274
+ // "price": "9.0000",
2275
+ // "executedQty": "0.0",
2276
+ // "avgPrice": "0.0000",
2277
+ // "cumQuote": "0",
2278
+ // "stopPrice": "9.5000",
2279
+ // "profit": "",
2280
+ // "commission": "",
2281
+ // "status": "NEW",
2282
+ // "time": 1669776326000,
2283
+ // "updateTime": 1669776326000
2284
+ // }
2285
+ // ],
2286
+ // "failed": null
2287
+ // }
2288
+ // }
2289
+ //
2290
+ }
2291
+ else {
2292
+ throw new BadRequest(this.id + ' cancelAllOrders is only supported for spot and swap markets.');
2293
+ }
2255
2294
  return response;
2256
2295
  }
2257
2296
  async cancelOrders(ids, symbol = undefined, params = {}) {
@@ -1335,6 +1335,12 @@ export default class bitstamp extends Exchange {
1335
1335
  * @method
1336
1336
  * @name bitstamp#createOrder
1337
1337
  * @description create a trade order
1338
+ * @see https://www.bitstamp.net/api/#tag/Orders/operation/OpenInstantBuyOrder
1339
+ * @see https://www.bitstamp.net/api/#tag/Orders/operation/OpenMarketBuyOrder
1340
+ * @see https://www.bitstamp.net/api/#tag/Orders/operation/OpenLimitBuyOrder
1341
+ * @see https://www.bitstamp.net/api/#tag/Orders/operation/OpenInstantSellOrder
1342
+ * @see https://www.bitstamp.net/api/#tag/Orders/operation/OpenMarketSellOrder
1343
+ * @see https://www.bitstamp.net/api/#tag/Orders/operation/OpenLimitSellOrder
1338
1344
  * @param {string} symbol unified symbol of the market to create an order in
1339
1345
  * @param {string} type 'market' or 'limit'
1340
1346
  * @param {string} side 'buy' or 'sell'
@@ -1345,27 +1351,42 @@ export default class bitstamp extends Exchange {
1345
1351
  */
1346
1352
  await this.loadMarkets();
1347
1353
  const market = this.market(symbol);
1348
- let method = 'privatePost' + this.capitalize(side);
1349
1354
  const request = {
1350
1355
  'pair': market['id'],
1351
1356
  'amount': this.amountToPrecision(symbol, amount),
1352
1357
  };
1358
+ const clientOrderId = this.safeString2(params, 'client_order_id', 'clientOrderId');
1359
+ if (clientOrderId !== undefined) {
1360
+ request['client_order_id'] = clientOrderId;
1361
+ params = this.omit(params, ['clientOrderId']);
1362
+ }
1363
+ let response = undefined;
1364
+ const capitalizedSide = this.capitalize(side);
1353
1365
  if (type === 'market') {
1354
- method += 'Market';
1366
+ if (capitalizedSide === 'Buy') {
1367
+ response = await this.privatePostBuyMarketPair(this.extend(request, params));
1368
+ }
1369
+ else {
1370
+ response = await this.privatePostSellMarketPair(this.extend(request, params));
1371
+ }
1355
1372
  }
1356
1373
  else if (type === 'instant') {
1357
- method += 'Instant';
1374
+ if (capitalizedSide === 'Buy') {
1375
+ response = await this.privatePostBuyInstantPair(this.extend(request, params));
1376
+ }
1377
+ else {
1378
+ response = await this.privatePostSellInstantPair(this.extend(request, params));
1379
+ }
1358
1380
  }
1359
1381
  else {
1360
1382
  request['price'] = this.priceToPrecision(symbol, price);
1383
+ if (capitalizedSide === 'Buy') {
1384
+ response = await this.privatePostBuyPair(this.extend(request, params));
1385
+ }
1386
+ else {
1387
+ response = await this.privatePostSellPair(this.extend(request, params));
1388
+ }
1361
1389
  }
1362
- method += 'Pair';
1363
- const clientOrderId = this.safeString2(params, 'client_order_id', 'clientOrderId');
1364
- if (clientOrderId !== undefined) {
1365
- request['client_order_id'] = clientOrderId;
1366
- params = this.omit(params, ['client_order_id', 'clientOrderId']);
1367
- }
1368
- const response = await this[method](this.extend(request, params));
1369
1390
  const order = this.parseOrder(response, market);
1370
1391
  order['type'] = type;
1371
1392
  return order;
@@ -1398,13 +1419,16 @@ export default class bitstamp extends Exchange {
1398
1419
  await this.loadMarkets();
1399
1420
  let market = undefined;
1400
1421
  const request = {};
1401
- let method = 'privatePostCancelAllOrders';
1422
+ let response = undefined;
1402
1423
  if (symbol !== undefined) {
1403
1424
  market = this.market(symbol);
1404
1425
  request['pair'] = market['id'];
1405
- method = 'privatePostCancelAllOrdersPair';
1426
+ response = await this.privatePostCancelAllOrdersPair(this.extend(request, params));
1427
+ }
1428
+ else {
1429
+ response = await this.privatePostCancelAllOrders(this.extend(request, params));
1406
1430
  }
1407
- return await this[method](this.extend(request, params));
1431
+ return response;
1408
1432
  }
1409
1433
  parseOrderStatus(status) {
1410
1434
  const statuses = {
package/js/src/lykke.js CHANGED
@@ -435,7 +435,13 @@ export default class lykke extends Exchange {
435
435
  };
436
436
  // publicGetTickers or publicGetPrices
437
437
  const method = this.safeString(this.options, 'fetchTickerMethod', 'publicGetTickers');
438
- const response = await this[method](this.extend(request, params));
438
+ let response = undefined;
439
+ if (method === 'publicGetPrices') {
440
+ response = await this.publicGetPrices(this.extend(request, params));
441
+ }
442
+ else {
443
+ response = await this.publicGetTickers(this.extend(request, params));
444
+ }
439
445
  const ticker = this.safeValue(response, 'payload', []);
440
446
  //
441
447
  // publicGetTickers
@@ -789,8 +795,13 @@ export default class lykke extends Exchange {
789
795
  if (type === 'limit') {
790
796
  query['price'] = parseFloat(this.priceToPrecision(market['symbol'], price));
791
797
  }
792
- const method = 'privatePostOrders' + this.capitalize(type);
793
- const result = await this[method](this.extend(query, params));
798
+ let result = undefined;
799
+ if (this.capitalize(type) === 'Market') {
800
+ result = await this.privatePostOrdersMarket(this.extend(query, params));
801
+ }
802
+ else {
803
+ result = await this.privatePostOrdersLimit(this.extend(query, params));
804
+ }
794
805
  //
795
806
  // market
796
807
  //
@@ -1192,9 +1192,15 @@ export default class poloniexfutures extends Exchange {
1192
1192
  if (symbol !== undefined) {
1193
1193
  request['symbol'] = this.marketId(symbol);
1194
1194
  }
1195
- const stop = this.safeValue(params, 'stop');
1196
- const method = stop ? 'privateDeleteStopOrders' : 'privateDeleteOrders';
1197
- const response = await this[method](this.extend(request, params));
1195
+ const stop = this.safeValue2(params, 'stop', 'trigger');
1196
+ params = this.omit(params, ['stop', 'trigger']);
1197
+ let response = undefined;
1198
+ if (stop) {
1199
+ response = await this.privateDeleteStopOrders(this.extend(request, params));
1200
+ }
1201
+ else {
1202
+ response = await this.privateDeleteOrders(this.extend(request, params));
1203
+ }
1198
1204
  //
1199
1205
  // {
1200
1206
  // "code": "200000",
@@ -1256,9 +1262,9 @@ export default class poloniexfutures extends Exchange {
1256
1262
  * @returns An [array of order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1257
1263
  */
1258
1264
  await this.loadMarkets();
1259
- const stop = this.safeValue(params, 'stop');
1265
+ const stop = this.safeValue2(params, 'stop', 'trigger');
1260
1266
  const until = this.safeInteger2(params, 'until', 'till');
1261
- params = this.omit(params, ['stop', 'until', 'till']);
1267
+ params = this.omit(params, ['triger', 'stop', 'until', 'till']);
1262
1268
  if (status === 'closed') {
1263
1269
  status = 'done';
1264
1270
  }
@@ -1280,8 +1286,13 @@ export default class poloniexfutures extends Exchange {
1280
1286
  if (until !== undefined) {
1281
1287
  request['endAt'] = until;
1282
1288
  }
1283
- const method = stop ? 'privateGetStopOrders' : 'privateGetOrders';
1284
- const response = await this[method](this.extend(request, params));
1289
+ let response = undefined;
1290
+ if (stop) {
1291
+ response = await this.privateGetStopOrders(this.extend(request, params));
1292
+ }
1293
+ else {
1294
+ response = await this.privateGetOrders(this.extend(request, params));
1295
+ }
1285
1296
  //
1286
1297
  // {
1287
1298
  // "code": "200000",
@@ -1391,20 +1402,20 @@ export default class poloniexfutures extends Exchange {
1391
1402
  */
1392
1403
  await this.loadMarkets();
1393
1404
  const request = {};
1394
- let method = 'privateGetOrdersOrderId';
1405
+ let response = undefined;
1395
1406
  if (id === undefined) {
1396
1407
  const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId');
1397
1408
  if (clientOrderId === undefined) {
1398
1409
  throw new InvalidOrder(this.id + ' fetchOrder() requires parameter id or params.clientOid');
1399
1410
  }
1400
1411
  request['clientOid'] = clientOrderId;
1401
- method = 'privateGetOrdersByClientOid';
1402
1412
  params = this.omit(params, ['clientOid', 'clientOrderId']);
1413
+ response = await this.privateGetClientOrderIdClientOid(this.extend(request, params));
1403
1414
  }
1404
1415
  else {
1405
1416
  request['order-id'] = id;
1417
+ response = await this.privateGetOrdersOrderId(this.extend(request, params));
1406
1418
  }
1407
- const response = await this[method](this.extend(request, params));
1408
1419
  //
1409
1420
  // {
1410
1421
  // "code": "200000",
@@ -1724,7 +1735,7 @@ export default class poloniexfutures extends Exchange {
1724
1735
  const version = this.safeString(params, 'version', defaultVersion);
1725
1736
  const tail = '/api/' + version + '/' + this.implodeParams(path, params);
1726
1737
  url += tail;
1727
- const query = this.omit(params, path);
1738
+ const query = this.omit(params, this.extractParams(path));
1728
1739
  const queryLength = Object.keys(query).length;
1729
1740
  if (api === 'public') {
1730
1741
  if (queryLength) {
@@ -1117,25 +1117,27 @@ export default class binance extends binanceRest {
1117
1117
  const listenKeyRefreshRate = this.safeInteger(this.options, 'listenKeyRefreshRate', 1200000);
1118
1118
  const delay = this.sum(listenKeyRefreshRate, 10000);
1119
1119
  if (time - lastAuthenticatedTime > delay) {
1120
- let method = 'publicPostUserDataStream';
1120
+ let response = undefined;
1121
1121
  if (type === 'future') {
1122
- method = 'fapiPrivatePostListenKey';
1122
+ response = await this.fapiPrivatePostListenKey(query);
1123
1123
  }
1124
1124
  else if (type === 'delivery') {
1125
- method = 'dapiPrivatePostListenKey';
1125
+ response = await this.dapiPrivatePostListenKey(query);
1126
1126
  }
1127
1127
  else if (type === 'margin' && isCrossMargin) {
1128
- method = 'sapiPostUserDataStream';
1128
+ response = await this.sapiPostUserDataStream(query);
1129
1129
  }
1130
1130
  else if (isIsolatedMargin) {
1131
- method = 'sapiPostUserDataStreamIsolated';
1132
1131
  if (symbol === undefined) {
1133
1132
  throw new ArgumentsRequired(this.id + ' authenticate() requires a symbol argument for isolated margin mode');
1134
1133
  }
1135
1134
  const marketId = this.marketId(symbol);
1136
1135
  query = this.extend(query, { 'symbol': marketId });
1136
+ response = await this.sapiPostUserDataStreamIsolated(query);
1137
+ }
1138
+ else {
1139
+ response = await this.publicPostUserDataStream(query);
1137
1140
  }
1138
- const response = await this[method](query);
1139
1141
  this.options[type] = this.extend(options, {
1140
1142
  'listenKey': this.safeString(response, 'listenKey'),
1141
1143
  'lastAuthenticatedTime': time,
@@ -1161,26 +1163,27 @@ export default class binance extends binanceRest {
1161
1163
  // A network error happened: we can't renew a listen key that does not exist.
1162
1164
  return;
1163
1165
  }
1164
- let method = 'publicPutUserDataStream';
1165
1166
  const request = {};
1166
1167
  const symbol = this.safeString(params, 'symbol');
1167
1168
  const sendParams = this.omit(params, ['type', 'symbol']);
1168
- if (type === 'future') {
1169
- method = 'fapiPrivatePutListenKey';
1170
- }
1171
- else if (type === 'delivery') {
1172
- method = 'dapiPrivatePutListenKey';
1173
- }
1174
- else {
1175
- request['listenKey'] = listenKey;
1176
- if (type === 'margin') {
1177
- request['symbol'] = symbol;
1178
- method = 'sapiPutUserDataStream';
1179
- }
1180
- }
1181
1169
  const time = this.milliseconds();
1182
1170
  try {
1183
- await this[method](this.extend(request, sendParams));
1171
+ if (type === 'future') {
1172
+ await this.fapiPrivatePutListenKey(this.extend(request, sendParams));
1173
+ }
1174
+ else if (type === 'delivery') {
1175
+ await this.dapiPrivatePutListenKey(this.extend(request, sendParams));
1176
+ }
1177
+ else {
1178
+ request['listenKey'] = listenKey;
1179
+ if (type === 'margin') {
1180
+ request['symbol'] = symbol;
1181
+ await this.sapiPutUserDataStream(this.extend(request, sendParams));
1182
+ }
1183
+ else {
1184
+ await this.publicPutUserDataStream(this.extend(request, sendParams));
1185
+ }
1186
+ }
1184
1187
  }
1185
1188
  catch (error) {
1186
1189
  const url = this.urls['api']['ws'][type] + '/' + this.options[type]['listenKey'];
@@ -889,10 +889,15 @@ export default class bybit extends bybitRest {
889
889
  }
890
890
  const trades = this.myTrades;
891
891
  const symbols = {};
892
- const method = spot ? 'parseWsTrade' : 'parseTrade';
893
892
  for (let i = 0; i < data.length; i++) {
894
893
  const rawTrade = data[i];
895
- const parsed = this[method](rawTrade);
894
+ let parsed = undefined;
895
+ if (spot) {
896
+ parsed = this.parseWsTrade(rawTrade);
897
+ }
898
+ else {
899
+ parsed = this.parseTrade(rawTrade);
900
+ }
896
901
  const symbol = parsed['symbol'];
897
902
  symbols[symbol] = true;
898
903
  trades.append(parsed);
@@ -15,7 +15,7 @@ export declare class BigInteger {
15
15
  protected intValue(): number;
16
16
  protected byteValue(): number;
17
17
  protected shortValue(): number;
18
- protected signum(): 0 | 1 | -1;
18
+ protected signum(): 1 | 0 | -1;
19
19
  toByteArray(): number[];
20
20
  protected equals(a: BigInteger): boolean;
21
21
  protected min(a: BigInteger): BigInteger;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.1",
3
+ "version": "4.2.2",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",