freqtrade/freqtrade

View on GitHub
freqtrade/exchange/exchange.py

Summary

Maintainability
F
1 wk
Test Coverage

File exchange.py has 2599 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# pragma pylint: disable=W0603
"""
Cryptocurrency Exchanges support
"""
import asyncio
Severity: Major
Found in freqtrade/exchange/exchange.py - About 1 wk to fix

    Exchange has 34 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Exchange:
    
        # Parameters to add directly to buy/sell calls (like agreeing to trading agreement)
        _params: Dict = {}
    
    
    Severity: Minor
    Found in freqtrade/exchange/exchange.py - About 4 hrs to fix

      Function __init__ has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def __init__(self, config: Config, *, exchange_config: Optional[ExchangeConfig] = None,
                       validate: bool = True, load_leverage_tiers: bool = False) -> None:
              """
              Initializes this module with the given config,
              it does basic validation whether the specified exchange and pairs are valid.
      Severity: Minor
      Found in freqtrade/exchange/exchange.py - About 1 hr to fix

        Function get_liquidation_price has 15 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def get_liquidation_price(
        Severity: Major
        Found in freqtrade/exchange/exchange.py - About 1 hr to fix

          Function dry_run_liquidation_price has 14 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def dry_run_liquidation_price(
          Severity: Major
          Found in freqtrade/exchange/exchange.py - About 1 hr to fix

            Function create_order has 10 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def create_order(
            Severity: Major
            Found in freqtrade/exchange/exchange.py - About 1 hr to fix

              Function create_dry_run_order has 9 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def create_dry_run_order(self, pair: str, ordertype: str, side: str, amount: float,
              Severity: Major
              Found in freqtrade/exchange/exchange.py - About 1 hr to fix

                Function _order_contracts_to_amount has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    def _order_contracts_to_amount(self, order: Dict) -> Dict:
                        if 'symbol' in order and order['symbol'] is not None:
                            contract_size = self.get_contract_size(order['symbol'])
                            if contract_size != 1:
                                for prop in self._ft_has.get('order_props_in_contracts', []):
                Severity: Minor
                Found in freqtrade/exchange/exchange.py - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function _process_ohlcv_df has 7 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def _process_ohlcv_df(self, pair: str, timeframe: str, c_type: CandleType, ticks: List[List],
                Severity: Major
                Found in freqtrade/exchange/exchange.py - About 50 mins to fix

                  Function _get_rate_from_ob has 7 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def _get_rate_from_ob(self, pair: str, side: EntryExit, order_book: OrderBook, name: str,
                  Severity: Major
                  Found in freqtrade/exchange/exchange.py - About 50 mins to fix

                    Function get_historic_ohlcv has 7 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def get_historic_ohlcv(self, pair: str, timeframe: str,
                    Severity: Major
                    Found in freqtrade/exchange/exchange.py - About 50 mins to fix

                      Function get_rate has 7 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          def get_rate(self, pair: str, refresh: bool,
                      Severity: Major
                      Found in freqtrade/exchange/exchange.py - About 50 mins to fix

                        Function create_stoploss has 7 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            def create_stoploss(self, pair: str, amount: float, stop_price: float, order_types: Dict,
                        Severity: Major
                        Found in freqtrade/exchange/exchange.py - About 50 mins to fix

                          Function get_fee has 7 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              def get_fee(self, symbol: str, type: str = '', side: str = '', amount: float = 1,
                          Severity: Major
                          Found in freqtrade/exchange/exchange.py - About 50 mins to fix

                            Function calculate_funding_fees has 7 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                                def calculate_funding_fees(
                            Severity: Major
                            Found in freqtrade/exchange/exchange.py - About 50 mins to fix

                              Function get_markets has 7 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                  def get_markets(
                              Severity: Major
                              Found in freqtrade/exchange/exchange.py - About 50 mins to fix

                                Function get_dry_market_fill_price has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                    def get_dry_market_fill_price(self, pair: str, side: str, amount: float, rate: float,
                                Severity: Minor
                                Found in freqtrade/exchange/exchange.py - About 45 mins to fix

                                  Function _get_params has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                  Open

                                      def _get_params(
                                  Severity: Minor
                                  Found in freqtrade/exchange/exchange.py - About 45 mins to fix

                                    Function _get_stake_amount_limit has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                    Open

                                        def _get_stake_amount_limit(
                                    Severity: Minor
                                    Found in freqtrade/exchange/exchange.py - About 45 mins to fix

                                      Function _build_coroutine has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                      Open

                                          def _build_coroutine(
                                      Severity: Minor
                                      Found in freqtrade/exchange/exchange.py - About 45 mins to fix

                                        Function market_is_tradable has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                        Open

                                            def market_is_tradable(self, market: Dict[str, Any]) -> bool:
                                                """
                                                Check if the market symbol is tradable by Freqtrade.
                                                Ensures that Configured mode aligns to
                                                """
                                        Severity: Minor
                                        Found in freqtrade/exchange/exchange.py - About 45 mins to fix

                                        Cognitive Complexity

                                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                        A method's cognitive complexity is based on a few simple rules:

                                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                        • Code is considered more complex for each "break in the linear flow of the code"
                                        • Code is considered more complex when "flow breaking structures are nested"

                                        Further reading

                                        Function _dry_is_price_crossed has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                        Open

                                            def _dry_is_price_crossed(self, pair: str, side: str, limit: float,
                                        Severity: Minor
                                        Found in freqtrade/exchange/exchange.py - About 45 mins to fix

                                          Function refresh_latest_ohlcv has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                          Open

                                              def refresh_latest_ohlcv(self, pair_list: ListPairsWithTimeframes, *,
                                          Severity: Minor
                                          Found in freqtrade/exchange/exchange.py - About 45 mins to fix

                                            Function _fetch_and_calculate_funding_fees has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                            Open

                                                def _fetch_and_calculate_funding_fees(
                                            Severity: Minor
                                            Found in freqtrade/exchange/exchange.py - About 45 mins to fix

                                              Function __init__ has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                                  def __init__(self, config: Config, *, exchange_config: Optional[ExchangeConfig] = None,
                                                               validate: bool = True, load_leverage_tiers: bool = False) -> None:
                                                      """
                                                      Initializes this module with the given config,
                                                      it does basic validation whether the specified exchange and pairs are valid.
                                              Severity: Minor
                                              Found in freqtrade/exchange/exchange.py - About 45 mins to fix

                                              Cognitive Complexity

                                              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                              A method's cognitive complexity is based on a few simple rules:

                                              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                              • Code is considered more complex for each "break in the linear flow of the code"
                                              • Code is considered more complex when "flow breaking structures are nested"

                                              Further reading

                                              Function get_markets has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                                  def get_markets(
                                                          self,
                                                          base_currencies: Optional[List[str]] = None,
                                                          quote_currencies: Optional[List[str]] = None,
                                                          spot_only: bool = False, margin_only: bool = False, futures_only: bool = False,
                                              Severity: Minor
                                              Found in freqtrade/exchange/exchange.py - About 45 mins to fix

                                              Cognitive Complexity

                                              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                              A method's cognitive complexity is based on a few simple rules:

                                              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                              • Code is considered more complex for each "break in the linear flow of the code"
                                              • Code is considered more complex when "flow breaking structures are nested"

                                              Further reading

                                              Function price_to_precision has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                              Open

                                                  def price_to_precision(self, pair: str, price: float, *, rounding_mode: int = ROUND) -> float:
                                              Severity: Minor
                                              Found in freqtrade/exchange/exchange.py - About 35 mins to fix

                                                Function calculate_fee_rate has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                Open

                                                    def calculate_fee_rate(
                                                Severity: Minor
                                                Found in freqtrade/exchange/exchange.py - About 35 mins to fix

                                                  Function set_margin_mode has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                  Open

                                                      def set_margin_mode(self, pair: str, margin_mode: MarginMode, accept_fail: bool = False,
                                                  Severity: Minor
                                                  Found in freqtrade/exchange/exchange.py - About 35 mins to fix

                                                    Function _get_rate_from_ticker has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                    Open

                                                        def _get_rate_from_ticker(self, side: EntryExit, ticker: Ticker, conf_strategy: Dict[str, Any],
                                                    Severity: Minor
                                                    Found in freqtrade/exchange/exchange.py - About 35 mins to fix

                                                      Function __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                      Open

                                                          def __init__(self, config: Config, *, exchange_config: Optional[ExchangeConfig] = None,
                                                      Severity: Minor
                                                      Found in freqtrade/exchange/exchange.py - About 35 mins to fix

                                                        Function _lev_prep has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                        Open

                                                            def _lev_prep(self, pair: str, leverage: float, side: BuySell, accept_fail: bool = False):
                                                        Severity: Minor
                                                        Found in freqtrade/exchange/exchange.py - About 35 mins to fix

                                                          Function get_trades_for_order has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                          Open

                                                              def get_trades_for_order(self, order_id: str, pair: str, since: datetime,
                                                          Severity: Minor
                                                          Found in freqtrade/exchange/exchange.py - About 35 mins to fix

                                                            Function extract_cost_curr_rate has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                            Open

                                                                def extract_cost_curr_rate(self, fee: Dict, symbol: str, cost: float,
                                                            Severity: Minor
                                                            Found in freqtrade/exchange/exchange.py - About 35 mins to fix

                                                              Function get_historic_trades has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                              Open

                                                                  def get_historic_trades(self, pair: str,
                                                              Severity: Minor
                                                              Found in freqtrade/exchange/exchange.py - About 35 mins to fix

                                                                Function get_funding_fees has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                Open

                                                                    def get_funding_fees(
                                                                Severity: Minor
                                                                Found in freqtrade/exchange/exchange.py - About 35 mins to fix

                                                                  Function get_min_pair_stake_amount has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                  Open

                                                                      def get_min_pair_stake_amount(
                                                                  Severity: Minor
                                                                  Found in freqtrade/exchange/exchange.py - About 35 mins to fix

                                                                    Function _trades_contracts_to_amount has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                    Open

                                                                        def _trades_contracts_to_amount(self, trades: List) -> List:
                                                                            if len(trades) > 0 and 'symbol' in trades[0]:
                                                                                contract_size = self.get_contract_size(trades[0]['symbol'])
                                                                                if contract_size != 1:
                                                                                    for trade in trades:
                                                                    Severity: Minor
                                                                    Found in freqtrade/exchange/exchange.py - About 25 mins to fix

                                                                    Cognitive Complexity

                                                                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                                                    A method's cognitive complexity is based on a few simple rules:

                                                                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                                                    • Code is considered more complex for each "break in the linear flow of the code"
                                                                    • Code is considered more complex when "flow breaking structures are nested"

                                                                    Further reading

                                                                    Function _init_ccxt has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                    Open

                                                                        def _init_ccxt(self, exchange_config: Dict[str, Any], ccxt_module: CcxtModuleType = ccxt, *,
                                                                                       ccxt_kwargs: Dict) -> ccxt.Exchange:
                                                                            """
                                                                            Initialize ccxt with given config and return valid
                                                                            ccxt instance.
                                                                    Severity: Minor
                                                                    Found in freqtrade/exchange/exchange.py - About 25 mins to fix

                                                                    Cognitive Complexity

                                                                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                                                    A method's cognitive complexity is based on a few simple rules:

                                                                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                                                    • Code is considered more complex for each "break in the linear flow of the code"
                                                                    • Code is considered more complex when "flow breaking structures are nested"

                                                                    Further reading

                                                                    Function get_contract_size has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                    Open

                                                                        def get_contract_size(self, pair: str) -> Optional[float]:
                                                                            if self.trading_mode == TradingMode.FUTURES:
                                                                                market = self.markets.get(pair, {})
                                                                                contract_size: float = 1.0
                                                                                if not market:
                                                                    Severity: Minor
                                                                    Found in freqtrade/exchange/exchange.py - About 25 mins to fix

                                                                    Cognitive Complexity

                                                                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                                                    A method's cognitive complexity is based on a few simple rules:

                                                                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                                                    • Code is considered more complex for each "break in the linear flow of the code"
                                                                    • Code is considered more complex when "flow breaking structures are nested"

                                                                    Further reading

                                                                    There are no issues that match your filters.

                                                                    Category
                                                                    Status