Fix opportunity ignore_dust handling
This commit is contained in:
@@ -100,6 +100,39 @@ class FakeSpotClient:
|
||||
return rows
|
||||
|
||||
|
||||
class DustOverlapSpotClient(FakeSpotClient):
|
||||
def account_info(self):
|
||||
return {"balances": [{"asset": "XRP", "free": "5", "locked": "0"}]}
|
||||
|
||||
def ticker_price(self, symbols=None):
|
||||
mapping = {"XRPUSDT": {"symbol": "XRPUSDT", "price": "1.5"}}
|
||||
return [mapping[symbol] for symbol in symbols]
|
||||
|
||||
def ticker_stats(self, symbols=None, *, window="1d"):
|
||||
rows = {
|
||||
"XRPUSDT": {
|
||||
"symbol": "XRPUSDT",
|
||||
"lastPrice": "1.5",
|
||||
"priceChangePercent": "10",
|
||||
"quoteVolume": "5000000",
|
||||
"highPrice": "1.52",
|
||||
"lowPrice": "1.2",
|
||||
}
|
||||
}
|
||||
if not symbols:
|
||||
return list(rows.values())
|
||||
return [rows[symbol] for symbol in symbols]
|
||||
|
||||
def exchange_info(self):
|
||||
return {"symbols": [{"symbol": "XRPUSDT", "status": "TRADING"}]}
|
||||
|
||||
def klines(self, symbol, interval, limit):
|
||||
rows = []
|
||||
for index, close in enumerate([1.0, 1.1, 1.2, 1.3, 1.4, 1.45, 1.5][-limit:]):
|
||||
rows.append([index, close * 0.98, close * 1.01, close * 0.97, close, 100 + index * 10, index + 1, close * 100])
|
||||
return rows
|
||||
|
||||
|
||||
class OpportunityServiceTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.config = {
|
||||
@@ -149,6 +182,31 @@ class OpportunityServiceTestCase(unittest.TestCase):
|
||||
self.assertEqual([item["symbol"] for item in payload["recommendations"]], ["SOLUSDT", "BTCUSDT"])
|
||||
self.assertEqual([item["action"] for item in payload["recommendations"]], ["enter", "enter"])
|
||||
|
||||
def test_scan_respects_ignore_dust_for_overlap_penalty(self):
|
||||
client = DustOverlapSpotClient()
|
||||
base_config = self.config | {
|
||||
"opportunity": self.config["opportunity"] | {
|
||||
"top_n": 1,
|
||||
"ignore_dust": True,
|
||||
"overlap_penalty": 2.0,
|
||||
}
|
||||
}
|
||||
with patch.object(opportunity_service, "audit_event", return_value=None):
|
||||
ignored = opportunity_service.scan_opportunities(base_config, spot_client=client, symbols=["XRPUSDT"])
|
||||
included = opportunity_service.scan_opportunities(
|
||||
base_config | {"opportunity": base_config["opportunity"] | {"ignore_dust": False}},
|
||||
spot_client=client,
|
||||
symbols=["XRPUSDT"],
|
||||
)
|
||||
ignored_rec = ignored["recommendations"][0]
|
||||
included_rec = included["recommendations"][0]
|
||||
|
||||
self.assertEqual(ignored_rec["action"], "enter")
|
||||
self.assertEqual(ignored_rec["metrics"]["position_weight"], 0.0)
|
||||
self.assertEqual(included_rec["action"], "skip")
|
||||
self.assertEqual(included_rec["metrics"]["position_weight"], 1.0)
|
||||
self.assertLess(included_rec["score"], ignored_rec["score"])
|
||||
|
||||
def test_signal_score_handles_empty_klines(self):
|
||||
score, metrics = signal_service.score_market_signal([], [], {"price_change_pct": 1.0}, {})
|
||||
self.assertEqual(score, 0.0)
|
||||
|
||||
Reference in New Issue
Block a user