1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package common
- import (
- "fmt"
- "tickserver/api/lmaxapi"
- "tickserver/api/lmaxapi/request"
- "tickserver/api/lmaxapi/response"
- "os"
- "time"
- )
- func EnableLog(filename string) (*os.File, error) {
- logw, e := os.Create(filename)
- if e != nil {
- return nil, e
- }
- lmaxapi.EnableLog(logw)
- return logw, nil
- }
- func CreateSession() (*lmaxapi.Session, error) {
- lmaxapi.SetBaseUrl("https://trade.lmaxtrader.com")
- req := request.NewLoginRequest("wave3366", "Tg417395", request.ProductType.CFD_DEMO)
- session, err := lmaxapi.Login(req)
- if err == nil {
- fmt.Println("My accountId is:", session.GetAccountDetails().AccountId)
- }
- return session, err
- }
- func Heartbeat(session *lmaxapi.Session) {
- req2 := request.NewHeartbeatSubscriptionRequest()
- session.Subscribe(req2, nil)
- req3 := request.NewHeartbeatRequest("hello")
- go func() {
- for {
- time.Sleep(10 * time.Second)
- session.RequestHeartbeat(req3, nil)
- }
- }()
- }
- func DefaultSubscribeCB(err error) {
- if err != nil {
- fmt.Println("Failed:", err)
- }
- }
- func DefaultStreamFailureCB(s *lmaxapi.Session, err error) {
- fmt.Println("Error occured on the stream ", err)
- s.Stop()
- }
- func DefaultOrderCB(s *lmaxapi.Session, event *response.OrderEvent) {
- fmt.Println("OrderEvent:",event)
- }
- func DefaultInstructionRejectedCB(s *lmaxapi.Session, event *response.InstructionRejectedEvent) {
- fmt.Println("Rejection Received:",event)
- }
- func DefaultExecutionCB(s *lmaxapi.Session, event *response.ExecutionEvent) {
- fmt.Println("ExecutionEvent:",event)
- }
- func DefaultPositionCB(s *lmaxapi.Session, event *response.PositionEvent) {
- fmt.Println("Position Received:", event)
- }
|