def test_stock_df(self): from_date = date(2001,1,15) to_date = date(2002,1,15) raw = nse.stock_raw("SBIN", from_date, to_date) df = nse.stock_df("SBIN", from_date, to_date) assert len(raw) == len(df) assert df['DATE'].iloc[0] == np.datetime64("2002-01-15") assert df['DATE'].iloc[-1] == np.datetime64("2001-01-15") assert df['OPEN'].iloc[0] == 220
def test_stock_raw(self): from_date = date(2001,1,15) to_date = date(2002,1,15) d = nse.stock_raw("SBIN", from_date, to_date) assert len(d) > 240 assert len(d) < 250 all_dates = [datetime.strptime(k["CH_TIMESTAMP"], "%Y-%m-%d").date() for k in d] assert to_date in all_dates assert from_date in all_dates assert d[-1]["CH_TIMESTAMP"] == str(from_date) assert d[0]["CH_TIMESTAMP"] == str(to_date) app_name = nse.APP_NAME + '-stock' files = os.listdir(user_cache_dir(app_name, app_name)) assert len(files) == 13
def test_stock_csv(self): from_date = date(2001, 1, 15) to_date = date(2002, 1, 15) raw = nse.stock_raw("SBIN", from_date, to_date) output = nse.stock_csv("SBIN", from_date, to_date) with open(output) as fp: text = fp.read() rows = [x.split(',') for x in text.split('\n')] headers = [ "DATE", "SERIES", "OPEN", "HIGH", "LOW", "PREV. CLOSE", "LTP", "CLOSE", "VWAP", "52W H", "52W L", "VOLUME", "VALUE", "NO OF TRADES", "SYMBOL" ] assert headers == rows[0] assert raw[0]['CH_TIMESTAMP'] == rows[1][0] assert raw[0]['CH_OPENING_PRICE'] == int(rows[1][2])