ccxt 4.2.95 → 4.2.97

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +3 -3
  3. package/dist/ccxt.browser.js +746 -148
  4. package/dist/ccxt.browser.min.js +2 -2
  5. package/dist/cjs/ccxt.js +1 -1
  6. package/dist/cjs/src/base/Exchange.js +18 -3
  7. package/dist/cjs/src/base/functions/crypto.js +15 -2
  8. package/dist/cjs/src/base/functions/rsa.js +2 -2
  9. package/dist/cjs/src/binance.js +11 -12
  10. package/dist/cjs/src/coinbase.js +621 -102
  11. package/dist/cjs/src/deribit.js +8 -3
  12. package/dist/cjs/src/gemini.js +29 -11
  13. package/dist/cjs/src/okx.js +2 -2
  14. package/dist/cjs/src/poloniexfutures.js +4 -1
  15. package/dist/cjs/src/pro/binance.js +10 -4
  16. package/dist/cjs/src/pro/coinbase.js +19 -4
  17. package/dist/cjs/src/pro/poloniexfutures.js +5 -1
  18. package/js/ccxt.d.ts +1 -1
  19. package/js/ccxt.js +1 -1
  20. package/js/src/abstract/coinbase.d.ts +1 -0
  21. package/js/src/base/Exchange.d.ts +1 -1
  22. package/js/src/base/Exchange.js +18 -3
  23. package/js/src/base/functions/crypto.d.ts +1 -1
  24. package/js/src/base/functions/crypto.js +15 -2
  25. package/js/src/base/functions/rsa.js +2 -2
  26. package/js/src/base/types.d.ts +1 -0
  27. package/js/src/base/ws/OrderBook.d.ts +1 -0
  28. package/js/src/base/ws/OrderBookSide.d.ts +2 -2
  29. package/js/src/binance.js +11 -12
  30. package/js/src/coinbase.d.ts +8 -1
  31. package/js/src/coinbase.js +622 -103
  32. package/js/src/deribit.js +8 -3
  33. package/js/src/gemini.js +29 -11
  34. package/js/src/okx.d.ts +1 -1
  35. package/js/src/okx.js +2 -2
  36. package/js/src/poloniexfutures.js +4 -1
  37. package/js/src/pro/binance.js +11 -5
  38. package/js/src/pro/coinbase.js +19 -4
  39. package/js/src/pro/poloniexfutures.js +6 -2
  40. package/package.json +1 -1
  41. package/skip-tests.json +163 -31
package/dist/cjs/ccxt.js CHANGED
@@ -182,7 +182,7 @@ var woo$1 = require('./src/pro/woo.js');
182
182
 
183
183
  //-----------------------------------------------------------------------------
184
184
  // this is updated by vss.js when building
185
- const version = '4.2.95';
185
+ const version = '4.2.97';
186
186
  Exchange["default"].ccxtVersion = version;
