fix: render basis with explicit sign and absolute delta
Format basis row as +/-$abs(delta) to match the spec and avoid awkward %+s formatting behavior. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package view
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -102,7 +103,11 @@ func RenderRichTokenMessage(in RichTokenMessageInput) string {
|
|||||||
if in.HasSpot && in.HasFuture && in.SpotPrice > 0 {
|
if in.HasSpot && in.HasFuture && in.SpotPrice > 0 {
|
||||||
delta := in.FuturePrice - in.SpotPrice
|
delta := in.FuturePrice - in.SpotPrice
|
||||||
deltaPct := delta / in.SpotPrice * 100
|
deltaPct := delta / in.SpotPrice * 100
|
||||||
rows = append(rows, fmt.Sprintf("🧭 Basis: $%+s (%+.2f%%)", RenderPrice(delta), deltaPct))
|
sign := "+"
|
||||||
|
if delta < 0 {
|
||||||
|
sign = "-"
|
||||||
|
}
|
||||||
|
rows = append(rows, fmt.Sprintf("🧭 Basis: %s$%s (%+.2f%%)", sign, RenderPrice(math.Abs(delta)), deltaPct))
|
||||||
}
|
}
|
||||||
|
|
||||||
if in.HasFuture {
|
if in.HasFuture {
|
||||||
|
|||||||
@@ -118,6 +118,20 @@ func TestRenderRichTokenMessage_SpotAndFuture(t *testing.T) {
|
|||||||
MarginAPRPercent: 5.11,
|
MarginAPRPercent: 5.11,
|
||||||
})
|
})
|
||||||
|
|
||||||
assertContainsAll(t, msg, "🪙 SOL", "💵 Spot:", "📈 Future:", "🧭 Basis:", "💸 Funding:", "🏦 Margin:")
|
assertContainsAll(t, msg, "🪙 SOL", "💵 Spot:", "📈 Future:", "🧭 Basis: +$0.6000", "💸 Funding:", "🏦 Margin:")
|
||||||
assertContainsNone(t, msg, "🅰️ Alpha:", "📊 Alpha 24h:")
|
assertContainsNone(t, msg, "🅰️ Alpha:", "📊 Alpha 24h:")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRenderRichTokenMessage_SpotAndFutureNegativeBasis(t *testing.T) {
|
||||||
|
msg := RenderRichTokenMessage(RichTokenMessageInput{
|
||||||
|
Token: "ADA",
|
||||||
|
HasSpot: true,
|
||||||
|
SpotPrice: 1.2,
|
||||||
|
HasFuture: true,
|
||||||
|
FuturePrice: 1.1,
|
||||||
|
FundingRate: 0.000011,
|
||||||
|
FundingTimeMs: 1740000000000,
|
||||||
|
})
|
||||||
|
|
||||||
|
assertContainsAll(t, msg, "🧭 Basis: -$0.10000 (-8.33%)")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user