feat: archive entry type from review, prune stale trades on sync, manual delete

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-08 12:39:27 +08:00
parent e68e29629e
commit 46963a4498
7 changed files with 260 additions and 19 deletions
+26
View File
@@ -9,6 +9,7 @@ from hub_ohlcv_lib import aggregate_ohlcv_bars
from hub_symbol_archive_lib import (
_fill_missing_bars,
init_db,
load_symbol_trades,
resolve_archive_chart,
upsert_bars_5m,
upsert_trade_overlay,
@@ -134,6 +135,31 @@ def test_resolve_archive_chart_history_range():
assert len(out["candles"]) >= 40
def test_sync_prunes_missing_trades():
with tempfile.TemporaryDirectory() as td:
db = Path(td) / "archive.db"
init_db(db)
upsert_trades_cache(
"gate",
[
{"id": 1, "symbol": "BNB/USDT", "result": "止损", "pnl_amount": -1},
{"id": 2, "symbol": "BNB/USDT", "result": "止盈", "pnl_amount": 1},
],
db_path=db,
prune_missing=False,
)
stats = upsert_trades_cache(
"gate",
[{"id": 1, "symbol": "BNB/USDT", "result": "止损", "pnl_amount": -1}],
db_path=db,
prune_missing=True,
)
rows = load_symbol_trades("gate", "BNB/USDT", db_path=db)
assert len(rows) == 1
assert rows[0]["trade_id"] == 1
assert stats["removed"] == 1
def test_list_with_overlay_filters():
with tempfile.TemporaryDirectory() as td:
db = Path(td) / "archive.db"
+15 -1
View File
@@ -8,10 +8,24 @@ from datetime import datetime, timedelta
from pathlib import Path
from hub_symbol_archive_lib import init_db, load_symbol_trades, upsert_trades_cache
from hub_trades_lib import _normalize_archive_trade_row, effective_entry_type, effective_hold_minutes
from hub_trades_lib import (
_normalize_archive_trade_row,
display_entry_type_label,
effective_entry_type,
effective_hold_minutes,
)
class TestHubTradesReviewFields(unittest.TestCase):
def test_display_entry_type_for_manual_monitor_review(self):
d = {
"monitor_type": "下单监控",
"entry_reason": "",
"reviewed_entry_reason": "突破回踩",
"reviewed_at": "2026-06-08 10:00:00",
}
self.assertEqual(display_entry_type_label(d), "突破回踩")
def test_effective_entry_type_prefers_reviewed(self):
d = {
"entry_reason": "突破回踩",