ccxt 4.2.86 → 4.2.87

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 (93) hide show
  1. package/README.md +3 -3
  2. package/build.sh +1 -1
  3. package/dist/ccxt.browser.js +671 -130
  4. package/dist/ccxt.browser.min.js +3 -3
  5. package/dist/cjs/ccxt.js +1 -1
  6. package/dist/cjs/src/ascendex.js +11 -1
  7. package/dist/cjs/src/binance.js +14 -1
  8. package/dist/cjs/src/bingx.js +37 -1
  9. package/dist/cjs/src/bitfinex.js +3 -0
  10. package/dist/cjs/src/bitfinex2.js +16 -1
  11. package/dist/cjs/src/bitflyer.js +19 -0
  12. package/dist/cjs/src/bitget.js +15 -1
  13. package/dist/cjs/src/bitopro.js +3 -0
  14. package/dist/cjs/src/bitrue.js +13 -7
  15. package/dist/cjs/src/bitvavo.js +3 -0
  16. package/dist/cjs/src/btcmarkets.js +1 -1
  17. package/dist/cjs/src/btcturk.js +2 -1
  18. package/dist/cjs/src/coinex.js +182 -54
  19. package/dist/cjs/src/currencycom.js +1 -1
  20. package/dist/cjs/src/delta.js +3 -1
  21. package/dist/cjs/src/digifinex.js +4 -2
  22. package/dist/cjs/src/exmo.js +11 -12
  23. package/dist/cjs/src/gate.js +5 -2
  24. package/dist/cjs/src/hitbtc.js +26 -2
  25. package/dist/cjs/src/htx.js +2 -2
  26. package/dist/cjs/src/huobijp.js +1 -1
  27. package/dist/cjs/src/hyperliquid.js +249 -12
  28. package/dist/cjs/src/idex.js +1 -1
  29. package/dist/cjs/src/krakenfutures.js +2 -6
  30. package/dist/cjs/src/lbank.js +3 -0
  31. package/dist/cjs/src/oceanex.js +1 -1
  32. package/dist/cjs/src/okx.js +24 -10
  33. package/dist/cjs/src/phemex.js +3 -1
  34. package/dist/cjs/src/pro/kucoin.js +11 -6
  35. package/dist/cjs/src/wazirx.js +1 -1
  36. package/dist/cjs/src/zonda.js +3 -0
  37. package/examples/js/benchmark.js +104 -0
  38. package/examples/ts/benchmark.ts +134 -0
  39. package/js/ccxt.d.ts +1 -1
  40. package/js/ccxt.js +1 -1
  41. package/js/src/ascendex.d.ts +5 -12
  42. package/js/src/ascendex.js +11 -1
  43. package/js/src/base/Exchange.d.ts +4 -4
  44. package/js/src/base/types.d.ts +11 -0
  45. package/js/src/binance.d.ts +4 -11
  46. package/js/src/binance.js +14 -1
  47. package/js/src/bingx.d.ts +5 -2
  48. package/js/src/bingx.js +37 -1
  49. package/js/src/bitfinex.js +3 -0
  50. package/js/src/bitfinex2.d.ts +3 -17
  51. package/js/src/bitfinex2.js +16 -1
  52. package/js/src/bitflyer.d.ts +1 -0
  53. package/js/src/bitflyer.js +20 -1
  54. package/js/src/bitget.d.ts +5 -12
  55. package/js/src/bitget.js +15 -1
  56. package/js/src/bitopro.js +3 -0
  57. package/js/src/bitrue.d.ts +3 -17
  58. package/js/src/bitrue.js +13 -7
  59. package/js/src/bitvavo.js +3 -0
  60. package/js/src/btcmarkets.js +1 -1
  61. package/js/src/btcturk.js +2 -1
  62. package/js/src/coinex.d.ts +4 -11
  63. package/js/src/coinex.js +182 -54
  64. package/js/src/currencycom.js +1 -1
  65. package/js/src/delta.d.ts +5 -37
  66. package/js/src/delta.js +3 -1
  67. package/js/src/digifinex.d.ts +5 -13
  68. package/js/src/digifinex.js +4 -2
  69. package/js/src/exmo.d.ts +5 -37
  70. package/js/src/exmo.js +11 -12
  71. package/js/src/gate.d.ts +5 -33
  72. package/js/src/gate.js +5 -2
  73. package/js/src/hitbtc.d.ts +5 -12
  74. package/js/src/hitbtc.js +26 -2
  75. package/js/src/htx.js +2 -2
  76. package/js/src/huobijp.js +1 -1
  77. package/js/src/hyperliquid.d.ts +7 -4
  78. package/js/src/hyperliquid.js +249 -12
  79. package/js/src/idex.js +1 -1
  80. package/js/src/krakenfutures.js +2 -6
  81. package/js/src/kucoinfutures.d.ts +2 -2
  82. package/js/src/lbank.js +3 -0
  83. package/js/src/mexc.d.ts +3 -3
  84. package/js/src/oceanex.js +1 -1
  85. package/js/src/okx.d.ts +5 -33
  86. package/js/src/okx.js +24 -10
  87. package/js/src/phemex.d.ts +3 -11
  88. package/js/src/phemex.js +3 -1
  89. package/js/src/pro/kucoin.js +11 -6
  90. package/js/src/wazirx.js +1 -1
  91. package/js/src/zonda.js +3 -0
  92. package/package.json +3 -2
  93. package/skip-tests.json +3 -3
