Skip to content

Commit

Permalink
remove decimal package
Browse files Browse the repository at this point in the history
  • Loading branch information
kiberdruzhinnik committed Dec 17, 2023
1 parent 65e45ae commit 72daae7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
14 changes: 6 additions & 8 deletions api/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions api/moex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand All @@ -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
}
}

Expand Down
9 changes: 4 additions & 5 deletions api/spbex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 72daae7

Please sign in to comment.