ccxt 4.3.8 → 4.3.9

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.
@@ -161,6 +161,7 @@ class coinmetro extends coinmetro$1 {
161
161
  'private': {
162
162
  'get': {
163
163
  'users/balances': 1,
164
+ 'users/wallets': 1,
164
165
  'users/wallets/history/{since}': 1.67,
165
166
  'exchange/orders/status/{orderID}': 1,
166
167
  'exchange/orders/active': 1,
@@ -941,49 +942,48 @@ class coinmetro extends coinmetro$1 {
941
942
  * @method
942
943
  * @name coinmetro#fetchBalance
943
944
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
944
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#698ae067-43dd-4e19-a0ac-d9ba91381816
945
+ * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#741a1dcc-7307-40d0-acca-28d003d1506a
945
946
  * @param {object} [params] extra parameters specific to the exchange API endpoint
946
947
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
947
948
  */
948
949
  await this.loadMarkets();
949
- const response = await this.privateGetUsersBalances(params);
950
- return this.parseBalance(response);
950
+ const response = await this.privateGetUsersWallets(params);
951
+ const list = this.safeList(response, 'list', []);
952
+ return this.parseBalance(list);
951
953
  }
952
- parseBalance(response) {
954
+ parseBalance(balances) {
953
955
  //
954
- // {
955
- // "USDC": {
956
- // "USDC": 99,
957
- // "EUR": 91.16,
958
- // "BTC": 0.002334
959
- // },
960
- // "XCM": {
961
- // "XCM": 0,
962
- // "EUR": 0,
963
- // "BTC": 0
964
- // },
965
- // "TOTAL": {
966
- // "EUR": 91.16,
967
- // "BTC": 0.002334
956
+ // [
957
+ // {
958
+ // "xcmLocks": [],
959
+ // "xcmLockAmounts": [],
960
+ // "refList": [],
961
+ // "balanceHistory": [],
962
+ // "_id": "5fecd3c998e75c2e4d63f7c3",
963
+ // "currency": "BTC",
964
+ // "label": "BTC",
965
+ // "userId": "5fecd3c97fbfed1521db23bd",
966
+ // "__v": 0,
967
+ // "balance": 0.5,
968
+ // "createdAt": "2020-12-30T19:23:53.646Z",
969
+ // "disabled": false,
970
+ // "updatedAt": "2020-12-30T19:23:53.653Z",
971
+ // "reserved": 0,
972
+ // "id": "5fecd3c998e75c2e4d63f7c3"
968
973
  // },
969
- // "REF": {
970
- // "XCM": 0,
971
- // "EUR": 0,
972
- // "BTC": 0
973
- // }
974
- // }
974
+ // ...
975
+ // ]
975
976
  //
976
977
  const result = {
977
- 'info': response,
978
+ 'info': balances,
978
979
  };
979
- const balances = this.omit(response, ['TOTAL', 'REF']);
980
- const currencyIds = Object.keys(balances);
981
- for (let i = 0; i < currencyIds.length; i++) {
982
- const currencyId = currencyIds[i];
980
+ for (let i = 0; i < balances.length; i++) {
981
+ const balanceEntry = this.safeDict(balances, i, {});
982
+ const currencyId = this.safeString(balanceEntry, 'currency');
983
983
  const code = this.safeCurrencyCode(currencyId);
984
984
  const account = this.account();
985
- const currency = this.safeValue(balances, currencyId, {});
986
- account['total'] = this.safeString(currency, currencyId);
985
+ account['total'] = this.safeString(balanceEntry, 'balance');
986
+ account['used'] = this.safeString(balanceEntry, 'reserved');
987
987
  result[code] = account;
988
988
  }
989
989
  return this.safeBalance(result);
@@ -2629,6 +2629,8 @@ class okx extends okx$1 {
2629
2629
  const takeProfitDefined = (takeProfit !== undefined);
2630
2630
  const trailingPercent = this.safeString2(params, 'trailingPercent', 'callbackRatio');
2631
2631
  const isTrailingPercentOrder = trailingPercent !== undefined;
2632
+ const trigger = (triggerPrice !== undefined) || (type === 'trigger');
2633
+ const isReduceOnly = this.safeValue(params, 'reduceOnly', false);
2632
2634
  const defaultMarginMode = this.safeString2(this.options, 'defaultMarginMode', 'marginMode', 'cross');
2633
2635
  let marginMode = this.safeString2(params, 'marginMode', 'tdMode'); // cross or isolated, tdMode not ommited so as to be extended into the request
2634
2636
  let margin = false;
@@ -2655,6 +2657,25 @@ class okx extends okx$1 {
2655
2657
  if (positionSide !== undefined) {
2656
2658
  request['posSide'] = positionSide;
2657
2659
  }
2660
+ else {
2661
+ let hedged = undefined;
2662
+ [hedged, params] = this.handleOptionAndParams(params, 'createOrder', 'hedged');
2663
+ if (hedged) {
2664
+ const isBuy = (side === 'buy');
2665
+ const isProtective = (takeProfitPrice !== undefined) || (stopLossPrice !== undefined) || isReduceOnly;
2666
+ if (isProtective) {
2667
+ // in case of protective orders, the posSide should be opposite of position side
2668
+ // reduceOnly is emulated and not natively supported by the exchange
2669
+ request['posSide'] = isBuy ? 'short' : 'long';
2670
+ if (isReduceOnly) {
2671
+ params = this.omit(params, 'reduceOnly');
2672
+ }
2673
+ }
2674
+ else {
2675
+ request['posSide'] = isBuy ? 'long' : 'short';
2676
+ }
2677
+ }
2678
+ }
2658
2679
  }
2659
2680
  request['tdMode'] = marginMode;
2660
2681
  }
@@ -2664,7 +2685,6 @@ class okx extends okx$1 {
2664
2685
  params = this.omit(params, ['currency', 'ccy', 'marginMode', 'timeInForce', 'stopPrice', 'triggerPrice', 'clientOrderId', 'stopLossPrice', 'takeProfitPrice', 'slOrdPx', 'tpOrdPx', 'margin', 'stopLoss', 'takeProfit', 'trailingPercent']);
2665
2686
  const ioc = (timeInForce === 'IOC') || (type === 'ioc');
2666
2687
  const fok = (timeInForce === 'FOK') || (type === 'fok');
2667
- const trigger = (triggerPrice !== undefined) || (type === 'trigger');
2668
2688
  const conditional = (stopLossPrice !== undefined) || (takeProfitPrice !== undefined) || (type === 'conditional');
2669
2689
  const marketIOC = (isMarketOrder && ioc) || (type === 'optimal_limit_ioc');
2670
2690
  const defaultTgtCcy = this.safeString(this.options, 'tgtCcy', 'base_ccy');
@@ -2874,6 +2894,7 @@ class okx extends okx$1 {
2874
2894
  * @param {string} [params.positionSide] if position mode is one-way: set to 'net', if position mode is hedge-mode: set to 'long' or 'short'
2875
2895
  * @param {string} [params.trailingPercent] the percent to trail away from the current market price
2876
2896
  * @param {string} [params.tpOrdKind] 'condition' or 'limit', the default is 'condition'
2897
+ * @param {string} [params.hedged] true/false, to automatically set exchange-specific params needed when trading in hedge mode
2877
2898
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2878
2899
  */
2879
2900
  await this.loadMarkets();
@@ -6261,6 +6282,42 @@ class okx extends okx$1 {
6261
6282
  //
6262
6283
  return response;
6263
6284
  }
6285
+ async fetchPositionMode(symbol = undefined, params = {}) {
6286
+ /**
6287
+ * @method
6288
+ * @name okx#fetchPositionMode
6289
+ * @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-account-configuration
6290
+ * @description fetchs the position mode, hedged or one way, hedged for binance is set identically for all linear markets or all inverse markets
6291
+ * @param {string} symbol unified symbol of the market to fetch the order book for
6292
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
6293
+ * @param {string} [param.accountId] if you have multiple accounts, you must specify the account id to fetch the position mode
6294
+ * @returns {object} an object detailing whether the market is in hedged or one-way mode
6295
+ */
6296
+ const accounts = await this.fetchAccounts();
6297
+ const length = accounts.length;
6298
+ let selectedAccount = undefined;
6299
+ if (length > 1) {
6300
+ const accountId = this.safeString(params, 'accountId');
6301
+ if (accountId === undefined) {
6302
+ const accountIds = this.getListFromObjectValues(accounts, 'id');
6303
+ throw new errors.ExchangeError(this.id + ' fetchPositionMode() can not detect position mode, because you have multiple accounts. Set params["accountId"] to desired id from: ' + accountIds.join(', '));
6304
+ }
6305
+ else {
6306
+ const accountsById = this.indexBy(accounts, 'id');
6307
+ selectedAccount = this.safeDict(accountsById, accountId);
6308
+ }
6309
+ }
6310
+ else {
6311
+ selectedAccount = accounts[0];
6312
+ }
6313
+ const mainAccount = selectedAccount['info'];
6314
+ const posMode = this.safeString(mainAccount, 'posMode'); // long_short_mode, net_mode
6315
+ const isHedged = posMode === 'long_short_mode';
6316
+ return {
6317
+ 'info': mainAccount,
6318
+ 'hedged': isHedged,
6319
+ };
6320
+ }
6264
6321
  async setPositionMode(hedged, symbol = undefined, params = {}) {
6265
6322
  /**
6266
6323
  * @method
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, Conversion } from './src/base/types.js';
6
6
  import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, ProxyError, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout } from './src/base/errors.js';
7
- declare const version = "4.3.7";
7
+ declare const version = "4.3.8";
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, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, ProxyError, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.3.8';
41
+ const version = '4.3.9';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -85,13 +85,13 @@ interface Exchange {
85
85
  walletsV1PrivatePostCapitalDepositCreateSubAddress(params?: {}): Promise<implicitReturnType>;
86
86
  subAccountV1PrivateGetList(params?: {}): Promise<implicitReturnType>;
87
87
  subAccountV1PrivateGetAssets(params?: {}): Promise<implicitReturnType>;
88
- subAccountV1PrivateGetApiKeyQuery(params?: {}): Promise<implicitReturnType>;
89
88
  subAccountV1PrivatePostCreate(params?: {}): Promise<implicitReturnType>;
90
89
  subAccountV1PrivatePostApiKeyCreate(params?: {}): Promise<implicitReturnType>;
91
90
  subAccountV1PrivatePostApiKeyEdit(params?: {}): Promise<implicitReturnType>;
92
91
  subAccountV1PrivatePostApiKeyDel(params?: {}): Promise<implicitReturnType>;
93
92
  subAccountV1PrivatePostUpdateStatus(params?: {}): Promise<implicitReturnType>;
94
93
  accountV1PrivateGetUid(params?: {}): Promise<implicitReturnType>;
94
+ accountV1PrivateGetApiKeyQuery(params?: {}): Promise<implicitReturnType>;
95
95
  accountV1PrivatePostInnerTransferAuthorizeSubAccount(params?: {}): Promise<implicitReturnType>;
96
96
  userAuthPrivatePostUserDataStream(params?: {}): Promise<implicitReturnType>;
97
97
  userAuthPrivatePutUserDataStream(params?: {}): Promise<implicitReturnType>;
@@ -10,6 +10,7 @@ interface Exchange {
10
10
  publicGetExchangeBookPair(params?: {}): Promise<implicitReturnType>;
11
11
  publicGetExchangeBookUpdatesPairFrom(params?: {}): Promise<implicitReturnType>;
12
12
  privateGetUsersBalances(params?: {}): Promise<implicitReturnType>;
13
+ privateGetUsersWallets(params?: {}): Promise<implicitReturnType>;
13
14
  privateGetUsersWalletsHistorySince(params?: {}): Promise<implicitReturnType>;
14
15
  privateGetExchangeOrdersStatusOrderID(params?: {}): Promise<implicitReturnType>;
15
16
  privateGetExchangeOrdersActive(params?: {}): Promise<implicitReturnType>;
package/js/src/bingx.js CHANGED
@@ -292,7 +292,6 @@ export default class bingx extends Exchange {
292
292
  'get': {
293
293
  'list': 3,
294
294
  'assets': 3,
295
- 'apiKey/query': 1,
296
295
  },
297
296
  'post': {
298
297
  'create': 3,
@@ -309,6 +308,7 @@ export default class bingx extends Exchange {
309
308
  'private': {
310
309
  'get': {
311
310
  'uid': 1,
311
+ 'apiKey/query': 1,
312
312
  },
313
313
  'post': {
314
314
  'innerTransfer/authorizeSubAccount': 3,
@@ -1838,6 +1838,12 @@ export default class bingx extends Exchange {
1838
1838
  };
1839
1839
  const isMarketOrder = type === 'MARKET';
1840
1840
  const isSpot = marketType === 'spot';
1841
+ const stopLossPrice = this.safeString(params, 'stopLossPrice');
1842
+ const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
1843
+ const triggerPrice = this.safeString2(params, 'stopPrice', 'triggerPrice');
1844
+ const isTriggerOrder = triggerPrice !== undefined;
1845
+ const isStopLossPriceOrder = stopLossPrice !== undefined;
1846
+ const isTakeProfitPriceOrder = takeProfitPrice !== undefined;
1841
1847
  const exchangeClientOrderId = isSpot ? 'newClientOrderId' : 'clientOrderID';
1842
1848
  const clientOrderId = this.safeString2(params, exchangeClientOrderId, 'clientOrderId');
1843
1849
  if (clientOrderId !== undefined) {
@@ -1854,7 +1860,6 @@ export default class bingx extends Exchange {
1854
1860
  else if (timeInForce === 'GTC') {
1855
1861
  request['timeInForce'] = 'GTC';
1856
1862
  }
1857
- const triggerPrice = this.safeString2(params, 'stopPrice', 'triggerPrice');
1858
1863
  if (isSpot) {
1859
1864
  const cost = this.safeNumber2(params, 'cost', 'quoteOrderQty');
1860
1865
  params = this.omit(params, 'cost');
@@ -1886,19 +1891,24 @@ export default class bingx extends Exchange {
1886
1891
  request['type'] = 'TRIGGER_MARKET';
1887
1892
  }
1888
1893
  }
1894
+ else if ((stopLossPrice !== undefined) || (takeProfitPrice !== undefined)) {
1895
+ const stopTakePrice = (stopLossPrice !== undefined) ? stopLossPrice : takeProfitPrice;
1896
+ if (type === 'LIMIT') {
1897
+ request['type'] = 'TAKE_STOP_LIMIT';
1898
+ }
1899
+ else if (type === 'MARKET') {
1900
+ request['type'] = 'TAKE_STOP_MARKET';
1901
+ }
1902
+ request['stopPrice'] = this.parseToNumeric(this.priceToPrecision(symbol, stopTakePrice));
1903
+ }
1889
1904
  }
1890
1905
  else {
1891
1906
  if (timeInForce === 'FOK') {
1892
1907
  request['timeInForce'] = 'FOK';
1893
1908
  }
1894
- const stopLossPrice = this.safeString(params, 'stopLossPrice');
1895
- const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
1896
1909
  const trailingAmount = this.safeString(params, 'trailingAmount');
1897
1910
  const trailingPercent = this.safeString2(params, 'trailingPercent', 'priceRate');
1898
1911
  const trailingType = this.safeString(params, 'trailingType', 'TRAILING_STOP_MARKET');
1899
- const isTriggerOrder = triggerPrice !== undefined;
1900
- const isStopLossPriceOrder = stopLossPrice !== undefined;
1901
- const isTakeProfitPriceOrder = takeProfitPrice !== undefined;
1902
1912
  const isTrailingAmountOrder = trailingAmount !== undefined;
1903
1913
  const isTrailingPercentOrder = trailingPercent !== undefined;
1904
1914
  const isTrailing = isTrailingAmountOrder || isTrailingPercentOrder;
@@ -1997,8 +2007,8 @@ export default class bingx extends Exchange {
1997
2007
  }
1998
2008
  request['positionSide'] = positionSide;
1999
2009
  request['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, amount));
2000
- params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'trailingAmount', 'trailingPercent', 'trailingType', 'takeProfit', 'stopLoss', 'clientOrderId']);
2001
2010
  }
2011
+ params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'trailingAmount', 'trailingPercent', 'trailingType', 'takeProfit', 'stopLoss', 'clientOrderId']);
2002
2012
  return this.extend(request, params);
2003
2013
  }
2004
2014
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
@@ -2018,9 +2028,9 @@ export default class bingx extends Exchange {
2018
2028
  * @param {bool} [params.postOnly] true to place a post only order
2019
2029
  * @param {string} [params.timeInForce] spot supports 'PO', 'GTC' and 'IOC', swap supports 'PO', 'GTC', 'IOC' and 'FOK'
2020
2030
  * @param {bool} [params.reduceOnly] *swap only* true or false whether the order is reduce only
2021
- * @param {float} [params.triggerPrice] *swap only* triggerPrice at which the attached take profit / stop loss order will be triggered
2022
- * @param {float} [params.stopLossPrice] *swap only* stop loss trigger price
2023
- * @param {float} [params.takeProfitPrice] *swap only* take profit trigger price
2031
+ * @param {float} [params.triggerPrice] triggerPrice at which the attached take profit / stop loss order will be triggered
2032
+ * @param {float} [params.stopLossPrice] stop loss trigger price
2033
+ * @param {float} [params.takeProfitPrice] take profit trigger price
2024
2034
  * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount
2025
2035
  * @param {float} [params.trailingAmount] *swap only* the quote amount to trail away from the current market price
2026
2036
  * @param {float} [params.trailingPercent] *swap only* the percent to trail away from the current market price