def test_sec_source(): from decouple import config subs_key = { "fundfactsheet": config("FUND_FACTSHEET_KEY"), "funddailyinfo": config("FUND_DAILY_INFO_KEY"), } # should auto convert to friday if it is a weekend # kt_nav = nav.get("KT-PRECIOUS", source="sec", subscription_key=subs_key) # print(kt_nav) # assert kt_nav.value >= 0 kt_nav = nav.get("KT-PRECIOUS", source="sec", subscription_key=subs_key, date="03/04/2020") print(kt_nav) assert kt_nav.value >= 0
def _fetchClosePrice(self, symbol: str, requested_date: datetime.date) -> dict: """internal function to fecth price of stock/mutual fund Returns: float -- stock price / nav Raises: GetNAVPriceError -- when the price of requested date is not available SymbolNotFoundError -- when the symbol is not found """ requested_str_date = str(requested_date) try: close = float(pdr.get_data_yahoo(symbol)["Close"][requested_str_date]) asset_type = "stock" # symbol not found in stock market, find it in mutual fund except pdr._utils.RemoteDataError: try: a_nav = nav.get(symbol) if str(a_nav.updated)[:10] != requested_str_date: raise GetNAVPriceError( f"NAV for symbol {symbol} on {requested_str_date} is not available!" ) else: close = a_nav.value asset_type = "mutual fund" # symbol is not valid except KeyError: raise SymbolNotFoundError(f"Symbol {symbol} is not found!") # symbol is found in stock market, but the price on the date is not available except KeyError as x: raise GetNAVPriceError( f"Price for symbol {symbol} on {requested_str_date} is not available!" ) return {"close": close, "asset_type": asset_type}
import pythainav as nav print(nav.get("BERMF", date="12/11/2020"))
def test_get_nav(): kt_nav = nav.get("KT-PRECIOUS") print(kt_nav) assert kt_nav.value >= 0
def test_get_nav_with_date(): oil_nav = nav.get("TMBOIL", date="1 week ago") print(oil_nav) assert oil_nav.value >= 0
def test_get_nav(): import pythainav as nav kt_nav = nav.get("KT-PRECIOUS") print(kt_nav) assert kt_nav.value >= 0
def test_get_nav_with_date(): kt_nav = nav.get("KT-PRECIOUS", date="1 week ago") print(kt_nav) assert kt_nav.value >= 0