Fix options review empty lists when search box has symbol text.

Treat the filter as fuzzy q over underlying/inst/strategy (BTCUSDT->BTC) instead of exact strategy_tag, which always wiped pending rows.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-19 16:17:45 +08:00
parent 426afb8dbe
commit 12574ae88a
5 changed files with 87 additions and 7 deletions
+41
View File
@@ -337,6 +337,47 @@ class OptionsReviewTests(unittest.TestCase):
self.assertEqual(stats["by_strategy"][0]["key"], "假破")
self.assertEqual(stats["kpi"]["total"], 2)
def test_q_search_btcusdt_matches_btc_pending(self):
from lib.options.options_review_lib import count_review_trades
conn = _conn()
upsert_option_history_row(
conn,
{
"history_key": "ex:btc1",
"inst_id": "BTC-USD-260328-90000-C",
"underlying": "BTC",
"opt_type": "C",
"realized_pnl": 1.2,
"created_at": "2026-01-01 00:00:00",
"closed_at": "2026-01-01 02:00:00",
},
)
upsert_option_history_row(
conn,
{
"history_key": "ex:eth1",
"inst_id": "ETH-USD-260328-2000-C",
"underlying": "ETH",
"opt_type": "C",
"realized_pnl": 2.0,
"created_at": "2026-01-01 00:00:00",
"closed_at": "2026-01-01 03:00:00",
},
)
# 旧精确 strategy_tag 会把待复盘滤成空
self.assertEqual(
count_review_trades(conn, strategy_tag="BTCUSDT", reviewed="0"),
0,
)
self.assertEqual(
count_review_trades(conn, q="BTCUSDT", reviewed="0"),
1,
)
rows = list_review_trades(conn, q="BTCUSDT", reviewed="0")
self.assertEqual(len(rows), 1)
self.assertEqual(rows[0]["underlying"], "BTC")
if __name__ == "__main__":
unittest.main()