HistoricMarketDataRequestKline.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package main
  2. import (
  3. "fmt"
  4. "tickserver/api/lmaxapi"
  5. "tickserver/api/lmaxapi/main/common"
  6. "tickserver/api/lmaxapi/request"
  7. "tickserver/api/lmaxapi/response"
  8. "runtime"
  9. "time"
  10. )
  11. var session *lmaxapi.Session
  12. func main() {
  13. fmt.Println(runtime.NumCPU())
  14. runtime.GOMAXPROCS(runtime.NumCPU())
  15. fmt.Println("HistoricMarketDataRequest")
  16. common.EnableLog("proto.log")
  17. session, _ = common.CreateSession()
  18. session.RegisterHistoricMarketDataEvent(HistoricEvent)
  19. req := request.NewHistoricSubscriptionRequest()
  20. session.Subscribe(req, func(err error) {
  21. if err == nil {
  22. req1 := request.NewAggregateHistoricRequest("1", 4001,
  23. time.Date(2012, 9, 1, 0, 0, 0, 0, time.UTC),
  24. time.Date(2013, 9, 2, 0, 0, 0, 0, time.UTC),
  25. "CSV",//暂时只有一种格式
  26. "MINUTE",//还可以 DAY, 也就是只有分钟线 和 日线两种
  27. []string{"ASK"} //BID/ASK/TRADE 可以是这三种形式
  28. )
  29. session.RequestHistoricMarketData(req1, func(err error) {
  30. if err != nil {
  31. fmt.Println("Failed to request historic market data:", err)
  32. }
  33. })
  34. } else {
  35. fmt.Println("Failed to subscribe:", err)
  36. }
  37. })
  38. common.Heartbeat(session)
  39. session.Start()
  40. fmt.Println("stop")
  41. }
  42. func HistoricEvent(s *lmaxapi.Session, event *response.HistoricMarketDataEvent) {
  43. fmt.Println(event)
  44. }