Add futures_quote tool: CBOT price + change since open + on day

New futures_quote(commodity, delivery?) tool wraps the new /api/data/futures
endpoint: reports latest price, today's session open, prior settle, and both
moves (since open and on the day). With a delivery month it resolves the listed
contract; without it, the continuous nearby. Adds client.futures(), fmt_futures(),
tests, and a CHANGELOG entry.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-29 15:36:56 -04:00
parent 61c1736539
commit 0c9bc3b328
6 changed files with 159 additions and 0 deletions
+23
View File
@@ -71,6 +71,29 @@ def test_get_drops_none_params(monkeypatch):
assert captured["params"] == {"commodity": "corn"}
def test_futures_endpoint_params(monkeypatch):
client = _reload_client(monkeypatch)
captured = {}
class FakeResp:
status_code = 200
text = ""
def json(self): return {"quote": None}
def fake_get(url, params=None, timeout=None, headers=None):
captured["url"] = url
captured["params"] = dict(params or {})
return FakeResp()
monkeypatch.setattr(client.httpx, "get", fake_get)
client.futures(commodity="corn", delivery="Jul 2026")
assert captured["url"].endswith("/api/data/futures")
assert captured["params"] == {"commodity": "corn", "delivery": "Jul 2026"}
# delivery omitted → dropped
client.futures(commodity="corn")
assert captured["params"] == {"commodity": "corn"}
def test_history_without_commodity_drops_param(monkeypatch):
client = _reload_client(monkeypatch)
captured = {}
+40
View File
@@ -35,6 +35,46 @@ def test_fmt_best_no_winner():
assert "wheat" in out
def test_fmt_futures_with_changes():
payload = {
"commodity": "corn", "delivery": "Jul 2026", "contract": "ZCN26",
"symbol": "ZC",
"quote": {
"settle_date": "2026-05-29", "open_cents": 461, "last_cents": 455,
"prev_close_cents": 460, "change_since_open_cents": -6,
"change_on_day_cents": -5, "fetched_at": "2026-05-29T18:00:00+00:00",
},
}
out = fmt.fmt_futures(payload)
assert "ZCN26" in out and "Jul 2026" in out
assert "$4.5500" in out # last
assert "$4.6100" in out # open
assert "▼ -0.06" in out # change since open
assert "▼ -0.05" in out # change on day
def test_fmt_futures_no_open_yet():
payload = {
"commodity": "soy", "delivery": None, "contract": "continuous",
"symbol": "ZS=F",
"quote": {
"settle_date": "2026-05-29", "open_cents": None, "last_cents": 1180,
"prev_close_cents": 1177, "change_since_open_cents": None,
"change_on_day_cents": 3, "fetched_at": "2026-05-29T18:00:00+00:00",
},
}
out = fmt.fmt_futures(payload)
assert "continuous nearby" in out
assert "no open captured yet" in out
assert "▲ +0.03" in out # change on day still shown
def test_fmt_futures_no_quote():
out = fmt.fmt_futures({"commodity": "wheat", "delivery": None,
"contract": "continuous", "quote": None})
assert "No futures quote on file" in out
def test_fmt_inputs_lime_table():
payload = {
"product": "lime", "count": 2,