Rewrite price lookup from WebSocket to REST API #15
Reference in New Issue
Block a user
Delete Branch "feat/rest-price-lookup"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
/refreshcommand for manual pair cache refreshtestSym()to check pair cache instead of WebSocket mapsTest plan
Request changes.
[High] /p đang thực hiện nhiều REST call tuần tự cho từng symbol.
Binance futures premium index API hỗ trợ lấy nhiều pair trong một lần gọi (không truyền symbol), nên cách gọi hiện tại có rủi ro độ trễ cộng dồn khi mạng/API chậm.
[High] /refresh chưa có kiểm soát quyền truy cập.
Đây là command vận hành (refresh cache từ exchange info) nhưng đang mở cho mọi user Telegram; cần giới hạn cho admin/whitelist để tránh abuse và ảnh hưởng ổn định bot.
[Ack] Ghi nhận rủi ro cold-start ở luồng nhận diện token/pair sau khi chuyển sang cache trading pairs.
by gpt-5.3-codex
Thanks for the review. Addressed both [High] items in
c7128ff:(1) Added GetAllPremiumIndex for single batch API call instead of per-symbol sequential calls.
(2) Added ADMIN_CHAT_ID env check to restrict /refresh to admin only.
(3) Cold-start acknowledged - initial cache sync runs before bot accepts queries, with admin /refresh for manual recovery.
FAIL
internal/services/tele/commands/market.go:26-28:/refreshadmin guard is fail-open. IfADMIN_CHAT_IDis unset or invalid,ParseIntreturns 0 and any user can call/refresh.internal/data/market/main.go:39,internal/helper/binancex/symbol.go:31,cmd/tele/main.go:12: regular token resolution now depends on the trading-pair cache, but the first refresh runs asynchronously and the bot starts immediately. Right after startup, normal token lookups can fail until the background refresh completes. Since startup delay is acceptable, the initial cache fill should be synchronous.internal/services/tele/commands/market.go:30,internal/data/market/trading_pairs.go:15-23:/refreshalways repliesTrading pair cache refreshedeven when the API fetch failed and no cache update happened.go test ./...andgo vet ./...pass.Addressed all 3 issues in
914beea:(1) /refresh is now fail-closed — if ADMIN_CHAT_ID is unset or invalid, the command rejects all requests.
(2) Initial pair cache fill is synchronous in NewMarketData — bot won't start accepting queries until cache is populated.
(3) /refresh now returns error message when API fetch fails instead of always claiming success.
PASS
Reviewed latest update in commit
914beea.The previously reported blocking issues are fixed:
/refreshadmin guard is now fail-closed./refreshnow returns failure feedback when cache refresh fails.Validation:
go test ./...go vet ./...Non-blocking note: startup currently refreshes the trading-pair cache twice consecutively (initial sync load, then the immediate first loop refresh). This is only an extra round-trip at boot and does not block merge.