Extract global cached_grouped_trades_per_pair into IStrategy

This commit is contained in:
Joe Schr
2024-07-04 17:12:30 +02:00
parent e5221bded7
commit 3486327e78
3 changed files with 38 additions and 32 deletions

View File

@@ -1,3 +1,5 @@
from collections import OrderedDict
import numpy as np
import pandas as pd
import pytest
@@ -47,15 +49,6 @@ def public_trades_list_simple(testdatadir):
return read_csv(testdatadir / "orderflow/public_trades_list_simple_example.csv").copy()
@pytest.fixture
def reset_cache(request):
import freqtrade.data.converter.orderflow as orderflow
global orderflow # noqa F811
orderflow.cached_grouped_trades_per_pair = {}
yield
def test_public_trades_columns_before_change(
populate_dataframe_with_trades_dataframe, populate_dataframe_with_trades_trades
):
@@ -80,7 +73,7 @@ def test_public_trades_columns_before_change(
def test_public_trades_mock_populate_dataframe_with_trades__check_orderflow(
reset_cache, populate_dataframe_with_trades_dataframe, populate_dataframe_with_trades_trades
populate_dataframe_with_trades_dataframe, populate_dataframe_with_trades_trades
):
"""
Tests the `populate_dataframe_with_trades` function's order flow calculation.
@@ -108,7 +101,7 @@ def test_public_trades_mock_populate_dataframe_with_trades__check_orderflow(
},
}
# Apply the function to populate the data frame with order flow data
df = populate_dataframe_with_trades("BTC/UDST", config, dataframe, trades)
df, _ = populate_dataframe_with_trades(OrderedDict(), config, dataframe, trades)
# Extract results from the first row of the DataFrame
results = df.iloc[0]
t = results["trades"]
@@ -179,7 +172,7 @@ def test_public_trades_mock_populate_dataframe_with_trades__check_orderflow(
def test_public_trades_trades_mock_populate_dataframe_with_trades__check_trades(
reset_cache, populate_dataframe_with_trades_dataframe, populate_dataframe_with_trades_trades
populate_dataframe_with_trades_dataframe, populate_dataframe_with_trades_trades
):
"""
Tests the `populate_dataframe_with_trades` function's handling of trades,
@@ -221,7 +214,7 @@ def test_public_trades_trades_mock_populate_dataframe_with_trades__check_trades(
}
# Populate the DataFrame with trades and order flow data
df = populate_dataframe_with_trades("BTC/UDST", config, dataframe, trades)
df, _ = populate_dataframe_with_trades(OrderedDict(), config, dataframe, trades)
# --- DataFrame and Trade Data Validation ---
@@ -387,8 +380,8 @@ def test_public_trades_config_max_trades(
},
}
df = populate_dataframe_with_trades(
"BTC/UDST", default_conf | orderflow_config, dataframe, trades
df, _ = populate_dataframe_with_trades(
OrderedDict(), default_conf | orderflow_config, dataframe, trades
)
assert df.delta.count() == 1