Ruff --fix

This commit is contained in:
Joe Schr
2024-02-07 12:45:39 +01:00
parent 72a20e9928
commit 39ba6fe56b
4 changed files with 10 additions and 19 deletions

View File

@@ -1,7 +1,6 @@
""" """
Functions to convert data from one format to another Functions to convert data from one format to another
""" """
import itertools
import logging import logging
import time import time
from typing import Dict from typing import Dict
@@ -125,7 +124,7 @@ def populate_dataframe_with_trades(config: Config, dataframe: DataFrame, trades:
pd.Timedelta(minutes=timeframe_minutes) pd.Timedelta(minutes=timeframe_minutes)
# skip if there are no trades at next candle because that this candle isn't finished yet # skip if there are no trades at next candle because that this candle isn't finished yet
# if not np.any((candle_next == df.candle_start)): # if not np.any((candle_next == df.candle_start)):
if not candle_next in trades_grouped_by_candle_start.groups: if candle_next not in trades_grouped_by_candle_start.groups:
logger.warning( logger.warning(
f"candle at {candle_start} with {len(trades_grouped_df)} trades might be unfinished, because no finished trades at {candle_next}") f"candle at {candle_start} with {len(trades_grouped_df)} trades might be unfinished, because no finished trades at {candle_next}")

View File

@@ -13,7 +13,7 @@ from pandas import DataFrame, Timedelta, Timestamp, to_timedelta
from freqtrade.configuration import TimeRange from freqtrade.configuration import TimeRange
from freqtrade.constants import (FULL_DATAFRAME_THRESHOLD, Config, ListPairsWithTimeframes, from freqtrade.constants import (FULL_DATAFRAME_THRESHOLD, Config, ListPairsWithTimeframes,
ListTicksWithTimeframes, PairWithTimeframe) PairWithTimeframe)
from freqtrade.data.converter import public_trades_to_dataframe from freqtrade.data.converter import public_trades_to_dataframe
from freqtrade.data.history import load_pair_history from freqtrade.data.history import load_pair_history
from freqtrade.data.history.idatahandler import get_datahandler from freqtrade.data.history.idatahandler import get_datahandler

View File

@@ -447,7 +447,7 @@ class Exchange:
def trades(self, pair_interval: PairWithTimeframe, copy: bool = True) -> DataFrame: def trades(self, pair_interval: PairWithTimeframe, copy: bool = True) -> DataFrame:
if pair_interval in self._trades: if pair_interval in self._trades:
if copy: if copy:
return self._trades[pair_interval].copy() return self._trades[pair_interval].copy()
else: else:
return self._trades[pair_interval] return self._trades[pair_interval]
else: else:
@@ -2310,7 +2310,7 @@ class Exchange:
def refresh_latest_trades(self, def refresh_latest_trades(self,
pair_list: ListPairsWithTimeframes, pair_list: ListPairsWithTimeframes,
data_handler: Callable, # using IDataHandler ends with circular import, data_handler: Callable, # using IDataHandler ends with circular import,
*, *,
cache: bool = True, cache: bool = True,
) -> Dict[PairWithTimeframe, DataFrame]: ) -> Dict[PairWithTimeframe, DataFrame]:
@@ -2342,13 +2342,13 @@ class Exchange:
# fetch trades since latest _trades and # fetch trades since latest _trades and
# store together with existing trades # store together with existing trades
try: try:
until = None until = None
from_id = None from_id = None
if is_in_cache: if is_in_cache:
from_id = self._trades[(pair, timeframe, candle_type)].iloc[-1]['id'] from_id = self._trades[(pair, timeframe, candle_type)].iloc[-1]['id']
until = dt_ts() # now until = dt_ts() # now
else: else:
until = int(timeframe_to_prev_date(timeframe).timestamp()) * 1000 until = int(timeframe_to_prev_date(timeframe).timestamp()) * 1000
all_stored_ticks_df = data_handler.trades_load(f"{pair}-cached") all_stored_ticks_df = data_handler.trades_load(f"{pair}-cached")
@@ -2358,7 +2358,7 @@ class Exchange:
# only use cached if it's closer than first_candle_ms # only use cached if it's closer than first_candle_ms
since_ms = last_cached_ms if last_cached_ms > first_candle_ms else first_candle_ms since_ms = last_cached_ms if last_cached_ms > first_candle_ms else first_candle_ms
# doesn't go far enough # doesn't go far enough
else: else:
all_stored_ticks_df = DataFrame(columns=DEFAULT_TRADES_COLUMNS + ['date']) all_stored_ticks_df = DataFrame(columns=DEFAULT_TRADES_COLUMNS + ['date'])
# from_id overrules with exchange set to id paginate # from_id overrules with exchange set to id paginate
@@ -2406,7 +2406,7 @@ class Exchange:
# Timeframe in seconds # Timeframe in seconds
df = self.klines((pair, timeframe, candle_type), True) df = self.klines((pair, timeframe, candle_type), True)
_calculate_ohlcv_candle_start_and_end(df, timeframe) _calculate_ohlcv_candle_start_and_end(df, timeframe)
interval_in_sec = timeframe_to_seconds(timeframe) timeframe_to_seconds(timeframe)
# plr = self._trades_last_refresh_time.get((pair, timeframe, candle_type), 0) + interval_in_sec # plr = self._trades_last_refresh_time.get((pair, timeframe, candle_type), 0) + interval_in_sec
plr = round(df.iloc[-1]["candle_end"].timestamp()) plr = round(df.iloc[-1]["candle_end"].timestamp())
now = int(timeframe_to_prev_date(timeframe).timestamp()) now = int(timeframe_to_prev_date(timeframe).timestamp())
@@ -2498,7 +2498,7 @@ class Exchange:
pair, candle_type, timeframe, since_ms pair, candle_type, timeframe, since_ms
) )
params = deepcopy(self._ft_has.get('trades_params', {})) params = deepcopy(self._ft_has.get('trades_params', {}))
candle_limit = self.trades_candle_limit( candle_limit = self.trades_candle_limit(
timeframe, candle_type=candle_type, since_ms=since_ms) timeframe, candle_type=candle_type, since_ms=since_ms)
if candle_type and candle_type != CandleType.SPOT: if candle_type and candle_type != CandleType.SPOT:
@@ -2777,7 +2777,7 @@ class Exchange:
pass pass
return self.loop.run_until_complete(task) return self.loop.run_until_complete(task)
def _download_trades_history(self, def _download_trades_history(self,
pair: str, pair: str,
*, *,
new_pairs_days: int = 30, new_pairs_days: int = 30,

View File

@@ -1,18 +1,10 @@
import logging
from pathlib import Path
import arrow
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import pytest import pytest
from pandas import DataFrame
from freqtrade.configuration import Configuration
from freqtrade.constants import DEFAULT_ORDERFLOW_COLUMNS
from freqtrade.data.converter import populate_dataframe_with_trades, public_trades_to_dataframe from freqtrade.data.converter import populate_dataframe_with_trades, public_trades_to_dataframe
from freqtrade.data.converter.converter import trades_to_volumeprofile_with_total_delta_bid_ask from freqtrade.data.converter.converter import trades_to_volumeprofile_with_total_delta_bid_ask
from freqtrade.enums import CandleType, MarginMode, TradingMode
from freqtrade.exchange.exchange import timeframe_to_minutes
BIN_SIZE_SCALE = 0.5 BIN_SIZE_SCALE = 0.5