123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- //
- //
- //
- package main
- import (
- "bufio"
- "compress/gzip"
- "encoding/binary"
- "flag"
- "log"
- "os"
- "strings"
- "tickserver/server/market"
- )
- // var file = flag.String("", "", "open .TK or .Mn file")
- 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)
- filelow := strings.ToLower(file)
- if strings.Contains(filelow, ".tk") {
- log.Fatal(simplifyData(file))
- } else {
- log.Println("%s maybe not a tick file", file)
- }
- }
- func simplifyData(fname string) error {
- ticks, err := market.ReadTickFile(fname)
- if err != nil {
- return err
- }
- fnameSimplify := fname + ".simplify"
- fps, err := os.Create(fnameSimplify)
- if err != nil {
- return err
- }
- gw := gzip.NewWriter(fps)
- bw := bufio.NewWriter(gw)
- var lasttick market.Tick
- for _, x := range ticks {
- if x.Price == lasttick.Price && x.Ask[0] == lasttick.Ask[0] && x.Bid[0] == lasttick.Bid[0] {
- continue
- } else {
- binary.Write(bw, binary.LittleEndian, x)
- lasttick = x
- }
- }
- bw.Flush()
- gw.Close()
- fps.Close()
- os.Remove(fname)
- os.Rename(fnameSimplify, fname)
- return nil
- }
|