def test_apiChooserLimitReached(self): ''' This is designed to hit the limits of the apis. Do not want to run this with tests most of the time. Just fiddle with the orprefs and the REPEATS and watch the result ''' REPEATS = 15 orprefs = ['av'] symbol = 'AAPL' minutes = 1 d = util.getPrevTuesWed(pd.Timestamp.now()) start = pd.Timestamp(d.strftime("%Y%m%d " + '09:36:42')) end = pd.Timestamp(d.strftime("%Y%m%d " + '09:38:53')) chooser = APIChooser(self.apiset, orprefs=orprefs) for i in range(REPEATS): chooser.apiChooserList(start, end) if chooser.api: intraday = chooser.apiChooser() meta, df, ma = intraday(symbol, start, end, minutes) if not df.empty: print(i + 1, ' ', end='') else: print() print(meta) print() else: print() print('Call number', i) for rule in chooser.violatedRules: print(rule)
def test_apiChooser(self): ''' Test the method FinPlot.apiChooser for the same interface in each api ''' chooser = APIChooser(self.apiset) yesterday = dt.datetime.today() - dt.timedelta(1) biz = util.getLastWorkDay(yesterday) start = dt.datetime(biz.year, biz.month, biz.day, 12, 30) end = dt.datetime(biz.year, biz.month, biz.day, 16, 1) minutes = 1 apis = chooser.preferences symbol = 'SQ' for api in apis: chooser.api = api result = chooser.apiChooserList(start, end, api) if result[0]: dummy, df, maDict = chooser.apiChooser()(symbol, start=start, end=end, minutes=minutes, showUrl=True) self.assertEqual( len(df.columns), 5, f"Failed to retrieve data with the {chooser.api} api.") self.assertTrue( isinstance(df.index[0], dt.datetime), f'Failed to set index to datetime in {chooser.api} api') cols = ['open', 'high', 'low', 'close', 'volume'] for col in cols: # print(col, type(df[col][0]), isinstance(df[col][0], (np.float, np.integer))) self.assertTrue(col in df.columns) self.assertTrue( isinstance(df[col][0], (np.float, np.integer))) # This call should retrieve data within 1 bar of the requested start and finish. # Idiosyncracies of the APIs vary as to inclusion of first and last time index delt = df.index[0] - \ start if df.index[0] > start else start - df.index[0] self.assertLessEqual(delt.seconds, minutes * 60) # print('Retrieved {} candles from {} to {} for {}'.format( # len(df), df.index[0], df.index[-1], symbol)) # print() else: print(f'Skipped {api} at {start} to {end} because...') for rule in result[1]: print(rule)