/// <summary> /// Connects/Starts a client /// </summary> public bool Start() { try { // Read account credentials _credentials = CredentialReader.ReadCredentials("RediParams.xml"); if (!CheckParameterValidity()) { return(false); } // Create TCP Request _rediSocketConnection = new SocketCommunication(new Queue(), _credentials.Username, _credentials.Password, _credentials.IpAddress, Convert.ToInt32(_credentials.Port), _logger); _rediSocketConnection.SendMessage += DataRecieved; _rediSocketConnection.ErrorInTcp += new SocketCommunication.ConnectionError(RediSocketConnectionErrorInTcp); _isConnected = true; _rediSocketConnection.Connect(); if (_logger.IsInfoEnabled) { _logger.Info("Session is available.", _type.FullName, "Start"); } if (LogonArrived != null) { LogonArrived(_marketDataProviderName); } return(true); } catch (Exception exception) { _logger.Error(exception, _type.FullName, "Start"); } return(false); }
/// <summary> /// Connects/Starts a client /// </summary> public bool Start() { try { // Read account credentials _credentials = CredentialReader.ReadCredentials("TradierParams.xml"); if (String.IsNullOrEmpty(_credentials.ApiUrl) || String.IsNullOrWhiteSpace(_credentials.ApiUrl)) { return(false); } // Create HTTP Request var client = new RestClient(_credentials.ApiUrl + "/user/profile"); var request = new RestRequest(Method.GET); request.AddHeader("authorization", "Bearer " + _credentials.AccessToken); request.AddHeader("accept", "application/json"); // Send Request IRestResponse response = client.Execute(request); var requestResult = JsonConvert.DeserializeObject <dynamic>(response.Content); string profileId = requestResult.profile.id.ToString(); if (!String.IsNullOrEmpty(profileId)) { _isConnected = true; // Start process to consume quotes StartDataConsumer(); if (Logger.IsInfoEnabled) { Logger.Info("Session is available.", _type.FullName, "Start"); } if (LogonArrived != null) { LogonArrived(_marketDataProviderName); } return(_isConnected); } // Get error message string faultstring = requestResult.fault.faultstring.ToString(); if (Logger.IsInfoEnabled) { Logger.Info("Session not available " + faultstring, _type.FullName, "Start"); } return(_isConnected); } catch (Exception exception) { _logger.Error(exception, _type.FullName, "Start"); } return(false); }