Use Cases
Build a Crypto Trading Bot with Live Data
This guide shows how to wire an AI-driven crypto trading bot to live market data, DEX liquidity, perpetual funding rates, and token-security signals through one MCP endpoint. You'll build a reusable pre-trade check function, run a worked example on a live pool, and ship a bot that makes grounded decisions instead of hallucinating from stale training data.
Why trading bots need more than a price feed
A naive bot asks "what is the price?" and trades on it. A production bot answers four questions before every position:
- Is the market priced correctly? Spot price and short-term OHLC from CoinGecko or a DEX aggregator.
- Is there enough liquidity to enter and exit? Pool depth and price impact from Codex or DeFiLlama.
- Is this leg financially expensive to hold? Funding rates and basis across exchanges via CCXT.
- Is the token itself safe? Honeypot flags, owner privileges, and tax walls from GoPlus.
Four questions, four providers, four auth schemes, four rate limiters. Before Hive, a solo dev typically gave up on one or two of them and shipped a bot that lost money to conditions it couldn't see. Hive consolidates those four signals behind one MCP endpoint and one API key.
Architecture overview
┌────────────────────────┐
│ Your trading bot │
│ (Python / Node / Go) │
└───────────┬────────────┘
│ one MCP / REST call per signal
▼
┌────────────────────────┐
│ Hive Intelligence MCP │
│ mcp.hiveintelligence │
└─┬──────┬──────┬─────┬──┘
│ │ │ │
CoinGecko Codex CCXT GoPlus (+ 5 more providers)The bot speaks one protocol (MCP or REST). Hive routes each tool call to the correct provider, applies a single credit, and returns a normalized response. No upstream keys to rotate, no per-provider retry logic.
Prerequisites
- A Hive API key. Create one free. The Demo tier (10,000 credits/mo, 30 req/min) is enough to ship a production-shape bot for a single trading pair; upgrade to Analyst or Pro for higher throughput.
- Node.js 20+ or Python 3.11+ depending on which example you follow.
- Familiarity with async/await.
Step 1: Configure your client
Hive's JavaScript SDK reads HIVE_API_KEY from your environment:
npm install hive-intelligence
export HIVE_API_KEY=sk_live_...import { HiveClient } from 'hive-intelligence'
const hive = new HiveClient({ apiKey: process.env.HIVE_API_KEY })If you're not on Node, use the REST API -- every example below maps one-to-one to a POST /execute call.
Step 2: Build the pre-trade check
The pre-trade check answers all four questions in parallel. Failing any one of them short-circuits the trade.
export async function preTradeCheck({ tokenAddress, poolAddress, symbol }) {
const [security, pool, price, funding] = await Promise.all([
hive.execute('get_token_security', {
chainId: '1',
contract_addresses: tokenAddress,
}),
hive.execute('get_pool_info', {
poolAddress,
networkId: 1,
}),
hive.execute('get_price', {
ids: symbol,
vs_currencies: 'usd',
}),
hive.execute('get_funding_rate', {
exchange: 'binance',
symbol: `${symbol.toUpperCase()}/USDT:USDT`,
}),
])
const secRecord = security?.result?.[tokenAddress.toLowerCase()] ?? {}
const isHoneypot = secRecord.is_honeypot === '1'
const ownerCanMint = secRecord.owner_change_balance === '1'
const buyTax = Number(secRecord.buy_tax ?? 0)
const sellTax = Number(secRecord.sell_tax ?? 0)
const liquidity = Number(pool?.liquidity ?? 0)
const spot = Number(price?.[symbol]?.usd ?? 0)
const fundingAnnualized = Number(funding?.fundingRate ?? 0) * 3 * 365 * 100
const reasons = []
if (isHoneypot) reasons.push('honeypot flagged')
if (ownerCanMint) reasons.push('owner can mint')
if (buyTax > 5 || sellTax > 5) reasons.push(`tax wall (${buyTax}%/${sellTax}%)`)
if (liquidity < 100_000) reasons.push(`thin liquidity ($${liquidity})`)
if (Math.abs(fundingAnnualized) > 50) reasons.push(`extreme funding (${fundingAnnualized.toFixed(1)}% APR)`)
return {
safe: reasons.length === 0,
reasons,
liquidity,
spot,
fundingAnnualized,
}
}Four tool calls run in parallel via Promise.all. Total latency is bounded by the slowest provider -- usually under 500 ms end-to-end on Demo-tier infrastructure.
Expected shape of the result:
{
"safe": false,
"reasons": ["thin liquidity ($42000)"],
"liquidity": 42000,
"spot": 0.00001342,
"fundingAnnualized": 12.4
}Your bot reads safe. If false, log reasons and skip the trade. If true, size the position against liquidity and spot.
Step 3: Wire the check into your trade loop
export async function handleSignal(signal) {
const check = await preTradeCheck(signal)
if (!check.safe) {
logger.warn({ signal, reasons: check.reasons }, 'pre-trade check failed')
return { executed: false, reasons: check.reasons }
}
// Size: never take more than 1% of pool liquidity
const maxNotionalUsd = check.liquidity * 0.01
const notionalUsd = Math.min(signal.targetNotionalUsd, maxNotionalUsd)
const qty = notionalUsd / check.spot
// Funding-rate-aware perp sizing
const leverage = check.fundingAnnualized > 20 ? 1 : signal.baseLeverage
const order = await exchange.submitOrder({
symbol: signal.symbol,
side: signal.side,
qty,
leverage,
})
return { executed: true, order, check }
}The loop does three things Hive data made possible:
- Liquidity-aware sizing prevents you from moving the market against yourself.
- Funding-rate-aware leverage cuts leverage when the cost of carry turns hostile.
- Security gating filters out honeypots and high-tax tokens before any order hits the wire.
Step 4: Add monitoring
While a position is open, poll for two conditions every N seconds:
- Liquidity crash.
get_pool_inforeturns a newliquidityvalue -- if it drops by >40% from entry, exit. - Funding flip.
get_funding_rateturns from positive to negative or vice versa -- adjust the hedge.
setInterval(async () => {
const [pool, funding] = await Promise.all([
hive.execute('get_pool_info', { poolAddress, networkId: 1 }),
hive.execute('get_funding_rate', { exchange: 'binance', symbol: 'ETH/USDT:USDT' }),
])
if (Number(pool.liquidity) < entryLiquidity * 0.6) {
await exchange.close('liquidity crash')
}
if (Math.sign(Number(funding.fundingRate)) !== Math.sign(lastFundingSign)) {
await rebalance()
}
}, 30_000)Credit math: two tool calls every 30 seconds is 240 credits/hour. A 24-hour position costs ~5,800 credits -- fits comfortably inside Analyst (500,000/mo).
Tools used end-to-end
| Tool | Provider | Purpose |
|---|---|---|
get_price | CoinGecko | Spot reference price |
get_ohlc_range | CoinGecko | Custom-range OHLC for lookback |
get_pool_info | Codex | DEX pool depth, volume, price impact |
get_trending_pools | CoinGecko | Pools with rising volume |
get_token_security | GoPlus | Honeypot, tax, ownership risk |
get_funding_rate | CCXT | Perpetual funding across exchanges |
get_token_top_holders | Moralis | Holder concentration |
All seven tools are available through the root /mcp endpoint. For a narrower agent, the category endpoints /hive_market_data/mcp, /hive_onchain_dex/mcp, and /hive_security_risk/mcp cover the same seven between them.
What to tune next
- Caching. Hive deduplicates upstream calls, but keeping a 30-second local cache of
get_pricefor frequently-polled pairs saves credits without degrading signal. - Backtesting. Run
get_ohlc_rangeover a historical window to backtest the sizing and funding-adjusted leverage rules before deploying capital. - Alerts. Wire
get_token_securityinto a cron task that checks every token in your allowlist daily -- tokens go malicious through owner proxy upgrades even after they were safe at entry.
Related
- Playground -- try every tool used here in the browser.
- Market Data Tools -- full catalog of price, OHLC, and volume tools.
- Security Tools -- full GoPlus and contract-risk surface.
- DEX Analytics Tools -- pool liquidity, trending, and volume data.
- MCP Integration Tutorial -- wire the same bot up through Claude Desktop or Cursor instead of direct REST.