Merge pull request #13161 from ducky-duke/fix/historic-balance-bot-managed-bool
fix: /api/v1/historic_balance returns 500 on MySQL/MariaDB backends
This commit is contained in:
@@ -796,7 +796,7 @@ class RPC:
|
|||||||
results = results.rename({"timestamp": "date"}, axis=1)
|
results = results.rename({"timestamp": "date"}, axis=1)
|
||||||
results.loc[:, "__date_ts"] = results.loc[:, "date"].dt.as_unit("ms").astype("int64")
|
results.loc[:, "__date_ts"] = results.loc[:, "date"].dt.as_unit("ms").astype("int64")
|
||||||
# Exclude non-bot managed for now
|
# Exclude non-bot managed for now
|
||||||
results_filtered = results.loc[results["bot_managed"]]
|
results_filtered = results.loc[results["bot_managed"].astype(bool)]
|
||||||
|
|
||||||
results_final = (
|
results_final = (
|
||||||
results_filtered.groupby(["date", "__date_ts"])
|
results_filtered.groupby(["date", "__date_ts"])
|
||||||
|
|||||||
@@ -1471,6 +1471,44 @@ def test_api_historic_balance(botclient, mocker, ticker, fee, markets, is_short)
|
|||||||
assert "total_quote" in resp1["columns"]
|
assert "total_quote" in resp1["columns"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_api_historic_balance_int_bot_managed(botclient, mocker):
|
||||||
|
"""
|
||||||
|
read_sql may return the wallet_history `bot_managed` column as an
|
||||||
|
integer (e.g. MySQL/MariaDB TINYINT)
|
||||||
|
"""
|
||||||
|
_, client = botclient
|
||||||
|
|
||||||
|
# Single row: with an int64 `bot_managed`
|
||||||
|
one_row = pd.DataFrame(
|
||||||
|
{
|
||||||
|
"timestamp": pd.to_datetime(["2024-01-01"]),
|
||||||
|
"total_quote": [100.0],
|
||||||
|
"bot_managed": [1],
|
||||||
|
}
|
||||||
|
).astype({"bot_managed": "int64"})
|
||||||
|
mocker.patch("freqtrade.rpc.rpc.read_sql", return_value=one_row)
|
||||||
|
rc = client_get(client, f"{BASE_URI}/historic_balance")
|
||||||
|
assert_response(rc, 200)
|
||||||
|
assert rc.json()["length"] == 1
|
||||||
|
assert rc.json()["data"][0][0] == "2024-01-01T00:00:00"
|
||||||
|
assert rc.json()["data"][0][2] == 100.0
|
||||||
|
|
||||||
|
# Mixed rows: the non-bot-managed row (bot_managed=0) must be excluded.
|
||||||
|
two_rows = pd.DataFrame(
|
||||||
|
{
|
||||||
|
"timestamp": pd.to_datetime(["2024-01-01", "2024-01-02"]),
|
||||||
|
"total_quote": [100.0, 200.0],
|
||||||
|
"bot_managed": [0, 1],
|
||||||
|
}
|
||||||
|
).astype({"bot_managed": "int64"})
|
||||||
|
mocker.patch("freqtrade.rpc.rpc.read_sql", return_value=two_rows)
|
||||||
|
rc = client_get(client, f"{BASE_URI}/historic_balance")
|
||||||
|
assert_response(rc, 200)
|
||||||
|
assert rc.json()["length"] == 1
|
||||||
|
assert rc.json()["data"][0][0] == "2024-01-02T00:00:00"
|
||||||
|
assert rc.json()["data"][0][2] == 200.0
|
||||||
|
|
||||||
|
|
||||||
def test_api_performance(botclient, fee):
|
def test_api_performance(botclient, fee):
|
||||||
ftbot, client = botclient
|
ftbot, client = botclient
|
||||||
patch_get_signal(ftbot)
|
patch_get_signal(ftbot)
|
||||||
|
|||||||
Reference in New Issue
Block a user