Skip to content

Commit

Permalink
trivial things
Browse files Browse the repository at this point in the history
  • Loading branch information
adyzng committed Dec 29, 2017
1 parent eec5d16 commit 5b225ae
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 42 deletions.
4 changes: 4 additions & 0 deletions core/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func (h *HTTPDownload) Download(URL string) ([]byte, error) {

if resp.StatusCode != http.StatusOK {
log.Warn("[%d] Download %s response %d:%s.", retry, URL, resp.StatusCode, resp.Status)
if resp.StatusCode == http.StatusNotFound {
// 404
break
}
err = fmt.Errorf("http response %d:%s", resp.StatusCode, resp.Status)
continue
}
Expand Down
4 changes: 4 additions & 0 deletions core/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ type Saver interface {
// Converter convert raw tick data into different file format
// such as fxt, hst, csv
type Converter interface {
// PackTicks by timeframe M1,M5...
// `barTimestamp` is the timeframe in seconds
// `ticks` is all the ticks data within timeframe
PackTicks(barTimestamp uint32, ticks []*TickData) error
// Finish current timeframe
Finish() error
}
File renamed without changes.
File renamed without changes.
42 changes: 20 additions & 22 deletions dukapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,31 @@ type DukaApp struct {
// AppOption download options
//
type AppOption struct {
Start time.Time
End time.Time
Symbol string
Format string
Folder string
Periods string
Spread uint32
Mode uint32
//Timeframe uint32
Convert bool
Start time.Time
End time.Time
Symbol string
Format string
Folder string
Periods string
Spread uint32
Mode uint32
Local bool
CsvHeader bool
}

// ParseOption parse input command line
//
func ParseOption(args argsList) (*AppOption, error) {
var (
err error
opt AppOption
)
var err error
opt := AppOption{
CsvHeader: args.Header,
Local: args.Local,
Format: args.Format,
Symbol: strings.ToUpper(args.Symbol),
Spread: uint32(args.Spread),
Mode: uint32(args.Model),
}

if args.Symbol == "" {
err = fmt.Errorf("Invalid symbol parameter")
return nil, err
Expand Down Expand Up @@ -102,13 +107,6 @@ func ParseOption(args argsList) (*AppOption, error) {
opt.Periods = args.Period
}

opt.Symbol = strings.ToUpper(args.Symbol)
opt.CsvHeader = args.Header
opt.Convert = args.Convert
opt.Format = args.Format
opt.Spread = uint32(args.Spread)
opt.Mode = uint32(args.Model)

return &opt, nil
}

Expand Down Expand Up @@ -240,7 +238,7 @@ func (app *DukaApp) fetchDay(day time.Time) <-chan *hReader {
err error
data []byte
)
if opt.Convert {
if opt.Local {
str = "Load Bi5"
data, err = bi5File.Load()
} else {
Expand Down
File renamed without changes.
25 changes: 10 additions & 15 deletions fxt4/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ type FXTHeader struct {
_ [240]byte // 488 240 unused
}

// FxtTick
// FxtTick ...
//
type FxtTick struct {
BarTimestamp uint32
_ uint32
Open float64
High float64
Low float64
Close float64
Volume uint64
TickTimestamp uint32
LaunchExpert uint32
BarTimestamp uint32 // 0 4 bar timestamp align with timeframe, unit seconds
_ uint32 // 4 4 for padding
Open float64 // 8 8
High float64 // 16 8
Low float64 // 24 8
Close float64 // 32 8
Volume uint64 // 40 8
TickTimestamp uint32 // 48 4 tick data timestamp in seconds
LaunchExpert uint32 // 52 4
}

func (t FxtTick) String() string {
Expand Down Expand Up @@ -176,8 +176,3 @@ func NewHeader(version uint32, symbol string, timeframe, spread, model uint32) *

return h
}

// AdjustHeader after all ticks writed to file
func (h *FXTHeader) AdjustHeader() {

}
10 changes: 5 additions & 5 deletions duka.go → main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func init() {
type argsList struct {
Verbose bool
Header bool
Convert bool
Local bool
Spread uint
Model uint
Symbol string
Expand Down Expand Up @@ -82,9 +82,9 @@ func main() {
flag.BoolVar(&args.Header,
"header", false,
"save csv with header")
flag.BoolVar(&args.Convert,
"convert", false,
"convert to given format with local data instead of download from dukascopy")
flag.BoolVar(&args.Local,
"local", false,
"convert to given format with local data instead of downloading from dukascopy")
flag.BoolVar(&args.Verbose,
"verbose", false,
"verbose output trace log")
Expand Down Expand Up @@ -115,7 +115,7 @@ func main() {
fmt.Printf(" Timeframe: %s\n", opt.Periods)
fmt.Printf(" Format: %s\n", opt.Format)
fmt.Printf(" CsvHeader: %t\n", opt.CsvHeader)
fmt.Printf(" LocalData: %t\n", opt.Convert)
fmt.Printf(" LocalData: %t\n", opt.Local)
fmt.Printf(" StartDate: %s\n", opt.Start.Format("2006-01-02:15H"))
fmt.Printf(" EndDate: %s\n", opt.End.Format("2006-01-02:15H"))

Expand Down

0 comments on commit 5b225ae

Please sign in to comment.