Skip to content

Commit

Permalink
fix for float formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekonan committed Nov 17, 2021
1 parent af2903c commit 21e2471
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package model
import (
"bytes"
"fmt"
"strconv"
)

type Candle struct {
Expand All @@ -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 {
Expand Down

0 comments on commit 21e2471

Please sign in to comment.