Fix concurrent map read/write race condition in MarketData
Add sync.RWMutex to protect future and spot price maps accessed by WebSocket handlers (writers) and Telegram bot handlers (readers). Also adds Alpha token support with caching. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/message"
|
||||
"gopkg.in/telebot.v3"
|
||||
@@ -9,7 +11,6 @@ import (
|
||||
"me.thuanle/bbot/internal/helper/binancex"
|
||||
"me.thuanle/bbot/internal/services/tele/chat"
|
||||
"me.thuanle/bbot/internal/services/tele/view"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var lastEthPrice float64
|
||||
@@ -27,6 +28,22 @@ func showStickerMode(context telebot.Context, token string) {
|
||||
}
|
||||
|
||||
func OnTokenInfoByToken(context telebot.Context, token string) error {
|
||||
token = strings.ToUpper(token)
|
||||
|
||||
// Check if it's an Alpha token first
|
||||
if data.Market.IsAlphaToken(token) {
|
||||
showStickerMode(context, token)
|
||||
|
||||
if alphaToken, exists := data.Market.GetAlphaToken(token); exists {
|
||||
sp := alphaToken.GetPrice()
|
||||
// For Alpha tokens, we don't have future price, funding rate, etc.
|
||||
// Use spot price for both spot and future in the display
|
||||
_ = chat.ReplyMessage(context, view.RenderOnPriceMessage(token, sp, sp, 0, 0, 0))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Regular token handling
|
||||
symbols := binancex.Token2Symbols(token)
|
||||
if len(symbols) == 0 {
|
||||
return nil
|
||||
@@ -36,7 +53,7 @@ func OnTokenInfoByToken(context telebot.Context, token string) error {
|
||||
|
||||
fp, fundRate, fundTime, ok := data.Market.GetFuturePrice(symbols[0])
|
||||
marginRates := data.Market.GetMarginInterestRates()
|
||||
tokenInterestRate := marginRates[strings.ToUpper(token)]
|
||||
tokenInterestRate := marginRates[token]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user