Trading Bots
Patterns, architectures, risk management, and production tips for building automated Solana trading bots powered by GmGnAPI's real-time data streams.
Automated cryptocurrency trading involves substantial financial risk. This documentation is for educational purposes. Always test with amounts you can afford to lose entirely.
Bot Architecture Overview
A GmGnAPI-based trading bot has four layers:
1. Data Layer
GmGnAPI WebSocket stream — real-time token events filtered to your criteria.
2. Signal Layer
Your logic that decides whether a token event is worth acting on.
3. Execution Layer
The code that calls a DEX, Jupiter, or your wallet to place the trade.
4. Risk Layer
Position sizing, max loss limits, stop losses, and circuit breakers.
Pattern 1: New Pool Sniper
Buy tiny positions in brand-new pools that pass strict quality filters. High risk, high reward.
import asyncio
from gmgnapi import GmGnClient
from gmgnapi.filters import TokenFilter
MAX_SOL_PER_TRADE = 0.05 # never risk more than this
MAX_TRADES_PER_HOUR = 10 # circuit breaker
trades_this_hour = 0
async def execute_buy(address: str, sol_amount: float):
print(f"[BUY] {sol_amount} SOL → {address}")
# TODO: plug in Jupiter or your DEX SDK here
async def execute_sell(address: str):
print(f"[SELL] {address}")
async def main():
global trades_this_hour
filters = TokenFilter(
min_market_cap=5_000,
max_market_cap=100_000,
min_liquidity=3_000,
chains=["solana"],
exclude_honeypots=True,
max_holder_concentration=0.3,
)
async with GmGnClient(filters=filters) as client:
await client.subscribe_new_pools()
@client.on_new_pool
async def on_pool(pool):
global trades_this_hour
if trades_this_hour >= MAX_TRADES_PER_HOUR:
print("⛔ Circuit breaker: max trades reached this hour")
return
sol_amount = min(MAX_SOL_PER_TRADE, pool.liquidity * 0.001)
await execute_buy(pool.address, sol_amount)
trades_this_hour += 1
# simple time-based exit: sell after 5 minutes
await asyncio.sleep(300)
await execute_sell(pool.address)
await client.listen()
asyncio.run(main())
Pattern 2: Volume Trend Follower
Wait for volume to confirm momentum before entering. Lower risk than sniping.
import asyncio
from gmgnapi import GmGnClient
from gmgnapi.filters import TokenFilter
seen_tokens: dict[str, dict] = {}
async def main():
filters = TokenFilter(
min_market_cap=200_000,
min_volume_1h=20_000,
min_buy_count_1h=50,
chains=["solana"],
)
async with GmGnClient(filters=filters) as client:
await client.subscribe_new_pools()
@client.on_new_pool
async def on_pool(pool):
prev = seen_tokens.get(pool.address)
seen_tokens[pool.address] = {
"volume": pool.volume_1h,
"mcap": pool.market_cap,
}
if prev is None:
return # first time seeing this token
volume_growth = pool.volume_1h / max(prev["volume"], 1)
if volume_growth > 2.0:
print(f"📈 Volume 2x spike: {pool.address}")
print(f" Old vol: ${prev['volume']:,.0f} → New: ${pool.volume_1h:,.0f}")
# place trade here
await client.listen()
asyncio.run(main())
Pattern 3: Multi-Signal Scoring
Score each token across multiple dimensions. Only trade when the combined score exceeds a threshold.
def score_token(pool) -> float:
score = 0.0
# market cap sweet spot
if 50_000 <= pool.market_cap <= 500_000:
score += 2.0
# healthy liquidity ratio
if pool.liquidity / max(pool.market_cap, 1) > 0.15:
score += 1.5
# strong buy pressure
if pool.buy_count_1h > pool.sell_count_1h * 1.5:
score += 2.0
# low concentration risk
if pool.top_holder_pct < 0.15:
score += 1.0
# volume momentum
if pool.volume_1h > 10_000:
score += 1.0
return score
@client.on_new_pool
async def on_pool(pool):
s = score_token(pool)
print(f"Score: {s:.1f} | {pool.address}")
if s >= 6.0:
print(f"🎯 HIGH CONFIDENCE SIGNAL: {pool.address}")
# execute trade
Risk Management Essentials
Position Sizing
Never risk more than 1-2% of your total capital on a single trade. Use min(MAX_SOL, total_capital * 0.01).
Stop Losses
Set automatic sells when price drops 30-50%. Track entry price and poll periodically.
Circuit Breakers
Pause trading after N consecutive losses, or when daily loss exceeds a threshold.
Paper Trade First
Log trades without executing them for at least 48 hours before going live.
Share Your Bot — Get Feedback
Our Discord has a dedicated #trading-bots channel where builders share strategies, get code reviews, and collaborate. Join 500+ developers who are already building.
Join Discord →