Refactor market package filenames for consistent data-dimension naming #26

Closed
opened 2026-04-27 04:36:36 +07:00 by claudecode · 1 comment
Owner

Summary

Chuẩn hóa tên file trong internal/data/market theo dimension dữ liệu để dễ đọc và nhất quán, tránh naming theo endpoint/lịch sử implementation.

Problem

Hiện tại package market có naming lẫn lộn (trading_pairs.go, future_price.go, spot_price.go, alpha_tokens.go), làm khó nhận biết trách nhiệm file khi đọc nhanh.

Proposed Direction

Đổi naming về dạng nhất quán theo nhóm dữ liệu:

  • spot_pairs.go
  • futures_pairs.go
  • spot_prices.go
  • futures_prices.go
  • giữ alpha_tokens.go

Nguyên tắc: nhìn tên file là biết ngay loại dữ liệu mà file quản lý.

Scope

  • Đây là rename-only PR (không đổi logic behavior).
  • Nếu cần chỉnh import/path do rename thì giữ ở mức mechanical update.
  • Không gộp với các thay đổi logic khác để giảm review noise.

Why separate issue/PR

  • Rename tạo diff lớn nhưng ít giá trị logic.
  • Tách PR giúp review dễ hơn, giảm rủi ro và giúp blame/history rõ ràng.
## Summary Chuẩn hóa tên file trong `internal/data/market` theo dimension dữ liệu để dễ đọc và nhất quán, tránh naming theo endpoint/lịch sử implementation. ## Problem Hiện tại package market có naming lẫn lộn (`trading_pairs.go`, `future_price.go`, `spot_price.go`, `alpha_tokens.go`), làm khó nhận biết trách nhiệm file khi đọc nhanh. ## Proposed Direction Đổi naming về dạng nhất quán theo nhóm dữ liệu: - `spot_pairs.go` - `futures_pairs.go` - `spot_prices.go` - `futures_prices.go` - giữ `alpha_tokens.go` Nguyên tắc: nhìn tên file là biết ngay loại dữ liệu mà file quản lý. ## Scope - Đây là **rename-only PR** (không đổi logic behavior). - Nếu cần chỉnh import/path do rename thì giữ ở mức mechanical update. - Không gộp với các thay đổi logic khác để giảm review noise. ## Why separate issue/PR - Rename tạo diff lớn nhưng ít giá trị logic. - Tách PR giúp review dễ hơn, giảm rủi ro và giúp blame/history rõ ràng.
Owner

Mình đã rà lại code hiện tại sau PR canonical maps.

Issue này vẫn hợp lý, nhưng nên chỉnh scope một chút: trading_pairs.go hiện không chỉ là “trading pairs” nữa mà đang chứa cả:

  • spot pair cache
  • futures pair cache
  • canonical token -> symbol lookup
  • shared quote-priority helpers
  • cache refresh orchestration

Vì vậy nếu chỉ rename file thì vẫn chưa sạch về mặt boundary. Đề nghị làm PR này theo hướng move-only / no behavior change:

  1. Rename price files:

    • spot_price.go -> spot_prices.go
    • future_price.go -> futures_prices.go
  2. Split trading_pairs.go theo responsibility:

    • spot_pairs.go: refreshSpotPairCache, IsSpotPair, GetSpotSymbolByToken
    • futures_pairs.go: refreshFuturePairCache, IsFuturesPair, GetFutureSymbolByToken, futureCacheTokenKey
    • pair_symbols.go hoặc symbol_canonical.go: shared helpers như parseTokenFromSymbolByQuotePriority, selectCanonicalSymbolByQuotePriority
    • cache_refresh.go: refreshTradingPairCache, refreshAllCaches, cacheRefreshLoop
  3. Clean up small dead-code item:

    • alphaCacheRefreshLoop trong main.go hiện không còn được gọi sau khi có cacheRefreshLoop; nên remove trong cùng PR nếu vẫn giữ no-behavior-change.

Acceptance:

  • Không đổi public behavior.
  • Không đổi resolver logic.
  • Không đổi cache semantics.
  • Chỉ move/rename function giữa files và update test filenames tương ứng.
  • go test ./... pass.

Như vậy issue #26 vẫn là refactor naming/structure, nhưng tránh rename nửa vời khiến trading_pairs.go tiếp tục là “god file” của market cache.

Mình đã rà lại code hiện tại sau PR canonical maps. Issue này vẫn hợp lý, nhưng nên chỉnh scope một chút: `trading_pairs.go` hiện không chỉ là “trading pairs” nữa mà đang chứa cả: - spot pair cache - futures pair cache - canonical token -> symbol lookup - shared quote-priority helpers - cache refresh orchestration Vì vậy nếu chỉ rename file thì vẫn chưa sạch về mặt boundary. Đề nghị làm PR này theo hướng move-only / no behavior change: 1. Rename price files: - `spot_price.go` -> `spot_prices.go` - `future_price.go` -> `futures_prices.go` 2. Split `trading_pairs.go` theo responsibility: - `spot_pairs.go`: `refreshSpotPairCache`, `IsSpotPair`, `GetSpotSymbolByToken` - `futures_pairs.go`: `refreshFuturePairCache`, `IsFuturesPair`, `GetFutureSymbolByToken`, `futureCacheTokenKey` - `pair_symbols.go` hoặc `symbol_canonical.go`: shared helpers như `parseTokenFromSymbolByQuotePriority`, `selectCanonicalSymbolByQuotePriority` - `cache_refresh.go`: `refreshTradingPairCache`, `refreshAllCaches`, `cacheRefreshLoop` 3. Clean up small dead-code item: - `alphaCacheRefreshLoop` trong `main.go` hiện không còn được gọi sau khi có `cacheRefreshLoop`; nên remove trong cùng PR nếu vẫn giữ no-behavior-change. Acceptance: - Không đổi public behavior. - Không đổi resolver logic. - Không đổi cache semantics. - Chỉ move/rename function giữa files và update test filenames tương ứng. - `go test ./...` pass. Như vậy issue #26 vẫn là refactor naming/structure, nhưng tránh rename nửa vời khiến `trading_pairs.go` tiếp tục là “god file” của market cache.
Sign in to join this conversation.
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: public/crypto-price-bot#26