From 72daae7a7492a443272ab4fbbd9c43295cd49c54 Mon Sep 17 00:00:00 2001 From: Konstantin Romanov Date: Sun, 17 Dec 2023 16:50:48 +0300 Subject: [PATCH] remove decimal package --- api/history.go | 14 ++++++-------- api/moex.go | 13 ++++++------- api/spbex.go | 9 ++++----- go.mod | 1 - 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/api/history.go b/api/history.go index 00a6f12..32a7698 100644 --- a/api/history.go +++ b/api/history.go @@ -3,17 +3,15 @@ package api import ( "encoding/json" "time" - - "github.com/shopspring/decimal" ) type HistoryEntry struct { - Date time.Time `json:"date"` - Close decimal.Decimal `json:"close"` - High decimal.Decimal `json:"high"` - Low decimal.Decimal `json:"low"` - Volume uint64 `json:"volume"` - Facevalue decimal.Decimal `json:"facevalue"` + Date time.Time `json:"date"` + Close float64 `json:"close"` + High float64 `json:"high"` + Low float64 `json:"low"` + Volume uint64 `json:"volume"` + Facevalue float64 `json:"facevalue"` } type HistoryEntries []HistoryEntry diff --git a/api/moex.go b/api/moex.go index 5e8f34a..c576b1f 100644 --- a/api/moex.go +++ b/api/moex.go @@ -8,7 +8,6 @@ import ( custom_errors "github.com/kiberdruzhinnik/go-exchange-api/errors" "github.com/kiberdruzhinnik/go-exchange-api/utils" - "github.com/shopspring/decimal" ) const PAGE_SIZE = 100 @@ -125,7 +124,6 @@ func (api *MoexAPI) getSecurityParameters(ticker string) (MoexSecurityParameters return MoexSecurityParameters{}, custom_errors.ErrorCouldNotParseJSON } - // var output MoexSecurityParameters for _, entry := range moexJson.Boards.Data { isPrimary := int(entry[3].(float64)) if isPrimary == 1 { @@ -220,9 +218,10 @@ func (api *MoexAPI) getSecurityHistoryOffset(ticker string, if entry[1] == nil || entry[2] == nil || entry[3] == nil { continue } - moexHistory[i].Close = decimal.NewFromFloat(entry[1].(float64)) - moexHistory[i].High = decimal.NewFromFloat(entry[2].(float64)) - moexHistory[i].Low = decimal.NewFromFloat(entry[3].(float64)) + + moexHistory[i].Close = entry[1].(float64) + moexHistory[i].High = entry[2].(float64) + moexHistory[i].Low = entry[3].(float64) if len(entry) > 4 { moexHistory[i].Volume = uint64(entry[4].(float64)) @@ -231,9 +230,9 @@ func (api *MoexAPI) getSecurityHistoryOffset(ticker string, } if len(entry) > 5 { - moexHistory[i].Facevalue = decimal.NewFromFloat(entry[5].(float64)) + moexHistory[i].Facevalue = entry[5].(float64) } else { - moexHistory[i].Facevalue = decimal.Zero + moexHistory[i].Facevalue = 1.0 } } diff --git a/api/spbex.go b/api/spbex.go index 1828ace..c91b7bd 100644 --- a/api/spbex.go +++ b/api/spbex.go @@ -8,7 +8,6 @@ import ( custom_errors "github.com/kiberdruzhinnik/go-exchange-api/errors" "github.com/kiberdruzhinnik/go-exchange-api/utils" - "github.com/shopspring/decimal" ) type SpbexAPI struct { @@ -47,11 +46,11 @@ func (api *SpbexAPI) GetTicker(ticker string) (HistoryEntries, error) { entry := HistoryEntry{ Date: api.parseTime(int64(jsonHistory.Time[i])), - Close: decimal.NewFromFloat(jsonHistory.Close[i]), - High: decimal.NewFromFloat(jsonHistory.High[i]), - Low: decimal.NewFromFloat(jsonHistory.Low[i]), + Close: jsonHistory.Close[i], + High: jsonHistory.High[i], + Low: jsonHistory.Low[i], Volume: 0, - Facevalue: decimal.Zero, + Facevalue: 1.0, } historyEntries[i] = entry } diff --git a/go.mod b/go.mod index 5c36b28..37361b0 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.21.5 require ( github.com/gin-gonic/gin v1.9.1 github.com/redis/go-redis/v9 v9.3.0 - github.com/shopspring/decimal v1.3.1 ) require (