Replace unreliable WebSocket connections with on-demand REST API calls
for spot and futures prices. Add cached trading pair list (refreshed
hourly) for symbol validation, and /refresh command for manual updates.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
[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
Request changes.
1) [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.
2) [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.
3) [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
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>
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.
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.
internal/services/tele/commands/market.go:26-28: /refresh admin guard is fail-open. If ADMIN_CHAT_ID is unset or invalid, ParseInt returns 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: /refresh always replies Trading pair cache refreshed even when the API fetch failed and no cache update happened.
go test ./... and go vet ./... pass.
FAIL
1. `internal/services/tele/commands/market.go:26-28`: `/refresh` admin guard is fail-open. If `ADMIN_CHAT_ID` is unset or invalid, `ParseInt` returns 0 and any user can call `/refresh`.
2. `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.
3. `internal/services/tele/commands/market.go:30`, `internal/data/market/trading_pairs.go:15-23`: `/refresh` always replies `Trading pair cache refreshed` even when the API fetch failed and no cache update happened.
`go test ./...` and `go vet ./...` pass.
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>
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.
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.
The previously reported blocking issues are fixed:
/refresh admin guard is now fail-closed.
Initial trading-pair cache load is now synchronous before bot startup.
/refresh now 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.
PASS
Reviewed latest update in commit `914beea`.
The previously reported blocking issues are fixed:
- `/refresh` admin guard is now fail-closed.
- Initial trading-pair cache load is now synchronous before bot startup.
- `/refresh` now 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.
thuanle
merged commit 733cf48e41 into main2026-04-26 16:19:28 +07:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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.