main.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. //
  3. //
  4. package main
  5. import (
  6. "flag"
  7. "fmt"
  8. "log"
  9. "strings"
  10. "time"
  11. "tickserver/server/market"
  12. )
  13. // var file = flag.String("", "", "open .TK or .Mn file")
  14. func main() {
  15. flag.Parse()
  16. n := flag.NArg()
  17. if n != 1 {
  18. log.Println("must input file name", n)
  19. return
  20. }
  21. file := flag.Arg(0)
  22. filelow := strings.ToLower(file)
  23. if strings.Contains(filelow, ".tk") {
  24. log.Fatal(readTickFile(file))
  25. }
  26. readCandleFile(file)
  27. }
  28. func readTickFile(file string) error {
  29. ticks, err := market.ReadTickFile(file)
  30. if err != nil {
  31. return err
  32. }
  33. for _, x := range ticks {
  34. log.Printf("%s: %+v\n", market.GetTime(x.Timestamp).String(), x)
  35. }
  36. log.Println("totle:", len(ticks))
  37. return nil
  38. }
  39. func readCandleFile(file string) error {
  40. candles, err := market.ReadCandleFile(file)
  41. if err != nil {
  42. return err
  43. }
  44. for _, x := range candles {
  45. t := time.Unix(x.Timestamp/1000, 0)
  46. fmt.Printf("%04d%02d%02d %02d:%02d:%02d %v\n", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), x)
  47. }
  48. return nil
  49. }