Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] develop from freqtrade:develop #1239

Merged
merged 6 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repos:

- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.9.3'
rev: 'v0.9.4'
hooks:
- id: ruff
- id: ruff-format
Expand Down Expand Up @@ -62,7 +62,7 @@ repos:
- id: strip-exif

- repo: https://github.com/codespell-project/codespell
rev: v2.4.0
rev: v2.4.1
hooks:
- id: codespell
additional_dependencies:
Expand Down
26 changes: 14 additions & 12 deletions freqtrade/exchange/binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ def get_historic_ohlcv(
:param candle_type: Any of the enum CandleType (must match trading mode!)
"""
if is_new_pair:
x = self.loop.run_until_complete(
self._async_get_candle_history(pair, timeframe, candle_type, 0)
)
with self._loop_lock:
x = self.loop.run_until_complete(
self._async_get_candle_history(pair, timeframe, candle_type, 0)
)
if x and x[3] and x[3][0] and x[3][0][0] > since_ms:
# Set starting date to first available candle.
since_ms = x[3][0][0]
Expand Down Expand Up @@ -201,16 +202,17 @@ def get_historic_ohlcv_fast(
"""
Fastly fetch OHLCV data by leveraging https://data.binance.vision.
"""
df = self.loop.run_until_complete(
download_archive_ohlcv(
candle_type=candle_type,
pair=pair,
timeframe=timeframe,
since_ms=since_ms,
until_ms=until_ms,
markets=self.markets,
with self._loop_lock:
df = self.loop.run_until_complete(
download_archive_ohlcv(
candle_type=candle_type,
pair=pair,
timeframe=timeframe,
since_ms=since_ms,
until_ms=until_ms,
markets=self.markets,
)
)
)

# download the remaining data from rest API
if df.empty:
Expand Down
20 changes: 11 additions & 9 deletions freqtrade/exchange/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,8 @@ async def _api_reload_markets(self, reload: bool = False) -> dict[str, Any]:

def _load_async_markets(self, reload: bool = False) -> dict[str, Any]:
try:
markets = self.loop.run_until_complete(self._api_reload_markets(reload=reload))
with self._loop_lock:
markets = self.loop.run_until_complete(self._api_reload_markets(reload=reload))

if isinstance(markets, Exception):
raise markets
Expand Down Expand Up @@ -2342,15 +2343,16 @@ def get_historic_ohlcv(
:param until_ms: Timestamp in milliseconds to get history up to
:return: Dataframe with candle (OHLCV) data
"""
pair, _, _, data, _ = self.loop.run_until_complete(
self._async_get_historic_ohlcv(
pair=pair,
timeframe=timeframe,
since_ms=since_ms,
until_ms=until_ms,
candle_type=candle_type,
with self._loop_lock:
pair, _, _, data, _ = self.loop.run_until_complete(
self._async_get_historic_ohlcv(
pair=pair,
timeframe=timeframe,
since_ms=since_ms,
until_ms=until_ms,
candle_type=candle_type,
)
)
)
logger.debug(f"Downloaded data for {pair} from ccxt with length {len(data)}.")
return ohlcv_to_dataframe(data, timeframe, pair, fill_missing=False, drop_incomplete=True)

Expand Down
2 changes: 1 addition & 1 deletion freqtrade/resolvers/exchange_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import freqtrade.exchange as exchanges
from freqtrade.constants import Config, ExchangeConfig
from freqtrade.exchange import MAP_EXCHANGE_CHILDCLASS, Exchange
from freqtrade.resolvers import IResolver
from freqtrade.resolvers.iresolver import IResolver


logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion freqtrade/resolvers/strategy_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from freqtrade.constants import REQUIRED_ORDERTIF, REQUIRED_ORDERTYPES, USERPATH_STRATEGIES, Config
from freqtrade.enums import TradingMode
from freqtrade.exceptions import OperationalException
from freqtrade.resolvers import IResolver
from freqtrade.resolvers.iresolver import IResolver
from freqtrade.strategy.interface import IStrategy


Expand Down
22 changes: 12 additions & 10 deletions freqtrade/rpc/api_server/api_backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,18 @@ def __run_backtest_bg(btconfig: Config):
ApiBG.bt["data"], ApiBG.bt["bt"].all_results, min_date=min_date, max_date=max_date
)

if btconfig.get("export", "none") == "trades":
combined_res = combined_dataframes_with_rel_mean(ApiBG.bt["data"], min_date, max_date)
fn = store_backtest_results(
btconfig,
ApiBG.bt["bt"].results,
datetime.now().strftime("%Y-%m-%d_%H-%M-%S"),
market_change_data=combined_res,
)
ApiBG.bt["bt"].results["metadata"][strategy_name]["filename"] = str(fn.stem)
ApiBG.bt["bt"].results["metadata"][strategy_name]["strategy"] = strategy_name
if btconfig.get("export", "none") == "trades":
combined_res = combined_dataframes_with_rel_mean(
ApiBG.bt["data"], min_date, max_date
)
fn = store_backtest_results(
btconfig,
ApiBG.bt["bt"].results,
datetime.now().strftime("%Y-%m-%d_%H-%M-%S"),
market_change_data=combined_res,
)
ApiBG.bt["bt"].results["metadata"][strategy_name]["filename"] = str(fn.stem)
ApiBG.bt["bt"].results["metadata"][strategy_name]["strategy"] = strategy_name

logger.info("Backtest finished.")

Expand Down
1 change: 1 addition & 0 deletions freqtrade/rpc/api_server/api_pair_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ def pair_history_filtered(payload: PairHistoryRequest, config=Depends(get_config
payload.live_mode,
)
except Exception as e:
logger.exception("Error in pair_history_filtered")
raise HTTPException(status_code=502, detail=str(e))
Loading