123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- 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()
- }
|