Build Limit Order Bot with Swap API

Traders begged for limit orders on DEXs. Swap API delivers the missing piece: dead-simple price polling and calldata for bots. No more FOMO swaps at the peak.

Python code snippet for a limit order bot polling Swap API on Ethereum

Key Takeaways

  • Swap API enables no-key limit order bots on 46 EVM chains, polling real executable prices.
  • DEX volume exploded to $876B Q2 2025, but limits were missing—bots fix that instantly.
  • Democratizes HFT-like precision for retail; predicts DEX surpassing CEX spot by 2027.

Everyone figured DEXs would stay the wild west of market orders forever.

$876 billion in spot volume last quarter — that’s what decentralized exchanges cranked out — but nearly all of it? Sloppy market takes, right at whatever price the pool spits back. Traders screamed for limit orders, the kind CEXs flaunt so effortlessly. Buy below 2400, sell above 3500 — basic stuff that could’ve saved fortunes during those 2025 dumps. Then Swap API drops this free, no-key gateway. Suddenly, you’re polling real executable quotes across 46 EVM chains, firing off swaps the instant prices hit your line. It’s not hype. It’s the architectural pivot DEXs desperately needed.

Decentralized exchanges processed $876 billion in spot volume in Q2 2025 alone, yet most of that volume still executes as market orders.

Look. No order books on-chain. That’s the brutal truth. CEXs park your limit in a ledger, match it later. Here? Your bot hustles — polls, checks, swaps. Polling sounds dumb, inefficient even. But with DEX-to-CEX volume doubling to 13.6%, liquidity’s thick enough now. Bots like this aren’t scraping by; they’re feasting on it.

Why Build Your Own Limit Order Bot Right Now?

Because custody’s the enemy.

You’ve seen it: token moons, you swap manually, it dumps 20% mid-tx. A dedicated bot wallet — never your main one — waits like a sniper. Define USDC for WETH below 2400. Poll every 30 seconds via Swap API. Boom, executed calldata in one GET. No front-running nightmares if you gas right.

Here’s the config that makes it tick:

CONFIG = {
"chain_id": 1,
"token_in": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"token_out": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"amount": "2400000000",
"target_price": 2400.0,
"direction": "buy_below",
"max_slippage": 0.005,
"poll_interval": 30,
"rpc_url": "https://cloudflare-eth.com",
}

That’s 2400 USDC (six decimals) chasing one WETH or better. Flip chain_id to 42161 for Arbitrum, tweak addresses — table’s right there in the original docs. Python 3.10, web3.py, requests. Pip install and go.

But wait — the genius? This API spits executable calldata. Not some oracle fantasy price. Real swap routes, liquidity-aware, slippage-capped. Your bot grabs expectedAmountOut, crunches human-readable price: amount_in / 10^decimals divided by out. Hits target? Sign, send via web3.

No Order Book? No Problem — Here’s the Flow

Polling loop’s the heart.

Hit https://api.swapapi.dev/v1/swap/{chain_id} with tokenIn, tokenOut, amount, sender (your bot address), slippage. JSON back: success, data, timestamp. Parse calculate_price — boom, effective rate.

def calculate_price(quote, token_in_decimals, token_out_decimals):
    amount_in = int(quote["data"]["amountIn"])
    amount_out = int(quote["data"]["expectedAmountOut"])
    human_in = amount_in / (10 ** token_in_decimals)
    human_out = amount_out / (10 ** token_out_decimals)
    return human_in / human_out

“Buy below” triggers if price <= target. Sell above? Reverse the math. Web3 hooks your wallet, estimates gas, broadcasts. Rinse, repeat.

Skeptical? Curl a live quote yourself:

curl "https://api.swapapi.dev/v1/swap/1?tokenIn=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48&tokenOut=0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2&amount=2400000000&sender=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"

9.7 million wallets hit DEXs by mid-2025. Pools are deep — this works.

And here’s my take, the one nobody’s saying: this echoes the ’90s NASDAQ wars. HFT firms built proprietary bots to outpace order books. Retail got screwed. Now? Swap API levels it — free, open, on-chain. No $47B bot market gatekeepers needed. Prediction: by 2027, limit bots push DEX spot past CEX entirely. On-chain becomes the default.

Does Swap API Work smoothly on Base or Arbitrum?

Dead yes.

ChainId 8453 for Base, WETH at 0x4200000000000000000000000000000000000006. USDC? 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913. Same curl, same logic. Gas cheaper, liquidity solid post-2025 boom. But watch RPC — Cloudflare’s fine for Eth, but layer-2s? Pick public nodes wisely, or MEV bites.

Full bot skeleton? Slap the quote func in a while True: sleep(poll_interval). Check price vs target. If go-time, web3.eth.account.from_key(private_key).sign_transaction(tx). Send.

Edge cases? Slippage spikes in thin pairs — crank max_slippage, but don’t. Gas wars? Dynamic bidding via web3. Failed polls? Timeout 15s, retry.

It’s raw power. No auth, 46 chains. Corporate DEXs charge for this. Swap API? Free forever? That’s the spin to watch — but for now, it’s printing money for builders.

The shift’s bigger than code. Limit bots kill the ‘manual swap regret’ era. Traders automate precision without trusting custodians. DEXs win volume. Retail wins edge.

One punchy caveat: polling burns gas on checks. Not TWAP elegant, but viable till on-chain order books mature (they won’t, soon).

Build it. Test small. Scale.


🧬 Related Insights

Frequently Asked Questions

How do I build a limit order bot with Swap API?
Start with Python, web3.py, requests. Config chain, tokens, target price. Poll API for quotes, trigger on condition, execute via web3. Full code in this piece.

Does Swap API require an API key for limit order bots?
Nope — zero auth. Free for all 46 EVM chains. Just pass sender address.

Can I run limit order bots on Arbitrum or Base?
Absolutely. Swap chain_id (42161 Arbitrum, 8453 Base), update token addresses. Same polling flow, cheaper gas.

Aisha Patel
Written by

Former ML engineer turned writer. Covers computer vision and robotics with a practitioner perspective.

Frequently asked questions

How do I build a limit order bot with Swap API?
Start with Python, web3.py, requests. Config chain, tokens, target price. Poll API for quotes, trigger on condition, execute via web3. Full code in this piece.
Does Swap API require an API key for limit order bots?
Nope — zero auth. Free for all 46 EVM chains. Just pass sender address.
Can I run limit order bots on Arbitrum or Base?
Absolutely. Swap chain_id (42161 Arbitrum, 8453 Base), update token addresses. Same polling flow, cheaper gas.

Worth sharing?

Get the best AI stories of the week in your inbox — no noise, no spam.

Originally reported by dev.to

Stay in the loop

The week's most important stories from theAIcatchup, delivered once a week.