From 7f87478ee1d5311d9b7c938b5a9851e136b5c958 Mon Sep 17 00:00:00 2001 From: ZhouYongyou <128128010+zhouyongyou@users.noreply.github.com> Date: Mon, 3 Nov 2025 21:03:55 +0800 Subject: [PATCH] refactor: align variable naming and add Binance time sync 1. Rename `traderRecord` to `trader` in handleCreateTrader - Aligns with upstream naming convention (nofxaios/dev) - Line 403: variable definition - Line 424: CreateTrader call 2. Add Binance server time synchronization (PR #145 simple fix) - Fixes timestamp errors (code=-1021) - Sets UseTestnet=false (ensure production network) - Syncs server time on trader initialization - Based on commit 64299c1 from pr-145 branch Both changes improve compatibility with upstream and prevent timestamp-related API failures. --- api/server.go | 4 ++-- trader/binance_futures.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/api/server.go b/api/server.go index 4fd793a2..0b5cbe06 100644 --- a/api/server.go +++ b/api/server.go @@ -400,7 +400,7 @@ func (s *Server) handleCreateTrader(c *gin.Context) { } // 创建交易员配置(数据库实体) - traderRecord := &config.TraderRecord{ + trader := &config.TraderRecord{ ID: traderID, UserID: userID, Name: req.Name, @@ -421,7 +421,7 @@ func (s *Server) handleCreateTrader(c *gin.Context) { } // 保存到数据库 - err = s.database.CreateTrader(traderRecord) + err = s.database.CreateTrader(trader) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("创建交易员失败: %v", err)}) return diff --git a/trader/binance_futures.go b/trader/binance_futures.go index abaf5c9a..52af087d 100644 --- a/trader/binance_futures.go +++ b/trader/binance_futures.go @@ -32,6 +32,11 @@ type FuturesTrader struct { // NewFuturesTrader 创建合约交易器 func NewFuturesTrader(apiKey, secretKey string) *FuturesTrader { client := futures.NewClient(apiKey, secretKey) + + // 🔧 修复时间戳问题:启用时间同步 + futures.UseTestnet = false // 确保使用正式网络 + client.NewSetServerTimeService().Do(context.Background()) // 同步服务器时间 + return &FuturesTrader{ client: client, cacheDuration: 15 * time.Second, // 15秒缓存