mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-04 01:48:22 +08:00
cb31782be4
- Rename experience/ to telemetry/ for clarity - Split 15+ large Go files (800-2200 lines) into focused modules: kernel/engine.go, backtest/runner.go, market/data.go, store/position.go, api/handler_trader.go, trader/auto_trader_grid.go, and 9 exchange traders - Split frontend monoliths: types.ts, api.ts, AITradersPage.tsx, BacktestPage.tsx into domain-specific modules with barrel re-exports - Remove stale files: screenshots, .yml.old, pyproject.toml - Remove unused scripts/ and cmd/ directories - Remove broken/outdated test files (network-dependent, stale expectations)
80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"nofx/logger"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// handleUpdateTraderPrompt Update trader custom prompt
|
|
func (s *Server) handleUpdateTraderPrompt(c *gin.Context) {
|
|
traderID := c.Param("id")
|
|
userID := c.GetString("user_id")
|
|
|
|
var req struct {
|
|
CustomPrompt string `json:"custom_prompt"`
|
|
OverrideBasePrompt bool `json:"override_base_prompt"`
|
|
}
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
SafeBadRequest(c, "Invalid request parameters")
|
|
return
|
|
}
|
|
|
|
// Update database
|
|
err := s.store.Trader().UpdateCustomPrompt(userID, traderID, req.CustomPrompt, req.OverrideBasePrompt)
|
|
if err != nil {
|
|
SafeInternalError(c, "Failed to update custom prompt", err)
|
|
return
|
|
}
|
|
|
|
// If trader is in memory, update its custom prompt and override settings
|
|
trader, err := s.traderManager.GetTrader(traderID)
|
|
if err == nil {
|
|
trader.SetCustomPrompt(req.CustomPrompt)
|
|
trader.SetOverrideBasePrompt(req.OverrideBasePrompt)
|
|
logger.Infof("✓ Updated trader %s custom prompt (override base=%v)", trader.GetName(), req.OverrideBasePrompt)
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{"message": "Custom prompt updated"})
|
|
}
|
|
|
|
// handleToggleCompetition Toggle trader competition visibility
|
|
func (s *Server) handleToggleCompetition(c *gin.Context) {
|
|
traderID := c.Param("id")
|
|
userID := c.GetString("user_id")
|
|
|
|
var req struct {
|
|
ShowInCompetition bool `json:"show_in_competition"`
|
|
}
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
SafeBadRequest(c, "Invalid request parameters")
|
|
return
|
|
}
|
|
|
|
// Update database
|
|
err := s.store.Trader().UpdateShowInCompetition(userID, traderID, req.ShowInCompetition)
|
|
if err != nil {
|
|
SafeInternalError(c, "Update competition visibility", err)
|
|
return
|
|
}
|
|
|
|
// Update in-memory trader if it exists
|
|
if trader, err := s.traderManager.GetTrader(traderID); err == nil {
|
|
trader.SetShowInCompetition(req.ShowInCompetition)
|
|
}
|
|
|
|
status := "shown"
|
|
if !req.ShowInCompetition {
|
|
status = "hidden"
|
|
}
|
|
logger.Infof("✓ Trader %s competition visibility updated: %s", traderID, status)
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"message": "Competition visibility updated",
|
|
"show_in_competition": req.ShowInCompetition,
|
|
})
|
|
}
|