123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- //
- //
- //
- package main
- import (
- "bufio"
- "compress/gzip"
- "encoding/binary"
- "flag"
- "log"
- "os"
- "tickserver/server/market"
- )
- var cs = []market.Candle{
- {1438646400000, 3641.199951171875, 3873.39990234375, 3640.800048828125, 3837.60009765625, 0, 22895},
- {1438819200000, 3715.199951171875, 3845.60009765625, 3696, 3766.39990234375, 0, 541},
- {1438905600000, 3768, 3924.39990234375, 3768, 3855, 0, 1307},
- {1439164800000, 3867.199951171875, 4085.199951171875, 3867.199951171875, 4038, 0, 1904},
- {1439424000000, 4003.199951171875, 4025.800048828125, 3928.39990234375, 4014.60009765625, 0, 1282},
- {1439510400000, 4039.60009765625, 4063.800048828125, 3989.800048828125, 4007.60009765625, 0, 797},
- {1439769600000, 3944, 4008, 3916.60009765625, 4003.199951171875, 0, 1144},
- {1439856000000, 4017.199951171875, 4037.199951171875, 3646.800048828125, 3755, 0, 2200},
- {1439942400000, 3735, 3840.199951171875, 3676.199951171875, 3806.60009765625, 0, 2494},
- {1440028800000, 3801, 3827.199951171875, 3741.60009765625, 3749.800048828125, 0, 1640},
- {1440115200000, 3733, 3746.39990234375, 3604.60009765625, 3645.60009765625, 0, 1624},
- {1440374400000, 2163.60009765625, 2163.60009765625, 2005.199951171875, 2005.199951171875, 0, 1392},
- {1440460800000, 2929.39990234375, 2999.199951171875, 2910, 2999.199951171875, 0, 8},
- {1440547200000, 2833.39990234375, 2940, 2638.39990234375, 2670.800048828125, 0, 864},
- {1440720000000, 3087.199951171875, 3228, 3013.60009765625, 3188.39990234375, 0, 26195},
- {1440979200000, 3166, 3166, 3006.39990234375, 3070.199951171875, 0, 16864},
- {1441065600000, 3086.199951171875, 3138, 2888.199951171875, 2999, 0, 30953},
- }
- func main() {
- flag.Parse()
- n := flag.NArg()
- if n != 2 {
- log.Println("must input file name", n)
- return
- }
- candlesNew, _ := market.ReadCandleFile(flag.Arg(1))
- file := flag.Arg(0)
- log.Println(file)
- candles, _ := market.ReadCandleFile(file)
- candlesNew = append(candlesNew, candles...)
- w, err := os.OpenFile(file, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
- if err != nil {
- return
- }
- defer w.Close()
- gw := gzip.NewWriter(w)
- bw := bufio.NewWriter(gw)
- for i := 0; i < len(candlesNew); i++ {
- binary.Write(bw, binary.LittleEndian, candlesNew[i])
- }
- bw.Flush()
- gw.Close()
- }
- // var file = flag.String("", "", "open .TK or .Mn file")
- /*func main() {
- flag.Parse()
- n := flag.NArg()
- if n != 2 {
- log.Println("must input file name", n)
- return
- }
- fileV := flag.Arg(1)
- log.Println(fileV)
- candlesV, _ := market.ReadCandleFile(fileV)
- wV, errV := os.OpenFile(fileV, os.O_RDONLY, 0666)
- if errV != nil {
- return
- }
- defer wV.Close()
- file := flag.Arg(0)
- log.Println(file)
- candles, _ := market.ReadCandleFile(file)
- w, err := os.OpenFile(file, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
- if err != nil {
- return
- }
- defer w.Close()
- gw := gzip.NewWriter(w)
- bw := bufio.NewWriter(gw)
- for i, v := range candles {
- v.RealVolums = candlesV[i].RealVolums
- binary.Write(bw, binary.LittleEndian, v)
- }
- bw.Flush()
- gw.Close()
- }*/
- /*func main() {
- flag.Parse()
- n := flag.NArg()
- if n != 1 {
- log.Println("must input file name", n)
- return
- }
- file := flag.Arg(0)
- log.Println(file)
- candles, _ := market.ReadCandleFile(file)
- w, err := os.OpenFile(file, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
- if err != nil {
- return
- }
- defer w.Close()
- gw := gzip.NewWriter(w)
- bw := bufio.NewWriter(gw)
- //var candle market.Candle
- //for i := 0; i < 15; i++ {
- //j := i
- //if j >= len(candles) {
- //j -= len(candles)
- //}
- //candle = candles[j]
- //candle.Timestamp = candles[0].Timestamp - (15-int64(i))*3600000
- //binary.Write(bw, binary.LittleEndian, &candle)
- //}
- for i, v := range candles {
- //if v.Timestamp == 1465542000000 {
- //v.Open = 3601.570068359375
- //}
- //v.Timestamp += 24 * 3600000
- timestamp := v.Timestamp
- if v.TickVolums == 0 {
- v = candles[i-3]
- v.Timestamp = timestamp
- }
- binary.Write(bw, binary.LittleEndian, v)
- }
- bw.Flush()
- gw.Close()
- }*/
- func readCandleFile(file string) error {
- candles, err := market.ReadCandleFile(file)
- if err != nil {
- return err
- }
- for _, x := range candles {
- log.Printf("%s %+v\n", market.GetTime(x.Timestamp).String(), x)
- }
- log.Println("totle:", len(candles))
- return nil
- }
|