| name | platform-market-analysis-system |
| description | Market analysis system using AI agents, streaming chat interface, and real-time data integration. Use when this capability is needed. |
| metadata | {"author":"aaaa47080"} |
Platform Market Analysis Skill
Overview
The Market Analysis System is an AI-powered chat interface that allows users to ask questions about crypto markets, trends, and technical indicators. It uses a "ReAct" style agent approach to reason, fetch data, and formulate answers.
Key Features:
- Natural Language Parsing: Understands "Analyze BTC" or "Is ETH bullish?".
- Real-time Data: Fetches live prices, technical indicators (RSI, MAX), and news.
- Streaming Response: Shows the "thought process" (steps) in real-time before the final answer.
- Session Management: Multi-session chat history with pinning and persistence.
Key Files:
- Frontend:
web/js/chat.js (Chat UI & Stream Handler), web/js/market.js (Data Visualization)
- Backend API:
api/routers/analysis.py (Endpoints)
- Core Logic:
interfaces/chat_interface.py (Bot & Parser), core/agents.py (Agent Logic)
Architecture
Data Flow
- User Input: Typed in
web/js/chat.js.
- API Request:
POST /api/analyze (Stream).
- Query Parsing:
CryptoQueryParser calls LLM to extract intent (Symbol: BTC, Action: Analyze).
- Execution:
CryptoAnalysisBot decides which tools to run (Price, News, Indicators).
- Streaming:
- Backend yields "Process Steps" (
[PROCESS] Fetching data...)
- Backend yields "Final Answer" (
[RESULT] Bitcoin is currently...)
- Rendering: Frontend parses the stream and updates the UI incrementally.
Components
1. CryptoAnalysisBot (interfaces/chat_interface.py)
the main orchestrator. It:
- Maintains conversation history.
- Manages the
CryptoAgent or executes the "Standard Analysis Mode" (legacy).
- Generates the streaming response generator.
2. Streaming Protocol (NDJSON style)
The /api/analyze endpoint returns a stream of JSON objects or specially formatted text lines.
data: {"content": "[PROCESS] Checking limits..."} -> Updates the "Thinking" UI.
data: {"content": "[RESULT] **Analysis**: ..."} -> Renders the final markdown response.
data: {"done": true} -> Closes the stream.
3. Frontend Chat (web/js/chat.js)
- Session Management: Loads/Creates/Deletes sessions via
/api/chat/sessions.
- Stream Reader: Uses
response.body.getReader() to process chunks.
- UI Rendering:
renderStoredBotMessage() parses the special tags ([PROCESS_START], [RESULT]) to create the collapsible "Process" section and the Markdown result.
API Endpoints
Analysis
POST /api/analyze
Streamed analysis response.
Payload:
{
"message": "Analyze BTC",
"manual_selection": ["rsi", "macd"],
"market_type": "spot",
"session_id": "uuid..."
}
POST /api/analysis/backtest
Runs a quick backtest for a strategy.
Session Management
GET /api/chat/sessions
List user's chat sessions.
POST /api/chat/sessions
Create a new session.
GET /api/chat/history?session_id=...
Get message history for a session.
Frontend Integration (chat.js)
Key Function: sendMessage()
- Checks for API Key.
- Creates/Selects a session.
- Sends
POST /api/analyze.
- Reads stream loop:
while (true) {
const { value, done } = await reader.read();
botMsgDiv.innerHTML = renderStoredBotMessage(fullContent, true);
}
UI States:
- Thinking: Shows a spinner and elapsed time.
- Process: Collapsible details tag showing step-by-step actions.
- Result: Final markdown content.
Modification Guidelines
✅ Safe Modifications
-
Adding New Tools:
- Add tool function in
core/tools.py.
- Register tool in
core/agents.py.
- The Bot will automatically have access to it (if using Agent mode).
-
Customizing UI:
web/js/chat.js: renderStoredBotMessage controls how the message looks. You can change styling here.
⚠️ Risks
-
LLM Context Window:
- Passing too much history or too large data (news articles) can hit token limits.
- Fix: Use
trim_history or summarization techniques in CryptoAnalysisBot.
-
Timeout:
- Complex analysis takes time (>30s).
- Fix: Ensure Nginx/frontend timeout settings allow for long-lived streams.
Related Skills
- platform-db-pattern: For session storage logic.
- pi-auth: For user identification in sessions.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.