AccountEventsClient.go 804 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package main
  2. import (
  3. "fmt"
  4. "lmaxapi"
  5. "lmaxapi/main/common"
  6. "tickserver/api/lmaxapi/request"
  7. "tickserver/api/lmaxapi/response"
  8. "time"
  9. )
  10. func main() {
  11. fmt.Println("AccountEventsClient")
  12. session, err := common.CreateSession()
  13. if err != nil {
  14. // fmt.Println("Login Failed:", err)
  15. return
  16. }
  17. go func() {
  18. session.KeepAlive(30 * time.Second)
  19. }()
  20. session.RegisterAccountStateEvent(func(s *lmaxapi.Session, event *response.AccountStateEvent) {
  21. // fmt.Println(event)
  22. })
  23. session.RegisterHeartbeatEvent(func(s *lmaxapi.Session, id int64, token string) {
  24. // fmt.Println("heartbeat accountId:", id)
  25. })
  26. c := make(chan int, 0)
  27. session.Subscribe(request.NewAccountSubscriptionRequest(), func(err error) {
  28. session.Start()
  29. c <- 1
  30. })
  31. common.Heartbeat(session)
  32. <-c
  33. //session.start
  34. }