public Portfolio() { TastyWorks.InitiateSession(Config.GetEncryptedProp("Username"), Config.GetEncryptedProp("Password")); }
public static void Load(Accounts accounts) { try { // establish db connection App.OpenConnection(); if (TastyWorks.InitiateSession(Config.GetEncryptedProp("Username"), Config.GetEncryptedProp("Password"))) { // cache the current positions for details required to establish default risk and capreq twpositions = new Dictionary <string, TWPositions>(); twMarginReq = new Dictionary <string, TWMargins>(); foreach (Account a in accounts) { if (a.Active) { // retrieve Tastyworks positions for given account TWPositions pos = TastyWorks.Positions(a.ID); twpositions.Add(a.ID, pos); TWMargins mar = TastyWorks.MarginData(a.ID); twMarginReq.Add(a.ID, mar); } } // proceed with transactions from all accounts foreach (Account a in accounts) { if (a.Active) { Debug.WriteLine(a.ID); // retrieve Tastyworks transactions for the past month TWTransactions transactions = TastyWorks.Transactions(a.ID, DateTime.Today.AddDays(-30), null); SaveTransactions(transactions); // transfer transaction array to database // save latest transaction for next upload SQLiteCommand cmd = new SQLiteCommand("SELECT max(time) FROM transactions WHERE Account = @ac", App.ConnStr); cmd.Parameters.AddWithValue("ac", a.ID); SQLiteDataReader rdr = cmd.ExecuteReader(); string propName = "LastDate-" + a.ID; if (rdr.Read()) { Config.SetProp(propName, rdr[0].ToString()); } } } UpdateNewTransactions(); // matches unassociated asignments and exercises } else { MessageBox.Show("Login to TastyWorks failed", "Error"); } } catch (Exception ex) { Console.WriteLine("ERROR DataLoader: " + ex.Message); MessageBox.Show(ex.Message, "Sync Error"); } }