main.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // main.go
  2. package main
  3. import (
  4. "encoding/binary"
  5. "log"
  6. "runtime"
  7. "time"
  8. "unsafe"
  9. "tickserver/client"
  10. "tickserver/server/market"
  11. )
  12. var saddr1 = "115.29.207.108:19528" //115.231.103.7
  13. var saddr2 = "115.29.207.108:19528" //115.236.75.194
  14. var saddr3 = "115.29.207.108:19529" //127.0.0.1
  15. var saddr4 = "115.29.207.108:9090" //115.29.207.108
  16. var sizeofTick = int(unsafe.Sizeof(market.Tick{}))
  17. var sizeofCandle = int(unsafe.Sizeof(market.Candle{}))
  18. func main() {
  19. runtime.GOMAXPROCS(runtime.NumCPU())
  20. client, err := client.NewClientSimple(saddr1, saddr2, saddr3, saddr4, "./tmp")
  21. if err != nil {
  22. log.Println("new client", err)
  23. return
  24. }
  25. insMap := client.GetInsMap()
  26. log.Println("ins len:", len(insMap))
  27. //for k, v := range insMap {
  28. //log.Println("ins", k, v)
  29. //}
  30. ts := (time.Now().Unix() - 12*3600) * 1000
  31. ts = 1439424300000
  32. resp, err := client.GetHis("lmax_4001", market.M1, 100, ts, false)
  33. log.Println("GetHis.ts", ts, resp)
  34. if err != nil {
  35. log.Println("GetHis", err)
  36. } else {
  37. for {
  38. var candle market.Candle
  39. err = binary.Read(resp, binary.LittleEndian, &candle)
  40. if err != nil {
  41. log.Println("GetHis.Read", err)
  42. break
  43. }
  44. log.Println("GetHis.read", candle)
  45. }
  46. }
  47. respEx, err := client.GetHisEx("lmax_4001", market.M1, ts, 1439488920000, false)
  48. log.Println("GetHisEx.st.et", ts, 1439488920000, respEx)
  49. if err != nil {
  50. log.Println("GetHisEx", err)
  51. } else {
  52. for {
  53. var candle market.Candle
  54. err = binary.Read(respEx, binary.LittleEndian, &candle)
  55. if err != nil {
  56. log.Println("GetHisEx.Read", err)
  57. break
  58. }
  59. log.Println("GetHisEx.read", candle)
  60. }
  61. }
  62. ticks, err := client.GetLastTicks("lmax_4001", 100)
  63. if err != nil {
  64. log.Println("GetLastTicks", err)
  65. } else {
  66. for i, v := range ticks {
  67. log.Println("GetLastTicks.tick", i, v)
  68. }
  69. }
  70. candles, err := client.GetLastCandles("lmax_4001", market.M1, 100)
  71. if err != nil {
  72. log.Println("GetLastCandles", err)
  73. } else {
  74. for i, v := range candles {
  75. log.Println("GetLastCandles.candle", i, v)
  76. }
  77. }
  78. ticks, err = client.GetLastTicksByTime("lmax_4001", ticks[2].Timestamp, ticks[4].Timestamp)
  79. if err != nil {
  80. log.Println("GetLastTicksByTime", err)
  81. } else {
  82. for i, v := range ticks {
  83. log.Println("GetLastTicksByTime.tick", i, v)
  84. }
  85. }
  86. candles, err = client.GetLastCandlesByTime("lmax_4001", market.M1, candles[2].Timestamp, candles[4].Timestamp)
  87. if err != nil {
  88. log.Println("GetLastCandlesByTime", err)
  89. } else {
  90. for i, v := range candles {
  91. log.Println("GetLastCandlesByTime.candle", i, v)
  92. }
  93. }
  94. //select {}
  95. }