Skip to content

Latest commit

 

History

History
41 lines (35 loc) · 3.74 KB

persona-model.md

File metadata and controls

41 lines (35 loc) · 3.74 KB

Trader vs Persona Data Model Audit

Summary

  • ⚠️ Many-to-many relationship is represented by storing an array of personas on each trader profile (TraderProfile.personas); stats fallback now writes hashes for ~200 traders, but coverage is still synthetic until live collectors resume.
  • ⚠️ Persona aggregation (intelligence:persona:*) runs every ~5 minutes and publishes stats + member sets, yet relies entirely on stats-derived personas (no Hyperliquid signal).
  • ⚠️ Gateway persona endpoints (/api/v1/personas, /api/v1/personas/:personaName/stats, /api/v1/personas/:personaName/traders) respond when Redis is hydrated, but TTL expirations drop them back to empty.
  • ⚠️ Multi-persona queries now leverage Redis sets (intelligence:persona:{name}:members), but we still need validation at scale and better fallbacks when sets expire.

Trader Profile Schema

  • services/trader-intelligence/src/types.ts
    • TraderProfile.personas: TraderPersona[] (all personas assigned).
    • TraderProfile.primaryPersona: TraderPersona (dominant persona).
    • Personas are stored alongside analysis outputs (PnL, risk, positions).
  • Profiles are written to Redis by RedisPublisher.publishTraderProfile under intelligence:trader:{address}:profile (hash) when collection succeeds.
  • Current state: stats snapshot collector emits hashes (intelligence:trader:0xabc...:profile), but live Hyperliquid collectors still need to run for production fidelity.

Persona Storage

  • Persona catalog defined in services/trader-intelligence/src/personas/catalog.ts and detected via PersonaDetector.
  • Aggregated stats use keys such as:
    • intelligence:persona:{personaName}:stats (hash)
    • intelligence:persona:{personaName}:trend (sorted set)
    • intelligence:persona:{personaName}:members (set of lowercase trader addresses; now implemented and refreshed with each aggregation pass)
  • Persona aggregation job (aggregateAllPersonas) runs every 5 minutes; it currently operates on synthetic stats data and logs warnings when no trader profiles exist.

API Endpoints

  • Gateway endpoints in services/gateway/src/server/http.ts:
    • GET /api/v1/personas → lists persona stats; returns empty array when Redis TTL expires.
    • GET /api/v1/personas/:personaName/stats → detailed stats; 404s until persona aggregation writes the hash.
    • GET /api/v1/personas/:personaName/traders → supports persona=a,b&match=all|any, using Redis set intersection/union when member sets exist, otherwise falling back to profile scans.
  • Frontend UI (apps/ui/components/trader/PersonaCardsGrid.tsx) expects persona stats to populate persona tabs and surfaces skeleton/empty states when data dries up.

Query Capabilities

  • Single persona filter: gateway first checks intelligence:persona:{name}:members; if absent, it falls back to scanning profile.personas.
  • Multiple persona intersection: supported via Redis set ops when member sets exist (match=all uses SINTER; match=any uses SUNION); needs load/perf testing with >10k traders.
  • Persona + time window metrics: dependent on persona aggregation; currently limited to stats fallback windows.

Gaps & Recommendations

  1. Ensure trader profiles are persisted from live collectors (not just stats fallback) so persona assignments reflect real activity.
  2. Monitor + alert on intelligence:persona:{name}:members TTL expirations—gateway persona filters silently degrade when sets disappear.
  3. Expand gateway responses to include persona confidence scores + sourcing so UI can communicate synthetic vs real data.
  4. Add integration tests that assert persona stats/member sets and persona-based trader queries after docker-dev bootstrap (see tests/personaAggregation.integration.test.ts for a starting point).