orderflow: fixing typing

This commit is contained in:
Joe Schr
2024-06-26 19:43:13 +02:00
parent 323274ecee
commit dad2cad525
+5 -4
View File
@@ -4,6 +4,7 @@ Functions to convert orderflow data from public_trades
import logging import logging
import time import time
import typing
from collections import OrderedDict from collections import OrderedDict
import numpy as np import numpy as np
@@ -101,7 +102,7 @@ def populate_dataframe_with_trades(config, dataframe, trades):
if is_between.any(): if is_between.any():
from freqtrade.exchange import timeframe_to_next_date from freqtrade.exchange import timeframe_to_next_date
candle_next = timeframe_to_next_date(timeframe, candle_start) candle_next = timeframe_to_next_date(timeframe, typing.cast(datetime, candle_start))
if candle_next not 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 " f"candle at {candle_start} with {len(trades_grouped_df)} trades "
@@ -113,7 +114,7 @@ def populate_dataframe_with_trades(config, dataframe, trades):
trades_series.loc[indices] = [trades_grouped_df] trades_series.loc[indices] = [trades_grouped_df]
# Use caching mechanism # Use caching mechanism
if (candle_start, candle_next) in cached_grouped_trades: if (candle_start, candle_next) in cached_grouped_trades:
cache_entry = cached_grouped_trades[(candle_start, candle_next)] cache_entry = cached_grouped_trades[(typing.cast(datetime, candle_start), candle_next)]
# dataframe.loc[is_between] = cache_entry # doesn't take, so we need workaround: # dataframe.loc[is_between] = cache_entry # doesn't take, so we need workaround:
# Create a dictionary of the column values to be assigned # Create a dictionary of the column values to be assigned
update_dict = {c: cache_entry[c].iat[0] for c in cache_entry.columns} update_dict = {c: cache_entry[c].iat[0] for c in cache_entry.columns}
@@ -169,7 +170,7 @@ def populate_dataframe_with_trades(config, dataframe, trades):
dataframe.loc[indices, "total_trades"] = len(trades_grouped_df) dataframe.loc[indices, "total_trades"] = len(trades_grouped_df)
# Cache the result # Cache the result
cached_grouped_trades[(candle_start, candle_next)] = dataframe.loc[ cached_grouped_trades[(typing.cast(datetime, candle_start), candle_next)] = dataframe.loc[
is_between is_between
].copy() ].copy()
@@ -194,7 +195,7 @@ def populate_dataframe_with_trades(config, dataframe, trades):
return dataframe return dataframe
def trades_to_volumeprofile_with_total_delta_bid_ask(trades: pd.DataFrame, scale: float): def trades_to_volumeprofile_with_total_delta_bid_ask(trades: pd.DataFrame, scale: float) -> pd.DataFrame:
""" """
:param trades: dataframe :param trades: dataframe
:param scale: scale aka bin size e.g. 0.5 :param scale: scale aka bin size e.g. 0.5