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.
@@ -28,7 +28,7 @@ export default class coinmetro extends Exchange {
28
28
  fetchBidsAsks(symbols?: Strings, params?: {}): Promise<import("./base/types.js").Dictionary<Ticker>>;
29
29
  parseTicker(ticker: any, market?: Market): Ticker;
30
30
  fetchBalance(params?: {}): Promise<Balances>;
31
- parseBalance(response: any): Balances;
31
+ parseBalance(balances: any): Balances;
32
32
  fetchLedger(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<any>;
33
33
  parseLedgerEntry(item: any, currency?: Currency): {
34
34
  id: string;
@@ -164,6 +164,7 @@ export default class coinmetro extends Exchange {
164
164
  'private': {
165
165
  'get': {
166
166
  'users/balances': 1,
167
+ 'users/wallets': 1,
167
168
  'users/wallets/history/{since}': 1.67,
168
169
  'exchange/orders/status/{orderID}': 1,
169
170
  'exchange/orders/active': 1,
@@ -944,49 +945,48 @@ export default class coinmetro extends Exchange {
944
945
  * @method
945
946
  * @name coinmetro#fetchBalance
946
947
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
947
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#698ae067-43dd-4e19-a0ac-d9ba91381816
948
+ * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#741a1dcc-7307-40d0-acca-28d003d1506a
948
949
  * @param {object} [params] extra parameters specific to the exchange API endpoint
949
950
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
950
951
  */
951
952
  await this.loadMarkets();
952
- const response = await this.privateGetUsersBalances(params);
953
- return this.parseBalance(response);
953
+ const response = await this.privateGetUsersWallets(params);
954
+ const list = this.safeList(response, 'list', []);
955
+ return this.parseBalance(list);
954
956
  }
955
- parseBalance(response) {
957
+ parseBalance(balances) {
956
958
  //
957
- // {
958
- // "USDC": {
959
- // "USDC": 99,
960
- // "EUR": 91.16,
961
- // "BTC": 0.002334
962
- // },
963
- // "XCM": {
964
- // "XCM": 0,
965
- // "EUR": 0,
966
- // "BTC": 0
967
- // },
968
- // "TOTAL": {
969
- // "EUR": 91.16,
970
- // "BTC": 0.002334
959
+ // [
960
+ // {
961
+ // "xcmLocks": [],
962
+ // "xcmLockAmounts": [],
963
+ // "refList": [],
964
+ // "balanceHistory": [],
965
+ // "_id": "5fecd3c998e75c2e4d63f7c3",
966
+ // "currency": "BTC",
967
+ // "label": "BTC",
968
+ // "userId": "5fecd3c97fbfed1521db23bd",
969
+ // "__v": 0,
970
+ // "balance": 0.5,
971
+ // "createdAt": "2020-12-30T19:23:53.646Z",
972
+ // "disabled": false,
973
+ // "updatedAt": "2020-12-30T19:23:53.653Z",
974
+ // "reserved": 0,
975
+ // "id": "5fecd3c998e75c2e4d63f7c3"
971
976
  // },
972
- // "REF": {
973
- // "XCM": 0,
974
- // "EUR": 0,
975
- // "BTC": 0
976
- // }
977
- // }
977
+ // ...
978
+ // ]
978
979
  //
979
980
  const result = {
980
- 'info': response,
981
+ 'info': balances,
981
982
  };
982
- const balances = this.omit(response, ['TOTAL', 'REF']);
983
- const currencyIds = Object.keys(balances);
984
- for (let i = 0; i < currencyIds.length; i++) {
985
- const currencyId = currencyIds[i];
983
+ for (let i = 0; i < balances.length; i++) {
984
+ const balanceEntry = this.safeDict(balances, i, {});
985
+ const currencyId = this.safeString(balanceEntry, 'currency');
986
986
  const code = this.safeCurrencyCode(currencyId);
987
987
  const account = this.account();
988
- const currency = this.safeValue(balances, currencyId, {});
989
- account['total'] = this.safeString(currency, currencyId);
988
+ account['total'] = this.safeString(balanceEntry, 'balance');
989
+ account['used'] = this.safeString(balanceEntry, 'reserved');
990
990
  result[code] = account;
991
991
  }
992
992
  return this.safeBalance(result);
package/js/src/okx.d.ts CHANGED
@@ -171,6 +171,10 @@ export default class okx extends Exchange {
171
171
  }>;
172
172
  fetchFundingHistory(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<FundingHistory[]>;
173
173
  setLeverage(leverage: Int, symbol?: Str, params?: {}): Promise<any>;
174
+ fetchPositionMode(symbol?: Str, params?: {}): Promise<{
175
+ info: any;
176
+ hedged: boolean;
177
+ }>;
174
178
  setPositionMode(hedged: boolean, symbol?: Str, params?: {}): Promise<any>;
175
179
  setMarginMode(marginMode: string, symbol?: Str, params?: {}): Promise<any>;
176
180
  fetchCrossBorrowRates(params?: {}): Promise<any>;
package/js/src/okx.js CHANGED
@@ -2632,6 +2632,8 @@ export default class okx extends Exchange {
2632
2632
  const takeProfitDefined = (takeProfit !== undefined);
2633
2633
  const trailingPercent = this.safeString2(params, 'trailingPercent', 'callbackRatio');
2634
2634
  const isTrailingPercentOrder = trailingPercent !== undefined;
2635
+ const trigger = (triggerPrice !== undefined) || (type === 'trigger');
2636
+ const isReduceOnly = this.safeValue(params, 'reduceOnly', false);
2635
2637
  const defaultMarginMode = this.safeString2(this.options, 'defaultMarginMode', 'marginMode', 'cross');
2636
2638
  let marginMode = this.safeString2(params, 'marginMode', 'tdMode'); // cross or isolated, tdMode not ommited so as to be extended into the request
2637
2639
  let margin = false;
@@ -2658,6 +2660,25 @@ export default class okx extends Exchange {
2658
2660
  if (positionSide !== undefined) {
2659
2661
  request['posSide'] = positionSide;
2660
2662
  }
2663
+ else {
2664
+ let hedged = undefined;
2665
+ [hedged, params] = this.handleOptionAndParams(params, 'createOrder', 'hedged');
2666
+ if (hedged) {
2667
+ const isBuy = (side === 'buy');
2668
+ const isProtective = (takeProfitPrice !== undefined) || (stopLossPrice !== undefined) || isReduceOnly;
2669
+ if (isProtective) {
2670
+ // in case of protective orders, the posSide should be opposite of position side
2671
+ // reduceOnly is emulated and not natively supported by the exchange
2672
+ request['posSide'] = isBuy ? 'short' : 'long';
2673
+ if (isReduceOnly) {
2674
+ params = this.omit(params, 'reduceOnly');
2675
+ }
2676
+ }
2677
+ else {
2678
+ request['posSide'] = isBuy ? 'long' : 'short';
2679
+ }
2680
+ }
2681
+ }
2661
2682
  }
2662
2683
  request['tdMode'] = marginMode;
2663
2684
  }
@@ -2667,7 +2688,6 @@ export default class okx extends Exchange {
2667
2688
  params = this.omit(params, ['currency', 'ccy', 'marginMode', 'timeInForce', 'stopPrice', 'triggerPrice', 'clientOrderId', 'stopLossPrice', 'takeProfitPrice', 'slOrdPx', 'tpOrdPx', 'margin', 'stopLoss', 'takeProfit', 'trailingPercent']);
2668
2689
  const ioc = (timeInForce === 'IOC') || (type === 'ioc');
2669
2690
  const fok = (timeInForce === 'FOK') || (type === 'fok');
2670
- const trigger = (triggerPrice !== undefined) || (type === 'trigger');
2671
2691
  const conditional = (stopLossPrice !== undefined) || (takeProfitPrice !== undefined) || (type === 'conditional');
2672
2692
  const marketIOC = (isMarketOrder && ioc) || (type === 'optimal_limit_ioc');
2673
2693
  const defaultTgtCcy = this.safeString(this.options, 'tgtCcy', 'base_ccy');
@@ -2877,6 +2897,7 @@ export default class okx extends Exchange {
2877
2897
  * @param {string} [params.positionSide] if position mode is one-way: set to 'net', if position mode is hedge-mode: set to 'long' or 'short'
2878
2898
  * @param {string} [params.trailingPercent] the percent to trail away from the current market price
2879
2899
  * @param {string} [params.tpOrdKind] 'condition' or 'limit', the default is 'condition'
2900
+ * @param {string} [params.hedged] true/false, to automatically set exchange-specific params needed when trading in hedge mode
2880
2901
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2881
2902
  */
2882
2903
  await this.loadMarkets();
@@ -6264,6 +6285,42 @@ export default class okx extends Exchange {
6264
6285
  //
6265
6286
  return response;
6266
6287
  }
6288
+ async fetchPositionMode(symbol = undefined, params = {}) {
6289
+ /**
6290
+ * @method
6291
+ * @name okx#fetchPositionMode
6292
+ * @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-account-configuration
6293
+ * @description fetchs the position mode, hedged or one way, hedged for binance is set identically for all linear markets or all inverse markets
6294
+ * @param {string} symbol unified symbol of the market to fetch the order book for
6295
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
6296
+ * @param {string} [param.accountId] if you have multiple accounts, you must specify the account id to fetch the position mode
6297
+ * @returns {object} an object detailing whether the market is in hedged or one-way mode
6298
+ */
6299
+ const accounts = await this.fetchAccounts();
6300
+ const length = accounts.length;
6301
+ let selectedAccount = undefined;
6302
+ if (length > 1) {
6303
+ const accountId = this.safeString(params, 'accountId');
6304
+ if (accountId === undefined) {
6305
+ const accountIds = this.getListFromObjectValues(accounts, 'id');
6306
+ throw new ExchangeError(this.id + ' fetchPositionMode() can not detect position mode, because you have multiple accounts. Set params["accountId"] to desired id from: ' + accountIds.join(', '));
6307
+ }
6308
+ else {
6309
+ const accountsById = this.indexBy(accounts, 'id');
6310
+ selectedAccount = this.safeDict(accountsById, accountId);
6311
+ }
6312
+ }
6313
+ else {
6314
+ selectedAccount = accounts[0];
6315
+ }
6316
+ const mainAccount = selectedAccount['info'];
6317
+ const posMode = this.safeString(mainAccount, 'posMode'); // long_short_mode, net_mode
6318
+ const isHedged = posMode === 'long_short_mode';
6319
+ return {
6320
+ 'info': mainAccount,
6321
+ 'hedged': isHedged,
6322
+ };
6323
+ }
6267
6324
  async setPositionMode(hedged, symbol = undefined, params = {}) {
6268
6325
  /**
6269
6326
  * @method
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.3.8",
3
+ "version": "4.3.9",
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",
@@ -30,8 +30,8 @@
30
30
  "coverage-js": "npm run instrument && npm run nyc-coverage && rm -rf jsInstrumented",
31
31
  "docker": "docker-compose run --rm ccxt",
32
32
  "fixTSBug": "node build/fixTSBug",
33
- "transpileCS": "node --no-warnings --loader ts-node/esm build/csharpTranspiler.ts --multi",
34
- "transpileCSWs": "node --no-warnings --loader ts-node/esm build/csharpTranspiler.ts --ws",
33
+ "transpileCS": "tsx build/csharpTranspiler.ts --multi",
34
+ "transpileCSWs": "tsx build/csharpTranspiler.ts --ws",
35
35
  "buildCS": "dotnet build cs/ccxt.sln",
36
36
  "buildCSRelease": "dotnet build cs --configuration Release",
37
37
  "csharp": "npm run transpileCS && npm run transpileCSWs && npm run buildCS",
@@ -74,7 +74,7 @@
74
74
  "cli.js": "node ./examples/js/cli.js",
75
75
  "cli.py": "python3 ./examples/py/cli.py",
76
76
  "cli.php": "php ./examples/php/cli.php",
77
- "cli.ts": "node --loader ts-node/esm examples/ts/cli.ts",
77
+ "cli.ts": "tsx examples/ts/cli.ts",
78
78
  "cli.cs": "dotnet run --project \"./cs/cli/cli.csproj\"",
79
79
  "export-exchanges": "node build/export-exchanges",
80
80
  "capabilities": "node ./examples/js/exchange-capabilities.js",
@@ -121,7 +121,7 @@
121
121
  "copy-python-keys": "node build/copy keys.json python/keys.json",
122
122
  "copy-python-readme": "node build/copy README.md python/README.md",
123
123
  "postinstall": "node postinstall.js",
124
- "validate-types": "node --loader ts-node/esm build/validate-types.ts",
124
+ "validate-types": "tsx build/validate-types.ts",
125
125
  "response-js": "node js/src/test/test.js --responseTests",
126
126
  "request-js": "node js/src/test/test.js --requestTests",
127
127
  "request-py": "python3 python/ccxt/test/test_async.py --requestTests",
@@ -138,7 +138,7 @@
138
138
  "id-tests-php": "php php/test/test_async.php --idTests",
139
139
  "id-tests-cs": "dotnet run --project cs/tests/tests.csproj --idTests",
140
140
  "id-tests": "npm run id-tests-js && npm run id-tests-py && npm run id-tests-php && npm run id-tests-cs",
141
- "benchmark": "node --loader ts-node/esm examples/ts/benchmark.ts"
141
+ "benchmark": "tsx examples/ts/benchmark.ts"
142
142
  },
143
143
  "types": "./js/ccxt.d.ts",
144
144
  "devDependencies": {
@@ -168,7 +168,7 @@
168
168
  "rollup-plugin-execute": "1.1.1",
169
169
  "terser-webpack-plugin": "^5.3.9",
170
170
  "ts-loader": "^9.4.2",
171
- "ts-node": "^10.9.1",
171
+ "tsx": "^4.7.2",
172
172
  "typescript": "4.7.4",
173
173
  "webpack": "^5.76.2",
174
174
  "webpack-cli": "^5.0.1"