@@ -6460,26 +6460,40 @@ class okx extends okx$1 {
6460
6460
  // "msg": ""
6461
6461
  // }
6462
6462
  //
6463
- return this.parseMarginModification(response, market);
6463
+ const data = this.safeList(response, 'data', []);
6464
+ const errorCode = this.safeString(response, 'code');
6465
+ const item = this.safeDict(data, 0, {});
6466
+ return this.extend(this.parseMarginModification(item, market), {
6467
+ 'status': (errorCode === '0') ? 'ok' : 'failed',
6468
+ });
6464
6469
  }
6465
6470
  parseMarginModification(data, market = undefined) {
6466
- const innerData = this.safeValue(data, 'data', []);
6467
- const entry = this.safeValue(innerData, 0, {});
6468
- const errorCode = this.safeString(data, 'code');
6469
- const status = (errorCode === '0') ? 'ok' : 'failed';
6470
- const amountRaw = this.safeNumber(entry, 'amt');
6471
- const typeRaw = this.safeString(entry, 'type');
6471
+ //
6472
+ // addMargin/reduceMargin
6473
+ //
6474
+ // {
6475
+ // "amt": "0.01",
6476
+ // "instId": "ETH-USD-SWAP",
6477
+ // "posSide": "net",
6478
+ // "type": "reduce"
6479
+ // }
6480
+ //
6481
+ const amountRaw = this.safeNumber(data, 'amt');
6482
+ const typeRaw = this.safeString(data, 'type');
6472
6483
  const type = (typeRaw === 'reduce') ? 'reduce' : 'add';
6473
- const marketId = this.safeString(entry, 'instId');
6484
+ const marketId = this.safeString(data, 'instId');
6474
6485
  const responseMarket = this.safeMarket(marketId, market);
6475
6486
  const code = responseMarket['inverse'] ? responseMarket['base'] : responseMarket['quote'];
6476
6487
  return {
6477
6488
  'info': data,
6489
+ 'symbol': responseMarket['symbol'],
6478
6490
  'type': type,
6479
6491
  'amount': amountRaw,
6492
+ 'total': undefined,
6480
6493
  'code': code,
6481
- 'symbol': responseMarket['symbol'],
6482
- 'status': status,
6494
+ 'status': undefined,
6495
+ 'timestamp': undefined,
6496
+ 'datetime': undefined,
6483
6497
  };
6484
6498
  }
