chore: update to modern typing syntax

This commit is contained in:
Matthias
2024-10-04 06:36:00 +02:00
parent 7db0e3ac3f
commit 74b8dca63e
5 changed files with 21 additions and 20 deletions
+8 -8
View File
@@ -4,7 +4,7 @@
bot constants bot constants
""" """
from typing import Any, Dict, List, Literal, Optional, Tuple from typing import Any, Literal, Optional
from freqtrade.enums import CandleType, PriceType from freqtrade.enums import CandleType, PriceType
@@ -187,14 +187,14 @@ CANCEL_REASON = {
} }
# List of pairs with their timeframes # List of pairs with their timeframes
PairWithTimeframe = Tuple[str, str, CandleType] PairWithTimeframe = tuple[str, str, CandleType]
ListPairsWithTimeframes = List[PairWithTimeframe] ListPairsWithTimeframes = list[PairWithTimeframe]
# Type for trades list # Type for trades list
TradeList = List[List] TradeList = list[list]
# ticks, pair, timeframe, CandleType # ticks, pair, timeframe, CandleType
TickWithTimeframe = Tuple[str, str, CandleType, Optional[int], Optional[int]] TickWithTimeframe = tuple[str, str, CandleType, Optional[int], Optional[int]]
ListTicksWithTimeframes = List[TickWithTimeframe] ListTicksWithTimeframes = list[TickWithTimeframe]
LongShort = Literal["long", "short"] LongShort = Literal["long", "short"]
EntryExit = Literal["entry", "exit"] EntryExit = Literal["entry", "exit"]
@@ -203,9 +203,9 @@ MakerTaker = Literal["maker", "taker"]
BidAsk = Literal["bid", "ask"] BidAsk = Literal["bid", "ask"]
OBLiteral = Literal["asks", "bids"] OBLiteral = Literal["asks", "bids"]
Config = Dict[str, Any] Config = dict[str, Any]
# Exchange part of the configuration. # Exchange part of the configuration.
ExchangeConfig = Dict[str, Any] ExchangeConfig = dict[str, Any]
IntOrInf = float IntOrInf = float
+2 -2
View File
@@ -6,7 +6,7 @@ Read the documentation to know what cli arguments you need.
import logging import logging
import sys import sys
from typing import Any, List, Optional from typing import Any, Optional
# check min. python version # check min. python version
@@ -25,7 +25,7 @@ from freqtrade.util.gc_setup import gc_set_threshold
logger = logging.getLogger("freqtrade") logger = logging.getLogger("freqtrade")
def main(sysargv: Optional[List[str]] = None) -> None: def main(sysargv: Optional[list[str]] = None) -> None:
""" """
This function will initiate the bot and start the trading loop. This function will initiate the bot and start the trading loop.
:return: None :return: None
+4 -3
View File
@@ -4,9 +4,10 @@ Various tool function for Freqtrade and scripts
import gzip import gzip
import logging import logging
from collections.abc import Iterator, Mapping
from io import StringIO from io import StringIO
from pathlib import Path from pathlib import Path
from typing import Any, Dict, Iterator, List, Mapping, Optional, TextIO, Union from typing import Any, Optional, TextIO, Union
from urllib.parse import urlparse from urllib.parse import urlparse
import pandas as pd import pandas as pd
@@ -128,7 +129,7 @@ def round_dict(d, n):
return {k: (round(v, n) if isinstance(v, float) else v) for k, v in d.items()} return {k: (round(v, n) if isinstance(v, float) else v) for k, v in d.items()}
DictMap = Union[Dict[str, Any], Mapping[str, Any]] DictMap = Union[dict[str, Any], Mapping[str, Any]]
def safe_value_fallback(obj: DictMap, key1: str, key2: Optional[str] = None, default_value=None): def safe_value_fallback(obj: DictMap, key1: str, key2: Optional[str] = None, default_value=None):
@@ -164,7 +165,7 @@ def plural(num: float, singular: str, plural: Optional[str] = None) -> str:
return singular if (num == 1 or num == -1) else plural or singular + "s" return singular if (num == 1 or num == -1) else plural or singular + "s"
def chunks(lst: List[Any], n: int) -> Iterator[List[Any]]: def chunks(lst: list[Any], n: int) -> Iterator[list[Any]]:
""" """
Split lst into chunks of the size n. Split lst into chunks of the size n.
:param lst: list to split into chunks :param lst: list to split into chunks
+5 -5
View File
@@ -4,7 +4,7 @@
import logging import logging
from copy import deepcopy from copy import deepcopy
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import Dict, NamedTuple, Optional from typing import NamedTuple, Optional
from freqtrade.constants import UNLIMITED_STAKE_AMOUNT, Config, IntOrInf from freqtrade.constants import UNLIMITED_STAKE_AMOUNT, Config, IntOrInf
from freqtrade.enums import RunMode, TradingMode from freqtrade.enums import RunMode, TradingMode
@@ -39,8 +39,8 @@ class Wallets:
self._config = config self._config = config
self._is_backtest = is_backtest self._is_backtest = is_backtest
self._exchange = exchange self._exchange = exchange
self._wallets: Dict[str, Wallet] = {} self._wallets: dict[str, Wallet] = {}
self._positions: Dict[str, PositionWallet] = {} self._positions: dict[str, PositionWallet] = {}
self.start_cap = config["dry_run_wallet"] self.start_cap = config["dry_run_wallet"]
self._last_wallet_refresh: Optional[datetime] = None self._last_wallet_refresh: Optional[datetime] = None
self.update() self.update()
@@ -199,10 +199,10 @@ class Wallets:
logger.info("Wallets synced.") logger.info("Wallets synced.")
self._last_wallet_refresh = dt_now() self._last_wallet_refresh = dt_now()
def get_all_balances(self) -> Dict[str, Wallet]: def get_all_balances(self) -> dict[str, Wallet]:
return self._wallets return self._wallets
def get_all_positions(self) -> Dict[str, PositionWallet]: def get_all_positions(self) -> dict[str, PositionWallet]:
return self._positions return self._positions
def _check_exit_amount(self, trade: Trade) -> bool: def _check_exit_amount(self, trade: Trade) -> bool:
+2 -2
View File
@@ -6,7 +6,7 @@ import logging
import time import time
import traceback import traceback
from os import getpid from os import getpid
from typing import Any, Callable, Dict, Optional from typing import Any, Callable, Optional
import sdnotify import sdnotify
@@ -27,7 +27,7 @@ class Worker:
Freqtradebot worker class Freqtradebot worker class
""" """
def __init__(self, args: Dict[str, Any], config: Optional[Config] = None) -> None: def __init__(self, args: dict[str, Any], config: Optional[Config] = None) -> None:
""" """
Init all variables and objects the bot needs to work Init all variables and objects the bot needs to work
""" """