ccxt 4.2.34 → 4.2.35

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
@@ -176,7 +176,7 @@ var woo$1 = require('./src/pro/woo.js');
176
176
 
177
177
  //-----------------------------------------------------------------------------
178
178
  // this is updated by vss.js when building
179
- const version = '4.2.34';
179
+ const version = '4.2.35';
180
180
  Exchange["default"].ccxtVersion = version;
181
181
  const exchanges = {
182
182
  'ace': ace,
@@ -1069,9 +1069,9 @@ class Exchange {
1069
1069
  }
1070
1070
  handleMessage(client, message) { } // stub to override
1071
1071
  // ping (client) {} // stub to override
1072
- ping(client) {
1073
- return undefined;
1074
- }
1072
+ // ping (client) {
1073
+ // return undefined;
1074
+ // }
1075
1075
  client(url) {
1076
1076
  this.clients = this.clients || {};
1077
1077
  if (!this.clients[url]) {
@@ -1451,6 +1451,9 @@ class Exchange {
1451
1451
  * @returns {object | undefined}
1452
1452
  */
1453
1453
  const value = this.safeValueN(dictionaryOrList, keys, defaultValue);
1454
+ if (value === undefined) {
1455
+ return defaultValue;
1456
+ }
1454
1457
  if (typeof value === 'object') {
1455
1458
  return value;
1456
1459
  }
@@ -1482,6 +1485,9 @@ class Exchange {
1482
1485
  * @returns {Array | undefined}
1483
1486
  */
1484
1487
  const value = this.safeValueN(dictionaryOrList, keys, defaultValue);
1488
+ if (value === undefined) {
1489
+ return defaultValue;
1490
+ }
1485
1491
  if (Array.isArray(value)) {
1486
1492
  return value;
1487
1493
  }
@@ -5281,7 +5287,8 @@ class Exchange {
5281
5287
  errors = 0;
5282
5288
  const responseLength = response.length;
5283
5289
  if (this.verbose) {
5284
- const cursorMessage = 'Cursor pagination call ' + i + 1 + ' method ' + method + ' response length ' + responseLength + ' cursor ' + cursorValue;
5290
+ const iteration = (i + 1).toString();
5291
+ const cursorMessage = 'Cursor pagination call ' + iteration + ' method ' + method + ' response length ' + responseLength.toString() + ' cursor ' + cursorValue;
5285
5292
  this.log(cursorMessage);
5286
5293
  }
5287
5294
  if (responseLength === 0) {
@@ -5326,7 +5333,8 @@ class Exchange {
5326
5333
  errors = 0;
5327
5334
  const responseLength = response.length;
5328
5335
  if (this.verbose) {
5329
- const incrementalMessage = 'Incremental pagination call ' + i + 1 + ' method ' + method + ' response length ' + responseLength;
5336
+ const iteration = (i + 1).toString();
5337
+ const incrementalMessage = 'Incremental pagination call ' + iteration + ' method ' + method + ' response length ' + responseLength.toString();
5330
5338
  this.log(incrementalMessage);
5331
5339
  }
5332
5340
  if (responseLength === 0) {
@@ -3143,9 +3143,24 @@ class binance extends binance$1 {
3143
3143
  let timestamp = undefined;
3144
3144
  const isolated = marginMode === 'isolated';
3145
3145
  const cross = (type === 'margin') || (marginMode === 'cross');
3146
- if (!isolated && ((type === 'spot') || cross)) {
3146
+ if (type === 'papi') {
3147
+ for (let i = 0; i < response.length; i++) {
3148
+ const entry = response[i];
3149
+ const account = this.account();
3150
+ const currencyId = this.safeString(entry, 'asset');
3151
+ const code = this.safeCurrencyCode(currencyId);
3152
+ const borrowed = this.safeString(entry, 'crossMarginBorrowed');
3153
+ const interest = this.safeString(entry, 'crossMarginInterest');
3154
+ account['free'] = this.safeString(entry, 'crossMarginFree');
3155
+ account['used'] = this.safeString(entry, 'crossMarginLocked');
3156
+ account['total'] = this.safeString(entry, 'crossMarginAsset');
3157
+ account['debt'] = Precise["default"].stringAdd(borrowed, interest);
3158
+ result[code] = account;
3159
+ }
3160
+ }
3161
+ else if (!isolated && ((type === 'spot') || cross)) {
3147
3162
  timestamp = this.safeInteger(response, 'updateTime');
3148
- const balances = this.safeValue2(response, 'balances', 'userAssets', []);
3163
+ const balances = this.safeList2(response, 'balances', 'userAssets', []);
3149
3164
  for (let i = 0; i < balances.length; i++) {
3150
3165
  const balance = balances[i];
3151
3166
  const currencyId = this.safeString(balance, 'asset');
@@ -3162,13 +3177,13 @@ class binance extends binance$1 {
3162
3177
  }
3163
3178
  }
3164
3179
  else if (isolated) {
3165
- const assets = this.safeValue(response, 'assets');
3180
+ const assets = this.safeList(response, 'assets');
3166
3181
  for (let i = 0; i < assets.length; i++) {
3167
3182
  const asset = assets[i];
3168
- const marketId = this.safeValue(asset, 'symbol');
3183
+ const marketId = this.safeString(asset, 'symbol');
3169
3184
  const symbol = this.safeSymbol(marketId, undefined, undefined, 'spot');
3170
- const base = this.safeValue(asset, 'baseAsset', {});
3171
- const quote = this.safeValue(asset, 'quoteAsset', {});
3185
+ const base = this.safeDict(asset, 'baseAsset', {});
3186
+ const quote = this.safeDict(asset, 'quoteAsset', {});
3172
3187
  const baseCode = this.safeCurrencyCode(this.safeString(base, 'asset'));
3173
3188
  const quoteCode = this.safeCurrencyCode(this.safeString(quote, 'asset'));
3174
3189
  const subResult = {};
@@ -3178,7 +3193,7 @@ class binance extends binance$1 {
3178
3193
  }
3179
3194
  }
3180
3195
  else if (type === 'savings') {
3181
- const positionAmountVos = this.safeValue(response, 'positionAmountVos', []);
3196
+ const positionAmountVos = this.safeList(response, 'positionAmountVos', []);
3182
3197
  for (let i = 0; i < positionAmountVos.length; i++) {
3183
3198
  const entry = positionAmountVos[i];
3184
3199
  const currencyId = this.safeString(entry, 'asset');
@@ -3207,7 +3222,7 @@ class binance extends binance$1 {
3207
3222
  else {
3208
3223
  let balances = response;
3209
3224
  if (!Array.isArray(response)) {
3210
- balances = this.safeValue(response, 'assets', []);
3225
+ balances = this.safeList(response, 'assets', []);
3211
3226
  }
3212
3227
  for (let i = 0; i < balances.length; i++) {
3213
3228
  const balance = balances[i];
@@ -3237,10 +3252,12 @@ class binance extends binance$1 {
3237
3252
  * @see https://binance-docs.github.io/apidocs/futures/en/#account-information-v2-user_data // swap
3238
3253
  * @see https://binance-docs.github.io/apidocs/delivery/en/#account-information-user_data // future
3239
3254
  * @see https://binance-docs.github.io/apidocs/voptions/en/#option-account-information-trade // option
3255
+ * @see https://binance-docs.github.io/apidocs/pm/en/#account-balance-user_data // portfolio margin
3240
3256
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3241
- * @param {string} [params.type] 'future', 'delivery', 'savings', 'funding', or 'spot'
3257
+ * @param {string} [params.type] 'future', 'delivery', 'savings', 'funding', or 'spot' or 'papi'
3242
3258
  * @param {string} [params.marginMode] 'cross' or 'isolated', for margin trading, uses this.options.defaultMarginMode if not passed, defaults to undefined/None/null
3243
3259
  * @param {string[]|undefined} [params.symbols] unified market symbols, only used in isolated margin mode
3260
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the balance for a portfolio margin account
3244
3261
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
3245
3262
  */
3246
3263
  await this.loadMarkets();
@@ -3248,13 +3265,19 @@ class binance extends binance$1 {
3248
3265
  let type = this.safeString(params, 'type', defaultType);
3249
3266
  let subType = undefined;
3250
3267
  [subType, params] = this.handleSubTypeAndParams('fetchBalance', undefined, params);
3268
+ let isPortfolioMargin = undefined;
3269
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchBalance', 'papi', 'portfolioMargin', false);
3251
3270
  let marginMode = undefined;
3252
3271
  let query = undefined;
3253
3272
  [marginMode, query] = this.handleMarginModeAndParams('fetchBalance', params);
3254
3273
  query = this.omit(query, 'type');
3255
3274
  let response = undefined;
3256
3275
  const request = {};
3257
- if (this.isLinear(type, subType)) {
3276
+ if (isPortfolioMargin || (type === 'papi')) {
3277
+ type = 'papi';
3278
+ response = await this.papiGetBalance(this.extend(request, query));
3279
+ }
3280
+ else if (this.isLinear(type, subType)) {
3258
3281
  type = 'linear';
3259
3282
  response = await this.fapiPrivateV2GetAccount(this.extend(request, query));
3260
3283
  }
@@ -3263,7 +3286,7 @@ class binance extends binance$1 {
3263
3286
  response = await this.dapiPrivateGetAccount(this.extend(request, query));
3264
3287
  }
3265
3288
  else if (marginMode === 'isolated') {
3266
- const paramSymbols = this.safeValue(params, 'symbols');
3289
+ const paramSymbols = this.safeList(params, 'symbols');
3267
3290
  query = this.omit(query, 'symbols');
3268
3291
  if (paramSymbols !== undefined) {
3269
3292
  let symbols = '';
@@ -3479,6 +3502,26 @@ class binance extends binance$1 {
3479
3502
  // }
3480
3503
  // ]
3481
3504
  //
3505
+ // portfolio margin
3506
+ //
3507
+ // [
3508
+ // {
3509
+ // "asset": "USDT",
3510
+ // "totalWalletBalance": "66.9923261",
3511
+ // "crossMarginAsset": "35.9697141",
3512
+ // "crossMarginBorrowed": "0.0",
3513
+ // "crossMarginFree": "35.9697141",
3514
+ // "crossMarginInterest": "0.0",
3515
+ // "crossMarginLocked": "0.0",
3516
+ // "umWalletBalance": "31.022612",
3517
+ // "umUnrealizedPNL": "0.0",
3518
+ // "cmWalletBalance": "0.0",
3519
+ // "cmUnrealizedPNL": "0.0",
3520
+ // "updateTime": 0,
3521
+ // "negativeBalance": "0.0"
3522
+ // },
3523
+ // ]
3524
+ //
3482
3525
  return this.parseBalanceCustom(response, type, marginMode);
3483
3526
  }
3484
3527
  async fetchOrderBook(symbol, limit = undefined, params = {}) {
@@ -25,11 +25,13 @@ class bitfinex2 extends bitfinex2$1 {
25
25
  'has': {
26
26
  'CORS': undefined,
27
27
  'spot': true,
28
- 'margin': undefined,
28
+ 'margin': true,
29
29
  'swap': true,
30
30
  'future': undefined,
31
31
  'option': undefined,
32
32
  'addMargin': false,
33
+ 'borrowCrossMargin': false,
34
+ 'borrowIsolatedMargin': false,
33
35
  'cancelAllOrders': true,
34
36
  'cancelOrder': true,
35
37
  'cancelOrders': true,
@@ -46,8 +48,13 @@ class bitfinex2 extends bitfinex2$1 {
46
48
  'createTriggerOrder': true,
47
49
  'editOrder': true,
48
50
  'fetchBalance': true,
51
+ 'fetchBorrowInterest': false,
52
+ 'fetchBorrowRateHistories': false,
53
+ 'fetchBorrowRateHistory': false,
49
54
  'fetchClosedOrder': true,
50
55
  'fetchClosedOrders': true,
56
+ 'fetchCrossBorrowRate': false,
57
+ 'fetchCrossBorrowRates': false,
51
58
  'fetchCurrencies': true,
52
59
  'fetchDepositAddress': true,
53
60
  'fetchDepositsWithdrawals': true,
@@ -56,6 +63,8 @@ class bitfinex2 extends bitfinex2$1 {
56
63
  'fetchFundingRateHistory': true,
57
64
  'fetchFundingRates': true,
58
65
  'fetchIndexOHLCV': false,
66
+ 'fetchIsolatedBorrowRate': false,
67
+ 'fetchIsolatedBorrowRates': false,
59
68
  'fetchLedger': true,
60
69
  'fetchLeverage': false,
61
70
  'fetchLeverageTiers': false,
@@ -83,6 +92,8 @@ class bitfinex2 extends bitfinex2$1 {
83
92
  'fetchTransactionFees': undefined,
84
93
  'fetchTransactions': 'emulated',
85
94
  'reduceMargin': false,
95
+ 'repayCrossMargin': false,
96
+ 'repayIsolatedMargin': false,
86
97
  'setLeverage': false,
87
98
  'setMargin': true,
88
99
  'setMarginMode': false,
@@ -151,10 +151,32 @@ class krakenfutures extends krakenfutures$1 {
151
151
  },
152
152
  'fees': {
153
153
  'trading': {
154
- 'tierBased': false,
154
+ 'tierBased': true,
155
155
  'percentage': true,
156
- 'maker': this.parseNumber('-0.0002'),
157
- 'taker': this.parseNumber('0.00075'),
156
+ 'taker': this.parseNumber('0.0005'),
157
+ 'maker': this.parseNumber('0.0002'),
158
+ 'tiers': {
159
+ 'taker': [
160
+ [this.parseNumber('0'), this.parseNumber('0.0005')],
161
+ [this.parseNumber('100000'), this.parseNumber('0.0004')],
162
+ [this.parseNumber('1000000'), this.parseNumber('0.0003')],
163
+ [this.parseNumber('5000000'), this.parseNumber('0.00025')],
164
+ [this.parseNumber('10000000'), this.parseNumber('0.0002')],
165
+ [this.parseNumber('20000000'), this.parseNumber('0.00015')],
166
+ [this.parseNumber('50000000'), this.parseNumber('0.000125')],
167
+ [this.parseNumber('100000000'), this.parseNumber('0.0001')],
168
+ ],
169
+ 'maker': [
170
+ [this.parseNumber('0'), this.parseNumber('0.0002')],
171
+ [this.parseNumber('100000'), this.parseNumber('0.0015')],
172
+ [this.parseNumber('1000000'), this.parseNumber('0.000125')],
173
+ [this.parseNumber('5000000'), this.parseNumber('0.0001')],
174
+ [this.parseNumber('10000000'), this.parseNumber('0.000075')],
175
+ [this.parseNumber('20000000'), this.parseNumber('0.00005')],
176
+ [this.parseNumber('50000000'), this.parseNumber('0.000025')],
177
+ [this.parseNumber('100000000'), this.parseNumber('0')],
178
+ ],
179
+ },
158
180
  },
159
181
  },
160
182
  'exceptions': {
@@ -2439,7 +2439,7 @@ class binance extends binance$1 {
2439
2439
  return this.safePosition({
2440
2440
  'info': position,
2441
2441
  'id': undefined,
2442
- 'symbol': this.safeSymbol(marketId, undefined, undefined, 'future'),
2442
+ 'symbol': this.safeSymbol(marketId, undefined, undefined, 'contract'),
2443
2443
  'notional': undefined,
2444
2444
  'marginMode': this.safeString(position, 'mt'),
2445
2445
  'liquidationPrice': undefined,
@@ -2593,9 +2593,9 @@ class binance extends binance$1 {
2593
2593
  const messageHash = 'myTrades';
2594
2594
  const executionType = this.safeString(message, 'x');
2595
2595
  if (executionType === 'TRADE') {
2596
- const trade = this.parseTrade(message);
2596
+ const trade = this.parseWsTrade(message);
2597
2597
  const orderId = this.safeString(trade, 'order');
2598
- let tradeFee = this.safeValue(trade, 'fee');
2598
+ let tradeFee = this.safeValue(trade, 'fee', {});
2599
2599
  tradeFee = this.extend({}, tradeFee);
2600
2600
  const symbol = this.safeString(trade, 'symbol');
2601
2601
  if (orderId !== undefined && tradeFee !== undefined && symbol !== undefined) {
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 } 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.33";
7
+ declare const version = "4.2.34";
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.34';
41
+ const version = '4.2.35';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -556,7 +556,6 @@ export default class Exchange {
556
556
  indexedOrderBook(snapshot?: {}, depth?: number): IndexedOrderBook;
557
557
  countedOrderBook(snapshot?: {}, depth?: number): CountedOrderBook;
558
558
  handleMessage(client: any, message: any): void;
559
- ping(client: any): any;
560
559
  client(url: any): WsClient;
561
560
  watchMultiple(url: any, messageHashes: any, message?: any, subscribeHashes?: any, subscription?: any): import("./ws/Future.js").FutureInterface;
562
561
  watch(url: any, messageHash: any, message?: any, subscribeHash?: any, subscription?: any): any;
@@ -1063,9 +1063,9 @@ export default class Exchange {
1063
1063
  }
1064
1064
  handleMessage(client, message) { } // stub to override
1065
1065
  // ping (client) {} // stub to override
1066
- ping(client) {
1067
- return undefined;
1068
- }
1066
+ // ping (client) {
1067
+ // return undefined;
1068
+ // }
1069
1069
  client(url) {
1070
1070
  this.clients = this.clients || {};
1071
1071
  if (!this.clients[url]) {
@@ -1447,6 +1447,9 @@ export default class Exchange {
1447
1447
  * @returns {object | undefined}
1448
1448
  */
1449
1449
  const value = this.safeValueN(dictionaryOrList, keys, defaultValue);
1450
+ if (value === undefined) {
1451
+ return defaultValue;
1452
+ }
1450
1453
  if (typeof value === 'object') {
1451
1454
  return value;
1452
1455
  }
@@ -1478,6 +1481,9 @@ export default class Exchange {
1478
1481
  * @returns {Array | undefined}
1479
1482
  */
1480
1483
  const value = this.safeValueN(dictionaryOrList, keys, defaultValue);
1484
+ if (value === undefined) {
1485
+ return defaultValue;
1486
+ }
1481
1487
  if (Array.isArray(value)) {
1482
1488
  return value;
1483
1489
  }
@@ -5277,7 +5283,8 @@ export default class Exchange {
5277
5283
  errors = 0;
5278
5284
  const responseLength = response.length;
5279
5285
  if (this.verbose) {
5280
- const cursorMessage = 'Cursor pagination call ' + i + 1 + ' method ' + method + ' response length ' + responseLength + ' cursor ' + cursorValue;
5286
+ const iteration = (i + 1).toString();
5287
+ const cursorMessage = 'Cursor pagination call ' + iteration + ' method ' + method + ' response length ' + responseLength.toString() + ' cursor ' + cursorValue;
5281
5288
  this.log(cursorMessage);
5282
5289
  }
5283
5290
  if (responseLength === 0) {
@@ -5322,7 +5329,8 @@ export default class Exchange {
5322
5329
  errors = 0;
5323
5330
  const responseLength = response.length;
5324
5331
  if (this.verbose) {
5325
- const incrementalMessage = 'Incremental pagination call ' + i + 1 + ' method ' + method + ' response length ' + responseLength;
5332
+ const iteration = (i + 1).toString();
5333
+ const incrementalMessage = 'Incremental pagination call ' + iteration + ' method ' + method + ' response length ' + responseLength.toString();
5326
5334
  this.log(incrementalMessage);
5327
5335
  }
5328
5336
  if (responseLength === 0) {
package/js/src/binance.js CHANGED
@@ -3146,9 +3146,24 @@ export default class binance extends Exchange {
3146
3146
  let timestamp = undefined;
3147
3147
  const isolated = marginMode === 'isolated';
3148
3148
  const cross = (type === 'margin') || (marginMode === 'cross');
3149
- if (!isolated && ((type === 'spot') || cross)) {
3149
+ if (type === 'papi') {
3150
+ for (let i = 0; i < response.length; i++) {
3151
+ const entry = response[i];
3152
+ const account = this.account();
3153
+ const currencyId = this.safeString(entry, 'asset');
3154
+ const code = this.safeCurrencyCode(currencyId);
3155
+ const borrowed = this.safeString(entry, 'crossMarginBorrowed');
3156
+ const interest = this.safeString(entry, 'crossMarginInterest');
3157
+ account['free'] = this.safeString(entry, 'crossMarginFree');
3158
+ account['used'] = this.safeString(entry, 'crossMarginLocked');
3159
+ account['total'] = this.safeString(entry, 'crossMarginAsset');
3160
+ account['debt'] = Precise.stringAdd(borrowed, interest);
3161
+ result[code] = account;
3162
+ }
3163
+ }
3164
+ else if (!isolated && ((type === 'spot') || cross)) {
3150
3165
  timestamp = this.safeInteger(response, 'updateTime');
3151
- const balances = this.safeValue2(response, 'balances', 'userAssets', []);
3166
+ const balances = this.safeList2(response, 'balances', 'userAssets', []);
3152
3167
  for (let i = 0; i < balances.length; i++) {
3153
3168
  const balance = balances[i];
3154
3169
  const currencyId = this.safeString(balance, 'asset');
@@ -3165,13 +3180,13 @@ export default class binance extends Exchange {
3165
3180
  }
3166
3181
  }
3167
3182
  else if (isolated) {
3168
- const assets = this.safeValue(response, 'assets');
3183
+ const assets = this.safeList(response, 'assets');
3169
3184
  for (let i = 0; i < assets.length; i++) {
3170
3185
  const asset = assets[i];
3171
- const marketId = this.safeValue(asset, 'symbol');
3186
+ const marketId = this.safeString(asset, 'symbol');
3172
3187
  const symbol = this.safeSymbol(marketId, undefined, undefined, 'spot');
3173
- const base = this.safeValue(asset, 'baseAsset', {});
3174
- const quote = this.safeValue(asset, 'quoteAsset', {});
3188
+ const base = this.safeDict(asset, 'baseAsset', {});
3189
+ const quote = this.safeDict(asset, 'quoteAsset', {});
3175
3190
  const baseCode = this.safeCurrencyCode(this.safeString(base, 'asset'));
3176
3191
  const quoteCode = this.safeCurrencyCode(this.safeString(quote, 'asset'));
3177
3192
  const subResult = {};
@@ -3181,7 +3196,7 @@ export default class binance extends Exchange {
3181
3196
  }
3182
3197
  }
3183
3198
  else if (type === 'savings') {
3184
- const positionAmountVos = this.safeValue(response, 'positionAmountVos', []);
3199
+ const positionAmountVos = this.safeList(response, 'positionAmountVos', []);
3185
3200
  for (let i = 0; i < positionAmountVos.length; i++) {
3186
3201
  const entry = positionAmountVos[i];
3187
3202
  const currencyId = this.safeString(entry, 'asset');
@@ -3210,7 +3225,7 @@ export default class binance extends Exchange {
3210
3225
  else {
3211
3226
  let balances = response;
3212
3227
  if (!Array.isArray(response)) {
3213
- balances = this.safeValue(response, 'assets', []);
3228
+ balances = this.safeList(response, 'assets', []);
3214
3229
  }
3215
3230
  for (let i = 0; i < balances.length; i++) {
3216
3231
  const balance = balances[i];
@@ -3240,10 +3255,12 @@ export default class binance extends Exchange {
3240
3255
  * @see https://binance-docs.github.io/apidocs/futures/en/#account-information-v2-user_data // swap
3241
3256
  * @see https://binance-docs.github.io/apidocs/delivery/en/#account-information-user_data // future
3242
3257
  * @see https://binance-docs.github.io/apidocs/voptions/en/#option-account-information-trade // option
3258
+ * @see https://binance-docs.github.io/apidocs/pm/en/#account-balance-user_data // portfolio margin
3243
3259
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3244
- * @param {string} [params.type] 'future', 'delivery', 'savings', 'funding', or 'spot'
3260
+ * @param {string} [params.type] 'future', 'delivery', 'savings', 'funding', or 'spot' or 'papi'
3245
3261
  * @param {string} [params.marginMode] 'cross' or 'isolated', for margin trading, uses this.options.defaultMarginMode if not passed, defaults to undefined/None/null
3246
3262
  * @param {string[]|undefined} [params.symbols] unified market symbols, only used in isolated margin mode
3263
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the balance for a portfolio margin account
3247
3264
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
3248
3265
  */
3249
3266
  await this.loadMarkets();
@@ -3251,13 +3268,19 @@ export default class binance extends Exchange {
3251
3268
  let type = this.safeString(params, 'type', defaultType);
3252
3269
  let subType = undefined;
3253
3270
  [subType, params] = this.handleSubTypeAndParams('fetchBalance', undefined, params);
3271
+ let isPortfolioMargin = undefined;
3272
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchBalance', 'papi', 'portfolioMargin', false);
3254
3273
  let marginMode = undefined;
3255
3274
  let query = undefined;
3256
3275
  [marginMode, query] = this.handleMarginModeAndParams('fetchBalance', params);
3257
3276
  query = this.omit(query, 'type');
3258
3277
  let response = undefined;
3259
3278
  const request = {};
3260
- if (this.isLinear(type, subType)) {
3279
+ if (isPortfolioMargin || (type === 'papi')) {
3280
+ type = 'papi';
3281
+ response = await this.papiGetBalance(this.extend(request, query));
3282
+ }
3283
+ else if (this.isLinear(type, subType)) {
3261
3284
  type = 'linear';
3262
3285
  response = await this.fapiPrivateV2GetAccount(this.extend(request, query));
3263
3286
  }
@@ -3266,7 +3289,7 @@ export default class binance extends Exchange {
3266
3289
  response = await this.dapiPrivateGetAccount(this.extend(request, query));
3267
3290
  }
3268
3291
  else if (marginMode === 'isolated') {
3269
- const paramSymbols = this.safeValue(params, 'symbols');
3292
+ const paramSymbols = this.safeList(params, 'symbols');
3270
3293
  query = this.omit(query, 'symbols');
3271
3294
  if (paramSymbols !== undefined) {
3272
3295
  let symbols = '';
@@ -3482,6 +3505,26 @@ export default class binance extends Exchange {
3482
3505
  // }
3483
3506
  // ]
3484
3507
  //
3508
+ // portfolio margin
3509
+ //
3510
+ // [
3511
+ // {
3512
+ // "asset": "USDT",
3513
+ // "totalWalletBalance": "66.9923261",
3514
+ // "crossMarginAsset": "35.9697141",
3515
+ // "crossMarginBorrowed": "0.0",
3516
+ // "crossMarginFree": "35.9697141",
3517
+ // "crossMarginInterest": "0.0",
3518
+ // "crossMarginLocked": "0.0",
3519
+ // "umWalletBalance": "31.022612",
3520
+ // "umUnrealizedPNL": "0.0",
3521
+ // "cmWalletBalance": "0.0",
3522
+ // "cmUnrealizedPNL": "0.0",
3523
+ // "updateTime": 0,
3524
+ // "negativeBalance": "0.0"
3525
+ // },
3526
+ // ]
3527
+ //
3485
3528
  return this.parseBalanceCustom(response, type, marginMode);
3486
3529
  }
3487
3530
  async fetchOrderBook(symbol, limit = undefined, params = {}) {
@@ -28,11 +28,13 @@ export default class bitfinex2 extends Exchange {
28
28
  'has': {
29
29
  'CORS': undefined,
30
30
  'spot': true,
31
- 'margin': undefined,
31
+ 'margin': true,
32
32
  'swap': true,
33
33
  'future': undefined,
34
34
  'option': undefined,
35
35
  'addMargin': false,
36
+ 'borrowCrossMargin': false,
37
+ 'borrowIsolatedMargin': false,
36
38
  'cancelAllOrders': true,
37
39
  'cancelOrder': true,
38
40
  'cancelOrders': true,
@@ -49,8 +51,13 @@ export default class bitfinex2 extends Exchange {
49
51
  'createTriggerOrder': true,
50
52
  'editOrder': true,
51
53
  'fetchBalance': true,
54
+ 'fetchBorrowInterest': false,
55
+ 'fetchBorrowRateHistories': false,
56
+ 'fetchBorrowRateHistory': false,
52
57
  'fetchClosedOrder': true,
53
58
  'fetchClosedOrders': true,
59
+ 'fetchCrossBorrowRate': false,
60
+ 'fetchCrossBorrowRates': false,
54
61
  'fetchCurrencies': true,
55
62
  'fetchDepositAddress': true,
56
63
  'fetchDepositsWithdrawals': true,
@@ -59,6 +66,8 @@ export default class bitfinex2 extends Exchange {
59
66
  'fetchFundingRateHistory': true,
60
67
  'fetchFundingRates': true,
61
68
  'fetchIndexOHLCV': false,
69
+ 'fetchIsolatedBorrowRate': false,
70
+ 'fetchIsolatedBorrowRates': false,
62
71
  'fetchLedger': true,
63
72
  'fetchLeverage': false,
64
73
  'fetchLeverageTiers': false,
@@ -86,6 +95,8 @@ export default class bitfinex2 extends Exchange {
86
95
  'fetchTransactionFees': undefined,
87
96
  'fetchTransactions': 'emulated',
88
97
  'reduceMargin': false,
98
+ 'repayCrossMargin': false,
99
+ 'repayIsolatedMargin': false,
89
100
  'setLeverage': false,
90
101
  'setMargin': true,
91
102
  'setMarginMode': false,
@@ -154,10 +154,32 @@ export default class krakenfutures extends Exchange {
154
154
  },
155
155
  'fees': {
156
156
  'trading': {
157
- 'tierBased': false,
157
+ 'tierBased': true,
158
158
  'percentage': true,
159
- 'maker': this.parseNumber('-0.0002'),
160
- 'taker': this.parseNumber('0.00075'),
159
+ 'taker': this.parseNumber('0.0005'),
160
+ 'maker': this.parseNumber('0.0002'),
161
+ 'tiers': {
162
+ 'taker': [
163
+ [this.parseNumber('0'), this.parseNumber('0.0005')],
164
+ [this.parseNumber('100000'), this.parseNumber('0.0004')],
165
+ [this.parseNumber('1000000'), this.parseNumber('0.0003')],
166
+ [this.parseNumber('5000000'), this.parseNumber('0.00025')],
167
+ [this.parseNumber('10000000'), this.parseNumber('0.0002')],
168
+ [this.parseNumber('20000000'), this.parseNumber('0.00015')],
169
+ [this.parseNumber('50000000'), this.parseNumber('0.000125')],
170
+ [this.parseNumber('100000000'), this.parseNumber('0.0001')],
171
+ ],
172
+ 'maker': [
173
+ [this.parseNumber('0'), this.parseNumber('0.0002')],
174
+ [this.parseNumber('100000'), this.parseNumber('0.0015')],
175
+ [this.parseNumber('1000000'), this.parseNumber('0.000125')],
176
+ [this.parseNumber('5000000'), this.parseNumber('0.0001')],
177
+ [this.parseNumber('10000000'), this.parseNumber('0.000075')],
178
+ [this.parseNumber('20000000'), this.parseNumber('0.00005')],
179
+ [this.parseNumber('50000000'), this.parseNumber('0.000025')],
180
+ [this.parseNumber('100000000'), this.parseNumber('0')],
181
+ ],
182
+ },
161
183
  },
162
184
  },
163
185
  'exceptions': {
@@ -2442,7 +2442,7 @@ export default class binance extends binanceRest {
2442
2442
  return this.safePosition({
2443
2443
  'info': position,
2444
2444
  'id': undefined,
2445
- 'symbol': this.safeSymbol(marketId, undefined, undefined, 'future'),
2445
+ 'symbol': this.safeSymbol(marketId, undefined, undefined, 'contract'),
2446
2446
  'notional': undefined,
2447
2447
  'marginMode': this.safeString(position, 'mt'),
2448
2448
  'liquidationPrice': undefined,
@@ -2596,9 +2596,9 @@ export default class binance extends binanceRest {
2596
2596
  const messageHash = 'myTrades';
2597
2597
  const executionType = this.safeString(message, 'x');
2598
2598
  if (executionType === 'TRADE') {
2599
- const trade = this.parseTrade(message);
2599
+ const trade = this.parseWsTrade(message);
2600
2600
  const orderId = this.safeString(trade, 'order');
2601
- let tradeFee = this.safeValue(trade, 'fee');
2601
+ let tradeFee = this.safeValue(trade, 'fee', {});
2602
2602
  tradeFee = this.extend({}, tradeFee);
2603
2603
  const symbol = this.safeString(trade, 'symbol');
2604
2604
  if (orderId !== undefined && tradeFee !== undefined && symbol !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.34",
3
+ "version": "4.2.35",
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",