Files
nofx/nofxi/internal/memory/models.go
shinchan-zhai cf7bf16c28 feat: init nofxi - AI Trading Agent module
NOFXi — Your AI Trading Agent, built on NOFX.

Architecture:
- Agent Core: intent routing, conversation memory, trade confirmation
- Memory: SQLite (trades, conversations, preferences, strategies)
- Thinking: LLM client (OpenAI/claw402/DeepSeek compatible)
- Execution: Bridge to NOFX trader engine (9 exchanges)
- Perception: Market monitor, price alerts, anomaly detection
- Interaction: Telegram bot + REST API + OpenAI-compatible endpoint

Features:
- Natural language trading (中英文)
- /buy /sell /analyze /watch /alert /positions /balance
- Daily P/L reports, portfolio risk checks
- Trade confirmation flow (safety first)
- Price polling and alert notifications
2026-03-22 17:48:14 +08:00

65 lines
2.3 KiB
Go

package memory
import "time"
// TradeRecord stores a completed or active trade.
type TradeRecord struct {
ID int64 `json:"id"`
Exchange string `json:"exchange"`
Symbol string `json:"symbol"`
Side string `json:"side"` // "buy" or "sell"
Type string `json:"type"` // "market", "limit"
Price float64 `json:"price"`
Quantity float64 `json:"quantity"`
PnL float64 `json:"pnl"` // Realized P/L
Fee float64 `json:"fee"`
Status string `json:"status"` // "open", "closed", "cancelled"
AIModel string `json:"ai_model"` // Which AI model made the decision
AIReason string `json:"ai_reason"` // Why AI made this decision
StrategyID string `json:"strategy_id"`
CreatedAt time.Time `json:"created_at"`
ClosedAt *time.Time `json:"closed_at,omitempty"`
}
// UserPreference stores user settings and preferences.
type UserPreference struct {
ID int64 `json:"id"`
UserID int64 `json:"user_id"` // Telegram user ID
Key string `json:"key"`
Value string `json:"value"`
UpdatedAt time.Time `json:"updated_at"`
}
// Conversation stores chat messages for context.
type Conversation struct {
ID int64 `json:"id"`
UserID int64 `json:"user_id"`
Role string `json:"role"` // "user", "assistant", "system"
Content string `json:"content"`
CreatedAt time.Time `json:"created_at"`
}
// StrategyPerformance tracks how well a strategy has performed.
type StrategyPerformance struct {
ID int64 `json:"id"`
StrategyID string `json:"strategy_id"`
StrategyName string `json:"strategy_name"`
TotalTrades int `json:"total_trades"`
WinRate float64 `json:"win_rate"`
TotalPnL float64 `json:"total_pnl"`
MaxDrawdown float64 `json:"max_drawdown"`
SharpeRatio float64 `json:"sharpe_ratio"`
UpdatedAt time.Time `json:"updated_at"`
}
// MarketSnapshot stores a point-in-time market state for pattern recognition.
type MarketSnapshot struct {
ID int64 `json:"id"`
Symbol string `json:"symbol"`
Price float64 `json:"price"`
Volume24h float64 `json:"volume_24h"`
Change24h float64 `json:"change_24h"`
Note string `json:"note"` // AI observation about this snapshot
CreatedAt time.Time `json:"created_at"`
}