
Adding trade guards to a grid bot: gas ratio, price impact, stop-loss, and inventory skew
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

![[Learning notes and hw] getting started with R-cnn: Manually implementing Intersection over Union (IoU)](/_next/image?url=https%3A%2F%2Fmedia2.dev.to%2Fdynamic%2Fimage%2Fwidth%3D800%252Cheight%3D%252Cfit%3Dscale-down%252Cgravity%3Dauto%252Cformat%3Dauto%2Fhttps%253A%252F%252Fdev-to-uploads.s3.amazonaws.com%252Fuploads%252Farticles%252Favit2emoxc0g68e5ltqj.jpg&w=1200&q=75)

