mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-12-03 14:36:30 +02:00
fix(yahoo): print prices with their significant digits (#1567)
- the price table and the verified snapshot keep six significant digits and at least two decimals, so a sub-cent close is no longer 0.00 and a currency pair keeps its pips
This commit is contained in:
@@ -73,3 +73,47 @@ class TestTool:
|
||||
{"symbol": "COF", "curr_date": "2026-05-20"}
|
||||
)
|
||||
assert "Verified market data snapshot for COF" in out
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
class TestPricesKeepTheirDigits:
|
||||
"""A price prints with its significant digits: a sub-cent coin is not 0.00, a rate keeps its pips."""
|
||||
|
||||
@pytest.mark.parametrize("value, text", [
|
||||
(0.00000503123456, "0.00000503123"),
|
||||
(1.123456, "1.12346"),
|
||||
(763.960022, "763.96"),
|
||||
(81074.1875, "81074.19"),
|
||||
(100.0, "100.00"),
|
||||
(-0.0012345678, "-0.00123457"),
|
||||
(0.0, "0.00"),
|
||||
])
|
||||
def test_price_text(self, value, text):
|
||||
from tradingagents.dataflows.vendors.yahoo.common import price_text
|
||||
assert price_text(value) == text
|
||||
|
||||
def test_the_snapshot_shows_a_sub_cent_close(self, monkeypatch):
|
||||
data = _sample_ohlcv()
|
||||
for col in ("Open", "High", "Low", "Close"):
|
||||
data[col] = data[col] * 0.0000001
|
||||
monkeypatch.setattr(validator, "load_ohlcv", lambda s, d, fill_gaps=True: data)
|
||||
text = validator.build_verified_market_snapshot("SHIB-USD", "2026-05-20")
|
||||
assert "| Close | 0.0000135 |" in text and "| Close | 0.00 |" not in text
|
||||
|
||||
def test_the_price_table_shows_a_sub_cent_close(self, monkeypatch):
|
||||
from tradingagents.dataflows.vendors.yahoo import market
|
||||
|
||||
days = pd.bdate_range("2026-05-11", "2026-05-15")
|
||||
frame = pd.DataFrame({"Open": 0.00000501, "High": 0.00000512, "Low": 0.00000499,
|
||||
"Close": 0.00000503, "Volume": 10**9}, index=days)
|
||||
|
||||
class _Ticker:
|
||||
def __init__(self, symbol):
|
||||
pass
|
||||
|
||||
def history(self, **kwargs):
|
||||
return frame
|
||||
|
||||
monkeypatch.setattr(market.yf, "Ticker", _Ticker)
|
||||
text = market.get_YFin_data_online("SHIB-USD", "2026-05-11", "2026-05-15")
|
||||
assert "0.00000503" in text and ",0.0," not in text
|
||||
|
||||
Reference in New Issue
Block a user