Address PR #15 round 2: fail-closed admin guard, sync init, error reporting
1. /refresh now fail-closed: rejects all if ADMIN_CHAT_ID unset or invalid 2. Initial pair cache fill is synchronous — bot waits before accepting queries 3. /refresh reports failure when API fetch fails instead of always saying success Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -36,6 +36,9 @@ func NewMarketData() *MarketData {
|
||||
futuresClient: futures.NewClient("", ""),
|
||||
}
|
||||
|
||||
if err := ms.refreshTradingPairCache(); err != nil {
|
||||
log.Error().Err(err).Msg("Failed initial trading pair cache load")
|
||||
}
|
||||
go ms.pairCacheRefreshLoop()
|
||||
go ms.alphaCacheRefreshLoop()
|
||||
|
||||
|
||||
@@ -7,20 +7,20 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (ms *MarketData) refreshTradingPairCache() {
|
||||
func (ms *MarketData) refreshTradingPairCache() error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancel()
|
||||
|
||||
spotInfo, err := ms.spotClient.NewExchangeInfoService().Do(ctx)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to fetch spot exchange info")
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
futuresInfo, err := ms.futuresClient.NewExchangeInfoService().Do(ctx)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to fetch futures exchange info")
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
ms.pairCacheMutex.Lock()
|
||||
@@ -45,6 +45,7 @@ func (ms *MarketData) refreshTradingPairCache() {
|
||||
Int("spot", len(ms.spotPairs)).
|
||||
Int("futures", len(ms.futuresPairs)).
|
||||
Msg("Trading pair cache refreshed")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ms *MarketData) pairCacheRefreshLoop() {
|
||||
@@ -68,6 +69,6 @@ func (ms *MarketData) IsFuturesPair(symbol string) bool {
|
||||
return ms.futuresPairs[symbol]
|
||||
}
|
||||
|
||||
func (ms *MarketData) RefreshTradingPairCache() {
|
||||
ms.refreshTradingPairCache()
|
||||
func (ms *MarketData) RefreshTradingPairCache() error {
|
||||
return ms.refreshTradingPairCache()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user