chore: drop candle_start and candle_end from trades and add test asserting trades columns
This commit is contained in:
@@ -115,7 +115,11 @@ def populate_dataframe_with_trades(
|
|||||||
|
|
||||||
indices = dataframe.index[is_between].tolist()
|
indices = dataframe.index[is_between].tolist()
|
||||||
# Add trades to each candle
|
# 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
|
# 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[
|
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")
|
logger.debug(f"trades.groups_keys in {time.time() - start_time} seconds")
|
||||||
|
|
||||||
# Merge the complex data Series back into the DataFrame
|
# 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["trades"] = trades_series
|
||||||
dataframe["orderflow"] = orderflow_series
|
dataframe["orderflow"] = orderflow_series
|
||||||
dataframe["imbalances"] = imbalances_series
|
dataframe["imbalances"] = imbalances_series
|
||||||
|
|||||||
@@ -279,6 +279,7 @@ def test_public_trades_trades_mock_populate_dataframe_with_trades__check_trades(
|
|||||||
|
|
||||||
# Assert specific details of the first trade
|
# Assert specific details of the first trade
|
||||||
t = row["trades"][0]
|
t = row["trades"][0]
|
||||||
|
assert list(t.keys()) == ["timestamp", "id", "type", "side", "price", "amount", "cost", "date"]
|
||||||
assert trades["id"][0] == t["id"]
|
assert trades["id"][0] == t["id"]
|
||||||
assert int(trades["timestamp"][0]) == int(t["timestamp"])
|
assert int(trades["timestamp"][0]) == int(t["timestamp"])
|
||||||
assert t["side"] == "sell"
|
assert t["side"] == "sell"
|
||||||
|
|||||||
Reference in New Issue
Block a user