def test_addTradeSummariesSA(self): ''' Tests addTradeSummaries. The method requires trades are already in the database. We achieve that with openStuff. For this test, I load everything (openStuff) and run addTradeSummaries on all covered days. Its slow. Could be partially sqlite but all the APL BAPL stuff is probably the main crawler. In practice, this will add daily or monthly statements. And in running the program there is no way to run the trade summaries in mass. Its desinged to load up a single day. ITs day-trader centric. Let it stay slow for now. ''' ibdb = StatementDB() self.clearTables() ibs, x = self.openStuff() # ibdb.getUncoveredDays tcrud = TradeCrud() covered = tcrud.getCoveredDays() for count, day in enumerate(covered): df = ibdb.getStatement(day) if not df.empty: tu = DefineTrades("DB") dframe, ldf = tu.processDBTrades(df) tradeSummaries, ts, entries, initialImageNames = runSummaries(ldf) ibdb.addTradeSummariesSA(ts, ldf) summaries = ibdb.getTradeSumByDateSA(day) for summary in summaries: entryTrades = ibdb.getEntryTradesSA(summary.id) self.assertGreater(len(entryTrades), 0) break # Use this to just test addTradeSummaries once bu = Backup() bu.restore()
def test_findTradeSummary(self): ''' Test findTradeSummary, a helper method for addTradeSummaries and updateTradeSummaries. Note that one of those needs to have run and succeeded inorder to test this method. ''' infile = "data/flex.369463.ActivityFlexMonth.20191008.20191106.csv" theDate = pd.Timestamp('2019-10-16') # Create these three objects ibs = IbStatement(db=self.db) ibdb = StatementDB(self.db) ibdb.reinitializeTradeTables() trades = DefineTrades("DB") # This call loads the statement into the db ibs.openIBStatementCSV(infile) # Here is an example of processing a single day of trades (3 calls) # This gets a collection of trades from a single day that can become a trade_sum entry df = ibdb.getStatement(theDate) # The following method and function process the statement transactions into a collection # of trades where each trade is a single row representing multiple transactions dframe, ldf = trades.processDBTrades(df) tradeSummaries, ts, entries, initialImageNames = runSummaries(ldf) ibdb.addTradeSummaries(ts, ldf) # The test database trades_sum should now only the trades from theDate, one # entry per trade for i, trade in enumerate(tradeSummaries): x = ibdb.findTradeSummary(theDate, trade['Start'].unique()[0]) self.assertEqual(trade['Name'].unique()[0], x[1])
def runTtoSummaries(self, ldf): ''' This script creates the tto object for each trade in the input file and appends it to a list It also creates a generic name for assoiated images. That name will be altered for speific images that may be created via the stock api or added by the user. Finally the sript creates the tradeList key and adds it to the tradeList widget. The key is used to retrieve the tto data from the tradeList widget currentText selection. :params ldf: A list of DataFrames. Each df is a complete trade from initial purchace or hold to 0 shares or hold. ''' newtradeSummaries, newts, newentries, initialImageNames = runSummaries( ldf) assert len(ldf) == len(initialImageNames) self.sc.ui.tradeList.clear() self.imageNames = initialImageNames self.ts = newts self.entries = newentries for tkey in newts: self.sc.ui.tradeList.addItem(tkey) self.tradeSummaries = newtradeSummaries return self.tradeSummaries