BasicOrderClient.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. )
  9. func main() {
  10. fmt.Println("BasicOrderClient")
  11. common.EnableLog("proto.log")
  12. session, err := common.CreateSession()
  13. if err != nil {
  14. fmt.Println("Login Failed:", err)
  15. return
  16. }
  17. session.RegisterOrderBookEvent(OrderBookEventListener)
  18. session.RegisterStreamFailureEvent(common.DefaultStreamFailureCB)
  19. session.RegisterOrderEvent(common.DefaultOrderCB)
  20. session.RegisterInstructionRejectedEvent(common.DefaultInstructionRejectedCB)
  21. session.RegisterExecutionEvent(common.DefaultExecutionCB)
  22. session.Subscribe(request.NewOrderSubscriptionRequest(), common.DefaultSubscribeCB)
  23. session.Subscribe(request.NewOrderBookSubscriptionRequest(4001), common.DefaultSubscribeCB)
  24. session.Start()
  25. }
  26. var qu float64 = 1
  27. func OrderBookEventListener(s *lmaxapi.Session, event *response.OrderBookEvent) {
  28. fmt.Println("OrderBookEvent:", event)
  29. qu = -qu
  30. orderReq := request.NewMarketOrderRequest(4001, "", qu, request.TimeInForce.IMMEDIATE_OR_CANCEL, 0, 0)
  31. s.PlaceMarketOrder(orderReq, nil)
  32. }