Files
crypto-price-bot/internal/services/tele/commands/market.go
T
thuanle c7128ff516 Address PR #15 review: batch API calls and admin-guard /refresh
1. Add GetAllPremiumIndex() to fetch all futures data in one call,
   used by GetTopPrices instead of per-symbol sequential calls.
2. Add ADMIN_CHAT_ID env check to /refresh command to restrict
   access to authorized users only.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-26 15:40:00 +07:00

33 lines
993 B
Go

package commands
import (
"os"
"strconv"
"gopkg.in/telebot.v3"
"me.thuanle/bbot/internal/configs/key"
"me.thuanle/bbot/internal/data"
"me.thuanle/bbot/internal/services/controllers"
"me.thuanle/bbot/internal/services/tele/chat"
"me.thuanle/bbot/internal/services/tele/view"
)
func OnGetTopPrices(context telebot.Context) error {
sym, price, rate := controllers.GetTopPrices()
return chat.ReplyMessagePre(context, view.RenderOnGetTopPricesMessage(sym, price, rate))
}
func OnGetTopFundingFee(context telebot.Context) error {
fee, float64s, cds := controllers.GetTopFundingFee()
return chat.ReplyMessagePre(context, view.RenderOnGetTopFundingFeeMessage(fee, float64s, cds))
}
func OnRefreshPairCache(context telebot.Context) error {
adminID, _ := strconv.ParseInt(os.Getenv(key.AdminChatID), 10, 64)
if adminID != 0 && context.Sender().ID != adminID {
return nil
}
data.Market.RefreshTradingPairCache()
return chat.ReplyMessage(context, "Trading pair cache refreshed")
}