Tutorials

🚀 New to GMGN.ai? Create your account with our referral link to support GmGnAPI’s development → Sign up on GMGN.ai
💬 Need help? Join the Chipa Discord · ⚡ Go no-code with ChipaEditor

Hands-on, step-by-step guides that take you from zero to production. Each tutorial builds on the previous — follow them in order or jump straight to what you need.

#TutorialWhat you’ll build
1First ConnectionConnect to the GMGN.ai WebSocket and receive your first live token event in under 5 minutes
2Filtering TokensUse the built-in filter system to only receive tokens that match your criteria
3Alerts & WebhooksSend Discord or Telegram notifications when high-potential tokens are spotted
4Saving to DatabasePersist token data to SQLite or CSV for backtesting and analysis
5Simple Trading BotWire GmGnAPI to a buy/sell execution layer for automated trading
6Production DeploymentRun your bot reliably with Docker, systemd, and health checks

💡 Pro tip: all of these tutorials pair perfectly with ChipaEditor — the AI-powered strategy editor that lets you build, backtest, and deploy trading strategies without writing a line of code.

01. Your First Connection

This tutorial assumes you have Python 3.8+ installed. If you haven’t installed GmGnAPI yet, see the Installation guide.

Step 1 — Install the package

pip install gmgnapi

Step 2 — Create a GMGN account

You need a free GMGN.ai account to access the API. Use our referral link — it’s free and helps support development: Create Free Account →

Step 3 — Write the code

# first_connection.py
import asyncio
from gmgnapi import GmGnClient

async def main():
    async with GmGnClient() as client:
        await client.subscribe_new_pools()

        @client.on_new_pool
        async def on_pool(pool):
            print(f"🆕 New pool on {pool.chain}: {pool.address}")
            print(f"   Market cap: ${pool.market_cap:,.0f}")

        print("Listening for new pools… (Ctrl+C to stop)")
        await client.listen()

asyncio.run(main())

Step 4 — Run it

python first_connection.py

You should see new Solana token pools streaming in within seconds. Next, learn to filter them.

02. Filtering Tokens

Most new pools are noise. The filter system lets you set hard conditions — only tokens that pass all filters fire your handler. See the full Filters Guide for every available option.

# filtered_monitor.py
import asyncio
from gmgnapi import GmGnClient
from gmgnapi.filters import TokenFilter

async def main():
    filters = TokenFilter(
        min_market_cap=50_000,       # at least $50k market cap
        max_market_cap=5_000_000,    # not already mega-cap
        min_liquidity=10_000,        # enough liquidity to trade
        min_volume_1h=5_000,         # some trading activity
        require_verified=False,      # include unverified
    )

    async with GmGnClient(filters=filters) as client:
        await client.subscribe_new_pools()

        @client.on_new_pool
        async def on_pool(pool):
            print(f"✅ PASSED FILTER: {pool.address} — mcap ${pool.market_cap:,.0f}")

        await client.listen()

asyncio.run(main())

Continue to Tutorial 3 to notify yourself when these tokens appear.

03. Alerts & Webhooks

Send real-time Discord alerts when a token passes your filters. Join the Chipa Discord to share your setups.

# discord_alerts.py
import asyncio, aiohttp
from gmgnapi import GmGnClient
from gmgnapi.filters import TokenFilter

DISCORD_WEBHOOK = "https://discord.com/api/webhooks/YOUR_WEBHOOK_HERE"

async def send_discord(pool):
    payload = {
        "embeds": [{
            "title": f"🚀 New Token Alert",
            "description": f"`{pool.address}`",
            "color": 0x00ff88,
            "fields": [
                {"name": "Chain", "value": pool.chain, "inline": True},
                {"name": "Market Cap", "value": f"${pool.market_cap:,.0f}", "inline": True},
                {"name": "Liquidity", "value": f"${pool.liquidity:,.0f}", "inline": True},
                {"name": "GMGN Link", "value": f"[View on GMGN](https://gmgn.ai/token/{pool.address})", "inline": False},
            ]
        }]
    }
    async with aiohttp.ClientSession() as session:
        await session.post(DISCORD_WEBHOOK, json=payload)

async def main():
    filters = TokenFilter(min_market_cap=50_000, min_liquidity=10_000)
    async with GmGnClient(filters=filters) as client:
        await client.subscribe_new_pools()

        @client.on_new_pool
        async def on_pool(pool):
            await send_discord(pool)

        await client.listen()

asyncio.run(main())

04. Saving to Database

Persist every token event for later analysis. GmGnAPI has built-in export helpers. See the Advanced docs for full options.

# save_to_db.py
import asyncio
from gmgnapi import GmGnClient
from gmgnapi.export import SQLiteExporter

async def main():
    exporter = SQLiteExporter("tokens.db")
    await exporter.init()

    async with GmGnClient() as client:
        await client.subscribe_new_pools()

        @client.on_new_pool
        async def on_pool(pool):
            await exporter.save(pool)
            print(f"Saved {pool.address}")

        await client.listen()

asyncio.run(main())

05. Simple Trading Bot

Wire the stream to your execution layer. See the full Trading Bots guide for patterns, risk management, and position sizing.

# simple_bot.py
import asyncio
from gmgnapi import GmGnClient
from gmgnapi.filters import TokenFilter

async def buy_token(address: str, amount_sol: float):
    # plug in your own DEX / wallet execution here
    print(f"BUY {amount_sol} SOL worth of {address}")

async def main():
    filters = TokenFilter(
        min_market_cap=30_000,
        max_market_cap=500_000,
        min_liquidity=8_000,
    )
    async with GmGnClient(filters=filters) as client:
        await client.subscribe_new_pools()

        @client.on_new_pool
        async def on_pool(pool):
            print(f"Signal: {pool.address}")
            await buy_token(pool.address, amount_sol=0.1)

        await client.listen()

asyncio.run(main())

⚠️ Risk warning: automated trading carries real financial risk. Always test with small amounts first. Read the full Trading Bots guide before running live.

06. Production Deployment

Run your bot reliably 24/7. See Advanced → Production Deployment for Docker Compose, Kubernetes, and monitoring.

Minimal Dockerfile

FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "bot.py"]

requirements.txt

gmgnapi>=1.0.0
aiohttp>=3.9.0

Run it

docker build -t my-gmgn-bot .
docker run -d --restart=always --name gmgn-bot my-gmgn-bot

What’s Next?

  • Filters Guide — every filter option explained with examples
  • Trading Bots — full bot patterns, risk management, position sizing
  • API Reference — complete method and model documentation
  • Community — share your bot, get feedback, find collaborators

Build Faster