chore: improve naming, don't duplicate column list
This commit is contained in:
@@ -15,7 +15,7 @@ from freqtrade.exceptions import DependencyException
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
ADDED_COLUMNS = [
|
ORDERFLOW_ADDED_COLUMNS = [
|
||||||
"trades",
|
"trades",
|
||||||
"orderflow",
|
"orderflow",
|
||||||
"imbalances",
|
"imbalances",
|
||||||
@@ -36,7 +36,7 @@ def _init_dataframe_with_trades_columns(dataframe: pd.DataFrame):
|
|||||||
:param dataframe: Dataframe to populate
|
:param dataframe: Dataframe to populate
|
||||||
"""
|
"""
|
||||||
# Initialize columns with appropriate dtypes
|
# Initialize columns with appropriate dtypes
|
||||||
for column in ADDED_COLUMNS:
|
for column in ORDERFLOW_ADDED_COLUMNS:
|
||||||
dataframe[column] = np.nan
|
dataframe[column] = np.nan
|
||||||
|
|
||||||
# Set columns to object type
|
# Set columns to object type
|
||||||
@@ -115,7 +115,7 @@ def populate_dataframe_with_trades(
|
|||||||
cache_idx = cached_grouped_trades.index[
|
cache_idx = cached_grouped_trades.index[
|
||||||
cached_grouped_trades["date"] == candle_start
|
cached_grouped_trades["date"] == candle_start
|
||||||
][0]
|
][0]
|
||||||
for col in ADDED_COLUMNS:
|
for col in ORDERFLOW_ADDED_COLUMNS:
|
||||||
dataframe.at[index, col] = cached_grouped_trades.at[cache_idx, col]
|
dataframe.at[index, col] = cached_grouped_trades.at[cache_idx, col]
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import pytest
|
|||||||
|
|
||||||
from freqtrade.constants import DEFAULT_TRADES_COLUMNS
|
from freqtrade.constants import DEFAULT_TRADES_COLUMNS
|
||||||
from freqtrade.data.converter import populate_dataframe_with_trades
|
from freqtrade.data.converter import populate_dataframe_with_trades
|
||||||
from freqtrade.data.converter.orderflow import trades_to_volumeprofile_with_total_delta_bid_ask
|
from freqtrade.data.converter.orderflow import (
|
||||||
|
ORDERFLOW_ADDED_COLUMNS,
|
||||||
|
trades_to_volumeprofile_with_total_delta_bid_ask,
|
||||||
|
)
|
||||||
from freqtrade.data.converter.trade_converter import trades_list_to_df
|
from freqtrade.data.converter.trade_converter import trades_list_to_df
|
||||||
from freqtrade.data.dataprovider import DataProvider
|
from freqtrade.data.dataprovider import DataProvider
|
||||||
from tests.strategy.strats.strategy_test_v3 import StrategyTestV3
|
from tests.strategy.strats.strategy_test_v3 import StrategyTestV3
|
||||||
@@ -505,21 +508,8 @@ def test_analyze_with_orderflow(
|
|||||||
assert "open" in df.columns
|
assert "open" in df.columns
|
||||||
assert spy.call_count == 0
|
assert spy.call_count == 0
|
||||||
|
|
||||||
expected_cols = [
|
|
||||||
"trades",
|
|
||||||
"orderflow",
|
|
||||||
"imbalances",
|
|
||||||
"stacked_imbalances_bid",
|
|
||||||
"stacked_imbalances_ask",
|
|
||||||
"max_delta",
|
|
||||||
"min_delta",
|
|
||||||
"bid",
|
|
||||||
"ask",
|
|
||||||
"delta",
|
|
||||||
"total_trades",
|
|
||||||
]
|
|
||||||
# Not expected to run - shouldn't have added orderflow columns
|
# Not expected to run - shouldn't have added orderflow columns
|
||||||
for col in expected_cols:
|
for col in ORDERFLOW_ADDED_COLUMNS:
|
||||||
assert col not in df.columns, f"Column {col} found in df.columns"
|
assert col not in df.columns, f"Column {col} found in df.columns"
|
||||||
|
|
||||||
default_conf_usdt["exchange"]["use_public_trades"] = True
|
default_conf_usdt["exchange"]["use_public_trades"] = True
|
||||||
@@ -539,7 +529,7 @@ def test_analyze_with_orderflow(
|
|||||||
assert "open" in df1.columns
|
assert "open" in df1.columns
|
||||||
assert spy.call_count == 5
|
assert spy.call_count == 5
|
||||||
|
|
||||||
for col in expected_cols:
|
for col in ORDERFLOW_ADDED_COLUMNS:
|
||||||
assert col in df1.columns, f"Column {col} not found in df.columns"
|
assert col in df1.columns, f"Column {col} not found in df.columns"
|
||||||
|
|
||||||
if col not in ("stacked_imbalances_bid", "stacked_imbalances_ask"):
|
if col not in ("stacked_imbalances_bid", "stacked_imbalances_ask"):
|
||||||
@@ -560,7 +550,7 @@ def test_analyze_with_orderflow(
|
|||||||
assert len(df2) == len(ohlcv_history)
|
assert len(df2) == len(ohlcv_history)
|
||||||
assert "open" in df2.columns
|
assert "open" in df2.columns
|
||||||
assert spy.call_count == 0
|
assert spy.call_count == 0
|
||||||
for col in expected_cols:
|
for col in ORDERFLOW_ADDED_COLUMNS:
|
||||||
assert col in df2.columns, f"Round2: Column {col} not found in df.columns"
|
assert col in df2.columns, f"Round2: Column {col} not found in df.columns"
|
||||||
|
|
||||||
if col not in ("stacked_imbalances_bid", "stacked_imbalances_ask"):
|
if col not in ("stacked_imbalances_bid", "stacked_imbalances_ask"):
|
||||||
|
|||||||
Reference in New Issue
Block a user