Skip to content

fsiksan/gmgn-service

 
 

Repository files navigation

gmgn-service

Solana token market-data library for the DLMM agent. Fetches OHLCV klines, smart-wallet activity, and token fundamentals from the GMGN OpenAPI, derives a trading signal, and caches results in a local SQLite database.

Features

  • Trading signalsbullish / neutral / bearish derived from RSI-14, price trend, volume trend, and smart-money net flow
  • Smart wallet analysis — top trader buy/sell counts and net flow via GMGN's smart_degen tag
  • Risk flags — automatic detection of top-10 holder concentration, fresh wallets, and bot activity
  • SQLite cache — configurable TTL (default 10 min) with raw snapshot storage for replay/debugging
  • Fault-tolerant — partial results returned if individual endpoints fail; never throws on API errors

Installation

npm install
# .env (copy from .env.example)
GMGN_API_KEY=<your key>
GMGN_BASE_URL=https://openapi.gmgn.ai   # optional
GMGN_CACHE_TTL_SECONDS=600              # optional, default 600

Usage

import { getGmgnAnalysis } from '/path/to/gmgn-service/index.js';

const result = await getGmgnAnalysis('So11111111111111111111111111111111111111112');

console.log(result.signal);      // 'bullish' | 'neutral' | 'bearish'
console.log(result.alert_text);  // plain-language summary for LLM consumption
console.log(result.risk_flags);  // e.g. ['top10_concentration', 'high_fresh_wallets']

Return shape

Field Type Description
signal string bullish | neutral | bearish | insufficient_data
alert_text string Plain-language summary for LLM context
rsi_14 number|null RSI value 0–100
trend string bullish | bearish | neutral (price vs SMA-20)
volume_trend string rising | falling | flat
volume_1h_usd number|null USD volume over last 1h
volume_4h_usd number|null USD volume over last 4h
volume_24h_usd number|null USD volume over last 24h
smart_money_net_flow_usd number|null Net USD flow from smart wallets
smart_buy_count number Smart wallets net-buying
smart_sell_count number Smart wallets net-selling
risk_flags string[] Active risk flags
data_quality string full | partial | error
_source string live | cache | error

CLI

# Test against wrapped SOL
npm test

# Test against any mint
node cli.js <mint_address>

Signal Scoring

deriveSignal sums weighted votes:

Indicator Condition Score
RSI-14 < 35 (oversold) −2
RSI-14 35–60 (healthy) +1
RSI-14 > 75 (overbought) −1
Trend bullish +1
Trend bearish −1
Volume rising +1
Volume falling −1
Smart flow net positive +2
Smart flow net negative −2

Score ≥ 2 → bullish · Score ≤ −2 → bearish · else neutral

Architecture

index.js          ← public API (getGmgnAnalysis)
├── gmgn-client.js  ← HTTP client (fetchKline, fetchTopTraders, fetchTokenInfo)
├── technicals.js   ← pure-math indicators (RSI, trend, volume trend)
└── db.js           ← SQLite cache (gmgn_alerts + gmgn_snapshots)

All three GMGN endpoints are fetched concurrently via Promise.allSettled. Raw responses are stored in gmgn_snapshots (pruned to 7 days) for debugging and replay.

License

MIT

About

GMGN market data service — volume, technicals, smart wallets for DLMM agent

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 100.0%