ccxt 4.2.36 → 4.2.38

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
@@ -44,6 +44,7 @@ var bitteam = require('./src/bitteam.js');
44
44
  var bitvavo = require('./src/bitvavo.js');
45
45
  var bl3p = require('./src/bl3p.js');
46
46
  var blockchaincom = require('./src/blockchaincom.js');
47
+ var blofin = require('./src/blofin.js');
47
48
  var btcalpha = require('./src/btcalpha.js');
48
49
  var btcbox = require('./src/btcbox.js');
49
50
  var btcmarkets = require('./src/btcmarkets.js');
@@ -176,7 +177,7 @@ var woo$1 = require('./src/pro/woo.js');
176
177
 
177
178
  //-----------------------------------------------------------------------------
178
179
  // this is updated by vss.js when building
179
- const version = '4.2.36';
180
+ const version = '4.2.38';
180
181
  Exchange["default"].ccxtVersion = version;
181
182
  const exchanges = {
182
183
  'ace': ace,
@@ -211,6 +212,7 @@ const exchanges = {
211
212
  'bitvavo': bitvavo,
212
213
  'bl3p': bl3p,
213
214
  'blockchaincom': blockchaincom,
215
+ 'blofin': blofin,
214
216
  'btcalpha': btcalpha,
215
217
  'btcbox': btcbox,
216
218
  'btcmarkets': btcmarkets,
@@ -416,6 +418,7 @@ exports.bitteam = bitteam;
416
418
  exports.bitvavo = bitvavo;
417
419
  exports.bl3p = bl3p;
418
420
  exports.blockchaincom = blockchaincom;
421
+ exports.blofin = blofin;
419
422
  exports.btcalpha = btcalpha;
420
423
  exports.btcbox = btcbox;
421
424
  exports.btcmarkets = btcmarkets;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var Exchange$1 = require('../base/Exchange.js');
4
+
5
+ // -------------------------------------------------------------------------------
6
+ class Exchange extends Exchange$1["default"] {
7
+ }
8
+
9
+ module.exports = Exchange;
@@ -5048,7 +5048,7 @@ class binance extends binance$1 {
5048
5048
  // "msg": "Quantity greater than max quantity."
5049
5049
  // }
5050
5050
  //
5051
- // createOrder: portfolio margin linear swap and future
5051
+ // createOrder, fetchOpenOrders: portfolio margin linear swap and future
5052
5052
  //
5053
5053
  // {
5054
5054
  // "symbol": "BTCUSDT",
@@ -5071,7 +5071,7 @@ class binance extends binance$1 {
5071
5071
  // "status": "NEW"
5072
5072
  // }
5073
5073
  //
5074
- // createOrder: portfolio margin inverse swap and future
5074
+ // createOrder, fetchOpenOrders: portfolio margin inverse swap and future
5075
5075
  //
5076
5076
  // {
5077
5077
  // "symbol": "ETHUSD_PERP",
@@ -5093,7 +5093,7 @@ class binance extends binance$1 {
5093
5093
  // "status": "NEW"
5094
5094
  // }
5095
5095
  //
5096
- // createOrder: portfolio margin linear swap and future conditional
5096
+ // createOrder, fetchOpenOrders: portfolio margin linear swap and future conditional
5097
5097
  //
5098
5098
  // {
5099
5099
  // "newClientStrategyId": "x-xcKtGhcu27f109953d6e4dc0974006",
@@ -5116,7 +5116,7 @@ class binance extends binance$1 {
5116
5116
  // "selfTradePreventionMode": "NONE"
5117
5117
  // }
5118
5118
  //
5119
- // createOrder: portfolio margin inverse swap and future conditional
5119
+ // createOrder, fetchOpenOrders: portfolio margin inverse swap and future conditional
5120
5120
  //
5121
5121
  // {
5122
5122
  // "newClientStrategyId": "x-xcKtGhcuc6b86f053bb34933850739",
@@ -5137,7 +5137,7 @@ class binance extends binance$1 {
5137
5137
  // "priceProtect": false
5138
5138
  // }
5139
5139
  //
5140
- // createOrder: portfolio margin spot margin
5140
+ // createOrder, cancelAllOrders: portfolio margin spot margin
5141
5141
  //
5142
5142
  // {
5143
5143
  // "clientOrderId": "x-R4BD3S82e9ef29d8346440f0b28b86",
@@ -5156,6 +5156,31 @@ class binance extends binance$1 {
5156
5156
  // "type": "LIMIT"
5157
5157
  // }
5158
5158
  //
5159
+ // fetchOpenOrders: portfolio margin spot margin
5160
+ //
5161
+ // {
5162
+ // "symbol": "BTCUSDT",
5163
+ // "orderId": 24700763749,
5164
+ // "clientOrderId": "x-R4BD3S826f724c2a4af6425f98c7b6",
5165
+ // "price": "35000.00000000",
5166
+ // "origQty": "0.00100000",
5167
+ // "executedQty": "0.00000000",
5168
+ // "cummulativeQuoteQty": "0.00000000",
5169
+ // "status": "NEW",
5170
+ // "timeInForce": "GTC",
5171
+ // "type": "LIMIT",
5172
+ // "side": "BUY",
5173
+ // "stopPrice": "0.00000000",
5174
+ // "icebergQty": "0.00000000",
5175
+ // "time": 1707199187679,
5176
+ // "updateTime": 1707199187679,
5177
+ // "isWorking": true,
5178
+ // "accountId": 200180970,
5179
+ // "selfTradePreventionMode": "EXPIRE_MAKER",
5180
+ // "preventedMatchId": null,
5181
+ // "preventedQuantity": null
5182
+ // }
5183
+ //
5159
5184
  const code = this.safeString(order, 'code');
5160
5185
  if (code !== undefined) {
5161
5186
  // cancelOrders/createOrders might have a partial success
@@ -5163,7 +5188,8 @@ class binance extends binance$1 {
5163
5188
  }
5164
5189
  const status = this.parseOrderStatus(this.safeString2(order, 'status', 'strategyStatus'));
5165
5190
  const marketId = this.safeString(order, 'symbol');
5166
- const marketType = ('closePosition' in order) ? 'contract' : 'spot';
5191
+ const isContract = ('positionSide' in order) || ('cumQuote' in order);
5192
+ const marketType = isContract ? 'contract' : 'spot';
5167
5193
  const symbol = this.safeSymbol(marketId, market, undefined, marketType);
5168
5194
  const filled = this.safeString(order, 'executedQty', '0');
5169
5195
  const timestamp = this.safeIntegerN(order, ['time', 'createTime', 'workingTime', 'transactTime', 'updateTime']); // order of the keys matters here
@@ -5470,21 +5496,6 @@ class binance extends binance$1 {
5470
5496
  }
5471
5497
  }
5472
5498
  }
5473
- if (!isPortfolioMargin) {
5474
- const postOnly = this.isPostOnly(isMarketOrder, initialUppercaseType === 'LIMIT_MAKER', params);
5475
- if (market['spot'] || marketType === 'margin') {
5476
- // only supported for spot/margin api (all margin markets are spot markets)
5477
- if (postOnly) {
5478
- type = 'LIMIT_MAKER';
5479
- }
5480
- if (marginMode === 'isolated') {
5481
- request['isIsolated'] = true;
5482
- }
5483
- }
5484
- if (market['contract'] && postOnly) {
5485
- request['timeInForce'] = 'GTX';
5486
- }
5487
- }
5488
5499
  const triggerPrice = this.safeString2(params, 'triggerPrice', 'stopPrice');
5489
5500
  const stopLossPrice = this.safeString(params, 'stopLossPrice', triggerPrice); // fallback to stopLoss
5490
5501
  const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
@@ -5561,6 +5572,19 @@ class binance extends binance$1 {
5561
5572
  else {
5562
5573
  request[clientOrderIdRequest] = clientOrderId;
5563
5574
  }
5575
+ let postOnly = undefined;
5576
+ if (!isPortfolioMargin) {
5577
+ postOnly = this.isPostOnly(isMarketOrder, initialUppercaseType === 'LIMIT_MAKER', params);
5578
+ if (market['spot'] || marketType === 'margin') {
5579
+ // only supported for spot/margin api (all margin markets are spot markets)
5580
+ if (postOnly) {
5581
+ uppercaseType = 'LIMIT_MAKER';
5582
+ }
5583
+ if (marginMode === 'isolated') {
5584
+ request['isIsolated'] = true;
5585
+ }
5586
+ }
5587
+ }
5564
5588
  const typeRequest = isPortfolioMarginConditional ? 'strategyType' : 'type';
5565
5589
  request[typeRequest] = uppercaseType;
5566
5590
  // additional required fields depending on the order type
@@ -5670,9 +5694,6 @@ class binance extends binance$1 {
5670
5694
  }
5671
5695
  request['price'] = this.priceToPrecision(symbol, price);
5672
5696
  }
5673
- if (timeInForceIsRequired) {
5674
- request['timeInForce'] = this.options['defaultTimeInForce']; // 'GTC' = Good To Cancel (default), 'IOC' = Immediate Or Cancel
5675
- }
5676
5697
  if (stopPriceIsRequired) {
5677
5698
  if (market['contract']) {
5678
5699
  if (stopPrice === undefined) {
@@ -5689,20 +5710,11 @@ class binance extends binance$1 {
5689
5710
  request['stopPrice'] = this.priceToPrecision(symbol, stopPrice);
5690
5711
  }
5691
5712
  }
5692
- if (!isPortfolioMargin) {
5693
- const postOnly = this.isPostOnly(isMarketOrder, initialUppercaseType === 'LIMIT_MAKER', params);
5694
- if (market['spot'] || marketType === 'margin') {
5695
- // only supported for spot/margin api (all margin markets are spot markets)
5696
- if (postOnly) {
5697
- type = 'LIMIT_MAKER';
5698
- }
5699
- if (marginMode === 'isolated') {
5700
- request['isIsolated'] = true;
5701
- }
5702
- }
5703
- if (market['contract'] && postOnly) {
5704
- request['timeInForce'] = 'GTX';
5705
- }
5713
+ if (timeInForceIsRequired && (this.safeString(params, 'timeInForce') === undefined)) {
5714
+ request['timeInForce'] = this.options['defaultTimeInForce']; // 'GTC' = Good To Cancel (default), 'IOC' = Immediate Or Cancel
5715
+ }
5716
+ if (!isPortfolioMargin && market['contract'] && postOnly) {
5717
+ request['timeInForce'] = 'GTX';
5706
5718
  }
5707
5719
  // remove timeInForce from params because PO is only used by this.isPostOnly and it's not a valid value for Binance
5708
5720
  if (this.safeString(params, 'timeInForce') === 'PO') {
@@ -5974,21 +5986,28 @@ class binance extends binance$1 {
5974
5986
  /**
5975
5987
  * @method
5976
5988
  * @name binance#fetchOpenOrders
5989
+ * @description fetch all unfilled currently open orders
5977
5990
  * @see https://binance-docs.github.io/apidocs/spot/en/#cancel-an-existing-order-and-send-a-new-order-trade
5978
5991
  * @see https://binance-docs.github.io/apidocs/futures/en/#current-all-open-orders-user_data
5979
5992
  * @see https://binance-docs.github.io/apidocs/delivery/en/#current-all-open-orders-user_data
5980
5993
  * @see https://binance-docs.github.io/apidocs/voptions/en/#query-current-open-option-orders-user_data
5981
- * @description fetch all unfilled currently open orders
5982
5994
  * @see https://binance-docs.github.io/apidocs/spot/en/#current-open-orders-user_data
5983
5995
  * @see https://binance-docs.github.io/apidocs/futures/en/#current-all-open-orders-user_data
5984
5996
  * @see https://binance-docs.github.io/apidocs/delivery/en/#current-all-open-orders-user_data
5985
5997
  * @see https://binance-docs.github.io/apidocs/voptions/en/#query-current-open-option-orders-user_data
5986
5998
  * @see https://binance-docs.github.io/apidocs/spot/en/#query-margin-account-39-s-open-orders-user_data
5999
+ * @see https://binance-docs.github.io/apidocs/pm/en/#query-all-current-um-open-orders-user_data
6000
+ * @see https://binance-docs.github.io/apidocs/pm/en/#query-all-current-cm-open-orders-user_data
6001
+ * @see https://binance-docs.github.io/apidocs/pm/en/#query-all-current-um-open-conditional-orders-user_data
6002
+ * @see https://binance-docs.github.io/apidocs/pm/en/#query-all-current-cm-open-conditional-orders-user_data
6003
+ * @see https://binance-docs.github.io/apidocs/pm/en/#query-current-margin-open-order-user_data
5987
6004
  * @param {string} symbol unified market symbol
5988
6005
  * @param {int} [since] the earliest time in ms to fetch open orders for
5989
6006
  * @param {int} [limit] the maximum number of open orders structures to retrieve
5990
6007
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5991
6008
  * @param {string} [params.marginMode] 'cross' or 'isolated', for spot margin trading
6009
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch open orders in the portfolio margin account
6010
+ * @param {boolean} [params.stop] set to true if you would like to fetch portfolio margin account conditional orders
5992
6011
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
5993
6012
  */
5994
6013
  await this.loadMarkets();
@@ -5996,14 +6015,16 @@ class binance extends binance$1 {
5996
6015
  let type = undefined;
5997
6016
  const request = {};
5998
6017
  let marginMode = undefined;
5999
- let query = undefined;
6000
- [marginMode, query] = this.handleMarginModeAndParams('fetchOpenOrders', params);
6018
+ [marginMode, params] = this.handleMarginModeAndParams('fetchOpenOrders', params);
6019
+ let isPortfolioMargin = undefined;
6020
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchOpenOrders', 'papi', 'portfolioMargin', false);
6021
+ const isConditional = this.safeBool2(params, 'stop', 'conditional');
6001
6022
  if (symbol !== undefined) {
6002
6023
  market = this.market(symbol);
6003
6024
  request['symbol'] = market['id'];
6004
6025
  const defaultType = this.safeString2(this.options, 'fetchOpenOrders', 'defaultType', 'spot');
6005
6026
  const marketType = ('type' in market) ? market['type'] : defaultType;
6006
- type = this.safeString(query, 'type', marketType);
6027
+ type = this.safeString(params, 'type', marketType);
6007
6028
  }
6008
6029
  else if (this.options['warnOnFetchOpenOrdersWithoutSymbol']) {
6009
6030
  const symbols = this.symbols;
@@ -6013,11 +6034,11 @@ class binance extends binance$1 {
6013
6034
  }
6014
6035
  else {
6015
6036
  const defaultType = this.safeString2(this.options, 'fetchOpenOrders', 'defaultType', 'spot');
6016
- type = this.safeString(query, 'type', defaultType);
6037
+ type = this.safeString(params, 'type', defaultType);
6017
6038
  }
6018
6039
  let subType = undefined;
6019
- [subType, query] = this.handleSubTypeAndParams('fetchOpenOrders', market, query);
6020
- const requestParams = this.omit(query, 'type');
6040
+ [subType, params] = this.handleSubTypeAndParams('fetchOpenOrders', market, params);
6041
+ params = this.omit(params, ['type', 'stop', 'conditional']);
6021
6042
  let response = undefined;
6022
6043
  if (type === 'option') {
6023
6044
  if (since !== undefined) {
@@ -6026,25 +6047,50 @@ class binance extends binance$1 {
6026
6047
  if (limit !== undefined) {
6027
6048
  request['limit'] = limit;
6028
6049
  }
6029
- response = await this.eapiPrivateGetOpenOrders(this.extend(request, requestParams));
6050
+ response = await this.eapiPrivateGetOpenOrders(this.extend(request, params));
6030
6051
  }
6031
6052
  else if (this.isLinear(type, subType)) {
6032
- response = await this.fapiPrivateGetOpenOrders(this.extend(request, requestParams));
6053
+ if (isPortfolioMargin) {
6054
+ if (isConditional) {
6055
+ response = await this.papiGetUmConditionalOpenOrders(this.extend(request, params));
6056
+ }
6057
+ else {
6058
+ response = await this.papiGetUmOpenOrders(this.extend(request, params));
6059
+ }
6060
+ }
6061
+ else {
6062
+ response = await this.fapiPrivateGetOpenOrders(this.extend(request, params));
6063
+ }
6033
6064
  }
6034
6065
  else if (this.isInverse(type, subType)) {
6035
- response = await this.dapiPrivateGetOpenOrders(this.extend(request, requestParams));
6066
+ if (isPortfolioMargin) {
6067
+ if (isConditional) {
6068
+ response = await this.papiGetCmConditionalOpenOrders(this.extend(request, params));
6069
+ }
6070
+ else {
6071
+ response = await this.papiGetCmOpenOrders(this.extend(request, params));
6072
+ }
6073
+ }
6074
+ else {
6075
+ response = await this.dapiPrivateGetOpenOrders(this.extend(request, params));
6076
+ }
6036
6077
  }
6037
6078
  else if (type === 'margin' || marginMode !== undefined) {
6038
- if (marginMode === 'isolated') {
6039
- request['isIsolated'] = true;
6040
- if (symbol === undefined) {
6041
- throw new errors.ArgumentsRequired(this.id + ' fetchOpenOrders() requires a symbol argument for isolated markets');
6079
+ if (isPortfolioMargin) {
6080
+ response = await this.papiGetMarginOpenOrders(this.extend(request, params));
6081
+ }
6082
+ else {
6083
+ if (marginMode === 'isolated') {
6084
+ request['isIsolated'] = true;
6085
+ if (symbol === undefined) {
6086
+ throw new errors.ArgumentsRequired(this.id + ' fetchOpenOrders() requires a symbol argument for isolated markets');
6087
+ }
6042
6088
  }
6089
+ response = await this.sapiGetMarginOpenOrders(this.extend(request, params));
6043
6090
  }
6044
- response = await this.sapiGetMarginOpenOrders(this.extend(request, requestParams));
6045
6091
  }
6046
6092
  else {
6047
- response = await this.privateGetOpenOrders(this.extend(request, requestParams));
6093
+ response = await this.privateGetOpenOrders(this.extend(request, params));
6048
6094
  }
6049
6095
  return this.parseOrders(response, market, since, limit);
6050
6096
  }
@@ -6162,46 +6208,82 @@ class binance extends binance$1 {
6162
6208
  /**
6163
6209
  * @method
6164
6210
  * @name binance#cancelAllOrders
6211
+ * @description cancel all open orders in a market
6165
6212
  * @see https://binance-docs.github.io/apidocs/spot/en/#cancel-all-open-orders-on-a-symbol-trade
6166
6213
  * @see https://binance-docs.github.io/apidocs/futures/en/#cancel-all-open-orders-trade
6167
6214
  * @see https://binance-docs.github.io/apidocs/delivery/en/#cancel-all-open-orders-trade
6168
6215
  * @see https://binance-docs.github.io/apidocs/voptions/en/#cancel-all-option-orders-on-specific-symbol-trade
6169
6216
  * @see https://binance-docs.github.io/apidocs/spot/en/#margin-account-cancel-order-trade
6170
- * @description cancel all open orders in a market
6217
+ * @see https://binance-docs.github.io/apidocs/pm/en/#cancel-all-um-open-orders-trade
6218
+ * @see https://binance-docs.github.io/apidocs/pm/en/#cancel-all-cm-open-orders-trade
6219
+ * @see https://binance-docs.github.io/apidocs/pm/en/#cancel-all-um-open-conditional-orders-trade
6220
+ * @see https://binance-docs.github.io/apidocs/pm/en/#cancel-all-cm-open-conditional-orders-trade
6221
+ * @see https://binance-docs.github.io/apidocs/pm/en/#cancel-margin-account-all-open-orders-on-a-symbol-trade
6171
6222
  * @param {string} symbol unified market symbol of the market to cancel orders in
6172
6223
  * @param {object} [params] extra parameters specific to the exchange API endpoint
6173
6224
  * @param {string} [params.marginMode] 'cross' or 'isolated', for spot margin trading
6225
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to cancel orders in a portfolio margin account
6226
+ * @param {boolean} [params.stop] set to true if you would like to cancel portfolio margin account conditional orders
6174
6227
  * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
6175
6228
  */
6176
6229
  if (symbol === undefined) {
6177
- throw new errors.ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument');
6230
+ throw new errors.ArgumentsRequired(this.id + ' cancelAllOrders() requires a symbol argument');
6178
6231
  }
6179
6232
  await this.loadMarkets();
6180
6233
  const market = this.market(symbol);
6181
6234
  const request = {
6182
6235
  'symbol': market['id'],
6183
6236
  };
6237
+ let isPortfolioMargin = undefined;
6238
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'cancelAllOrders', 'papi', 'portfolioMargin', false);
6239
+ const isConditional = this.safeBool2(params, 'stop', 'conditional');
6184
6240
  const type = this.safeString(params, 'type', market['type']);
6185
- params = this.omit(params, ['type']);
6186
- const [marginMode, query] = this.handleMarginModeAndParams('cancelAllOrders', params);
6241
+ params = this.omit(params, ['type', 'stop', 'conditional']);
6242
+ let marginMode = undefined;
6243
+ [marginMode, params] = this.handleMarginModeAndParams('cancelAllOrders', params);
6187
6244
  let response = undefined;
6188
6245
  if (market['option']) {
6189
- response = await this.eapiPrivateDeleteAllOpenOrders(this.extend(request, query));
6246
+ response = await this.eapiPrivateDeleteAllOpenOrders(this.extend(request, params));
6190
6247
  }
6191
6248
  else if (market['linear']) {
6192
- response = await this.fapiPrivateDeleteAllOpenOrders(this.extend(request, query));
6249
+ if (isPortfolioMargin) {
6250
+ if (isConditional) {
6251
+ response = await this.papiDeleteUmConditionalAllOpenOrders(this.extend(request, params));
6252
+ }
6253
+ else {
6254
+ response = await this.papiDeleteUmAllOpenOrders(this.extend(request, params));
6255
+ }
6256
+ }
6257
+ else {
6258
+ response = await this.fapiPrivateDeleteAllOpenOrders(this.extend(request, params));
6259
+ }
6193
6260
  }
6194
6261
  else if (market['inverse']) {
6195
- response = await this.dapiPrivateDeleteAllOpenOrders(this.extend(request, query));
6262
+ if (isPortfolioMargin) {
6263
+ if (isConditional) {
6264
+ response = await this.papiDeleteCmConditionalAllOpenOrders(this.extend(request, params));
6265
+ }
6266
+ else {
6267
+ response = await this.papiDeleteCmAllOpenOrders(this.extend(request, params));
6268
+ }
6269
+ }
6270
+ else {
6271
+ response = await this.dapiPrivateDeleteAllOpenOrders(this.extend(request, params));
6272
+ }
6196
6273
  }
6197
6274
  else if ((type === 'margin') || (marginMode !== undefined)) {
6198
- if (marginMode === 'isolated') {
6199
- request['isIsolated'] = true;
6275
+ if (isPortfolioMargin) {
6276
+ response = await this.papiDeleteMarginAllOpenOrders(this.extend(request, params));
6277
+ }
6278
+ else {
6279
+ if (marginMode === 'isolated') {
6280
+ request['isIsolated'] = true;
6281
+ }
6282
+ response = await this.sapiDeleteMarginOpenOrders(this.extend(request, params));
6200
6283
  }
6201
- response = await this.sapiDeleteMarginOpenOrders(this.extend(request, query));
6202
6284
  }
6203
6285
  else {
6204
- response = await this.privateDeleteOpenOrders(this.extend(request, query));
6286
+ response = await this.privateDeleteOpenOrders(this.extend(request, params));
6205
6287
  }
6206
6288
  if (Array.isArray(response)) {
6207
6289
  return this.parseOrders(response, market);