main.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // main.go
  2. package main
  3. import (
  4. "bufio"
  5. "flag"
  6. "fmt"
  7. "io"
  8. "log"
  9. "os"
  10. //"strconv"
  11. "strings"
  12. //"tickserver/server/market"
  13. "time"
  14. )
  15. func main() {
  16. loc, err := time.LoadLocation("Europe/Athens")
  17. flag.Parse()
  18. n := flag.NArg()
  19. if n != 1 {
  20. log.Println("must input file name", n)
  21. return
  22. }
  23. file := flag.Arg(0)
  24. fi, err := os.Open(file)
  25. if err != nil {
  26. fmt.Printf("Error: %s\n", err)
  27. return
  28. }
  29. defer fi.Close()
  30. files := strings.Split(file, ".")
  31. br := bufio.NewReader(fi)
  32. f, err := os.Create(files[0] + ".log")
  33. if err != nil {
  34. fmt.Printf("Error: %s\n", err)
  35. return
  36. }
  37. defer f.Close()
  38. bw := bufio.NewWriter(f)
  39. for {
  40. a, _, c := br.ReadLine()
  41. if c == io.EOF {
  42. break
  43. }
  44. datas := strings.Split(string(a), ",")
  45. if len(datas) != 6 {
  46. break
  47. }
  48. var year, month, day, hour, minute int
  49. fmt.Sscanf(datas[0], "%04d.%02d.%02d %02d:%02d", &year, &month, &day, &hour, &minute)
  50. t := time.Date(year, time.Month(month), day, hour, minute, 0, 0, loc)
  51. //log.Println(t.Unix())
  52. ut := time.Unix(t.Unix(), 0)
  53. line := files[0] + ","
  54. 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())
  55. line += "," + datas[1] + "," + datas[2] + "," + datas[3] + "," + datas[4] + "," + datas[5]
  56. //log.Println(line)
  57. fmt.Fprintln(bw, line)
  58. }
  59. bw.Flush()
  60. }
  61. /*
  62. // main.go
  63. package main
  64. import (
  65. "bufio"
  66. "flag"
  67. "fmt"
  68. "io"
  69. "log"
  70. "os"
  71. "strconv"
  72. "strings"
  73. "tickserver/server/market"
  74. "time"
  75. )
  76. func main() {
  77. flag.Parse()
  78. n := flag.NArg()
  79. if n != 1 {
  80. log.Println("must input file name", n)
  81. return
  82. }
  83. file := flag.Arg(0)
  84. fi, err := os.Open(file)
  85. if err != nil {
  86. fmt.Printf("Error: %s\n", err)
  87. return
  88. }
  89. defer fi.Close()
  90. files := strings.Split(file, ".")
  91. br := bufio.NewReader(fi)
  92. var candles []market.Candle
  93. for {
  94. var candle market.Candle
  95. a, _, c := br.ReadLine()
  96. if c == io.EOF {
  97. break
  98. }
  99. datas := strings.Split(string(a), ",")
  100. if datas[0] == files[0] {
  101. var year, month, day, hour, minute, second int
  102. fmt.Sscanf(datas[1], "%04d%02d%02d", &year, &month, &day)
  103. fmt.Sscanf(datas[2], "%02d%02d%02d", &hour, &minute, &second)
  104. t := time.Date(year, time.Month(month), day, hour, minute, second, 0, time.UTC)
  105. candle.Timestamp = t.Unix() * 1000
  106. candle.Open, _ = strconv.ParseFloat(datas[3], 64)
  107. candle.High, _ = strconv.ParseFloat(datas[4], 64)
  108. candle.Low, _ = strconv.ParseFloat(datas[5], 64)
  109. candle.Close, _ = strconv.ParseFloat(datas[6], 64)
  110. candle.RealVolums, _ = strconv.ParseFloat(datas[7], 64)
  111. candle.TickVolums, _ = strconv.ParseFloat(datas[7], 64)
  112. candles = append(candles, candle)
  113. }
  114. }
  115. market.SaveCandlesTmp("fzmnew/mt4", "mt4_"+files[0], candles, market.M1, false)
  116. r := market.NewCandleBuf(candles)
  117. candlesm5, _ := market.ConvPeriod(r, "mt4_"+files[0], market.M5)
  118. market.SaveCandlesTmp("fzmnew/mt4", "mt4_"+files[0], candlesm5, market.M5, false)
  119. r = market.NewCandleBuf(candlesm5)
  120. candlesh1, _ := market.ConvPeriod(r, "mt4_"+files[0], market.H1)
  121. market.SaveCandlesTmp("fzmnew/mt4", "mt4_"+files[0], candlesh1, market.H1, false)
  122. r = market.NewCandleBuf(candlesh1)
  123. candlesd1, _ := market.ConvPeriod(r, "mt4_"+files[0], market.D1)
  124. market.SaveCandlesTmp("fzmnew/mt4", "mt4_"+files[0], candlesd1, market.D1, false)
  125. }
  126. */