From 21e24718b0504f3099cb075a57fe01637da892c5 Mon Sep 17 00:00:00 2001 From: Mikalai Konan Date: Wed, 17 Nov 2021 15:37:49 +0300 Subject: [PATCH] fix for float formatting --- model/model.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/model/model.go b/model/model.go index ac76f58..4a483fe 100644 --- a/model/model.go +++ b/model/model.go @@ -3,6 +3,7 @@ package model import ( "bytes" "fmt" + "strconv" ) type Candle struct { @@ -20,11 +21,15 @@ type Candle struct { type Candles []Candle +func f(f float64) string { + return strconv.FormatFloat(f, 'f', -1, 64) +} + func (candles Candles) KucoinRespJSON() []byte { buff := bytes.NewBuffer(nil) buff.Write([]byte(`{"code":"200000","data":[`)) for _, c := range candles { - buff.Write([]byte(fmt.Sprintf(`["%d","%f","%f","%f","%f","%f","%f"],`, c.Ts, c.Open, c.Close, c.High, c.Low, c.Volume, c.Amount))) + buff.Write([]byte(fmt.Sprintf(`["%d","%s","%s","%s","%s","%s","%s"],`, c.Ts, f(c.Open), f(c.Close), f(c.High), f(c.Low), f(c.Volume), f(c.Amount)))) } if len(candles) > 0 {