Files
nofx/config/config.go
tinkle-community e2d702c662 feat: enhance backtest with real-time positions, P&L fixes, and strategy integration
- Add real-time position display with unrealized P&L during backtest
- Fix P&L calculation by tracking accumulated opening fees
- Add strategy coin source resolution (AI500, OI Top, mixed)
- Infer AI provider from model name for better compatibility
- Cap position size to available margin to prevent insufficient cash errors
- Fix trade markers on K-line chart (long/short instead of buy/sell)
- Add QuantData and OI ranking to backtest decision context
2025-12-20 01:10:11 +08:00

91 lines
2.5 KiB
Go

package config
import (
"nofx/experience"
"os"
"strconv"
"strings"
)
// Global configuration instance
var global *Config
// Config is the global configuration (loaded from .env)
// Only contains truly global config, trading related config is at trader/strategy level
type Config struct {
// Service configuration
APIServerPort int
JWTSecret string
RegistrationEnabled bool
MaxUsers int // Maximum number of users allowed (0 = unlimited, default = 1)
// Security configuration
// TransportEncryption enables browser-side encryption for API keys
// Requires HTTPS or localhost. Set to false for HTTP access via IP.
TransportEncryption bool
// Experience improvement (anonymous usage statistics)
// Helps us understand product usage and improve the experience
// Set EXPERIENCE_IMPROVEMENT=false to disable
ExperienceImprovement bool
}
// Init initializes global configuration (from .env)
func Init() {
cfg := &Config{
APIServerPort: 8080,
RegistrationEnabled: true,
MaxUsers: 5, // Default: only 1 user allowed
ExperienceImprovement: true, // Default: enabled to help improve the product
}
// Load from environment variables
if v := os.Getenv("JWT_SECRET"); v != "" {
cfg.JWTSecret = strings.TrimSpace(v)
}
if cfg.JWTSecret == "" {
cfg.JWTSecret = "default-jwt-secret-change-in-production"
}
if v := os.Getenv("REGISTRATION_ENABLED"); v != "" {
cfg.RegistrationEnabled = strings.ToLower(v) == "true"
}
if v := os.Getenv("MAX_USERS"); v != "" {
if maxUsers, err := strconv.Atoi(v); err == nil && maxUsers >= 0 {
cfg.MaxUsers = maxUsers
}
}
if v := os.Getenv("API_SERVER_PORT"); v != "" {
if port, err := strconv.Atoi(v); err == nil && port > 0 {
cfg.APIServerPort = port
}
}
// Transport encryption: default false for easier deployment
// Set TRANSPORT_ENCRYPTION=true to enable (requires HTTPS or localhost)
if v := os.Getenv("TRANSPORT_ENCRYPTION"); v != "" {
cfg.TransportEncryption = strings.ToLower(v) == "true"
}
// Experience improvement: anonymous usage statistics
// Default enabled, set EXPERIENCE_IMPROVEMENT=false to disable
if v := os.Getenv("EXPERIENCE_IMPROVEMENT"); v != "" {
cfg.ExperienceImprovement = strings.ToLower(v) != "false"
}
global = cfg
// Initialize experience improvement (installation ID will be set after database init)
experience.Init(cfg.ExperienceImprovement, "")
}
// Get returns the global configuration
func Get() *Config {
if global == nil {
Init()
}
return global
}