187
187
  const exchanges = {
188
188
  'ace': ace,
@@ -4062,11 +4062,26 @@ class Exchange {
4062
4062
  const [result, empty] = this.handleOptionAndParams({}, methodName, optionName, defaultValue);
4063
4063
  return result;
4064
4064
  }
4065
- handleMarketTypeAndParams(methodName, market = undefined, params = {}) {
4065
+ handleMarketTypeAndParams(methodName, market = undefined, params = {}, defaultValue = undefined) {
4066
+ /**
4067
+ * @ignore
4068
+ * @method
4069
+ * @name exchange#handleMarketTypeAndParams
4070
+ * @param methodName the method calling handleMarketTypeAndParams
4071
+ * @param {Market} market
4072
+ * @param {object} params
4073
+ * @param {string} [params.type] type assigned by user
4074
+ * @param {string} [params.defaultType] same as params.type
4075
+ * @param {string} [defaultValue] assigned programatically in the method calling handleMarketTypeAndParams
4076
+ * @returns {[string, object]} the market type and params with type and defaultType omitted
4077
+ */
4066
4078
  const defaultType = this.safeString2(this.options, 'defaultType', 'type', 'spot');
4079
+ if (defaultValue === undefined) { // defaultValue takes precendence over exchange wide defaultType
4080
+ defaultValue = defaultType;
4081
+ }
4067
4082
  const methodOptions = this.safeDict(this.options, methodName);
4068
- let methodType = defaultType;
4069
- if (methodOptions !== undefined) {
4083
+ let methodType = defaultValue;
4084
+ if (methodOptions !== undefined) { // user defined methodType takes precedence over defaultValue
4070
4085
  if (typeof methodOptions === 'string') {
4071
4086
  methodType = methodOptions;
4072
4087
  }
@@ -8,6 +8,7 @@ var base64 = require('../../static_dependencies/jsencrypt/lib/asn1js/base64.js')
8
8
  var asn1 = require('../../static_dependencies/jsencrypt/lib/asn1js/asn1.js');
9
9
  var secp256k1 = require('../../static_dependencies/noble-curves/secp256k1.js');
10
10
  var p256 = require('../../static_dependencies/noble-curves/p256.js');
11
+ var utils = require('../../static_dependencies/noble-curves/abstract/utils.js');
11
12
 
12
13
  /* ------------------------------------------------------------------------ */
13
14
  /* ------------------------------------------------------------------------ */
@@ -31,7 +32,7 @@ const hmac = (request, secret, hash, digest = 'hex') => {
31
32
  return encoders[digest](binary);
32
33
  };
33
34
  /* ............................................. */
34
- function ecdsa(request, secret, curve, prehash = null) {
35
+ function ecdsa(request, secret, curve, prehash = null, fixedLength = false) {
35
36
  if (prehash) {
36
37
  request = hash(request, prehash, 'hex');
37
38
  }
@@ -65,7 +66,19 @@ function ecdsa(request, secret, curve, prehash = null) {
65
66
  throw new Error('Unsupported key format');
66
67
  }
67
68
  }
68
- const signature = curve.sign(request, secret);
69
+ let signature = curve.sign(request, secret, {
70
+ lowS: true,
71
+ });
72
+ const minimumSize = (BigInt(1) << (BigInt(8) * BigInt(31))) - BigInt(1);
73
+ const halfOrder = curve.CURVE.n / BigInt(2);
74
+ let counter = 0;
75
+ while (fixedLength && (signature.r > halfOrder || signature.r <= minimumSize || signature.s <= minimumSize)) {
76
+ signature = curve.sign(request, secret, {
77
+ lowS: true,
78
+ extraEntropy: utils.numberToBytesLE(BigInt(counter), 32)
79
+ });
80
+ counter += 1;
81
+ }
69
82
  return {
70
83
  'r': signature.r.toString(16),
71
84
  's': signature.s.toString(16),
@@ -38,8 +38,8 @@ function jwt(request, secret, hash, isRSA = false, opts = {}) {
38
38
  }
39
39
  else if (algoType === 'ES') {
40
40
  const signedHash = crypto.ecdsa(token, index.utf8.encode(secret), p256.P256, hash);
41
- const r = (signedHash.r.length === 64) ? signedHash.r : '0' + signedHash.r;
42
- const s = (signedHash.s.length === 64) ? signedHash.s : '0' + signedHash.s;
41
+ const r = signedHash.r.padStart(64, '0');
42
+ const s = signedHash.s.padStart(64, '0');
43
43
  signature = encode.urlencodeBase64(encode.binaryToBase64(encode.base16ToBinary(r + s)));
44
44
  }
45
45
  return [token, signature].join('.');
@@ -5796,7 +5796,7 @@ class binance extends binance$1 {
5796
5796
  response = await this.dapiPrivatePostOrder(request);
5797
5797
  }
5798
5798
  }
5799
- else if (marketType === 'margin' || marginMode !== undefined) {
5799
+ else if (marketType === 'margin' || marginMode !== undefined || isPortfolioMargin) {
5800
5800
  if (isPortfolioMargin) {
5801
5801
  response = await this.papiPostMarginOrder(request);
5802
5802
  }
@@ -5898,15 +5898,6 @@ class binance extends binance$1 {
5898
5898
  uppercaseType = market['contract'] ? 'TAKE_PROFIT' : 'TAKE_PROFIT_LIMIT';
5899
5899
  }
5900
5900
  }
5901
- if ((marketType === 'spot') || (marketType === 'margin')) {
5902
- request['newOrderRespType'] = this.safeString(this.options['newOrderRespType'], type, 'RESULT'); // 'ACK' for order id, 'RESULT' for full order or 'FULL' for order with fills
5903
- }
5904
- else {
5905
- // swap, futures and options
5906
- if (!isPortfolioMargin) {
5907
- request['newOrderRespType'] = 'RESULT'; // "ACK", "RESULT", default "ACK"
5908
- }
5909
- }
5910
5901
  if (market['option']) {
5911
5902
  if (type === 'market') {
5912
5903
  throw new errors.InvalidOrder(this.id + ' ' + type + ' is not a valid order type for the ' + symbol + ' market');
@@ -5946,6 +5937,14 @@ class binance extends binance$1 {
5946
5937
  }
5947
5938
  }
5948
5939
  }
5940
+ // handle newOrderRespType response type
5941
+ if (((marketType === 'spot') || (marketType === 'margin')) && !isPortfolioMargin) {
5942
+ request['newOrderRespType'] = this.safeString(this.options['newOrderRespType'], type, 'FULL'); // 'ACK' for order id, 'RESULT' for full order or 'FULL' for order with fills
5943
+ }
5944
+ else {
5945
+ // swap, futures and options
5946
+ request['newOrderRespType'] = 'RESULT'; // "ACK", "RESULT", default "ACK"
5947
+ }
5949
5948
  const typeRequest = isPortfolioMarginConditional ? 'strategyType' : 'type';
5950
5949
  request[typeRequest] = uppercaseType;
5951
5950
  // additional required fields depending on the order type
@@ -6599,7 +6598,7 @@ class binance extends binance$1 {
6599
6598
  response = await this.dapiPrivateGetOpenOrders(this.extend(request, params));
6600
6599
  }
6601
6600
  }
6602
- else if (type === 'margin' || marginMode !== undefined) {
6601
+ else if (type === 'margin' || marginMode !== undefined || isPortfolioMargin) {
6603
6602
  if (isPortfolioMargin) {
6604
6603
  response = await this.papiGetMarginOpenOrders(this.extend(request, params));
6605
6604
  }
@@ -7100,7 +7099,7 @@ class binance extends binance$1 {
7100
7099
  response = await this.dapiPrivateDeleteAllOpenOrders(this.extend(request, params));
7101
7100
  }
7102
7101
  }
7103
- else if ((type === 'margin') || (marginMode !== undefined)) {
7102
+ else if ((type === 'margin') || (marginMode !== undefined) || isPortfolioMargin) {
7104
7103
  if (isPortfolioMargin) {
7105
7104
  response = await this.papiDeleteMarginAllOpenOrders(this.extend(request, params));
7106
7105
  }