From 418d56aafa4dd2cf1dbd8bb23ab3259e53489d49 Mon Sep 17 00:00:00 2001 From: John Doe Date: Sat, 18 Apr 2026 20:44:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20remove=20balance=20guard=20in=20bet=5Fsi?= =?UTF-8?q?ze=20and=20place=5Fbuy=5Forder=20=E2=80=94=20execute=20on=20sig?= =?UTF-8?q?nal=20regardless=20of=20balance=20for=20full=20pipeline=20consi?= =?UTF-8?q?stency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_v3.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/bot_v3.py b/bot_v3.py index c54d8f6..4a1ec71 100644 --- a/bot_v3.py +++ b/bot_v3.py @@ -104,8 +104,9 @@ def calc_kelly(p, price): f = (p * b - (1.0 - p)) / b return round(min(max(0.0, f) * KELLY_FRAC, 1.0), 4) -def bet_size(kelly, balance): - raw = kelly * balance +def bet_size(kelly): + """Calculate bet size from Kelly fraction. Always uses MAX_BET as cap for consistency.""" + raw = kelly * MAX_BET return round(min(raw, MAX_BET), 2) # ============================================================================= @@ -582,16 +583,15 @@ def ensure_approvals(): # ============================================================================= def place_buy_order(market_id: str, token_id: str, price: float, shares: float, - balance: float, private_key: str, wallet: str) -> dict: + private_key: str, wallet: str) -> dict: """ Place a BUY order on Polymarket CLOB. Uses FOK (Fill-Or-Kill) market order to guarantee execution. Returns dict with success status and details. Uses _timeout_call to prevent indefinite hangs. + Balance check is done on-chain — we always attempt the order for consistency. """ cost = round(shares * price, 4) - if cost > balance: - return {"success": False, "reason": f"Insufficient balance (${balance:.2f} < ${cost:.2f})"} if not is_approved(USDC_ADDRESS, ROUTER, wallet): return {"success": False, "reason": "Router approval missing"} @@ -1034,7 +1034,7 @@ def scan_and_trade(): if ev < adaptive_ev_floor: continue - size = bet_size(adjusted_kelly, balance) + size = bet_size(adjusted_kelly) if size < 0.50: continue @@ -1076,7 +1076,6 @@ def scan_and_trade(): token_id=best_signal["token_id"], price=best_signal["entry_price"], shares=best_signal["shares"], - balance=balance, private_key=PK, wallet=WALLET, )