Skip to content

Commit

Permalink
Resolve sonar code quality issues
Browse files Browse the repository at this point in the history
  • Loading branch information
edward-yakop committed Jan 29, 2021
1 parent f596b01 commit fb3d531
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
1 change: 1 addition & 0 deletions api/tickdata/downloader/tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (h hours) Size() int {
}

var doNothingListener DownloadListener = func(symbol string, dayHour time.Time, err error, curr, count int) {
// Do nothing. This is a substitution when listener is passed as nil in Download
}

func (h *hours) Download(downloader *bi5.Downloader, symbol string, progress, count int, listener DownloadListener) int {
Expand Down
4 changes: 1 addition & 3 deletions api/tickdata/downloader/tick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ func TestDownloader(t *testing.T) {
d.Add(instrument.GetMetadata("EURUSD"), from, to).
Add(instrument.GetMetadata("GBPUSD"), from, to)

d.Download(func(instrumentCode string, dayHour time.Time, err error, curr, count int) {

})
d.Download(nil)

fileExists(t, bi5.BiFilePathTime(folder, "EURUSD", from))
fileExists(t, bi5.BiFilePathTime(folder, "EURUSD", to))
Expand Down
25 changes: 11 additions & 14 deletions api/tickdata/ticks/ticks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/ed-fx/go-duka/api/instrument"
"github.com/ed-fx/go-duka/api/tickdata"
"github.com/ed-fx/go-duka/internal/bi5"
"github.com/ed-fx/go-duka/internal/misc"
"github.com/pkg/errors"
"time"
"unknwon.dev/clog/v2"
Expand All @@ -22,19 +23,19 @@ type Ticks struct {
isCompleted bool
}

func (t Ticks) Start() time.Time {
func (t *Ticks) Start() time.Time {
return t.start
}

func (t Ticks) End() time.Time {
func (t *Ticks) End() time.Time {
return t.end
}

func (t Ticks) Current() *tickdata.TickData {
func (t *Ticks) Current() *tickdata.TickData {
return t.currTick
}

func (t Ticks) IsCompleted() bool {
func (t *Ticks) IsCompleted() bool {
return t.isCompleted
}

Expand Down Expand Up @@ -72,7 +73,7 @@ func (t *Ticks) Goto(to time.Time) (isSuccess bool, err error) {

to = to.In(time.UTC) // To ease debugging
t.isCompleted = false
for currTime := t.timeToHour(to); currTime.Before(t.end); currTime = currTime.Add(time.Hour) {
for currTime := misc.ToHourUTC(to); currTime.Before(t.end); currTime = currTime.Add(time.Hour) {
if t.ticksDayHour.Equal(currTime) {
return t.resetTicksPointer(to)
} else {
Expand Down Expand Up @@ -105,15 +106,15 @@ func (t *Ticks) complete() {
t.currTick = nil
}

func (t Ticks) nextDownloadHour() time.Time {
func (t *Ticks) nextDownloadHour() time.Time {
var next time.Time
if t.currTick == nil {
next = t.start.UTC()
next = t.start
} else {
next = t.currTick.UTC().Add(time.Hour)
}

return time.Date(next.Year(), next.Month(), next.Day(), next.Hour(), 0, 0, 0, time.UTC)
return misc.ToHourUTC(next)
}

func (t *Ticks) seek(target time.Time) {
Expand All @@ -133,7 +134,7 @@ func (t *Ticks) seek(target time.Time) {
t.currTick = t.ticks[i]
}

func (t Ticks) resetTicksPointer(to time.Time) (bool, error) {
func (t *Ticks) resetTicksPointer(to time.Time) (bool, error) {
if t.currTick == nil { // If beginning of hour
return t.Next()
}
Expand Down Expand Up @@ -174,17 +175,13 @@ func (t Ticks) resetTicksPointer(to time.Time) (bool, error) {
}
}

func (t Ticks) prevTick() *tickdata.TickData {
func (t *Ticks) prevTick() *tickdata.TickData {
if t.ticksIdx == 0 {
return nil
}
return t.ticks[t.ticksIdx-1]
}

func (t Ticks) timeToHour(tt time.Time) time.Time {
return time.Date(tt.Year(), tt.Month(), tt.Day(), tt.Hour(), 0, 0, 0, tt.Location()).UTC()
}

var isLogSetup = false

// time are in UTC
Expand Down

0 comments on commit fb3d531

Please sign in to comment.