ccxt 4.2.91 → 4.2.92

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/js/src/deribit.js CHANGED
@@ -700,117 +700,130 @@ export default class deribit extends Exchange {
700
700
  * @name deribit#fetchMarkets
701
701
  * @description retrieves data on all markets for deribit
702
702
  * @see https://docs.deribit.com/#public-get_currencies
703
+ * @see https://docs.deribit.com/#public-get_instruments
703
704
  * @param {object} [params] extra parameters specific to the exchange API endpoint
704
705
  * @returns {object[]} an array of objects representing market data
705
706
  */
706
- const currenciesResponse = await this.publicGetGetCurrencies(params);
707
- //
708
- // {
709
- // "jsonrpc": "2.0",
710
- // "result": [
711
- // {
712
- // "withdrawal_priorities": [
713
- // { value: 0.15, name: "very_low" },
714
- // { value: 1.5, name: "very_high" },
715
- // ],
716
- // "withdrawal_fee": 0.0005,
717
- // "min_withdrawal_fee": 0.0005,
718
- // "min_confirmations": 1,
719
- // "fee_precision": 4,
720
- // "currency_long": "Bitcoin",
721
- // "currency": "BTC",
722
- // "coin_type": "BITCOIN"
723
- // }
724
- // ],
725
- // "usIn": 1583761588590479,
726
- // "usOut": 1583761588590544,
727
- // "usDiff": 65,
728
- // "testnet": false
729
- // }
730
- //
731
- const parsedMarkets = {};
732
- const currenciesResult = this.safeValue(currenciesResponse, 'result', []);
707
+ const instrumentsResponses = [];
733
708
  const result = [];
734
- for (let i = 0; i < currenciesResult.length; i++) {
735
- const currencyId = this.safeString(currenciesResult[i], 'currency');
736
- const request = {
737
- 'currency': currencyId,
738
- };
739
- const instrumentsResponse = await this.publicGetGetInstruments(this.extend(request, params));
709
+ const parsedMarkets = {};
710
+ let fetchAllMarkets = undefined;
711
+ [fetchAllMarkets, params] = this.handleOptionAndParams(params, 'fetchMarkets', 'fetchAllMarkets', true);
712
+ if (fetchAllMarkets) {
713
+ const instrumentsResponse = await this.publicGetGetInstruments(params);
714
+ instrumentsResponses.push(instrumentsResponse);
715
+ }
716
+ else {
717
+ const currenciesResponse = await this.publicGetGetCurrencies(params);
740
718
  //
741
719
  // {
742
- // "jsonrpc":"2.0",
743
- // "result":[
720
+ // "jsonrpc": "2.0",
721
+ // "result": [
744
722
  // {
745
- // "tick_size":0.0005,
746
- // "taker_commission":0.0003,
747
- // "strike":52000.0,
748
- // "settlement_period":"month",
749
- // "settlement_currency":"BTC",
750
- // "quote_currency":"BTC",
751
- // "option_type":"put", // put, call
752
- // "min_trade_amount":0.1,
753
- // "maker_commission":0.0003,
754
- // "kind":"option",
755
- // "is_active":true,
756
- // "instrument_name":"BTC-24JUN22-52000-P",
757
- // "expiration_timestamp":1656057600000,
758
- // "creation_timestamp":1648199543000,
759
- // "counter_currency":"USD",
760
- // "contract_size":1.0,
761
- // "block_trade_commission":0.0003,
762
- // "base_currency":"BTC"
763
- // },
764
- // {
765
- // "tick_size":0.5,
766
- // "taker_commission":0.0005,
767
- // "settlement_period":"month", // month, week
768
- // "settlement_currency":"BTC",
769
- // "quote_currency":"USD",
770
- // "min_trade_amount":10.0,
771
- // "max_liquidation_commission":0.0075,
772
- // "max_leverage":50,
773
- // "maker_commission":0.0,
774
- // "kind":"future",
775
- // "is_active":true,
776
- // "instrument_name":"BTC-27MAY22",
777
- // "future_type":"reversed",
778
- // "expiration_timestamp":1653638400000,
779
- // "creation_timestamp":1648195209000,
780
- // "counter_currency":"USD",
781
- // "contract_size":10.0,
782
- // "block_trade_commission":0.0001,
783
- // "base_currency":"BTC"
784
- // },
785
- // {
786
- // "tick_size":0.5,
787
- // "taker_commission":0.0005,
788
- // "settlement_period":"perpetual",
789
- // "settlement_currency":"BTC",
790
- // "quote_currency":"USD",
791
- // "min_trade_amount":10.0,
792
- // "max_liquidation_commission":0.0075,
793
- // "max_leverage":50,
794
- // "maker_commission":0.0,
795
- // "kind":"future",
796
- // "is_active":true,
797
- // "instrument_name":"BTC-PERPETUAL",
798
- // "future_type":"reversed",
799
- // "expiration_timestamp":32503708800000,
800
- // "creation_timestamp":1534242287000,
801
- // "counter_currency":"USD",
802
- // "contract_size":10.0,
803
- // "block_trade_commission":0.0001,
804
- // "base_currency":"BTC"
805
- // },
723
+ // "withdrawal_priorities": [
724
+ // { value: 0.15, name: "very_low" },
725
+ // { value: 1.5, name: "very_high" },
726
+ // ],
727
+ // "withdrawal_fee": 0.0005,
728
+ // "min_withdrawal_fee": 0.0005,
729
+ // "min_confirmations": 1,
730
+ // "fee_precision": 4,
731
+ // "currency_long": "Bitcoin",
732
+ // "currency": "BTC",
733
+ // "coin_type": "BITCOIN"
734
+ // }
806
735
  // ],
807
- // "usIn":1648691472831791,
808
- // "usOut":1648691472831896,
809
- // "usDiff":105,
810
- // "testnet":false
736
+ // "usIn": 1583761588590479,
737
+ // "usOut": 1583761588590544,
738
+ // "usDiff": 65,
739
+ // "testnet": false
811
740
  // }
812
741
  //
813
- const instrumentsResult = this.safeValue(instrumentsResponse, 'result', []);
742
+ const currenciesResult = this.safeValue(currenciesResponse, 'result', []);
743
+ for (let i = 0; i < currenciesResult.length; i++) {
744
+ const currencyId = this.safeString(currenciesResult[i], 'currency');
745
+ const request = {
746
+ 'currency': currencyId,
747
+ };
748
+ const instrumentsResponse = await this.publicGetGetInstruments(this.extend(request, params));
749
+ //
750
+ // {
751
+ // "jsonrpc":"2.0",
752
+ // "result":[
753
+ // {
754
+ // "tick_size":0.0005,
755
+ // "taker_commission":0.0003,
756
+ // "strike":52000.0,
757
+ // "settlement_period":"month",
758
+ // "settlement_currency":"BTC",
759
+ // "quote_currency":"BTC",
760
+ // "option_type":"put", // put, call
761
+ // "min_trade_amount":0.1,
762
+ // "maker_commission":0.0003,
763
+ // "kind":"option",
764
+ // "is_active":true,
765
+ // "instrument_name":"BTC-24JUN22-52000-P",
766
+ // "expiration_timestamp":1656057600000,
767
+ // "creation_timestamp":1648199543000,
768
+ // "counter_currency":"USD",
769
+ // "contract_size":1.0,
770
+ // "block_trade_commission":0.0003,
771
+ // "base_currency":"BTC"
772
+ // },
773
+ // {
774
+ // "tick_size":0.5,
775
+ // "taker_commission":0.0005,
776
+ // "settlement_period":"month", // month, week
777
+ // "settlement_currency":"BTC",
778
+ // "quote_currency":"USD",
779
+ // "min_trade_amount":10.0,
780
+ // "max_liquidation_commission":0.0075,
781
+ // "max_leverage":50,
782
+ // "maker_commission":0.0,
783
+ // "kind":"future",
784
+ // "is_active":true,
785
+ // "instrument_name":"BTC-27MAY22",
786
+ // "future_type":"reversed",
787
+ // "expiration_timestamp":1653638400000,
788
+ // "creation_timestamp":1648195209000,
789
+ // "counter_currency":"USD",
790
+ // "contract_size":10.0,
791
+ // "block_trade_commission":0.0001,
792
+ // "base_currency":"BTC"
793
+ // },
794
+ // {
795
+ // "tick_size":0.5,
796
+ // "taker_commission":0.0005,
797
+ // "settlement_period":"perpetual",
798
+ // "settlement_currency":"BTC",
799
+ // "quote_currency":"USD",
800
+ // "min_trade_amount":10.0,
801
+ // "max_liquidation_commission":0.0075,
802
+ // "max_leverage":50,
803
+ // "maker_commission":0.0,
804
+ // "kind":"future",
805
+ // "is_active":true,
806
+ // "instrument_name":"BTC-PERPETUAL",
807
+ // "future_type":"reversed",
808
+ // "expiration_timestamp":32503708800000,
809
+ // "creation_timestamp":1534242287000,
810
+ // "counter_currency":"USD",
811
+ // "contract_size":10.0,
812
+ // "block_trade_commission":0.0001,
813
+ // "base_currency":"BTC"
814
+ // },
815
+ // ],
816
+ // "usIn":1648691472831791,
817
+ // "usOut":1648691472831896,
818
+ // "usDiff":105,
819
+ // "testnet":false
820
+ // }
821
+ //
822
+ instrumentsResponses.push(instrumentsResponse);
823
+ }
824
+ }
825
+ for (let i = 0; i < instrumentsResponses.length; i++) {
826
+ const instrumentsResult = this.safeValue(instrumentsResponses[i], 'result', []);
814
827
  for (let k = 0; k < instrumentsResult.length; k++) {
815
828
  const market = instrumentsResult[k];
816
829
  const kind = this.safeString(market, 'kind');
@@ -104,7 +104,8 @@ export default class kraken extends Exchange {
104
104
  info: any;
105
105
  };
106
106
  withdraw(code: string, amount: number, address: any, tag?: any, params?: {}): Promise<Transaction>;
107
- fetchPositions(symbols?: Strings, params?: {}): Promise<any>;
107
+ fetchPositions(symbols?: Strings, params?: {}): Promise<import("./base/types.js").Position[]>;
108
+ parsePosition(position: any, market?: Market): import("./base/types.js").Position;
108
109
  parseAccountType(account: any): string;
109
110
  transferOut(code: string, amount: any, params?: {}): Promise<TransferEntry>;
110
111
  transfer(code: string, amount: number, fromAccount: string, toAccount: string, params?: {}): Promise<TransferEntry>;
package/js/src/kraken.js CHANGED
@@ -2706,15 +2706,15 @@ export default class kraken extends Exchange {
2706
2706
  * @name kraken#fetchPositions
2707
2707
  * @description fetch all open positions
2708
2708
  * @see https://docs.kraken.com/rest/#tag/Account-Data/operation/getOpenPositions
2709
- * @param {string[]|undefined} symbols not used by kraken fetchPositions ()
2709
+ * @param {string[]} [symbols] not used by kraken fetchPositions ()
2710
2710
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2711
2711
  * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
2712
2712
  */
2713
2713
  await this.loadMarkets();
2714
2714
  const request = {
2715
- // 'txid': 'comma delimited list of transaction ids to restrict output to',
2716
- // 'docalcs': false, // whether or not to include profit/loss calculations
2717
- // 'consolidation': 'market', // what to consolidate the positions data around, market will consolidate positions based on market pair
2715
+ // 'txid': 'comma delimited list of transaction ids to restrict output to',
2716
+ 'docalcs': 'true',
2717
+ 'consolidation': 'market', // what to consolidate the positions data around, market will consolidate positions based on market pair
2718
2718
  };
2719
2719
  const response = await this.privatePostOpenPositions(this.extend(request, params));
2720
2720
  //
@@ -2762,9 +2762,58 @@ export default class kraken extends Exchange {
2762
2762
  // ]
2763
2763
  // }
2764
2764
  //
2765
- const result = this.safeValue(response, 'result');
2766
- // todo unify parsePosition/parsePositions
2767
- return result;
2765
+ symbols = this.marketSymbols(symbols);
2766
+ const result = this.safeList(response, 'result');
2767
+ const results = this.parsePositions(result, symbols);
2768
+ return this.filterByArrayPositions(results, 'symbol', symbols, false);
2769
+ }
2770
+ parsePosition(position, market = undefined) {
2771
+ //
2772
+ // {
2773
+ // "pair": "ETHUSDT",
2774
+ // "positions": "1",
2775
+ // "type": "buy",
2776
+ // "leverage": "2.00000",
2777
+ // "cost": "28.49800",
2778
+ // "fee": "0.07979",
2779
+ // "vol": "0.02000000",
2780
+ // "vol_closed": "0.00000000",
2781
+ // "margin": "14.24900"
2782
+ // }
2783
+ //
2784
+ const marketId = this.safeString(position, 'pair');
2785
+ const rawSide = this.safeString(position, 'type');
2786
+ const side = (rawSide === 'buy') ? 'long' : 'short';
2787
+ return this.safePosition({
2788
+ 'info': position,
2789
+ 'id': undefined,
2790
+ 'symbol': this.safeSymbol(marketId, market),
2791
+ 'notional': undefined,
2792
+ 'marginMode': undefined,
2793
+ 'liquidationPrice': undefined,
2794
+ 'entryPrice': undefined,
2795
+ 'unrealizedPnl': this.safeNumber(position, 'net'),
2796
+ 'realizedPnl': undefined,
2797
+ 'percentage': undefined,
2798
+ 'contracts': this.safeNumber(position, 'vol'),
2799
+ 'contractSize': undefined,
2800
+ 'markPrice': undefined,
2801
+ 'lastPrice': undefined,
2802
+ 'side': side,
2803
+ 'hedged': undefined,
2804
+ 'timestamp': undefined,
2805
+ 'datetime': undefined,
2806
+ 'lastUpdateTimestamp': undefined,
2807
+ 'maintenanceMargin': undefined,
2808
+ 'maintenanceMarginPercentage': undefined,
2809
+ 'collateral': undefined,
2810
+ 'initialMargin': this.safeNumber(position, 'margin'),
2811
+ 'initialMarginPercentage': undefined,
2812
+ 'leverage': this.safeNumber(position, 'leverage'),
2813
+ 'marginRatio': undefined,
2814
+ 'stopLossPrice': undefined,
2815
+ 'takeProfitPrice': undefined,
2816
+ });
2768
2817
  }
2769
2818
  parseAccountType(account) {
2770
2819
  const accountByType = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.91",
3
+ "version": "4.2.92",
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",