public async Task<IgResponse<AuthenticationResponse>> SecureAuthenticate(AuthenticationRequest ar, string apiKey) { _conversationContext = new ConversationContext(null, null, apiKey); var encryptedPassword = await SecurePassword(ar.password); if (encryptedPassword == ar.password) { ar.encryptedPassword = false; } else { ar.encryptedPassword = true; } ar.password = encryptedPassword; return await authenticate(ar); }
public async Task<IgResponse<AuthenticationResponse>> Authenticate(AuthenticationRequest ar, string apiKey) { _conversationContext = new ConversationContext(null, null, apiKey); return await authenticate(ar); }
///<Summary> ///Creates a trading session, obtaining session tokens for subsequent API access. ///<p> /// Please note that region-specific <a href=/loginrestrictions>login restrictions</a> may apply. ///</p> ///@param authenticationRequest Client login credentials ///@return Client summary account information ///</Summary> public async Task <IgResponse <dto.colibri.endpoint.auth.v2.AuthenticationResponse> > authenticate(dto.colibri.endpoint.auth.v2.AuthenticationRequest authenticationRequest) { return(await _igRestService.RestfulService <dto.colibri.endpoint.auth.v2.AuthenticationResponse>("/gateway/deal/session", HttpMethod.Post, "2", _conversationContext, authenticationRequest)); }
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); } }
///<Summary> ///loginButton_Click ///This method deals with logging into the app. ///</Summary> private async void loginButton_Click(object sender, EventArgs e) { try { AppendActivityMessage("Attempting login"); if (String.IsNullOrEmpty(_APIKey) || String.IsNullOrEmpty(passwordTextbox.Text) || String.IsNullOrEmpty(identifierTextbox.Text) || (_igRestApiClient == null)) { AppendActivityMessage("Please enter API key, Password and Username"); return; } // use v1 login... var ar = new AuthenticationRequest(); ar.identifier = identifierTextbox.Text; ar.password = passwordTextbox.Text; //log in... var authenticationResponse = await _igRestApiClient.SecureAuthenticate(ar, _APIKey); if (authenticationResponse && (authenticationResponse.Response != null) && (authenticationResponse.Response.accounts != null)) { if (authenticationResponse.Response.accounts.Count > 0) { AppendRestDataMessage(JsonConvert.SerializeObject(authenticationResponse, Formatting.Indented)); AppendActivityMessage("Logged in, current account: " + authenticationResponse.Response.currentAccountId); _currentAccount = authenticationResponse.Response.currentAccountId; ConversationContext context = _igRestApiClient.GetConversationContext(); AppendActivityMessage("establishing streaming data connection"); if ((context != null) && (authenticationResponse.Response.currentAccountId != null) && (authenticationResponse.Response.lightstreamerEndpoint != null)) { if (_igStreamApiClient != null) { var connectionEstablished = _igStreamApiClient.Connect(authenticationResponse.Response.currentAccountId, context.cst, context.xSecurityToken, context.apiKey, authenticationResponse.Response.lightstreamerEndpoint); if (connectionEstablished) { AppendActivityMessage("streaming data connection established"); EnableCommandButtons(true); } else { AppendActivityMessage("streaming data connection could NOT be established"); EnableCommandButtons(false); } } } else { AppendActivityMessage("Could not establish streaming data connection."); } } else { AppendActivityMessage("no accounts"); } } else { AppendActivityMessage("Authentication Rest Response error : " + authenticationResponse.StatusCode ); } } catch (Exception ex) { AppendActivityMessage(ex.Message); } }