6485
6499
  async reduceMargin(symbol, amount, params = {}) {
@@ -4060,12 +4060,14 @@ class phemex extends phemex$1 {
4060
4060
  const codeCurrency = inverse ? 'base' : 'quote';
4061
4061
  return {
4062
4062
  'info': data,
4063
+ 'symbol': this.safeSymbol(undefined, market),
4063
4064
  'type': 'set',
4064
4065
  'amount': undefined,
4065
4066
  'total': undefined,
4066
4067
  'code': market[codeCurrency],
4067
- 'symbol': this.safeSymbol(undefined, market),
4068
4068
  'status': this.parseMarginStatus(this.safeString(data, 'code')),
4069
+ 'timestamp': undefined,
4070
+ 'datetime': undefined,
4069
4071
  };
4070
4072
  }
4071
4073
  async setMarginMode(marginMode, symbol = undefined, params = {}) {
@@ -570,17 +570,22 @@ class kucoin extends kucoin$1 {
570
570
  const marketId = this.safeString(data, 'symbol', topicSymbol);
571
571
  const symbol = this.safeSymbol(marketId, undefined, '-');
572
572
  const messageHash = 'orderbook:' + symbol;
573
- let orderbook = this.safeDict(this.orderbooks, symbol);
573
+ // let orderbook = this.safeDict (this.orderbooks, symbol);
574
574
  if (subject === 'level2') {
575
- if (orderbook === undefined) {
576
- orderbook = this.orderBook();
575
+ if (!(symbol in this.orderbooks)) {
576
+ this.orderbooks[symbol] = this.orderBook();
577
577
  }
578
578
  else {
579
+ const orderbook = this.orderbooks[symbol];
579
580
  orderbook.reset();
580
581
  }
581
- orderbook['symbol'] = symbol;
582
+ this.orderbooks[symbol]['symbol'] = symbol;
582
583
  }
583
584
  else {
585
+ if (!(symbol in this.orderbooks)) {
586
+ this.orderbooks[symbol] = this.orderBook();
587
+ }
588
+ const orderbook = this.orderbooks[symbol];
584
589
  const nonce = this.safeInteger(orderbook, 'nonce');
585
590
  const deltaEnd = this.safeInteger2(data, 'sequenceEnd', 'timestamp');
586
591
  if (nonce === undefined) {
@@ -606,8 +611,8 @@ class kucoin extends kucoin$1 {
606
611
  return;
607
612
  }
608
613
  }
609
- this.handleDelta(orderbook, data);
610
- client.resolve(orderbook, messageHash);
614
+ this.handleDelta(this.orderbooks[symbol], data);
615
+ client.resolve(this.orderbooks[symbol], messageHash);
611
616
  }
612
617
  getCacheIndex(orderbook, cache) {
613
618
  const firstDelta = this.safeValue(cache, 0);
@@ -319,7 +319,7 @@ class wazirx extends wazirx$1 {
319
319
  'interval': this.safeString(this.timeframes, timeframe, timeframe),
320
320
  };
321
321
  if (limit !== undefined) {
322
- request['limit'] = limit;
322
+ request['limit'] = Math.min(limit, 2000);
323
323
  }
324
324
  const until = this.safeInteger(params, 'until');
325
325
  params = this.omit(params, ['until']);
@@ -1201,6 +1201,9 @@ class zonda extends zonda$1 {
1201
1201
  if (limit === undefined) {
1202
1202
  limit = 100;
1203
1203
  }
1204
+ else {
1205
+ limit = Math.min(limit, 11000); // supports up to 11k candles diapason
1206
+ }
1204
1207
  const duration = this.parseTimeframe(timeframe);
1205
1208
  const timerange = limit * duration * 1000;
1206
1209
  if (since === undefined) {
@@ -0,0 +1,104 @@
1
+ import { spawn } from 'child_process';
2
+ import asTable from 'as-table';
3
+ import ccxt, { version } from '../../js/ccxt.js';
4
+ const stats = (times) => {
5
+ // calculate statistics
6
+ const sum = times.reduce((a, b) => a + b, 0);
7
+ const avg = Math.round(sum / times.length);
8
+ const min = Math.min(...times);
9
+ const max = Math.max(...times);
10
+ times.sort((a, b) => a - b);
11
+ const median = times.length % 2 === 0 ? (times[times.length / 2 - 1] + times[times.length / 2]) / 2 : times[Math.floor(times.length / 2)];
12
+ return { min, 'average': avg, max, median, 'iterations': times.length };
13
+ };
14
+ async function benchmark(exchangeId, method, args, verbose = false, minIterations = 10, argsv = '') {
15
+ const exchange = new ccxt.pro[exchangeId]({});
16
+ const languages = ['js', 'py', 'php', 'cs'];
17
+ const commands = languages.map((language) => ({
18
+ 'language': language,
19
+ 'method': method,
20
+ 'command': `npm run cli.${language} ${exchangeId} ${method} ${args.join(' ')} -- ${argsv} --poll`,
21
+ }));
22
+ const wsMethod = method + 'Ws';
23
+ if (exchange.has[wsMethod]) {
24
+ const wsCommands = languages.map((language) => ({
25
+ 'language': language,
26
+ 'method': wsMethod,
27
+ 'command': `npm run cli.${language} ${exchangeId} ${wsMethod} ${args.join(' ')} -- ${argsv} --poll`,
28
+ }));
29
+ commands.push(...wsCommands);
30
+ }
31
+ const regex = /iteration (\d+) passed in (\d+) ms/g;
32
+ async function runCommand(command) {
33
+ if (verbose) {
34
+ console.log(exchange.iso8601(new Date().getTime()), ' running command:', command);
35
+ }
36
+ return new Promise((resolve, reject) => {
37
+ const [cmd, ...args] = command.split(' ');
38
+ const child = spawn(cmd, args);
39
+ const matches = [];
40
+ const language = command.slice(8, 15);
41
+ child.stdout.on('data', (data) => {
42
+ const message = data.toString();
43
+ matches.push(...Array.from(message.matchAll(regex)));
44
+ const match = matches[matches.length - 1];
45
+ if (match && match[1] && match[2]) {
46
+ const iteration = parseInt(match[1]);
47
+ const time = parseInt(match[2]);
48
+ if (iteration <= minIterations) {
49
+ if (verbose) {
50
+ console.log(exchange.iso8601(new Date().getTime()), `${language} iteration ${iteration} passed in ${time} ms`);
51
+ }
52
+ }
53
+ else {
54
+ const times = matches.map((m) => parseInt(m[2]));
55
+ child.kill();
56
+ if (verbose) {
57
+ console.log(exchange.iso8601(new Date().getTime()), `killed process - ${language} iteration ${iteration} passed in ${time} ms`);
58
+ }
59
+ resolve({ times });
60
+ }
61
+ }
62
+ });
63
+ child.stderr.on('data', (data) => {
64
+ const message = data.toString();
65
+ console.error(exchange.iso8601(new Date().getTime()), `command ${command} failed. stderr: ${message}`);
66
+ const times = matches.map((m) => parseInt(m[2]));
67
+ resolve({ times });
68
+ });
69
+ child.on('close', (code) => {
70
+ const times = matches.map((m) => parseInt(m[2]));
71
+ resolve({ times });
72
+ console.log(exchange.iso8601(new Date().getTime()), `${language} child process exited with code ${code}`);
73
+ });
74
+ child.on('error', (err) => {
75
+ console.error(exchange.iso8601(new Date().getTime()), `command ${command} failed. error: ${err}`);
76
+ reject(err);
77
+ });
78
+ });
79
+ }
80
+ const benchmarks = [];
81
+ const results = await Promise.all(commands.map((c) => runCommand(c.command)));
82
+ for (let i = 0; i < results.length; i++) {
83
+ const result = results[i];
84
+ benchmarks.push({ 'language': commands[i].language, 'method': commands[i].method, ...stats(result.times) });
85
+ }
86
+ if (verbose) {
87
+ const rawResults = results.map((r, i) => ({ 'language': commands[i].language, 'method': commands[i].method, ...stats(r.times), 'times': r.times }));
88
+ console.log(rawResults);
89
+ }
90
+ console.log(asTable(benchmarks));
91
+ }
92
+ const [_, , exchangeId, methodName, ...params] = process.argv.filter((x) => !x.startsWith('--'));
93
+ const verbose = process.argv.includes('--verbose');
94
+ const minIterationsString = process.argv.find((x) => x.startsWith('--min-iterations='))?.slice(18);
95
+ const minIterations = minIterationsString ? parseInt(minIterationsString) : 10;
96
+ const argsv = process.argv.filter((x) => x.startsWith('--') && !x.startsWith('--min-iterations')).join(' ');
97
+ console.log((new Date()).toISOString());
98
+ console.log('Node.js:', process.version);
99
+ console.log('CCXT v' + version);
100
+ const start = new Date().getTime();
101
+ await benchmark(exchangeId, methodName, params, verbose, minIterations, argsv);
102
+ const end = new Date().getTime();
103
+ console.log((new Date().toISOString()), 'Total time:', end - start, 'ms');
104
+ process.exit(0);
@@ -0,0 +1,134 @@
1
+ import { spawn } from 'child_process';
2
+ import asTable from 'as-table';
3
+ import ccxt, { version } from '../../js/ccxt.js';
4
+
5
+ interface Stats {
6
+ min: number;
7
+ average: number;
8
+ max: number;
9
+ median: number;
10
+ iterations: number;
11
+ }
12
+
13
+ interface Test {
14
+ language: string;
15
+ method: string;
16
+ command: string;
17
+ }
18
+
19
+ interface Benchmark extends Omit<Test, 'command'>, Stats { }
20
+
21
+ const stats = (times: number[]): Stats => {
22
+ // calculate statistics
23
+ const sum = times.reduce ((a, b) => a + b, 0);
24
+ const avg = Math.round (sum / times.length);
25
+ const min = Math.min (...times);
26
+ const max = Math.max (...times);
27
+ times.sort ((a, b) => a - b);
28
+ const median = times.length % 2 === 0 ? (times[times.length / 2 - 1] + times[times.length / 2]) / 2 : times[Math.floor (times.length / 2)];
29
+ return { min, 'average': avg, max, median, 'iterations': times.length };
30
+ };
31
+
32
+ async function benchmark (exchangeId, method, args, verbose = false, minIterations = 10, argsv = '') {
33
+ const exchange = new ccxt.pro[exchangeId] ({});
34
+ const languages = [ 'js', 'py', 'php', 'cs' ];
35
+ const commands: Test[] = languages.map ((language) => ({
36
+ 'language': language,
37
+ 'method': method,
38
+ 'command': `npm run cli.${language} ${exchangeId} ${method} ${args.join (' ')} -- ${argsv} --poll`,
39
+ }));
40
+ const wsMethod = method + 'Ws';
41
+ if (exchange.has[wsMethod]) {
42
+ const wsCommands: Test[] = languages.map ((language) => ({
43
+ 'language': language,
44
+ 'method': wsMethod,
45
+ 'command': `npm run cli.${language} ${exchangeId} ${wsMethod} ${args.join (' ')} -- ${argsv} --poll`,
46
+ }));
47
+ commands.push (...wsCommands);
48
+ }
49
+ const regex = /iteration (\d+) passed in (\d+) ms/g;
50
+
51
+ async function runCommand (command: string) {
52
+ if (verbose) {
53
+ console.log (exchange.iso8601 (new Date ().getTime ()), ' running command:', command);
54
+ }
55
+ return new Promise<{ times: number[] }> ((resolve, reject) => {
56
+ const [ cmd, ...args ] = command.split (' ');
57
+
58
+ const child = spawn (cmd, args);
59
+ const matches = [];
60
+ const language = command.slice (8, 15);
61
+ child.stdout.on ('data', (data: Buffer) => {
62
+ const message = data.toString ();
63
+ matches.push (...Array.from (message.matchAll (regex)));
64
+ const match = matches[matches.length - 1];
65
+
66
+ if (match && match[1] && match[2]) {
67
+ const iteration = parseInt (match[1]);
68
+ const time = parseInt (match[2]);
69
+
70
+ if (iteration <= minIterations) {
71
+ if (verbose) {
72
+ console.log (exchange.iso8601 (new Date ().getTime ()), `${language} iteration ${iteration} passed in ${time} ms`);
73
+ }
74
+ } else {
75
+ const times = matches.map ((m) => parseInt (m[2]));
76
+ child.kill ();
77
+ if (verbose) {
78
+ console.log (exchange.iso8601 (new Date ().getTime ()), `killed process - ${language} iteration ${iteration} passed in ${time} ms`);
79
+ }
80
+ resolve ({ times });
81
+ }
82
+ }
83
+ });
84
+
85
+ child.stderr.on ('data', (data: Buffer) => {
86
+ const message = data.toString ();
87
+ console.error (exchange.iso8601 (new Date ().getTime ()), `command ${command} failed. stderr: ${message}`);
88
+ const times = matches.map ((m) => parseInt (m[2]));
89
+ resolve ({ times });
90
+ });
91
+
92
+ child.on ('close', (code: number) => {
93
+ const times = matches.map ((m) => parseInt (m[2]));
94
+ resolve ({ times });
95
+ console.log (exchange.iso8601 (new Date ().getTime ()), `${language} child process exited with code ${code}`);
96
+ });
97
+
98
+ child.on ('error', (err) => {
99
+ console.error (exchange.iso8601 (new Date ().getTime ()), `command ${command} failed. error: ${err}`);
100
+ reject (err);
101
+ });
102
+ });
103
+ }
104
+
105
+ const benchmarks: Benchmark[] = [];
106
+ const results = await Promise.all (commands.map ((c) => runCommand (c.command)));
107
+ for (let i = 0; i < results.length; i++) {
108
+ const result = results[i];
109
+ benchmarks.push ({ 'language': commands[i].language, 'method': commands[i].method, ...stats (result.times) });
110
+ }
111
+ if (verbose) {
112
+ const rawResults = results.map ((r, i) => ({ 'language': commands[i].language, 'method': commands[i].method, ...stats (r.times), 'times': r.times }));
113
+ console.log (rawResults);
114
+ }
115
+ console.log (asTable (benchmarks));
116
+ }
117
+
118
+ const [ _, , exchangeId, methodName, ...params ] = process.argv.filter ((x) => !x.startsWith ('--'));
119
+ const verbose = process.argv.includes ('--verbose');
120
+ const minIterationsString = process.argv.find ((x) => x.startsWith ('--min-iterations='))?.slice (18);
121
+ const minIterations = minIterationsString ? parseInt (minIterationsString) : 10;
122
+ const argsv = process.argv.filter ((x) => x.startsWith ('--') && !x.startsWith ('--min-iterations')).join (' ');
123
+
124
+
125
+ console.log ((new Date ()).toISOString ());
126
+ console.log ('Node.js:', process.version);
127
+ console.log ('CCXT v' + version);
128
+
129
+ const start = new Date ().getTime ();
130
+ await benchmark (exchangeId, methodName, params, verbose, minIterations, argsv);
131
+ const end = new Date ().getTime ();
132
+
133
+ console.log ((new Date ().toISOString ()), 'Total time:', end - start, 'ms');
134
+ process.exit (0);
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 type { Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory, MarginMode, Greeks, Leverage, Leverages, Option, OptionChain } 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, NoChange } from './src/base/errors.js';
7
- declare const version = "4.2.85";
7
+ declare const version = "4.2.86";
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, NoChange } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.2.86';
41
+ const version = '4.2.87';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/ascendex.js';
2
- import type { TransferEntry, FundingHistory, Int, OHLCV, Order, OrderSide, OrderType, OrderRequest, Str, Trade, Balances, Transaction, Ticker, OrderBook, Tickers, Strings, Num, Currency, Market, Leverage, Leverages, Account, MarginModes, MarginMode } from './base/types.js';
2
+ import type { TransferEntry, FundingHistory, Int, OHLCV, Order, OrderSide, OrderType, OrderRequest, Str, Trade, Balances, Transaction, Ticker, OrderBook, Tickers, Strings, Num, Currency, Market, Leverage, Leverages, Account, MarginModes, MarginMode, MarginModification } from './base/types.js';
3
3
  /**
4
4
  * @class ascendex
5
5
  * @augments Exchange
@@ -70,17 +70,10 @@ export default class ascendex extends Exchange {
70
70
  fundingDatetime: string;
71
71
  };
72
72
  fetchFundingRates(symbols?: Strings, params?: {}): Promise<any>;
73
- modifyMarginHelper(symbol: string, amount: any, type: any, params?: {}): Promise<any>;
74
- parseMarginModification(data: any, market?: Market): {
75
- info: any;
76
- type: any;
77
- amount: any;
78
- code: string;
79
- symbol: string;
80
- status: string;
81
- };
82
- reduceMargin(symbol: string, amount: any, params?: {}): Promise<any>;
83
- addMargin(symbol: string, amount: any, params?: {}): Promise<any>;
73
+ modifyMarginHelper(symbol: string, amount: any, type: any, params?: {}): Promise<MarginModification>;
74
+ parseMarginModification(data: any, market?: Market): MarginModification;
75
+ reduceMargin(symbol: string, amount: any, params?: {}): Promise<MarginModification>;
76
+ addMargin(symbol: string, amount: any, params?: {}): Promise<MarginModification>;
84
77
  setLeverage(leverage: Int, symbol?: Str, params?: {}): Promise<any>;
85
78
  setMarginMode(marginMode: string, symbol?: Str, params?: {}): Promise<any>;
86
79
  fetchLeverageTiers(symbols?: Strings, params?: {}): Promise<{}>;
@@ -2876,15 +2876,25 @@ export default class ascendex extends Exchange {
2876
2876
  });
2877
2877
  }
2878
2878
  parseMarginModification(data, market = undefined) {
2879
+ //
2880
+ // addMargin/reduceMargin
2881
+ //
2882
+ // {
2883
+ // "code": 0
2884
+ // }
2885
+ //
2879
2886
  const errorCode = this.safeString(data, 'code');
2880
2887
  const status = (errorCode === '0') ? 'ok' : 'failed';
2881
2888
  return {
2882
2889
  'info': data,
2890
+ 'symbol': market['symbol'],
2883
2891
  'type': undefined,
2884
2892
  'amount': undefined,
2893
+ 'total': undefined,
2885
2894
  'code': market['quote'],
2886
- 'symbol': market['symbol'],
2887
2895
  'status': status,
2896
+ 'timestamp': undefined,
2897
+ 'datetime': undefined,
2888
2898
  };
2889
2899
  }
2890
2900
  async reduceMargin(symbol, amount, params = {}) {
@@ -3,7 +3,7 @@ import { // eslint-disable-line object-curly-newline
3
3
  ExchangeError, AuthenticationError, DDoSProtection, RequestTimeout, ExchangeNotAvailable, RateLimitExceeded } from "./errors.js";
4
4
  import WsClient from './ws/WsClient.js';
5
5
  import { OrderBook as WsOrderBook, IndexedOrderBook, CountedOrderBook } from './ws/OrderBook.js';
6
- import type { Market, Trade, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRate, DepositWithdrawFeeNetwork, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings } from './types.js';
6
+ import type { Market, Trade, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRate, DepositWithdrawFeeNetwork, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings, MarginModification } from './types.js';
7
7
  export type { Market, Trade, Fee, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, BorrowRate, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings } from './types.js';
8
8
  import { ArrayCache, ArrayCacheByTimestamp } from './ws/Cache.js';
9
9
  import { OrderBook as Ob } from './ws/OrderBook.js';
@@ -678,7 +678,7 @@ export default class Exchange {
678
678
  fetchCrossBorrowRates(params?: {}): Promise<{}>;
679
679
  fetchIsolatedBorrowRates(params?: {}): Promise<{}>;
680
680
  parseMarketLeverageTiers(info: any, market?: Market): object;
681
- fetchLeverageTiers(symbols?: string[], params?: {}): Promise<Dictionary<LeverageTier>>;
681
+ fetchLeverageTiers(symbols?: string[], params?: {}): Promise<Dictionary<LeverageTier[]>>;
682
682
  parsePosition(position: any, market?: Market): Position;
683
683
  parseFundingRateHistory(info: any, market?: Market): FundingRateHistory;
684
684
  parseBorrowInterest(info: any, market?: Market): BorrowInterest;
@@ -697,8 +697,8 @@ export default class Exchange {
697
697
  fetchLeverage(symbol: string, params?: {}): Promise<Leverage>;
698
698
  fetchLeverages(symbols?: string[], params?: {}): Promise<Leverages>;
699
699
  setPositionMode(hedged: boolean, symbol?: Str, params?: {}): Promise<{}>;
700
- addMargin(symbol: string, amount: number, params?: {}): Promise<{}>;
701
- reduceMargin(symbol: string, amount: number, params?: {}): Promise<{}>;
700
+ addMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
701
+ reduceMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
702
702
  setMargin(symbol: string, amount: number, params?: {}): Promise<{}>;
703
703
  setMarginMode(marginMode: string, symbol?: Str, params?: {}): Promise<{}>;
704
704
  fetchDepositAddressesByNetwork(code: string, params?: {}): Promise<{}>;
@@ -432,6 +432,17 @@ export interface Leverage {
432
432
  longLeverage: number;
433
433
  shortLeverage: number;
434
434
  }
435
+ export interface MarginModification {
436
+ 'info': any;
437
+ 'symbol': string;
438
+ 'type': 'add' | 'reduce' | 'set' | undefined;
439
+ 'amount': Num;
440
+ 'total': Num;
441
+ 'code': Str;
442
+ 'status': Str;
443
+ 'timestamp': Int;
444
+ 'datetime': Str;
445
+ }
435
446
  export interface Leverages extends Dictionary<Leverage> {
436
447
  }
437
448
  export interface LastPrices extends Dictionary<LastPrice> {
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/binance.js';
2
- import type { TransferEntry, Int, OrderSide, Balances, OrderType, Trade, OHLCV, Order, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, Str, Transaction, Ticker, OrderBook, Tickers, Market, Greeks, Strings, Currency, MarketInterface, MarginMode, MarginModes, Leverage, Leverages, Num, Option } from './base/types.js';
2
+ import type { TransferEntry, Int, OrderSide, Balances, OrderType, Trade, OHLCV, Order, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, Str, Transaction, Ticker, OrderBook, Tickers, Market, Greeks, Strings, Currency, MarketInterface, MarginMode, MarginModes, Leverage, Leverages, Num, Option, MarginModification } from './base/types.js';
3
3
  /**
4
4
  * @class binance
5
5
  * @augments Exchange
@@ -306,16 +306,9 @@ export default class binance extends Exchange {
306
306
  calculateRateLimiterCost(api: any, method: any, path: any, params: any, config?: {}): any;
307
307
  request(path: any, api?: string, method?: string, params?: {}, headers?: any, body?: any, config?: {}): Promise<any>;
308
308
  modifyMarginHelper(symbol: string, amount: any, addOrReduce: any, params?: {}): Promise<any>;
309
- parseMarginModification(data: any, market?: Market): {
310
- info: any;
311
- type: string;
312
- amount: number;
313
- code: any;
314
- symbol: string;
315
- status: string;
316
- };
317
- reduceMargin(symbol: string, amount: any, params?: {}): Promise<any>;
318
- addMargin(symbol: string, amount: any, params?: {}): Promise<any>;
309
+ parseMarginModification(data: any, market?: Market): MarginModification;
310
+ reduceMargin(symbol: string, amount: any, params?: {}): Promise<MarginModification>;
311
+ addMargin(symbol: string, amount: any, params?: {}): Promise<MarginModification>;
319
312
  fetchCrossBorrowRate(code: string, params?: {}): Promise<{
320
313
  currency: string;
321
314
  rate: number;
package/js/src/binance.js CHANGED
@@ -11215,6 +11215,16 @@ export default class binance extends Exchange {
11215
11215
  });
11216
11216
  }
11217
11217
  parseMarginModification(data, market = undefined) {
11218
+ //
11219
+ // add/reduce margin
11220
+ //
11221
+ // {
11222
+ // "code": 200,
11223
+ // "msg": "Successfully modify position margin.",
11224
+ // "amount": 0.001,
11225
+ // "type": 1
11226
+ // }
11227
+ //
11218
11228
  const rawType = this.safeInteger(data, 'type');
11219
11229
  const resultType = (rawType === 1) ? 'add' : 'reduce';
11220
11230
  const resultAmount = this.safeNumber(data, 'amount');
@@ -11222,11 +11232,14 @@ export default class binance extends Exchange {
11222
11232
  const status = (errorCode === '200') ? 'ok' : 'failed';
11223
11233
  return {
11224
11234
  'info': data,
11235
+ 'symbol': market['symbol'],
11225
11236
  'type': resultType,
11226
11237
  'amount': resultAmount,
11238
+ 'total': undefined,
11227
11239
  'code': undefined,
11228
- 'symbol': market['symbol'],
11229
11240
  'status': status,
11241
+ 'timestamp': undefined,
11242
+ 'datetime': undefined,
11230
11243
  };
11231
11244
  }
11232
11245
  async reduceMargin(symbol, amount, params = {}) {
package/js/src/bingx.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/bingx.js';
2
- import type { TransferEntry, Int, OrderSide, OHLCV, FundingRateHistory, Order, OrderType, OrderRequest, Str, Trade, Balances, Transaction, Ticker, OrderBook, Tickers, Market, Strings, Currency, Position, Dict, Leverage, MarginMode, Num } from './base/types.js';
2
+ import type { TransferEntry, Int, OrderSide, OHLCV, FundingRateHistory, Order, OrderType, OrderRequest, Str, Trade, Balances, Transaction, Ticker, OrderBook, Tickers, Market, Strings, Currency, Position, Dict, Leverage, MarginMode, Num, MarginModification } from './base/types.js';
3
3
  /**
4
4
  * @class bingx
5
5
  * @augments Exchange
@@ -109,7 +109,10 @@ export default class bingx extends Exchange {
109
109
  parseTransaction(transaction: any, currency?: Currency): Transaction;
110
110
  parseTransactionStatus(status: string): string;
111
111
  setMarginMode(marginMode: string, symbol?: Str, params?: {}): Promise<any>;
112
- setMargin(symbol: string, amount: number, params?: {}): Promise<any>;
112
+ addMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
113
+ reduceMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
114
+ setMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
115
+ parseMarginModification(data: any, market?: Market): MarginModification;
113
116
  fetchLeverage(symbol: string, params?: {}): Promise<Leverage>;
114
117
  parseLeverage(leverage: any, market?: any): Leverage;
115
118
  setLeverage(leverage: Int, symbol?: Str, params?: {}): Promise<any>;
package/js/src/bingx.js CHANGED
@@ -33,6 +33,7 @@ export default class bingx extends Exchange {
33
33
  'swap': true,
34
34
  'future': false,
35
35
  'option': false,
36
+ 'addMargin': true,
36
37
  'cancelAllOrders': true,
37
38
  'cancelOrder': true,
38
39
  'cancelOrders': true,
@@ -79,6 +80,7 @@ export default class bingx extends Exchange {
79
80
  'fetchTrades': true,
80
81
  'fetchTransfers': true,
81
82
  'fetchWithdrawals': true,
83
+ 'reduceMargin': true,
82
84
  'setLeverage': true,
83
85
  'setMargin': true,
84
86
  'setMarginMode': true,
@@ -3467,6 +3469,18 @@ export default class bingx extends Exchange {
3467
3469
  };
3468
3470
  return await this.swapV2PrivatePostTradeMarginType(this.extend(request, params));
3469
3471
  }
3472
+ async addMargin(symbol, amount, params = {}) {
3473
+ const request = {
3474
+ 'type': 1,
3475
+ };
3476
+ return await this.setMargin(symbol, amount, this.extend(request, params));
3477
+ }
3478
+ async reduceMargin(symbol, amount, params = {}) {
3479
+ const request = {
3480
+ 'type': 2,
3481
+ };
3482
+ return await this.setMargin(symbol, amount, this.extend(request, params));
3483
+ }
3470
3484
  async setMargin(symbol, amount, params = {}) {
3471
3485
  /**
3472
3486
  * @method
@@ -3501,7 +3515,29 @@ export default class bingx extends Exchange {
3501
3515
  // "type": 1
3502
3516
  // }
3503
3517
  //
3504
- return response;
3518
+ return this.parseMarginModification(response, market);
3519
+ }
3520
+ parseMarginModification(data, market = undefined) {
3521
+ //
3522
+ // {
3523
+ // "code": 0,
3524
+ // "msg": "",
3525
+ // "amount": 1,
3526
+ // "type": 1
3527
+ // }
3528
+ //
3529
+ const type = this.safeString(data, 'type');
3530
+ return {
3531
+ 'info': data,
3532
+ 'symbol': this.safeString(market, 'symbol'),
3533
+ 'type': (type === '1') ? 'add' : 'reduce',
3534
+ 'amount': this.safeNumber(data, 'amount'),
3535
+ 'total': this.safeNumber(data, 'margin'),
3536
+ 'code': this.safeString(market, 'settle'),
3537
+ 'status': undefined,
3538
+ 'timestamp': undefined,
3539
+ 'datetime': undefined,
3540
+ };
3505
3541
  }
3506
3542
  async fetchLeverage(symbol, params = {}) {
3507
3543
  /**