From be20774aae71db831a638fbd2a657dda6e451ecf Mon Sep 17 00:00:00 2001 From: Kevin Johnson Date: Sat, 27 Nov 2021 15:44:57 -0800 Subject: [PATCH] STY double quote consistency --- README.md | 2 +- pandas_ta/utils/data/polygon_api.py | 102 ++++++++++++++-------------- setup.py | 2 +- 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 621e039..3a1ada3 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ $ pip install pandas_ta Latest Version -------------- -Best choice! Version: *0.3.36b* +Best choice! Version: *0.3.37b* * Includes all fixes and updates between **pypi** and what is covered in this README. ```sh $ pip install -U git+https://github.com/twopirllc/pandas-ta diff --git a/pandas_ta/utils/data/polygon_api.py b/pandas_ta/utils/data/polygon_api.py index e145744..2fc6a11 100644 --- a/pandas_ta/utils/data/polygon_api.py +++ b/pandas_ta/utils/data/polygon_api.py @@ -57,28 +57,28 @@ def polygon_api(ticker: str, **kwargs): verbose = kwargs.pop("verbose", False) kind = kwargs.pop("kind", "nothing").lower() show = kwargs.pop("show", None) - desc = kwargs.pop('desc', False) + desc = kwargs.pop("desc", False) df = DataFrame() - api_key = kwargs.pop('api_key', None) + api_key = kwargs.pop("api_key", None) if api_key is None: - raise ValueError('Please make sure you pass your polygon api key through kwarg api_key') - if not Imports['polygon']: - raise ValueError('Please install package polygon to use this function (pip install polygon)') + raise ValueError("Please make sure you pass your polygon api key through kwarg api_key") + if not Imports["polygon"]: + raise ValueError("Please install package polygon to use this function (pip install polygon)") if ticker is not None and isinstance(ticker, str): ticker = ticker.upper() else: - raise ValueError('Ticker symbol name must be a valid name string. Eg: \'AMD\'') + raise ValueError("Ticker symbol name must be a valid name string. Eg: \'AMD\'") - start_date = kwargs.pop('start_date', (datetime.date.today() - datetime.timedelta(days=525))) - end_date = kwargs.pop('end_date', datetime.date.today()) - limit = kwargs.pop('limit', 50000) - multiplier = kwargs.pop('multiplier', 1) - timespan = kwargs.pop('timespan', 'day') + start_date = kwargs.pop("start_date", (datetime.date.today() - datetime.timedelta(days=525))) + end_date = kwargs.pop("end_date", datetime.date.today()) + limit = kwargs.pop("limit", 50000) + multiplier = kwargs.pop("multiplier", 1) + timespan = kwargs.pop("timespan", "day") - LOGGER.info(f'start date: {start_date} || end date: {end_date} || limit: {limit} || ' - f'multiplier: {multiplier} || timespan: {timespan}') + LOGGER.info(f"start date: {start_date} || end date: {end_date} || limit: {limit} || " + f"multiplier: {multiplier} || timespan: {timespan}") _all, div = ["all"], "=" * 53 # Max div width is 80 @@ -91,13 +91,13 @@ def polygon_api(ticker: str, **kwargs): resp = polygon_client.get_aggregate_bars(ticker, start_date, end_date, limit=limit, multiplier=multiplier, timespan=timespan) - if 'results' in resp.keys(): - df = pd.DataFrame.from_dict(resp['results']) + if "results" in resp.keys(): + df = pd.DataFrame.from_dict(resp["results"]) if len(df) > 0: - index = 't' + index = "t" df = df.set_index(pd.DatetimeIndex(unix_convert(df[index]))) - df = df[['v', 'o', 'c', 'h', 'l', 't']] - df.columns = ['Volume', 'Open', 'Close', 'High', 'Low', 'Date'] + df = df[["v", "o", "c", "h", "l", "t"]] + df.columns = ["Volume", "Open", "Close", "High", "Low", "Date"] df.name = ticker else: @@ -106,74 +106,74 @@ def polygon_api(ticker: str, **kwargs): if show is not None and isinstance(show, int) and show > 0: print(f"\n{df.name}\n{df.tail(show)}\n") - if kind in ['nothing', None]: # no additional data requested + if kind in ["nothing", None]: # no additional data requested return df # ADDITIONAL DATA FLOW ref_client, stock_client = polygon.ReferenceClient(api_key), polygon.StocksClient(api_key) # ALL THE INFORMATION - if kind in ['all', 'info'] or verbose: + if kind in ["all", "info"] or verbose: print("\n==== Company Information " + div) details = ref_client.get_ticker_details(ticker) - details_vx = ref_client.get_ticker_details_vx(ticker)['results'] + details_vx = ref_client.get_ticker_details_vx(ticker)["results"] - print(f'{details["name"]} [{details["symbol"]}]\n') + print(f"{details['name']} [{details['symbol']}]\n") if desc: # company description - print(f'{details["description"]}\n') + print(f"{details['description']}\n") # TODO: polygon returns hell lotta data for market info across a few endpoints. I don't know which ones to # include here lol. I wrote the ones i felt were important. Feel free to suggest more. # Common details + Market info - print(f'{details["hq_address"]}. {details["hq_country"]}\nPhone: {details_vx["phone_number"]}\n' - f'Website: {details["url"]} || Employees: {details["employees"]}\nSector: {details["sector"]} || ' - f'Industry: {details["industry"]}\n\n==== Market Information {div}\n' - f'Market: {details_vx["market"].upper()} || locale: {details_vx["locale"].upper()} || ' - f'Exchange: {details["exchange"]} || Symbol: {details["symbol"]}\nMarket Shares: ' - f'{details_vx["market_cap"]} || Outstanding Shares: {details_vx["outstanding_shares"]}\n') + print(f"{details['hq_address']}. {details['hq_country']}\nPhone: {details_vx['phone_number']}\n" + f"Website: {details['url']} || Employees: {details['employees']}\nSector: {details['sector']} || " + f"Industry: {details['industry']}\n\n==== Market Information {div}\n" + f"Market: {details_vx['market'].upper()} || locale: {details_vx['locale'].upper()} || " + f"Exchange: {details['exchange']} || Symbol: {details['symbol']}\nMarket Shares: " + f"{details_vx['market_cap']} || Outstanding Shares: {details_vx['outstanding_shares']}\n") # Price Info print(f"\n==== Price Information {div}") snap_res = stock_client.get_snapshot(ticker) try: - snap = snap_res['ticker'] + snap = snap_res["ticker"] - print(f'\nCurrent Price: {snap["lastTrade"]["p"]} || Today\'s Change: ${snap_res["todaysChange"]} - ' - f'{snap_res["todaysChangePerc"]}%\nBid: {snap["lastQuote"]["p"]} x {snap["lastQuote"]["s"]} || Ask: ' - f'{snap["lastQuote"]["P"]} x {snap["lastQuote"]["S"]} || Spread: ' - f'{round(snap["lastQuote"]["P"] - snap["lastQuote"]["p"], 4)}\nOpen: {snap["day"]["o"]} || High: ' - f'{snap["day"]["h"]} || Low: {snap["day"]["l"]} || Close: {snap["day"]["c"]} || Volume: ' - f'{snap["day"]["v"]} || VWA: {snap["day"]["vw"]}') + print(f"\nCurrent Price: {snap['lastTrade']['p']} || Today\'s Change: ${snap_res['todaysChange']} - " + f"{snap_res['todaysChangePerc']}%\nBid: {snap['lastQuote']['p']} x {snap['lastQuote']['s']} || Ask: " + f"{snap['lastQuote']['P']} x {snap['lastQuote']['S']} || Spread: " + f"{round(snap['lastQuote']['P'] - snap['lastQuote']['p'], 4)}\nOpen: {snap['day']['o']} || High: " + f"{snap['day']['h']} || Low: {snap['day']['l']} || Close: {snap['day']['c']} || Volume: " + f"{snap['day']['v']} || VWA: {snap['day']['vw']}") except KeyError: - print(f'Snapshot not found for {ticker}. Can Not print price information. Snapshot will be be back ' - f'available after pre market session opens\n') + print(f"Snapshot not found for {ticker}. Can Not print price information. Snapshot will be be back " + f"available after pre market session opens\n") # Splits and Dividends divs, splits = ref_client.get_stock_dividends(ticker), ref_client.get_stock_splits(ticker) # TODO: spits and dividends endpoints from polygon return a huge list. not sure if that entire list is useful - print(f'\nNumber of dividends: {divs["count"]} || Number of splits: {splits["count"]}\n') + print(f"\nNumber of dividends: {divs['count']} || Number of splits: {splits['count']}\n") # TODO: financials endpoint on polygon returns a huge response. I doubt if that's useful to be displayed. # Option Chains - if kind in ['option_chains', 'oc']: - contract_type = kwargs.pop('contract_type', 'all') - contract_limit = kwargs.pop('contract_limit', 10) + if kind in ["option_chains", "oc"]: + contract_type = kwargs.pop("contract_type", "all") + contract_limit = kwargs.pop("contract_limit", 10) chains = ref_client.get_option_contracts(ticker, limit=contract_limit, - contract_type=None if contract_type == 'all' else contract_type) + contract_type=None if contract_type == "all" else contract_type) - if len(chains['results']) > 0: - print(f'\n==== Option chains {div}\n\n') - for contract in chains['results']: - print(f'Symbol: {contract["ticker"]} || Type: {contract["contract_type"]}' - f' || Expiry: {contract["expiration_date"]} || Strike Price: ${contract["strike_price"]}' - f' || Shares Per Contract: {contract["shares_per_contract"]}\n') + if len(chains["results"]) > 0: + print(f"\n==== Option chains {div}\n\n") + for contract in chains["results"]: + print(f"Symbol: {contract['ticker']} || Type: {contract['contract_type']}" + f" || Expiry: {contract['expiration_date']} || Strike Price: ${contract['strike_price']}" + f" || Shares Per Contract: {contract['shares_per_contract']}\n") else: - print(f'\nNo option chains data found for {ticker}.') + print(f"\nNo option chains data found for {ticker}.") return df @@ -185,4 +185,4 @@ def unix_convert(ts: Union[int, pd.Series]) -> Union[datetime.datetime, str]: :param ts: The timestamp(s). An integer posix timestamp or a pd.Series of timestamps :return: The converted datetime string """ - return pd.to_datetime(ts, unit='ms') + return pd.to_datetime(ts, unit="ms") diff --git a/setup.py b/setup.py index 3a373f8..c8759e8 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ setup( "pandas_ta.volatility", "pandas_ta.volume" ], - version=".".join(("0", "3", "36b")), + version=".".join(("0", "3", "37b")), description=long_description, long_description=long_description, author="Kevin Johnson",