public async void Login() { UpdateDebugMessage("Attempting login"); //change this also @loginfeature //var igWebApiConnectionConfig = ConfigurationManager.GetSection("IgWebApiConnection") as NameValueCollection; var igWebApiConnectionConfig = GetLoginInfo(); string env = igWebApiConnectionConfig["environment"]; string userName = igWebApiConnectionConfig["username"]; string password = igWebApiConnectionConfig["password"]; string apiKey = igWebApiConnectionConfig["apikey"]; UpdateDebugMessage("User="******" is attempting to login to environment=" + env); if (String.IsNullOrEmpty(userName) || String.IsNullOrEmpty(password) || String.IsNullOrEmpty(apiKey)) { UpdateDebugMessage("Please enter a valid username / password / ApiKey combination in ApplicationViewModel ( Login method )"); return; } var ar = new AuthenticationRequest { identifier = userName, password = password }; try { var response = await igRestApiClient.SecureAuthenticate(ar, apiKey); if (response && (response.Response != null) && (response.Response.accounts.Count > 0)) { Accounts.Clear(); foreach (var account in response.Response.accounts) { var igAccount = new IgPublicApiData.AccountModel { ClientId = response.Response.clientId, ProfitLoss = response.Response.accountInfo.profitLoss, AvailableCash = response.Response.accountInfo.available, Deposit = response.Response.accountInfo.deposit, Balance = response.Response.accountInfo.balance, LsEndpoint = response.Response.lightstreamerEndpoint, AccountId = account.accountId, AccountName = account.accountName, AccountType = account.accountType }; Accounts.Add(igAccount); } LoggedIn = true; UpdateDebugMessage("Logged in, current account: " + response.Response.currentAccountId); ConversationContext context = igRestApiClient.GetConversationContext(); UpdateDebugMessage("establishing datastream connection"); if ((context != null) && (response.Response.lightstreamerEndpoint != null) && (context.apiKey != null) && (context.xSecurityToken != null) && (context.cst != null)) { try { CurrentAccountId = response.Response.currentAccountId; var connectionEstablished = igStreamApiClient.Connect(response.Response.currentAccountId, context.cst, context.xSecurityToken, context.apiKey, response.Response.lightstreamerEndpoint); if (connectionEstablished) { UpdateDebugMessage(String.Format("Connecting to Lightstreamer. Endpoint ={0}", response.Response.lightstreamerEndpoint)); // Subscribe to Account Details and Trade Subscriptions... SubscribeToAccountDetails(); SubscribeToTradeSubscription(); } else { igStreamApiClient = null; UpdateDebugMessage(String.Format( "Could NOT connect to Lightstreamer. Endpoint ={0}", response.Response.lightstreamerEndpoint)); } } catch (Exception ex) { UpdateDebugMessage(ex.Message); } } } else { UpdateDebugMessage("Failed to login. HttpResponse StatusCode = " + response.StatusCode); } } catch (Exception ex) { UpdateDebugMessage("ApplicationViewModel exception : " + ex.Message); } }
public async void Login() { UpdateDebugMessage("Attempting login"); var UserName = ""; //*** TODO enter your username here ***; var ApiKey = ""; //*** TODO enter your APIKey here ***; var Password = ""; //*** TODO enter your password here ***; if (String.IsNullOrEmpty(UserName) || String.IsNullOrEmpty(Password) || String.IsNullOrEmpty(ApiKey)) { UpdateDebugMessage("Please enter a valid username / password / ApiKey combination in ApplicationViewModel ( Login method )"); return; } // use v2 secure login... var ar = new dto.colibri.endpoint.auth.v2.AuthenticationRequest(); ar.identifier = UserName; ar.password = Password; try { var response = await igRestApiClient.SecureAuthenticate(ar, ApiKey); if (response && (response.Response != null) && (response.Response.accounts.Count > 0)) { Accounts.Clear(); foreach (var account in response.Response.accounts) { var igAccount = new IgPublicApiData.AccountModel(); igAccount.ClientId = response.Response.clientId; igAccount.ProfitLoss = response.Response.accountInfo.profitLoss; igAccount.AvailableCash = response.Response.accountInfo.available; igAccount.Deposit = response.Response.accountInfo.deposit; igAccount.Balance = response.Response.accountInfo.balance; igAccount.LsEndpoint = response.Response.lightstreamerEndpoint; igAccount.AvailableCash = response.Response.accountInfo.available; igAccount.Balance = response.Response.accountInfo.balance; igAccount.AccountId = account.accountId; igAccount.AccountName = account.accountName; igAccount.AccountType = account.accountType; _accounts.Add(igAccount); } LoggedIn = true; UpdateDebugMessage("Logged in, current account: " + response.Response.currentAccountId); ConversationContext context = igRestApiClient.GetConversationContext(); UpdateDebugMessage("establishing datastream connection"); if ((context != null) && (response.Response.lightstreamerEndpoint != null) && (context.apiKey != null) && (context.xSecurityToken != null) && (context.cst != null)) { try { CurrentAccountId = response.Response.currentAccountId; var connectionEstablished = igStreamApiClient.Connect(response.Response.currentAccountId, context.cst, context.xSecurityToken, context.apiKey, response.Response.lightstreamerEndpoint); if (connectionEstablished) { UpdateDebugMessage(String.Format("Connecting to Lightstreamer. Endpoint ={0}", response.Response.lightstreamerEndpoint)); // Subscribe to Account Details and Trade Subscriptions... SubscribeToAccountDetails(); SubscribeToTradeSubscription(); } else { igStreamApiClient = null; UpdateDebugMessage(String.Format( "Could NOT connect to Lightstreamer. Endpoint ={0}", response.Response.lightstreamerEndpoint)); } } catch (Exception ex) { UpdateDebugMessage(ex.Message); } } } else { UpdateDebugMessage("Failed to login. HttpResponse StatusCode = " + response.StatusCode); } } catch (Exception ex) { UpdateDebugMessage("ApplicationViewModel exception : " + ex.Message); } }