public void Start() { if (_api == null) { _api = new LmaxApi(Url); } _api.Login(new Com.Lmax.Api.LoginRequest(Username, Password, _productType), LoginCallback, FailureLoginCallback); }
/// <summary> /// установить соединение с биржей /// </summary> public void Connect() { LoginRequest loginRequest = new LoginRequest(_userName, _password, _isDemo ? ProductType.CFD_DEMO : ProductType.CFD_LIVE); _lmaxApi.Login(loginRequest, LoginCallback, FailureCallback("ошибка входа в систему")); IPAddress ipAddress = IPAddress.Parse(_fixTradingIp); IPEndPoint endPoint = new IPEndPoint(ipAddress, _port); _client = new TcpClient(); try { _client.Connect(endPoint); } catch (Exception e) { SendLogMessage("Не удалось установить соединение с биржей", LogMessageType.Error); Disconnected?.Invoke(); return; } _tradingSession = new Session(_client, _uiUrl); _tradingSession.NewMessageEvent += TradingSessionOnNewMessageEvent; StartAllThreads(); string logOnMsg = _creator.LogOnMsg(true, _heartbeatInterval); _tradingSession.Send(logOnMsg); }
public override void Login(AccountInfo account) { AccountInfo = account; AccountInfo.IsMarginAccount = true; if (_api == null) { _api = new LmaxApi(Uri); } _api.Login(new Com.Lmax.Api.LoginRequest(AccountInfo.UserName, AccountInfo.Password, _productType), session => { _session = session; AccountInfo.ID = _session.AccountDetails.AccountId.ToString(); AccountInfo.Currency = _session.AccountDetails.Currency; }, LoginFailureCallback); }
private void startThread() { Thread.CurrentThread.IsBackground = true; lmaxApi = new LmaxApi(DEMO_URL); LoginRequest loginRequest = new LoginRequest(textBox1.Text, textBox2.Text, ProductType.CFD_DEMO); lmaxApi.Login(loginRequest, LoginCallback, FailureCallback("log in")); }
public void fm() { ProductType productType = !this.i.type.Contains("CFD_DEMO") ? ProductType.CFD_LIVE : ProductType.CFD_DEMO; while (true) { LmaxApi lmaxApi = new LmaxApi(this.i.url); this.i.WriteLog("Attempting to login to: " + this.i.url + " as " + this.i.login); lmaxApi.Login(new LoginRequest(this.i.login, this.i.password, productType), new OnLogin(this.a1), b_сlass.a1("Failed to log in")); this.i.WriteLog("Logged out, pausing for 10s before retrying..."); Thread.Sleep(10000); } }
/// <summary> /// Send message. /// </summary> /// <param name="message">Message.</param> protected override void OnSendInMessage(Message message) { switch (message.Type) { case MessageTypes.Reset: { _isHistoricalSubscribed = false; if (_session != null) { try { _session.Stop(); _session.Logout(OnLogoutSuccess, OnLogoutFailure); } catch (Exception ex) { SendOutError(ex); } _session = null; } SendOutMessage(new ResetMessage()); break; } case MessageTypes.Connect: { if (_session != null) { throw new InvalidOperationException(LocalizedStrings.Str1619); } if (_api != null) { throw new InvalidOperationException(LocalizedStrings.Str3378); } _isDownloadSecurityFromSite = IsDownloadSecurityFromSite; _api = new LmaxApi(IsDemo ? "https://web-order.london-demo.lmax.com" : "https://api.lmaxtrader.com"); _api.Login(new LoginRequest(Login, Password.To <string>(), IsDemo ? ProductType.CFD_DEMO : ProductType.CFD_LIVE), OnLoginOk, OnLoginFailure); break; } case MessageTypes.Disconnect: { if (_session == null) { throw new InvalidOperationException(LocalizedStrings.Str1856); } _session.Stop(); _session.Logout(OnLogoutSuccess, OnLogoutFailure); _session = null; break; } case MessageTypes.PortfolioLookup: { ProcessPortfolioLookupMessage(); break; } case MessageTypes.OrderStatus: { ProcessOrderStatusMessage(); break; } case MessageTypes.Time: { _session.RequestHeartbeat(new HeartbeatRequest(TransactionIdGenerator.GetNextId().To <string>()), () => { }, CreateErrorHandler("RequestHeartbeat")); break; } case MessageTypes.OrderRegister: { ProcessOrderRegisterMessage((OrderRegisterMessage)message); break; } case MessageTypes.OrderCancel: { ProcessOrderCancelMessage((OrderCancelMessage)message); break; } case MessageTypes.SecurityLookup: { ProcessSecurityLookupMessage((SecurityLookupMessage)message); break; } case MessageTypes.MarketData: { ProcessMarketDataMessage((MarketDataMessage)message); break; } } }
/// <summary> /// Отправить сообщение. /// </summary> /// <param name="message">Сообщение.</param> protected override void OnSendInMessage(Message message) { switch (message.Type) { case MessageTypes.Connect: { if (SessionHolder.Session == null) { _isSessionOwner = true; if (_api != null) { throw new InvalidOperationException(LocalizedStrings.Str3378); } _api = new LmaxApi("https://{0}api.lmaxtrader.com".Put(SessionHolder.IsDemo ? "test" : string.Empty)); _api.Login(new LoginRequest(SessionHolder.Login, SessionHolder.Password.To <string>(), SessionHolder.IsDemo ? ProductType.CFD_DEMO : ProductType.CFD_LIVE), OnLoginOk, OnLoginFailure); } else { SendOutMessage(new ConnectMessage()); } break; } case MessageTypes.Disconnect: { if (!_isSessionOwner) { SendOutMessage(new DisconnectMessage()); break; } Session.Stop(); Session.Logout(OnLogoutSuccess, OnLogoutFailure); break; } case MessageTypes.PortfolioLookup: { Session.Subscribe(new AccountSubscriptionRequest(), () => { }, CreateErrorHandler("AccountSubscriptionRequest")); Session.Subscribe(new PositionSubscriptionRequest(), () => { }, CreateErrorHandler("PositionSubscriptionRequest")); break; } case MessageTypes.OrderStatus: { Session.Subscribe(new ExecutionSubscriptionRequest(), () => { }, CreateErrorHandler("ExecutionSubscriptionRequest")); Session.Subscribe(new OrderSubscriptionRequest(), () => { }, CreateErrorHandler("OrderSubscriptionRequest")); break; } case MessageTypes.Time: { var timeMsg = (TimeMessage)message; Session.RequestHeartbeat(new HeartbeatRequest(timeMsg.TransactionId), () => { }, CreateErrorHandler("RequestHeartbeat")); break; } case MessageTypes.OrderRegister: { ProcessOrderRegisterMessage((OrderRegisterMessage)message); break; } case MessageTypes.OrderCancel: { var cancelMsg = (OrderCancelMessage)message; Session.CancelOrder(new CancelOrderRequest(cancelMsg.TransactionId.To <string>(), (long)cancelMsg.SecurityId.Native, cancelMsg.OrderTransactionId.To <string>()), id => { }, CreateErrorHandler("CancelOrder")); break; } case MessageTypes.SecurityLookup: { var lookupMsg = (SecurityLookupMessage)message; ProcessSecurityLookupMessage(lookupMsg); break; } case MessageTypes.MarketData: { var mdMsg = (MarketDataMessage)message; ProcessMarketDataMessage(mdMsg); break; } } }