mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 00:23:07 +00:00
test: Add comprehensive test for stacked_imbalances with multiple price entries
This commit is contained in:
@@ -7,6 +7,7 @@ from freqtrade.data.converter.orderflow import (
|
||||
ORDERFLOW_ADDED_COLUMNS,
|
||||
timeframe_to_DateOffset,
|
||||
trades_to_volumeprofile_with_total_delta_bid_ask,
|
||||
stacked_imbalance,
|
||||
)
|
||||
from freqtrade.data.converter.trade_converter import trades_list_to_df
|
||||
from freqtrade.data.dataprovider import DataProvider
|
||||
@@ -569,6 +570,41 @@ def test_analyze_with_orderflow(
|
||||
assert isinstance(lastval_of2, dict)
|
||||
|
||||
|
||||
def test_stacked_imbalances_multiple_prices():
|
||||
"""Test that stacked imbalances correctly returns multiple price levels when present"""
|
||||
# Test with empty result
|
||||
df_no_stacks = pd.DataFrame(
|
||||
{
|
||||
'bid_imbalance': [False, False, True, False],
|
||||
'ask_imbalance': [False, True, False, False]
|
||||
},
|
||||
index=[234.95, 234.96, 234.97, 234.98]
|
||||
)
|
||||
no_stacks = stacked_imbalance(df_no_stacks, "bid", stacked_imbalance_range=2, should_reverse=False)
|
||||
assert no_stacks == [np.nan]
|
||||
|
||||
# Create a sample DataFrame with known imbalances
|
||||
df = pd.DataFrame(
|
||||
{
|
||||
'bid_imbalance': [True, True, True, False, False, True, True, False],
|
||||
'ask_imbalance': [False, False, True, True, True, False, False, True]
|
||||
},
|
||||
index=[234.95, 234.96, 234.97, 234.98, 234.99, 235.00, 235.01, 235.02]
|
||||
)
|
||||
# Test bid imbalances (should return prices in ascending order)
|
||||
bid_prices = stacked_imbalance(df, "bid", stacked_imbalance_range=2, should_reverse=False)
|
||||
assert bid_prices == [234.95, 234.96, 234.97, 235.00, 235.01]
|
||||
|
||||
# Test ask imbalances (should return prices in descending order)
|
||||
ask_prices = stacked_imbalance(df, "ask", stacked_imbalance_range=2, should_reverse=True)
|
||||
assert ask_prices == [235.02, 234.99, 234.98, 234.97]
|
||||
|
||||
# Test with higher stacked_imbalance_range
|
||||
bid_prices_higher = stacked_imbalance(df, "bid", stacked_imbalance_range=3, should_reverse=False)
|
||||
assert bid_prices_higher == [234.95, 234.96, 234.97]
|
||||
|
||||
|
||||
|
||||
def test_timeframe_to_DateOffset():
|
||||
assert timeframe_to_DateOffset("1s") == pd.DateOffset(seconds=1)
|
||||
assert timeframe_to_DateOffset("1m") == pd.DateOffset(minutes=1)
|
||||
|
||||
Reference in New Issue
Block a user