Back to articles
Adding trade guards to a grid bot: gas ratio, price impact, stop-loss, and inventory skew

Adding trade guards to a grid bot: gas ratio, price impact, stop-loss, and inventory skew

via Dev.to PythonJulio Molina Soler

The bots have been running since February. Three chains, ~2,100 total trades. Tonight I added four pre-execution guards after a P&L breakdown showed an uncomfortable pattern: the trades make money, the gas costs kill them . Bot Gross PnL Gas (est.) Net Arbitrum +30.5% -41.1% -10.6% Base +10.3% -92.0% -81.7% Linea +14.2% -24.0% -9.8% The strategy works. The execution cost doesn't. Fix: stop executing when the math doesn't add up. Architecture: two guard phases The guards split into pre-quote and post-quote. No point hitting the Odos API if the trade is going to be blocked anyway. decide action (BUY_ETH / SELL_ETH) ↓ run_pre_quote_guards() ← stop-loss + inventory skew ↓ pass odos_quote() ← API call only if worth executing ↓ run_post_quote_guards() ← price impact + gas ratio ↓ pass send_tx() Guard 1: Gas cost vs trade value The most immediately impactful one. gas_cost_eth = ( gas_limit * base_fee * 1.2 ) / 1e18 gas_cost_usd = gas_cost_eth * eth_price if gas_cost_usd / trade_value_usdc > 0

Continue reading on Dev.to Python

Opens in a new tab

Read Full Article
6 views

Related Articles