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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user