50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
import os
|
||
import sys
|
||
|
||
PROJECT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||
if PROJECT_DIR not in sys.path:
|
||
sys.path.insert(0, PROJECT_DIR)
|
||
|
||
from app.db import altcoin_db
|
||
from legacy import price_tracker_ws
|
||
|
||
|
||
def test_terminal_recommendation_action_status_cannot_be_overwritten_by_entry_signal(monkeypatch, tmp_path):
|
||
db_path = tmp_path / "altcoin_monitor.db"
|
||
monkeypatch.setattr(altcoin_db, "DB_PATH", str(db_path))
|
||
altcoin_db.init_db()
|
||
|
||
rec_id = altcoin_db.create_recommendation(
|
||
symbol="NOT/USDT",
|
||
rec_state="爆发",
|
||
rec_score=10,
|
||
entry_price=0.000619,
|
||
stop_loss=0.000521,
|
||
tp1=0.000684,
|
||
tp2=0.000726,
|
||
entry_plan={"entry_action": "等回踩", "entry_price": 0.000628},
|
||
)
|
||
altcoin_db.update_recommendation_tracking(rec_id, 0.000685)
|
||
|
||
# 即使后续动态入场逻辑误传“可即刻买入”,DB 层也必须保持止盈状态。
|
||
altcoin_db.update_recommendation_action_status(rec_id, "可即刻买入")
|
||
|
||
rows = altcoin_db.get_all_recommendations(limit=10)
|
||
rec = next(r for r in rows if r["id"] == rec_id)
|
||
assert rec["status"] == "hit_tp1"
|
||
assert rec["action_status"] == "止盈1"
|
||
assert rec["execution_status"] == "completed"
|
||
|
||
|
||
def test_ws_tracker_does_not_emit_entry_signal_for_closed_recommendation():
|
||
rec = {
|
||
"status": "hit_tp1",
|
||
"entry_price": 0.000619,
|
||
"stop_loss": 0.000521,
|
||
"tp1": 0.000684,
|
||
"tp2": 0.000726,
|
||
"entry_plan": {"entry_action": "等回踩", "entry_price": 0.000628},
|
||
"action_status": "止盈1",
|
||
}
|
||
assert price_tracker_ws.check_triggers("NOT/USDT", rec, 0.000628) is None
|