Skip to content

Commit

Permalink
* Bug: When creating bi5 for either empty or not found, downloader do…
Browse files Browse the repository at this point in the history
…esn't create directories if not exists

* Bug: BI5's downloader doesn't translate requested time to UTC when generating download folder and URL.
  • Loading branch information
edward-yakop committed Jan 2, 2021
1 parent 5e2507f commit 21dbcc9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ stream := stream.New("GBPJPY", start, end, createEmptyDir(t))
// Stream ticks with the requested parameter
stream.EachTick(func(time time.Time, tick *tickdata.TickData, err error) bool {
// time: Tick data time in new_york time zone
// tick: The tick data containg symbol, time (UTC), ask, bid, volume's ask and volume's bid
// tick: The tick data containg symbol, time (loc), ask, bid, volume's ask and volume's bid
// err: Error occurs either during download or decoding dukas tick data file

return true // Sets to true to continue to next tick, false to stop
Expand Down
7 changes: 3 additions & 4 deletions examples/stream/dd_finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
)

func Test_StreamExample_DDFinder(t *testing.T) {
est, _ := time.LoadLocation("EET")
loc, _ := time.LoadLocation("EET")

symbol := "GBPJPY"
openTime := time.Date(2020, time.November, 3, 17, 0, 0, 0, est)
openTime := time.Date(2020, time.November, 3, 17, 0, 0, 0, loc)
openPrice := 136.325
closeTime := time.Date(2020, time.November, 4, 00, 56, 56, 0, est)
closeTime := time.Date(2020, time.November, 4, 00, 56, 56, 0, loc)
closePrice := 136.725

openPriceDiff, maxDD, maxPositive, maxDDForMaxPositive, maxPositiveTime, closePriceDiff :=
Expand All @@ -40,7 +40,6 @@ func Test_StreamExample_DDFinder(t *testing.T) {
assert.Equal(t, 392, maxPositive)
assert.Equal(t, -240, maxDDForMaxPositive)
assert.Equal(t, 400, profitInPoints)

}

func buyDDFinder(t *testing.T, symbol string, openTime time.Time, closeTime time.Time, openPrice float64, closePrice float64) (
Expand Down
17 changes: 12 additions & 5 deletions internal/bi5/bi5.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ func (b Bi5) Symbol() string {
}

// New create an bi5 saver
func New(day time.Time, symbol, downloadFolderPath string) *Bi5 {
y, m, d := day.Date()
func New(dayHour time.Time, symbol, downloadFolderPath string) *Bi5 {
y, m, d := dayHour.UTC().Date()

biFilePath := filepath.FromSlash(fmt.Sprintf("%s/download/%s/%04d/%02d/%02d/%02dh_ticks.%s", downloadFolderPath, symbol, y, m, d, day.Hour(), ext))
biFilePath := filepath.FromSlash(fmt.Sprintf("%s/download/%s/%04d/%02d/%02d/%02dh_ticks.%s", downloadFolderPath, symbol, y, m, d, dayHour.Hour(), ext))
metadata := instrument.GetMetadata(symbol)

return &Bi5{
targetFilePath: biFilePath,
dayHour: day,
dayHour: dayHour,
symbol: symbol,
metadata: metadata,
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func (b Bi5) Download() error {
return nil
}

year, month, day := b.dayHour.Date()
year, month, day := b.dayHour.UTC().Date()
link := fmt.Sprintf(core.DukaTmplURL, b.symbol, year, month-1, day, b.dayHour.Hour())

var httpStatusCode int
Expand Down Expand Up @@ -170,6 +170,13 @@ func (b Bi5) symbolAndTime() string {
}

func (b Bi5) createFile(path string) error {
// Create dir if not exists
dir := filepath.Dir(path)
if err := os.MkdirAll(dir, 0755); err != nil {
err = errors.Wrap(err, "Create folder ["+dir+"] failed")
return err
}

emptyFile, err := os.Create(path)
if err == nil {
defer emptyFile.Close()
Expand Down

0 comments on commit 21dbcc9

Please sign in to comment.