Your trading bot spotted a perfect arbitrage opportunity between Uniswap and Balancer. The price difference is 2.5% — enough for solid profit. But gas is sitting at 80 gwei. By the time the transaction confirms, the opportunity vanishes and you're left holding the gas bill.
This scenario plays out thousands of times daily in DeFi. Trading bots either miss opportunities waiting for cheap gas or burn through profits on expensive transactions. What if your bot could automatically execute trades only when gas prices meet your profitability threshold?
Why Gas-Aware Execution Matters for Trading Bots
Gas costs can make or break trading strategies. A profitable arbitrage at 20 gwei becomes a loss at 100 gwei. MEV bots competing for the same opportunities often end up in gas wars, driving costs through the roof. Manual gas monitoring doesn't scale when you're running strategies across multiple chains and protocols.
The challenge isn't just gas prices — it's coordination. Your bot needs to:
- Monitor gas prices across networks in real-time
- Queue transactions with conditional execution
- Cancel outdated opportunities before they become losses
- Maintain execution across 14 DeFi protocols simultaneously
- Handle cross-chain arbitrage where timing matters
Building this infrastructure from scratch means maintaining gas price feeds, transaction queuing systems, and integrations with dozens of protocols. That's months of development before you even start on your actual trading logic.
Gas Conditional Execution: Your Bot Trades Smarter
WAIaaS solves this with gas conditional execution built into its 7-stage transaction pipeline. Your bot submits trades with gas price thresholds, and the system automatically executes only when conditions are met.
Here's how it works in practice. Your arbitrage bot spots an opportunity and submits a conditional trade:
curl -X POST http://127.0.0.1:3100/v1/actions/jupiter-swap/swap \
-H "Content-Type: application/json" \
-H "Authorization: Bearer wai_sess_<token>" \
-d '{
"inputMint": "So11111111111111111111111111111111111111112",
"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"amount": "1000000000",
"gasCondition": {
"maxGasPrice": "50000000",
"timeout": 300
}
}'
The transaction enters the pipeline and waits at stage 4 (wait) until gas drops below 50 lamports. If gas stays high for 300 seconds, the transaction expires automatically. No manual cancellation, no wasted gas on unprofitable trades.
Multi-Protocol Trading Through One API
Trading bots need access to liquidity across protocols. WAIaaS integrates 14 DeFi protocols through a unified API, so your bot can execute complex strategies without managing separate SDKs.
Execute a cross-protocol arbitrage in three API calls:
# 1. Swap on Jupiter (Solana)
curl -X POST http://127.0.0.1:3100/v1/actions/jupiter-swap/swap \
-H "Authorization: Bearer wai_sess_<token>" \
-d '{"inputMint": "SOL", "outputMint": "USDC", "amount": "10000000000"}'
# 2. Bridge to Ethereum via LI.FI
curl -X POST http://127.0.0.1:3100/v1/actions/lifi/bridge \
-H "Authorization: Bearer wai_sess_<token>" \
-d '{"fromChain": "solana", "toChain": "ethereum", "token": "USDC", "amount": "1000"}'
# 3. Lend on Aave v3
curl -X POST http://127.0.0.1:3100/v1/actions/aave-v3/supply \
-H "Authorization: Bearer wai_sess_<token>" \
-d '{"asset": "USDC", "amount": "1000"}'
Each action goes through the same gas-aware pipeline. Your bot submits the strategy, and WAIaaS handles execution timing across all three protocols.
Risk Controls That Scale
Trading bots need guardrails to prevent runaway losses. WAIaaS provides a 21-policy risk management system that operates at the wallet level, not per-strategy.
Set up automatic risk limits:
curl -X POST http://127.0.0.1:3100/v1/policies \
-H "Content-Type: application/json" \
-H "X-Master-Password: my-secret-password" \
-d '{
"walletId": "<wallet-uuid>",
"type": "SPENDING_LIMIT",
"rules": {
"instant_max_usd": 1000,
"notify_max_usd": 5000,
"delay_max_usd": 20000,
"delay_seconds": 300,
"daily_limit_usd": 50000
}
}'
Trades under $1000 execute instantly. Trades between $1000-$5000 send notifications but still execute. Trades between $5000-$20000 wait 5 minutes (cancellable if your bot detects the opportunity expired). Trades over $20000 require manual approval.
You can also restrict protocols, tokens, and trading venues:
# Only allow trading on whitelisted protocols
curl -X POST http://127.0.0.1:3100/v1/policies \
-H "X-Master-Password: my-secret-password" \
-d '{
"type": "CONTRACT_WHITELIST",
"rules": {
"contracts": [
{"address": "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4", "name": "Jupiter"},
{"address": "0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9", "name": "Aave"}
]
}
}'
Simulation and Backtesting
Before risking capital, test strategies with the dry-run API. Submit any transaction with "dryRun": true to see exactly what would happen:
curl -X POST http://127.0.0.1:3100/v1/transactions/send \
-H "Content-Type: application/json" \
-H "Authorization: Bearer wai_sess_<token>" \
-d '{
"type": "TRANSFER",
"to": "recipient-address",
"amount": "0.1",
"dryRun": true
}'
The response shows gas estimates, policy decisions, and potential errors without executing the transaction. Essential for backtesting strategies against historical gas prices.
High-Performance Bot Integration
Trading bots need minimal latency overhead. WAIaaS provides both REST APIs and TypeScript/Python SDKs optimized for high-frequency strategies:
import { WAIaaSClient } from '@waiaas/sdk';
const client = new WAIaaSClient({
baseUrl: 'http://127.0.0.1:3100',
sessionToken: process.env.WAIAAS_SESSION_TOKEN,
});
// Check opportunity profitability
const balance = await client.getBalance();
const gasPrice = await client.getGasPrice();
if (gasPrice < profitabilityThreshold) {
// Execute arbitrage
const tx = await client.executeAction('jupiter-swap', {
inputMint: 'SOL',
outputMint: 'USDC',
amount: balance.balance
});
}
The SDK handles connection pooling, request retries, and error handling so your bot focuses on trading logic, not infrastructure.
Quick Start: Gas-Aware Trading Bot
Get started with gas conditional execution in 5 steps:
- Deploy WAIaaS daemon:
git clone https://github.com/minhoyoo-iotrust/WAIaaS.git
cd WAIaaS
docker compose up -d
- Create a trading wallet:
npm install -g @waiaas/cli
waiaas quickset --mode mainnet
Set up risk policies (spending limits, protocol whitelist, gas thresholds)
Install the SDK:
npm install @waiaas/sdk
- Submit your first gas-conditional trade using the Jupiter swap example above
Your bot now executes trades only when gas conditions are favorable, with automatic risk controls and multi-protocol access.
What's Next
This is just the beginning. WAIaaS supports perpetual futures on Hyperliquid, prediction markets on Polymarket, liquid staking, cross-chain bridging, and more. Each protocol integration includes gas-aware execution and risk controls out of the box.
Ready to build smarter trading bots? Check out the full documentation and examples at https://github.com/minhoyoo-iotrust/WAIaaS or visit https://waiaas.ai to get started.
Top comments (0)