/// <summary> /// Reads the api key from a supplied file name /// </summary> /// <returns></returns> private static async Task InitializeApplicationAsync(string fileName = null) { // reading this from a file for now // should be read from db or secure key vault for production string environment = m_Environment.ToString(); fileName = fileName ?? $@"C:\Users\Osita\SourceCode\GitHub\ETrade10\etrade{environment}.credentials.json"; Credentials credentials = null; try { using (var sr = new StreamReader(fileName)) { // an ETrade account is required to generate a valid consumer key and secret // for info, go to: https://developer.etrade.com/home string jsonCredentials = await sr.ReadToEndAsync(); credentials = JsonConvert.DeserializeObject <Credentials>(jsonCredentials); credentials.environment = m_Environment; } } catch (Exception ex) { throw new ApplicationException("Could not read api credentials.", ex); } m_ETrade10 = new ETrade10(MEFLoader.Container.GetExport <IOAuthService>(), null); await m_ETrade10.Initialize(credentials); }
private static async Task AuthorizeApplication() { WriteNewLine("Setting your ETrade10 credentials ..."); _ETrade10 = new ETrade10(null, null); await _ETrade10.Initialize(GetCredentials(null)); WriteNewLine("Nice! Application is authorized."); }