chore: drop candle_start and candle_end from trades and add test asserting trades columns

This commit is contained in:
Joe Schr 2024-07-17 14:13:47 +02:00
parent 4cd75c9753
commit 9eb5993833
2 changed files with 6 additions and 2 deletions

View File

@ -115,7 +115,11 @@ def populate_dataframe_with_trades(
indices = dataframe.index[is_between].tolist()
# Add trades to each candle
trades_series.loc[indices] = [trades_grouped_df.to_dict(orient="records")]
trades_series.loc[indices] = [
trades_grouped_df.drop(columns=["candle_start", "candle_end"]).to_dict(
orient="records"
)
]
# Use caching mechanism
if (candle_start, candle_next) in cached_grouped_trades:
cache_entry = cached_grouped_trades[
@ -191,7 +195,6 @@ def populate_dataframe_with_trades(
logger.debug(f"trades.groups_keys in {time.time() - start_time} seconds")
# Merge the complex data Series back into the DataFrame
# TODO: maybe candle_start and candle_end should be dropped before assignment?
dataframe["trades"] = trades_series
dataframe["orderflow"] = orderflow_series
dataframe["imbalances"] = imbalances_series

View File

@ -279,6 +279,7 @@ def test_public_trades_trades_mock_populate_dataframe_with_trades__check_trades(
# Assert specific details of the first trade
t = row["trades"][0]
assert list(t.keys()) == ["timestamp", "id", "type", "side", "price", "amount", "cost", "date"]
assert trades["id"][0] == t["id"]
assert int(trades["timestamp"][0]) == int(t["timestamp"])
assert t["side"] == "sell"