feat: fetch alpha price by symbol ticker

Keep alpha token existence from list cache and fetch live alpha price via symbol ticker endpoint for richer token response accuracy.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 18:22:48 +07:00
parent 6e8a2e8f68
commit 82b0f2f1a8
4 changed files with 83 additions and 4 deletions
+5 -1
View File
@@ -66,9 +66,13 @@ func collectRichTokenData(token string) buildRichTokenMessageArgs {
if alphaToken, ok := data.Market.GetAlphaToken(token); ok {
a.HasAlpha = true
a.AlphaPrice = alphaToken.GetPrice()
a.HasAlpha24h = true
a.Alpha24h = alphaToken.GetPercentChange24h()
if alphaPrice, ok := data.Market.GetAlphaPrice(token + "USDT"); ok {
a.AlphaPrice = alphaPrice
} else {
a.AlphaPrice = alphaToken.GetPrice()
}
}
futureSymbol := token + "USDT"
@@ -56,6 +56,7 @@ type marketStub struct {
time int64
}
alphaTokens map[string]market.AlphaTokenInfo
alphaPrices map[string]float64
marginRates map[string]float64
}
@@ -81,6 +82,10 @@ func (m *marketStub) GetAlphaToken(symbol string) (market.AlphaTokenInfo, bool)
v, ok := m.alphaTokens[symbol]
return v, ok
}
func (m *marketStub) GetAlphaPrice(symbol string) (float64, bool) {
v, ok := m.alphaPrices[symbol]
return v, ok
}
func (m *marketStub) IsSpotPair(symbol string) bool { return m.spotPairs[symbol] }
func (m *marketStub) IsFuturesPair(symbol string) bool { return m.futuresPairs[symbol] }
func (m *marketStub) RefreshTradingPairCache() error { return nil }
@@ -126,3 +131,26 @@ func TestCollectRichTokenData_FutureFailureStillKeepsSpot(t *testing.T) {
t.Fatalf("did not expect future when future lookup fails: %+v", args)
}
}
func TestCollectRichTokenData_AlphaUsesSymbolPrice(t *testing.T) {
orig := data.Market
defer func() { data.Market = orig }()
data.Market = &marketStub{
alphaTokens: map[string]market.AlphaTokenInfo{
"ABC": {Symbol: "ABC", PercentChange24h: "12.4", Price: "0.1"},
},
alphaPrices: map[string]float64{"ABCUSDT": 0.1234},
}
args := collectRichTokenData("ABC")
if !args.HasAlpha {
t.Fatalf("expected alpha to be available: %+v", args)
}
if !args.HasAlpha24h {
t.Fatalf("expected alpha 24h to be available: %+v", args)
}
if args.AlphaPrice != 0.1234 {
t.Fatalf("expected alpha price from symbol lookup, got %.4f", args.AlphaPrice)
}
}