backtrader
Event-driven backtesting with bar-by-bar execution, complex order types, multiple analyzers,…
DEX orderflow analysis, trade classification, buyer/seller pressure, and microstructure signals for Solana tokens
$ npx -y skills add agiprolabs/claude-trading-skills --skill market-microstructure --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/market-microstructureContext preview
The summary Claude sees to decide when to auto-load this skill.
DEX orderflow analysis, trade classification, buyer/seller pressure, and microstructure signals for Solana tokens
name: market-microstructure description: DEX orderflow analysis, trade classification, buyer/seller pressure, and microstructure signals for Solana tokens
Market microstructure on Solana DEXes differs fundamentally from traditional finance. There are no orderbooks on AMMs — every trade is a swap against a liquidity pool. Yet trade flow analysis remains powerful: the sequence, size, and direction of swaps reveal accumulation, distribution, whale activity, and wash trading patterns.
This skill covers:
On CEXes, microstructure means orderbook depth, bid-ask spread, and queue position. On AMMs, liquidity sits in pool curves — there is no spread or queue. But the **trade tape** (the chronological list of swaps) contains rich signal:
1. **Who is trading?** — Whale wallets vs retail, smart money vs bots 2. **How are they trading?** — Large single swaps vs DCA-style splits 3. **When are they trading?** — Volume clustering around events or time zones 4. **What direction?** — Net buy vs sell pressure over sliding windows
These signals feed into entry/exit timing, position sizing, and token quality scoring.
On Solana DEXes, every swap has an input token and output token:
| Swap Direction | Classification | Meaning | |----------------|---------------|---------| | SOL → Token | **Buy** | Trader spending SOL to acquire token | | USDC → Token | **Buy** | Trader spending stables to acquire token | | Token → SOL | **Sell** | Trader converting token back to SOL | | Token → USDC | **Sell** | Trader converting token to stables | | Token A → Token B | Context-dependent | Classify based on which token you're analyzing |
**Birdeye Trade History** (`/defi/txs/token`):
**DexScreener Pair Trades:**
**Helius Parsed Transactions:**
See `references/trade_classification.md` for detailed classification logic and size buckets.
Aggregate trade volume into fixed time buckets to identify patterns:
# Hourly volume profile
hourly_volume = {}
for trade in trades:
hour = trade["timestamp"] // 3600 * 3600
hourly_volume.setdefault(hour, {"buy_vol": 0, "sell_vol": 0})
if trade["side"] == "buy":
hourly_volume[hour]["buy_vol"] += trade["volume_usd"]
else:
hourly_volume[hour]["sell_vol"] += trade["volume_usd"]Key metrics from time profiles:
Classify trades into size buckets to separate whale activity from retail:
| Bucket | SOL Range | Typical Actor | |--------|-----------|---------------| | Micro | < 0.1 SOL | Dust / test trades | | Small | 0.1 – 1 SOL | Retail traders | | Medium | 1 – 10 SOL | Active traders | | Large | 10 – 50 SOL | Serious positions | | Whale | 50+ SOL | Whales / institutions |
def compute_pressure(trades: list[dict], period_seconds: int = 3600) -> dict:
"""Compute buy/sell pressure metrics over a time period."""
buy_vol = sum(t["volume_usd"] for t in trades if t["side"] == "buy")
sell_vol = sum(t["volume_usd"] for t in trades if t["side"] == "sell")
total_vol = buy_vol + sell_vol
buy_trades = sum(1 for t in trades if t["side"] == "buy")
sell_trades = sum(1 for t in trades if t["side"] == "sell")
total_trades = buy_trades + sell_trades
return {
"buy_sell_ratio": buy_vol / sell_vol if sell_vol > 0 else float("inf"),
"buy_volume_pct": buy_vol / total_vol if total_vol > 0 else 0.5,
"net_flow_usd": buy_vol - sell_vol,
"trade_count_ratio": buy_trades / total_trades if total_trades > 0 else 0.5,
}| Metric | Bullish | Neutral | Bearish | |--------|---------|---------|---------| | Buy Volume % | > 60% | 40–60% | < 40% | | Net Flow | Positive, increasing | Near zero | Negative, increasing | | Trade Count Ratio | > 0.55 | 0.45–0.55 | < 0.45 | | Large Trade Ratio | High buy-side | Balanced | High sell-side |
See `references/flow_signals.md` for the full signal catalog and composite scoring.
Analyzing the distribution of trade sizes reveals market structure:
import statistics
def analyze_trade_sizes(trades: list[dict]) -> dict:
"""Analyze trade size distribution."""
sizes = [t["volume_usd"] for t in trades]
if not sizes:
return {}
return {
"mean": statistics.mean(sizes),
"median": statistics.median(sizes),
"stdev": statistics.stdev(sizes) if len(sizes) > 1 else 0,
"skew_indicator": statistics.mean(sizes) / statistics.median(sizes),
"max_trade": max(sizes),
"whale_pct": sum(s for s in sizes if s > 5000) / sum(sizes),
}**Interpreting skew:** A `skew_indicator` (mean/median) well above 1.0 indicates a fat-tailed distribution — a few large trades domina
A comprehensive collection of 68 ready-to-use trading, DeFi, and quantitative finance Agent Skills. Works with Claude Code, Cursor, Codex, Gemini CLI, and 30+ other tools.
Repo: agiprolabs/claude-trading-skills
Event-driven backtesting with bar-by-bar execution, complex order types, multiple analyzers,…
Solana token market data via Birdeye — prices, OHLCV, trades, token metadata, security…
Broad crypto market data from CoinGecko covering 13,000+ tokens. Global market stats,…
Cointegration testing for pairs trading using Engle-Granger, Johansen, and rolling stability…
Wallet evaluation, monitoring, and copy-trade strategy design for Solana DEX trading
Cross-asset correlation analysis including rolling correlation, hierarchical clustering, tail…