main.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. //
  3. //
  4. package main
  5. import (
  6. "bufio"
  7. "compress/gzip"
  8. "encoding/binary"
  9. "flag"
  10. "log"
  11. "os"
  12. "tickserver/server/market"
  13. )
  14. var cs = []market.Candle{
  15. {1438646400000, 3641.199951171875, 3873.39990234375, 3640.800048828125, 3837.60009765625, 0, 22895},
  16. {1438819200000, 3715.199951171875, 3845.60009765625, 3696, 3766.39990234375, 0, 541},
  17. {1438905600000, 3768, 3924.39990234375, 3768, 3855, 0, 1307},
  18. {1439164800000, 3867.199951171875, 4085.199951171875, 3867.199951171875, 4038, 0, 1904},
  19. {1439424000000, 4003.199951171875, 4025.800048828125, 3928.39990234375, 4014.60009765625, 0, 1282},
  20. {1439510400000, 4039.60009765625, 4063.800048828125, 3989.800048828125, 4007.60009765625, 0, 797},
  21. {1439769600000, 3944, 4008, 3916.60009765625, 4003.199951171875, 0, 1144},
  22. {1439856000000, 4017.199951171875, 4037.199951171875, 3646.800048828125, 3755, 0, 2200},
  23. {1439942400000, 3735, 3840.199951171875, 3676.199951171875, 3806.60009765625, 0, 2494},
  24. {1440028800000, 3801, 3827.199951171875, 3741.60009765625, 3749.800048828125, 0, 1640},
  25. {1440115200000, 3733, 3746.39990234375, 3604.60009765625, 3645.60009765625, 0, 1624},
  26. {1440374400000, 2163.60009765625, 2163.60009765625, 2005.199951171875, 2005.199951171875, 0, 1392},
  27. {1440460800000, 2929.39990234375, 2999.199951171875, 2910, 2999.199951171875, 0, 8},
  28. {1440547200000, 2833.39990234375, 2940, 2638.39990234375, 2670.800048828125, 0, 864},
  29. {1440720000000, 3087.199951171875, 3228, 3013.60009765625, 3188.39990234375, 0, 26195},
  30. {1440979200000, 3166, 3166, 3006.39990234375, 3070.199951171875, 0, 16864},
  31. {1441065600000, 3086.199951171875, 3138, 2888.199951171875, 2999, 0, 30953},
  32. }
  33. func main() {
  34. flag.Parse()
  35. n := flag.NArg()
  36. if n != 2 {
  37. log.Println("must input file name", n)
  38. return
  39. }
  40. candlesNew, _ := market.ReadCandleFile(flag.Arg(1))
  41. file := flag.Arg(0)
  42. log.Println(file)
  43. candles, _ := market.ReadCandleFile(file)
  44. candlesNew = append(candlesNew, candles...)
  45. w, err := os.OpenFile(file, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
  46. if err != nil {
  47. return
  48. }
  49. defer w.Close()
  50. gw := gzip.NewWriter(w)
  51. bw := bufio.NewWriter(gw)
  52. for i := 0; i < len(candlesNew); i++ {
  53. binary.Write(bw, binary.LittleEndian, candlesNew[i])
  54. }
  55. bw.Flush()
  56. gw.Close()
  57. }
  58. // var file = flag.String("", "", "open .TK or .Mn file")
  59. /*func main() {
  60. flag.Parse()
  61. n := flag.NArg()
  62. if n != 2 {
  63. log.Println("must input file name", n)
  64. return
  65. }
  66. fileV := flag.Arg(1)
  67. log.Println(fileV)
  68. candlesV, _ := market.ReadCandleFile(fileV)
  69. wV, errV := os.OpenFile(fileV, os.O_RDONLY, 0666)
  70. if errV != nil {
  71. return
  72. }
  73. defer wV.Close()
  74. file := flag.Arg(0)
  75. log.Println(file)
  76. candles, _ := market.ReadCandleFile(file)
  77. w, err := os.OpenFile(file, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
  78. if err != nil {
  79. return
  80. }
  81. defer w.Close()
  82. gw := gzip.NewWriter(w)
  83. bw := bufio.NewWriter(gw)
  84. for i, v := range candles {
  85. v.RealVolums = candlesV[i].RealVolums
  86. binary.Write(bw, binary.LittleEndian, v)
  87. }
  88. bw.Flush()
  89. gw.Close()
  90. }*/
  91. /*func main() {
  92. flag.Parse()
  93. n := flag.NArg()
  94. if n != 1 {
  95. log.Println("must input file name", n)
  96. return
  97. }
  98. file := flag.Arg(0)
  99. log.Println(file)
  100. candles, _ := market.ReadCandleFile(file)
  101. w, err := os.OpenFile(file, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
  102. if err != nil {
  103. return
  104. }
  105. defer w.Close()
  106. gw := gzip.NewWriter(w)
  107. bw := bufio.NewWriter(gw)
  108. //var candle market.Candle
  109. //for i := 0; i < 15; i++ {
  110. //j := i
  111. //if j >= len(candles) {
  112. //j -= len(candles)
  113. //}
  114. //candle = candles[j]
  115. //candle.Timestamp = candles[0].Timestamp - (15-int64(i))*3600000
  116. //binary.Write(bw, binary.LittleEndian, &candle)
  117. //}
  118. for i, v := range candles {
  119. //if v.Timestamp == 1465542000000 {
  120. //v.Open = 3601.570068359375
  121. //}
  122. //v.Timestamp += 24 * 3600000
  123. timestamp := v.Timestamp
  124. if v.TickVolums == 0 {
  125. v = candles[i-3]
  126. v.Timestamp = timestamp
  127. }
  128. binary.Write(bw, binary.LittleEndian, v)
  129. }
  130. bw.Flush()
  131. gw.Close()
  132. }*/
  133. func readCandleFile(file string) error {
  134. candles, err := market.ReadCandleFile(file)
  135. if err != nil {
  136. return err
  137. }
  138. for _, x := range candles {
  139. log.Printf("%s %+v\n", market.GetTime(x.Timestamp).String(), x)
  140. }
  141. log.Println("totle:", len(candles))
  142. return nil
  143. }