ccxt 4.2.36 → 4.2.37

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