package view import ( "fmt" "github.com/jedib0t/go-pretty/v6/table" "golang.org/x/text/language" "golang.org/x/text/message" "me.thuanle/bbot/internal/helper/binancex" "me.thuanle/bbot/internal/services/tele/view/helper" "me.thuanle/bbot/internal/utils/timex" "time" ) func RenderPrice(price float64) string { mFmt := message.NewPrinter(language.AmericanEnglish) switch { case price > 1000: return mFmt.Sprintf("%0.0f", price) case price > 100: return mFmt.Sprintf("%0.1f", price) case price > 10: return mFmt.Sprintf("%0.2f", price) case price > 1: return mFmt.Sprintf("%0.3f", price) case price > 0.1: return mFmt.Sprintf("%0.4f", price) case price > 0.01: return mFmt.Sprintf("%0.5f", price) case price > 0.001: return mFmt.Sprintf("%0.6f", price) case price > 0.0001: return mFmt.Sprintf("%0.7f", price) default: return mFmt.Sprintf("%0.8f", price) } } func RenderOnPriceMessage(symbol string, spotPrice float64, futurePrice float64, fundrate float64, fundtime int64, marginRate float64) string { return fmt.Sprintf( "%s: %s\n"+ "Fund rate: %.4f%% %s in %s\n"+ "Spot: %s\n"+ "Margin rate: %.3f%%", RenderSymbolInfo(symbol), RenderPrice(futurePrice), fundrate*100, IconOfFundingFeeDirection(fundrate), timex.CdMinuteStringTime(time.UnixMilli(fundtime)), RenderPrice(spotPrice), marginRate*365*100, ) } func RenderOnGetTopPricesMessage(symbols []string, price []float64, fundRate []float64) string { t := helper.NewNoBorderTableWriter("", "Price", "Fund") mFmt := message.NewPrinter(language.AmericanEnglish) for i, symbol := range symbols { t.AppendRow(table.Row{ binancex.Symbol2Token(symbol), mFmt.Sprintf("%.2f", price[i]), mFmt.Sprintf("%.3f%%", fundRate[i]*100), }) } return t.Render() }