mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-09-19 11:15:24 +03:00
fix(dataflows): map crypto to StockTwits/Reddit sentiment symbols
- crypto reached StockTwits as Yahoo's BTC-USD (404) instead of BTC.X, and Reddit searched the dashed pair that barely matches; both now resolve the base via a shared crypto_base() helper, restoring crypto sentiment - also fixes a StockTwits resilience test class that pytest never collected #1113
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
"""StockTwits fetch degrades (never raises) on transport errors, including the
|
||||
http.client chunked-transfer exceptions that are not OSErrors (#1024)."""
|
||||
"""StockTwits fetch: transport-error resilience (#1024) and crypto symbol
|
||||
mapping (#1113).
|
||||
|
||||
StockTwits lists crypto under ``<BASE>.X`` (Yahoo's ``BTC-USD`` 404s), and any
|
||||
transport error must degrade to a placeholder rather than raise.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -26,7 +30,7 @@ def _raise(exc):
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
class StockTwitsResilienceTests:
|
||||
class TestStockTwitsResilience:
|
||||
@pytest.mark.parametrize(
|
||||
"exc",
|
||||
[
|
||||
@@ -40,3 +44,34 @@ class StockTwitsResilienceTests:
|
||||
out = stocktwits.fetch_stocktwits_messages("NVDA")
|
||||
assert "unavailable" in out.lower()
|
||||
assert out.startswith("<stocktwits unavailable")
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
class TestStockTwitsCryptoSymbols:
|
||||
@pytest.mark.parametrize(
|
||||
("ticker", "expected"),
|
||||
[
|
||||
("BTC-USD", "BTC.X"),
|
||||
("eth-usd", "ETH.X"),
|
||||
("SOL-USD", "SOL.X"),
|
||||
("BTCUSD", "BTC.X"), # undashed broker form
|
||||
("BTC-USDT", "BTC.X"), # stablecoin quote
|
||||
("AMD", "AMD"),
|
||||
("BRK-B", "BRK-B"), # dashed class share: untouched
|
||||
("GOLD", "GOLD"), # real equity (aliases elsewhere): untouched here
|
||||
("XYZ-USD", "XYZ-USD"), # unknown base: not treated as crypto
|
||||
],
|
||||
)
|
||||
def test_symbol_mapping(self, ticker, expected):
|
||||
assert stocktwits._stocktwits_symbol(ticker) == expected
|
||||
|
||||
def test_crypto_pair_requests_dot_x_endpoint(self):
|
||||
seen = {}
|
||||
|
||||
def fake_urlopen(req, timeout=None):
|
||||
seen["url"] = req.full_url
|
||||
raise TimeoutError("stop after capturing the URL")
|
||||
|
||||
with patch.object(stocktwits, "urlopen", side_effect=fake_urlopen):
|
||||
stocktwits.fetch_stocktwits_messages("BTC-USD")
|
||||
assert "/symbol/BTC.X.json" in seen["url"]
|
||||
|
||||
Reference in New Issue
Block a user