123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- // main.go
- package main
- import (
- "bufio"
- "flag"
- "fmt"
- "io"
- "log"
- "os"
- //"strconv"
- "strings"
- //"tickserver/server/market"
- "time"
- )
- func main() {
- loc, err := time.LoadLocation("Europe/Athens")
- flag.Parse()
- n := flag.NArg()
- if n != 1 {
- log.Println("must input file name", n)
- return
- }
- file := flag.Arg(0)
- fi, err := os.Open(file)
- if err != nil {
- fmt.Printf("Error: %s\n", err)
- return
- }
- defer fi.Close()
- files := strings.Split(file, ".")
- br := bufio.NewReader(fi)
- f, err := os.Create(files[0] + ".log")
- if err != nil {
- fmt.Printf("Error: %s\n", err)
- return
- }
- defer f.Close()
- bw := bufio.NewWriter(f)
- for {
- a, _, c := br.ReadLine()
- if c == io.EOF {
- break
- }
- datas := strings.Split(string(a), ",")
- if len(datas) != 6 {
- break
- }
- var year, month, day, hour, minute int
- fmt.Sscanf(datas[0], "%04d.%02d.%02d %02d:%02d", &year, &month, &day, &hour, &minute)
- t := time.Date(year, time.Month(month), day, hour, minute, 0, 0, loc)
- //log.Println(t.Unix())
- ut := time.Unix(t.Unix(), 0)
- line := files[0] + ","
- line += fmt.Sprintf("%04d%02d%02d,%02d%02d%02d", ut.UTC().Year(), ut.UTC().Month(), ut.UTC().Day(), ut.UTC().Hour(), ut.UTC().Minute(), ut.UTC().Second())
- line += "," + datas[1] + "," + datas[2] + "," + datas[3] + "," + datas[4] + "," + datas[5]
- //log.Println(line)
- fmt.Fprintln(bw, line)
- }
- bw.Flush()
- }
- /*
- // main.go
- package main
- import (
- "bufio"
- "flag"
- "fmt"
- "io"
- "log"
- "os"
- "strconv"
- "strings"
- "tickserver/server/market"
- "time"
- )
- func main() {
- flag.Parse()
- n := flag.NArg()
- if n != 1 {
- log.Println("must input file name", n)
- return
- }
- file := flag.Arg(0)
- fi, err := os.Open(file)
- if err != nil {
- fmt.Printf("Error: %s\n", err)
- return
- }
- defer fi.Close()
- files := strings.Split(file, ".")
- br := bufio.NewReader(fi)
- var candles []market.Candle
- for {
- var candle market.Candle
- a, _, c := br.ReadLine()
- if c == io.EOF {
- break
- }
- datas := strings.Split(string(a), ",")
- if datas[0] == files[0] {
- var year, month, day, hour, minute, second int
- fmt.Sscanf(datas[1], "%04d%02d%02d", &year, &month, &day)
- fmt.Sscanf(datas[2], "%02d%02d%02d", &hour, &minute, &second)
- t := time.Date(year, time.Month(month), day, hour, minute, second, 0, time.UTC)
- candle.Timestamp = t.Unix() * 1000
- candle.Open, _ = strconv.ParseFloat(datas[3], 64)
- candle.High, _ = strconv.ParseFloat(datas[4], 64)
- candle.Low, _ = strconv.ParseFloat(datas[5], 64)
- candle.Close, _ = strconv.ParseFloat(datas[6], 64)
- candle.RealVolums, _ = strconv.ParseFloat(datas[7], 64)
- candle.TickVolums, _ = strconv.ParseFloat(datas[7], 64)
- candles = append(candles, candle)
- }
- }
- market.SaveCandlesTmp("fzmnew/mt4", "mt4_"+files[0], candles, market.M1, false)
- r := market.NewCandleBuf(candles)
- candlesm5, _ := market.ConvPeriod(r, "mt4_"+files[0], market.M5)
- market.SaveCandlesTmp("fzmnew/mt4", "mt4_"+files[0], candlesm5, market.M5, false)
- r = market.NewCandleBuf(candlesm5)
- candlesh1, _ := market.ConvPeriod(r, "mt4_"+files[0], market.H1)
- market.SaveCandlesTmp("fzmnew/mt4", "mt4_"+files[0], candlesh1, market.H1, false)
- r = market.NewCandleBuf(candlesh1)
- candlesd1, _ := market.ConvPeriod(r, "mt4_"+files[0], market.D1)
- market.SaveCandlesTmp("fzmnew/mt4", "mt4_"+files[0], candlesd1, market.D1, false)
- }
- */
|