From 82b0acd5f1f303906e072563093b1aea20a83e91 Mon Sep 17 00:00:00 2001 From: jaxperro Date: Thu, 9 Jul 2026 00:31:08 -0400 Subject: [PATCH] preflight: walk recent trades for a live book; auto_redeem off until the EOA is gassed Co-Authored-By: Claude Fable 5 --- config.live.example.json | 2 +- preflight_live.py | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/config.live.example.json b/config.live.example.json index 9cf81932..61aa6a4b 100644 --- a/config.live.example.json +++ b/config.live.example.json @@ -41,7 +41,7 @@ "funder_address": "", "signature_type": 1, "order_type": "FAK", - "auto_redeem": true, + "auto_redeem": false, "rpc_url": "" }, "stake_cap_usd": 24.73, diff --git a/preflight_live.py b/preflight_live.py index 568fd6fe..6eb296b8 100644 --- a/preflight_live.py +++ b/preflight_live.py @@ -84,18 +84,30 @@ def main(): check("USDC balance on funder", balance) def book(): + # a sharp's LATEST trade is often an in-play market that has already + # closed (404 = "no orderbook", which itself proves connectivity) — + # walk recent trades until one still has a live book req = urllib.request.Request( "https://data-api.polymarket.com/activity?user=" - + cfg["watchlist"][0] + "&type=TRADE&limit=1", + + cfg["watchlist"][0] + "&type=TRADE&limit=15", headers={"User-Agent": "Mozilla/5.0"}) - t = json.loads(urllib.request.urlopen(req, timeout=15, context=_SSL).read())[0] - ob = client.get_order_book(t["asset"]) - bid = ob.bids[-1].price if ob.bids else "—" - ask = ob.asks[-1].price if ob.asks else "—" - return f"{(t.get('title') or '')[:40]}… bid {bid} / ask {ask}" + trades = json.loads(urllib.request.urlopen(req, timeout=15, context=_SSL).read()) + last = None + for t in trades: + try: + ob = client.get_order_book(t["asset"]) + except Exception as e: + last = e + continue + bid = ob.bids[-1].price if ob.bids else "—" + ask = ob.asks[-1].price if ob.asks else "—" + return f"{(t.get('title') or '')[:40]}… bid {bid} / ask {ask}" + raise RuntimeError(f"no live book among the wallet's last {len(trades)} trades ({last})") check("order book fetch (market access)", book) def gas(): + if live.get("auto_redeem") is False: + return "auto_redeem OFF — manual UI redeems; no POL needed (CASH≠CHAIN will nag after wins until redeemed)" from web3 import Web3 rpc = live.get("rpc_url") or ( f"https://polygon-mainnet.g.alchemy.com/v2/{cfg.get('alchemy_key')}"