Skip to content

Commit 21dbcc9

Browse files
committed
* Bug: When creating bi5 for either empty or not found, downloader doesn't create directories if not exists
* Bug: BI5's downloader doesn't translate requested time to UTC when generating download folder and URL.
1 parent 5e2507f commit 21dbcc9

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ stream := stream.New("GBPJPY", start, end, createEmptyDir(t))
214214
// Stream ticks with the requested parameter
215215
stream.EachTick(func(time time.Time, tick *tickdata.TickData, err error) bool {
216216
// time: Tick data time in new_york time zone
217-
// tick: The tick data containg symbol, time (UTC), ask, bid, volume's ask and volume's bid
217+
// tick: The tick data containg symbol, time (loc), ask, bid, volume's ask and volume's bid
218218
// err: Error occurs either during download or decoding dukas tick data file
219219

220220
return true // Sets to true to continue to next tick, false to stop

examples/stream/dd_finder_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import (
1414
)
1515

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

1919
symbol := "GBPJPY"
20-
openTime := time.Date(2020, time.November, 3, 17, 0, 0, 0, est)
20+
openTime := time.Date(2020, time.November, 3, 17, 0, 0, 0, loc)
2121
openPrice := 136.325
22-
closeTime := time.Date(2020, time.November, 4, 00, 56, 56, 0, est)
22+
closeTime := time.Date(2020, time.November, 4, 00, 56, 56, 0, loc)
2323
closePrice := 136.725
2424

2525
openPriceDiff, maxDD, maxPositive, maxDDForMaxPositive, maxPositiveTime, closePriceDiff :=
@@ -40,7 +40,6 @@ func Test_StreamExample_DDFinder(t *testing.T) {
4040
assert.Equal(t, 392, maxPositive)
4141
assert.Equal(t, -240, maxDDForMaxPositive)
4242
assert.Equal(t, 400, profitInPoints)
43-
4443
}
4544

4645
func buyDDFinder(t *testing.T, symbol string, openTime time.Time, closeTime time.Time, openPrice float64, closePrice float64) (

internal/bi5/bi5.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ func (b Bi5) Symbol() string {
4444
}
4545

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

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

5353
return &Bi5{
5454
targetFilePath: biFilePath,
55-
dayHour: day,
55+
dayHour: dayHour,
5656
symbol: symbol,
5757
metadata: metadata,
5858
}
@@ -126,7 +126,7 @@ func (b Bi5) Download() error {
126126
return nil
127127
}
128128

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

132132
var httpStatusCode int
@@ -170,6 +170,13 @@ func (b Bi5) symbolAndTime() string {
170170
}
171171

172172
func (b Bi5) createFile(path string) error {
173+
// Create dir if not exists
174+
dir := filepath.Dir(path)
175+
if err := os.MkdirAll(dir, 0755); err != nil {
176+
err = errors.Wrap(err, "Create folder ["+dir+"] failed")
177+
return err
178+
}
179+
173180
emptyFile, err := os.Create(path)
174181
if err == nil {
175182
defer emptyFile.Close()

0 commit comments

Comments
 (0)