Skip to content

Commit

Permalink
Use same file names as dukascopy, to be able to use other dukascopy s…
Browse files Browse the repository at this point in the history
…ources
  • Loading branch information
leifcr committed Feb 6, 2019
1 parent 1376c03 commit 5a40a25
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
6 changes: 3 additions & 3 deletions bi5/bi5.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Bi5 struct {
// New create an bi5 saver
func New(day time.Time, symbol, dest string) *Bi5 {
y, m, d := day.Date()
dir := fmt.Sprintf("%s/%04d/%02d/%02d", symbol, y, m, d)
dir := fmt.Sprintf("%s/%04d/%02d/%02d", symbol, y, m-1, d)

return &Bi5{
dest: filepath.Join(dest, dir),
Expand Down Expand Up @@ -92,7 +92,7 @@ func (b *Bi5) Save(data []byte) error {
return err
}

fname := fmt.Sprintf("%02dh.%s", b.dayH.Hour(), ext)
fname := fmt.Sprintf("%02dh_ticks.%s", b.dayH.Hour(), ext)
fpath := filepath.Join(b.dest, fname)

f, err := os.OpenFile(fpath, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0666)
Expand All @@ -115,7 +115,7 @@ func (b *Bi5) Save(data []byte) error {
//
func (b *Bi5) Load() ([]byte, error) {

fname := fmt.Sprintf("%02dh.%s", b.dayH.Hour(), ext)
fname := fmt.Sprintf("%02dh_ticks.%s", b.dayH.Hour(), ext)
fpath := filepath.Join(b.dest, fname)

f, err := os.OpenFile(fpath, os.O_RDONLY, 0666)
Expand Down
4 changes: 2 additions & 2 deletions bi5/bi5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestLoadBi5(t *testing.T) {
//fname := `F:\00\EURUSD\2017\01\01\22h.bi5`
//fname := `F:\00\EURUSD\2017\01\01\22h_ticks.bi5`
dest := `F:\00`

day, err := time.ParseInLocation("2006-01-02 15", "2017-01-01 22", time.UTC)
Expand All @@ -32,7 +32,7 @@ func TestLoadBi5(t *testing.T) {
}

func TestDownloadBi5(t *testing.T) {
//fname := `F:\00\EURUSD\2017\01\01\22h.bi5`
//fname := `F:\00\EURUSD\2017\01\01\22h_ticks.bi5`
dest := `F:\test01`

day, err := time.ParseInLocation("2006-01-02 15", "2017-01-01 22", time.UTC)
Expand Down
11 changes: 10 additions & 1 deletion dukapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func (app *DukaApp) Execute() error {

//
// 创建输出目录
// Create an output directory
//
if _, err := os.Stat(opt.Folder); os.IsNotExist(err) {
if err = os.MkdirAll(opt.Folder, 666); err != nil {
Expand All @@ -179,17 +180,20 @@ func (app *DukaApp) Execute() error {

//
// 按天下载,每天24小时的数据由24个goroutine并行下载
// Download by day, 24 hours a day data is downloaded in parallel by 24 goroutines
//
for day := opt.Start; day.Unix() < opt.End.Unix(); day = day.Add(24 * time.Hour) {
//
// 周六没数据,跳过
// No data on Saturday, skip
//
if day.Weekday() == time.Saturday {
log.Warn("Skip Saturday %s.", day.Format("2006-01-02"))
continue
}
//
// 下载,解析,存储
// Download, parse, store
//
if err = app.saveData(day, app.fetchDay(day)); err != nil {
break
Expand Down Expand Up @@ -217,7 +221,9 @@ func (app *DukaApp) Execute() error {

// fetchDay 现在一天24小时的tick数据,24个goroutine并行下载,返回数据并不一定按时间顺序排序
// 转换端需要按天对tick数据排序。
//
// fetchDay now 24 hours a day tick data, 24 goroutine downloads in parallel, return data is not necessarily sorted in chronological order
// The conversion side needs to sort the tick data by day.

func (app *DukaApp) fetchDay(day time.Time) <-chan *hReader {
ch := make(chan *hReader, 24)
opt := app.option
Expand Down Expand Up @@ -268,6 +274,7 @@ func (app *DukaApp) fetchDay(day time.Time) <-chan *hReader {
}

// sortAndOutput 按时间戳,从前到后排序当天tick数据
// Sort the tick data of the day from front to back by timestamp
//
func (app *DukaApp) sortAndOutput(day time.Time, ticks []*core.TickData) error {
if len(ticks) == 0 {
Expand Down Expand Up @@ -307,12 +314,14 @@ func (app *DukaApp) saveData(day time.Time, chData <-chan *hReader) error {
var ticks []*core.TickData

// 解析 bi5 成 TickData 数据
// Parsing bi5 into TickData data
if ticks, err = bi5File.Decode(data.Data[:]); err != nil {
log.Error("Decode bi5 %s: %s failed: %v.", opt.Symbol, data.DayH.Format("2006-01-02:15H"), err)
continue
}

// 保留 bi5 数据
// Keep bi5 data
if err := bi5File.Save(data.Data[:]); err != nil {
log.Error("Save Bi5 %s: %s failed: %v.", opt.Symbol, data.DayH.Format("2006-01-02:15H"), err)
continue
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func main() {
"dump given file format")
flag.StringVar(&args.Period,
"timeframe", "M1",
"timeframe values: M1, M5, M15, M30, H1, H4, D1, W1, MN")
"timeframe values: M1, M5, M15, M30, H1, H4, D1, W1, MN (Comma separated list)")
flag.StringVar(&args.Symbol,
"symbol", "",
"symbol list using format, like: EURUSD EURGBP")
Expand All @@ -88,7 +88,7 @@ func main() {
"header", false,
"save csv with header")
flag.BoolVar(&args.Local,
"local", false,
"local", true, // Always use local data if available
"convert to given format with local data instead of downloading from dukascopy")
flag.BoolVar(&args.Verbose,
"verbose", false,
Expand Down

0 comments on commit 5a40a25

Please sign in to comment.