repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources15d ago| #1 | /** |
| #2 | * HERMES x402 TUI — Market Data Fetcher |
| #3 | * |
| #4 | * Pulls live SOL price + trending tokens from public APIs. |
| #5 | * No API key required for basic data. |
| #6 | */ |
| #7 | |
| #8 | import { addLog, type DashboardState, type TrendingToken, type TradeSignal } from './state.js'; |
| #9 | |
| #10 | interface CoinGeckoPrice { |
| #11 | solana: { usd: number; usd_24h_change: number }; |
| #12 | } |
| #13 | |
| #14 | interface SolanaTrackerToken { |
| #15 | symbol?: string; |
| #16 | change24h?: number; |
| #17 | priceChange24h?: number; |
| #18 | volume24h?: number; |
| #19 | volume?: number; |
| #20 | token?: { symbol?: string }; |
| #21 | } |
| #22 | |
| #23 | interface SolanaTrackerResponse { |
| #24 | tokens?: SolanaTrackerToken[]; |
| #25 | data?: SolanaTrackerToken[]; |
| #26 | } |
| #27 | |
| #28 | export async function fetchMarketData(state: DashboardState): Promise<void> { |
| #29 | state.oodaPhase = 'observe'; |
| #30 | addLog(state, 'OBSERVE', 'Fetching SOL price + trending tokens…', 'info'); |
| #31 | |
| #32 | const results = await Promise.allSettled([ |
| #33 | fetchSolPrice(), |
| #34 | fetchTrending(), |
| #35 | ]); |
| #36 | |
| #37 | if (results[0].status === 'fulfilled') { |
| #38 | const price = results[0].value; |
| #39 | state.solPrice = price.usd; |
| #40 | state.solChange24h = price.change; |
| #41 | addLog(state, 'OBSERVE', `SOL $${price.usd.toFixed(2)} (${price.change > 0 ? '+' : ''}${price.change.toFixed(2)}%)`, 'info'); |
| #42 | } else { |
| #43 | addLog(state, 'OBSERVE', `CoinGecko unavailable — ${String(results[0].reason).slice(0, 60)}`, 'warn'); |
| #44 | } |
| #45 | |
| #46 | if (results[1].status === 'fulfilled') { |
| #47 | state.trending = results[1].value; |
| #48 | addLog(state, 'OBSERVE', `Trending: ${state.trending.slice(0, 3).map(t => t.symbol).join(', ')}`, 'info'); |
| #49 | } else { |
| #50 | addLog(state, 'OBSERVE', 'Trending data unavailable', 'warn'); |
| #51 | } |
| #52 | |
| #53 | // ORIENT — score tokens |
| #54 | state.oodaPhase = 'orient'; |
| #55 | const scored = scoreTrending(state); |
| #56 | addLog(state, 'ORIENT', `Scored ${scored.length} tokens`, 'info'); |
| #57 | for (const s of scored.slice(0, 3)) { |
| #58 | addLog(state, 'ORIENT', `${s.symbol}: ${s.score}/100 → ${s.side.toUpperCase()} ${s.size}`, 'trade'); |
| #59 | } |
| #60 | |
| #61 | // DECIDE |
| #62 | state.oodaPhase = 'decide'; |
| #63 | const best = scored[0] ?? null; |
| #64 | if (best && best.score >= 65) { |
| #65 | state.lastSignal = best; |
| #66 | addLog(state, 'DECIDE', `Signal: ${best.symbol} score=${best.score} size=${best.size} — awaiting approval`, 'trade'); |
| #67 | } else { |
| #68 | addLog(state, 'DECIDE', `PASS — top score ${best?.score ?? 0}/100 below threshold 65`, 'info'); |
| #69 | state.lastSignal = null; |
| #70 | } |
| #71 | |
| #72 | // ACT — gated |
| #73 | state.oodaPhase = 'act'; |
| #74 | addLog(state, 'ACT', 'Trade execution gated — deny-first permission engine engaged', 'warn'); |
| #75 | |
| #76 | // LEARN |
| #77 | state.oodaPhase = 'learn'; |
| #78 | state.memory.known += state.trending.length; |
| #79 | state.memory.learned = Math.min(state.memory.learned + 1, 999); |
| #80 | if (best) state.memory.inferred += 1; |
| #81 | state.cycleCount += 1; |
| #82 | |
| #83 | addLog(state, 'LEARN', `Cycle #${state.cycleCount} complete. Memory K:${state.memory.known} L:${state.memory.learned} I:${state.memory.inferred}`, 'info'); |
| #84 | |
| #85 | state.oodaPhase = 'idle'; |
| #86 | state.lastRefresh = Date.now(); |
| #87 | } |
| #88 | |
| #89 | async function fetchSolPrice(): Promise<{ usd: number; change: number }> { |
| #90 | const r = await fetch( |
| #91 | 'https://api.coingecko.com/api/v3/simple/price?ids=solana&vs_currencies=usd&include_24hr_change=true', |
| #92 | { signal: AbortSignal.timeout(8000) }, |
| #93 | ); |
| #94 | if (!r.ok) throw new Error(`HTTP ${r.status}`); |
| #95 | const d = (await r.json()) as CoinGeckoPrice; |
| #96 | return { usd: d.solana.usd, change: d.solana.usd_24h_change }; |
| #97 | } |
| #98 | |
| #99 | async function fetchTrending(): Promise<TrendingToken[]> { |
| #100 | const r = await fetch( |
| #101 | 'https://data.solanatracker.io/tokens/trending?limit=8', |
| #102 | { |
| #103 | headers: { Accept: 'application/json' }, |
| #104 | signal: AbortSignal.timeout(8000), |
| #105 | }, |
| #106 | ); |
| #107 | if (!r.ok) throw new Error(`HTTP ${r.status}`); |
| #108 | const d = (await r.json()) as SolanaTrackerResponse; |
| #109 | const tokens = d.tokens ?? d.data ?? []; |
| #110 | return tokens.slice(0, 8).map((t) => ({ |
| #111 | symbol: (t.symbol ?? t.token?.symbol ?? '???').toUpperCase().slice(0, 10), |
| #112 | change: t.change24h ?? t.priceChange24h ?? 0, |
| #113 | volume24h: t.volume24h ?? t.volume, |
| #114 | })); |
| #115 | } |
| #116 | |
| #117 | function scoreTrending(state: DashboardState): TradeSignal[] { |
| #118 | return state.trending.map((t) => { |
| #119 | let score = 50; |
| #120 | if (t.change > 10) score += 20; |
| #121 | else if (t.change > 5) score += 10; |
| #122 | else if (t.change < -5) score -= 10; |
| #123 | if ((t.volume24h ?? 0) > 1_000_000) score += 15; |
| #124 | if (state.solChange24h > 0) score += 5; |
| #125 | else score -= 5; |
| #126 | score = Math.max(0, Math.min(100, score)); |
| #127 | |
| #128 | let size = '0.5x'; |
| #129 | if (score >= 90) size = '1.5x'; |
| #130 | else if (score >= 80) size = '1.25x'; |
| #131 | else if (score >= 70) size = '1.0x'; |
| #132 | |
| #133 | return { |
| #134 | symbol: t.symbol, |
| #135 | score, |
| #136 | size, |
| #137 | side: score >= 65 ? 'buy' : score <= 35 ? 'sell' : 'pass', |
| #138 | timestamp: Date.now(), |
| #139 | } satisfies TradeSignal; |
| #140 | }).sort((a, b) => b.score - a.score); |
| #141 | } |
| #142 |