package main import ( "tickserver/api/lmaxapi" "tickserver/api/lmaxapi/main/common" "tickserver/api/lmaxapi/request" "tickserver/api/lmaxapi/response" "log" "time" ) func CreateSession() (*lmaxapi.Session, error) { lmaxapi.SetBaseUrl("https://trade.lmaxtrader.com") // user, password := "wave1970", "Tg417397" user, password := "wave3366", "Tg417395" req := request.NewLoginRequest(user, password, request.ProductType.CFD_LIVE) session, err := lmaxapi.Login(req) if err == nil { log.Println("My accountId is:", session.GetAccountDetails().AccountId) } return session, err } func CreateSession2() (*lmaxapi.Session, error) { lmaxapi.SetBaseUrl("http://87.117.229.236:8088") req := request.NewLoginRequest("wave3366", "Tg417395", request.ProductType.CFD_LIVE) session, err := lmaxapi.Login(req) if err == nil { log.Println("My accountId is:", session.GetAccountDetails().AccountId) } return session, err } func CreateSession3() (*lmaxapi.Session, error) { lmaxapi.SetBaseUrl("http://199.188.105.71:8088") req := request.NewLoginRequest("wave3366", "Tg417395", request.ProductType.CFD_DEMO) session, err := lmaxapi.Login(req) if err == nil { log.Println("My accountId is:", session.GetAccountDetails().AccountId) } return session, err } func CreateSession6() (*lmaxapi.Session, error) { lmaxapi.SetBaseUrl("https://210.209.115.182:8088") req := request.NewLoginRequest("wave3366", "Tg417395", request.ProductType.CFD_DEMO) session, err := lmaxapi.Login(req) if err == nil { log.Println("My accountId is:", session.GetAccountDetails().AccountId) } return session, err } func CreateSession7() (*lmaxapi.Session, error) { lmaxapi.SetBaseUrl("https://122.10.93.170:8088") req := request.NewLoginRequest("wave3366", "Tg417395", request.ProductType.CFD_DEMO) session, err := lmaxapi.Login(req) if err == nil { log.Println("My accountId is:", session.GetAccountDetails().AccountId) } return session, err } func CreateSession4() (*lmaxapi.Session, error) { lmaxapi.SetBaseUrl("https://210.209.115.182:8087") req := request.NewLoginRequest("niniwzw", "P2assword123", request.ProductType.CFD_DEMO) session, err := lmaxapi.Login(req) if err == nil { log.Println("My accountId is:", session.GetAccountDetails().AccountId) } return session, err } func CreateSession5() (*lmaxapi.Session, error) { lmaxapi.SetBaseUrl("http://localhost:8088") req := request.NewLoginRequest("niniwzw", "Password123", request.ProductType.CFD_DEMO) session, err := lmaxapi.Login(req) if err == nil { log.Println("My accountId is:", session.GetAccountDetails().AccountId) } return session, err } func main() { log.Println("MarketDataClient") common.EnableLog("proto.log") session, err := CreateSession() if err != nil { log.Println("Login Failed:", err) return } iMap := make(map[int64]*response.Instrument) session.RegisterStreamFailureEvent(common.DefaultStreamFailureCB) var prevPrice float64 session.RegisterOrderBookEvent(func(s *lmaxapi.Session, event *response.OrderBookEvent) { id := event.InstrumentId if len(event.BidPrices) > 0 && len(event.AskPrices) > 0 && (iMap[id].Name == "EUR/USD" || iMap[id].Name == "GBP/USD") { if event.BidPrices[0].Price == prevPrice { return } // prevPrice = event.BidPrices[0].Price // log.Println(iMap[id].Name, event.BidPrices[0]) } log.Printf("%+v \n\n", event) }) session.RegisterHeartbeatEvent(func(s *lmaxapi.Session, id int64, token string) { //log.Println("heartbeat accountId:", id) }) // log.Println("begin subscribe") subs := lmaxapi.NewMultiSubscribe() session.LoadAllInstruments(func(value *response.Instrument) { iMap[value.Id] = value subs.Add(request.NewOrderBookSubscriptionRequest(value.Id)) }) session.Subscribe(subs, func(err error) { if err != nil { log.Println(err) } }) session.Wait() // log.Println("end subscribe") go func() { time.Sleep(10 * time.Second) sub := request.NewOrderBookSubscriptionRequest(4001) session.Unsubscribe(sub, func(err error) { if err != nil { log.Println(err) } }) }() common.Heartbeat(session) session.Start() }