$npx -y skills add agiprolabs/claude-trading-skills --skill market-microstructureDEX orderflow analysis, trade classification, buyer/seller pressure, and microstructure signals for Solana tokens
| 1 | # Market Microstructure — DEX Orderflow Analysis |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Market microstructure on Solana DEXes differs fundamentally from traditional finance. |
| 6 | There are no orderbooks on AMMs — every trade is a swap against a liquidity pool. Yet |
| 7 | trade flow analysis remains powerful: the sequence, size, and direction of swaps reveal |
| 8 | accumulation, distribution, whale activity, and wash trading patterns. |
| 9 | |
| 10 | This skill covers: |
| 11 | - **Trade classification** — identifying buys vs sells from swap direction |
| 12 | - **Volume profiles** — time-based and size-based breakdowns |
| 13 | - **Buyer/seller pressure** — ratio metrics, net flow, trade count asymmetry |
| 14 | - **Trade size distribution** — whale detection, retail vs institutional flow |
| 15 | - **Flow momentum signals** — acceleration, volume spikes, composite scores |
| 16 | - **Token velocity** — turnover rate as a sentiment proxy |
| 17 | - **Wash trading detection** — spotting fake volume and bot patterns |
| 18 | |
| 19 | ## Why Microstructure Matters on DEXes |
| 20 | |
| 21 | On CEXes, microstructure means orderbook depth, bid-ask spread, and queue position. |
| 22 | On AMMs, liquidity sits in pool curves — there is no spread or queue. But the **trade |
| 23 | tape** (the chronological list of swaps) contains rich signal: |
| 24 | |
| 25 | 1. **Who is trading?** — Whale wallets vs retail, smart money vs bots |
| 26 | 2. **How are they trading?** — Large single swaps vs DCA-style splits |
| 27 | 3. **When are they trading?** — Volume clustering around events or time zones |
| 28 | 4. **What direction?** — Net buy vs sell pressure over sliding windows |
| 29 | |
| 30 | These signals feed into entry/exit timing, position sizing, and token quality scoring. |
| 31 | |
| 32 | ## Trade Classification |
| 33 | |
| 34 | ### Buy vs Sell Identification |
| 35 | |
| 36 | On Solana DEXes, every swap has an input token and output token: |
| 37 | |
| 38 | | Swap Direction | Classification | Meaning | |
| 39 | |----------------|---------------|---------| |
| 40 | | SOL → Token | **Buy** | Trader spending SOL to acquire token | |
| 41 | | USDC → Token | **Buy** | Trader spending stables to acquire token | |
| 42 | | Token → SOL | **Sell** | Trader converting token back to SOL | |
| 43 | | Token → USDC | **Sell** | Trader converting token to stables | |
| 44 | | Token A → Token B | Context-dependent | Classify based on which token you're analyzing | |
| 45 | |
| 46 | ### From API Data Sources |
| 47 | |
| 48 | **Birdeye Trade History** (`/defi/txs/token`): |
| 49 | - Returns `side` field: `"buy"` or `"sell"` |
| 50 | - Includes `from` (input token) and `to` (output token) amounts |
| 51 | |
| 52 | **DexScreener Pair Trades:** |
| 53 | - Returns `type` field indicating swap direction relative to the pair |
| 54 | |
| 55 | **Helius Parsed Transactions:** |
| 56 | - Parse swap instructions to extract input/output mints and amounts |
| 57 | - Classify based on which mint matches your target token |
| 58 | |
| 59 | See `references/trade_classification.md` for detailed classification logic and size buckets. |
| 60 | |
| 61 | ## Volume Profiles |
| 62 | |
| 63 | ### Time-Based Profiles |
| 64 | |
| 65 | Aggregate trade volume into fixed time buckets to identify patterns: |
| 66 | |
| 67 | ```python |
| 68 | # Hourly volume profile |
| 69 | hourly_volume = {} |
| 70 | for trade in trades: |
| 71 | hour = trade["timestamp"] // 3600 * 3600 |
| 72 | hourly_volume.setdefault(hour, {"buy_vol": 0, "sell_vol": 0}) |
| 73 | if trade["side"] == "buy": |
| 74 | hourly_volume[hour]["buy_vol"] += trade["volume_usd"] |
| 75 | else: |
| 76 | hourly_volume[hour]["sell_vol"] += trade["volume_usd"] |
| 77 | ``` |
| 78 | |
| 79 | Key metrics from time profiles: |
| 80 | - **Peak hours** — when is the token most actively traded? |
| 81 | - **Volume trend** — is volume increasing, decreasing, or stable? |
| 82 | - **Volume anomalies** — spikes exceeding 3x the rolling average |
| 83 | |
| 84 | ### Size-Based Profiles |
| 85 | |
| 86 | Classify trades into size buckets to separate whale activity from retail: |
| 87 | |
| 88 | | Bucket | SOL Range | Typical Actor | |
| 89 | |--------|-----------|---------------| |
| 90 | | Micro | < 0.1 SOL | Dust / test trades | |
| 91 | | Small | 0.1 – 1 SOL | Retail traders | |
| 92 | | Medium | 1 – 10 SOL | Active traders | |
| 93 | | Large | 10 – 50 SOL | Serious positions | |
| 94 | | Whale | 50+ SOL | Whales / institutions | |
| 95 | |
| 96 | ## Buyer/Seller Pressure Metrics |
| 97 | |
| 98 | ### Core Ratios |
| 99 | |
| 100 | ```python |
| 101 | def compute_pressure(trades: list[dict], period_seconds: int = 3600) -> dict: |
| 102 | """Compute buy/sell pressure metrics over a time period.""" |
| 103 | buy_vol = sum(t["volume_usd"] for t in trades if t["side"] == "buy") |
| 104 | sell_vol = sum(t["volume_usd"] for t in trades if t["side"] == "sell") |
| 105 | total_vol = buy_vol + sell_vol |
| 106 | |
| 107 | buy_trades = sum(1 for t in trades if t["side"] == "buy") |
| 108 | sell_trades = sum(1 for t in trades if t["side"] == "sell") |
| 109 | total_trades = buy_trades + sell_trades |
| 110 | |
| 111 | return { |
| 112 | "buy_sell_ratio": buy_vol / sell_vol if sell_vol > 0 else float("inf"), |
| 113 | "buy_volume_pct": buy_vol / total_vol if total_vol > 0 else 0.5, |
| 114 | "net_flow_usd": buy_vol - sell_vol, |
| 115 | "trade_count_ratio": buy_trades / total_trades if total_trades > 0 else 0.5, |
| 116 | } |
| 117 | ``` |
| 118 | |
| 119 | ### Signal Interpretation |
| 120 | |
| 121 | | Metric | Bullish | Neutral | Bearish | |
| 122 | |--------|---------|---------|---------| |
| 123 | | Buy Volume % | > 60% | 40–60% | < 40% | |
| 124 | | Net Flow | Positive, increasing | Near zero | Negative, increasing |