Search is not available for this dataset
text
stringlengths
75
104k
def batchDF(symbols, fields=None, range_='1m', last=10, token='', version=''): '''Batch several data requests into one invocation https://iexcloud.io/docs/api/#batch-requests Args: symbols (list); List of tickers to request fields (list); List of fields to request range_ (string); Date range for chart last (int); token (string); Access token version (string); API version Returns: DataFrame: results in json ''' x = batch(symbols, fields, range_, last, token, version) ret = {} if isinstance(symbols, str): for field in x.keys(): ret[field] = _MAPPING[field](x[field]) else: for symbol in x.keys(): for field in x[symbol].keys(): if field not in ret: ret[field] = pd.DataFrame() dat = x[symbol][field] dat = _MAPPING[field](dat) dat['symbol'] = symbol ret[field] = pd.concat([ret[field], dat], sort=True) return ret
def bulkBatch(symbols, fields=None, range_='1m', last=10, token='', version=''): '''Optimized batch to fetch as much as possible at once https://iexcloud.io/docs/api/#batch-requests Args: symbols (list); List of tickers to request fields (list); List of fields to request range_ (string); Date range for chart last (int); token (string); Access token version (string); API version Returns: dict: results in json ''' fields = fields or _BATCH_TYPES args = [] empty_data = [] list_orig = empty_data.__class__ if not isinstance(symbols, list_orig): raise PyEXception('Symbols must be of type list') for i in range(0, len(symbols), 99): args.append((symbols[i:i+99], fields, range_, last, token, version)) pool = ThreadPool(20) rets = pool.starmap(batch, args) pool.close() ret = {} for i, d in enumerate(rets): symbols_subset = args[i][0] if len(d) != len(symbols_subset): empty_data.extend(list_orig(set(symbols_subset) - set(d.keys()))) ret.update(d) for k in empty_data: if k not in ret: if isinstance(fields, str): ret[k] = {} else: ret[k] = {x: {} for x in fields} return ret
def bulkBatchDF(symbols, fields=None, range_='1m', last=10, token='', version=''): '''Optimized batch to fetch as much as possible at once https://iexcloud.io/docs/api/#batch-requests Args: symbols (list); List of tickers to request fields (list); List of fields to request range_ (string); Date range for chart last (int); token (string); Access token version (string); API version Returns: DataFrame: results in json ''' dat = bulkBatch(symbols, fields, range_, last, token, version) ret = {} for symbol in dat: for field in dat[symbol]: if field not in ret: ret[field] = pd.DataFrame() d = dat[symbol][field] d = _MAPPING[field](d) d['symbol'] = symbol ret[field] = pd.concat([ret[field], d], sort=True) return ret
def _bookToDF(b): '''internal''' quote = b.get('quote', []) asks = b.get('asks', []) bids = b.get('bids', []) trades = b.get('trades', []) df1 = pd.io.json.json_normalize(quote) df1['type'] = 'quote' df2 = pd.io.json.json_normalize(asks) df2['symbol'] = quote['symbol'] df2['type'] = 'ask' df3 = pd.io.json.json_normalize(bids) df3['symbol'] = quote['symbol'] df3['type'] = 'bid' df4 = pd.io.json.json_normalize(trades) df4['symbol'] = quote['symbol'] df3['type'] = 'trade' df = pd.concat([df1, df2, df3, df4], sort=True) _toDatetime(df) return df
def bookDF(symbol, token='', version=''): '''Book data https://iextrading.com/developer/docs/#book realtime during Investors Exchange market hours Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' x = book(symbol, token, version) df = _bookToDF(x) return df
def cashFlow(symbol, token='', version=''): '''Pulls cash flow data. Available quarterly (4 quarters) or annually (4 years). https://iexcloud.io/docs/api/#cash-flow Updates at 8am, 9am UTC daily Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/cash-flow', token, version)
def cashFlowDF(symbol, token='', version=''): '''Pulls cash flow data. Available quarterly (4 quarters) or annually (4 years). https://iexcloud.io/docs/api/#cash-flow Updates at 8am, 9am UTC daily Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' val = cashFlow(symbol, token, version) df = pd.io.json.json_normalize(val, 'cashflow', 'symbol') _toDatetime(df) _reindex(df, 'reportDate') df.replace(to_replace=[None], value=np.nan, inplace=True) return df
def chart(symbol, timeframe='1m', date=None, token='', version=''): '''Historical price/volume data, daily and intraday https://iexcloud.io/docs/api/#historical-prices Data Schedule 1d: -9:30-4pm ET Mon-Fri on regular market trading days -9:30-1pm ET on early close trading days All others: -Prior trading day available after 4am ET Tue-Sat Args: symbol (string); Ticker to request timeframe (string); Timeframe to request e.g. 1m date (datetime): date, if requesting intraday token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) if timeframe is not None and timeframe != '1d': if timeframe not in _TIMEFRAME_CHART: raise PyEXception('Range must be in %s' % str(_TIMEFRAME_CHART)) return _getJson('stock/' + symbol + '/chart' + '/' + timeframe, token, version) if date: date = _strOrDate(date) return _getJson('stock/' + symbol + '/chart' + '/date/' + date, token, version) return _getJson('stock/' + symbol + '/chart', token, version)
def _chartToDF(c): '''internal''' df = pd.DataFrame(c) _toDatetime(df) _reindex(df, 'date') return df
def chartDF(symbol, timeframe='1m', date=None, token='', version=''): '''Historical price/volume data, daily and intraday https://iexcloud.io/docs/api/#historical-prices Data Schedule 1d: -9:30-4pm ET Mon-Fri on regular market trading days -9:30-1pm ET on early close trading days All others: -Prior trading day available after 4am ET Tue-Sat Args: symbol (string); Ticker to request timeframe (string); Timeframe to request e.g. 1m date (datetime): date, if requesting intraday token (string); Access token version (string); API version Returns: DataFrame: result ''' c = chart(symbol, timeframe, date, token, version) df = pd.DataFrame(c) _toDatetime(df) if timeframe is not None and timeframe != '1d': _reindex(df, 'date') else: if not df.empty: df.set_index(['date', 'minute'], inplace=True) else: return pd.DataFrame() return df
def bulkMinuteBars(symbol, dates, token='', version=''): '''fetch many dates worth of minute-bars for a given symbol''' _raiseIfNotStr(symbol) dates = [_strOrDate(date) for date in dates] list_orig = dates.__class__ args = [] for date in dates: args.append((symbol, '1d', date, token, version)) pool = ThreadPool(20) rets = pool.starmap(chart, args) pool.close() return list_orig(itertools.chain(*rets))
def bulkMinuteBarsDF(symbol, dates, token='', version=''): '''fetch many dates worth of minute-bars for a given symbol''' data = bulkMinuteBars(symbol, dates, token, version) df = pd.DataFrame(data) if df.empty: return df _toDatetime(df) df.set_index(['date', 'minute'], inplace=True) return df
def collections(tag, collectionName, token='', version=''): '''Returns an array of quote objects for a given collection type. Currently supported collection types are sector, tag, and list https://iexcloud.io/docs/api/#collections Args: tag (string); Sector, Tag, or List collectionName (string); Associated name for tag token (string); Access token version (string); API version Returns: dict: result ''' if tag not in _COLLECTION_TAGS: raise PyEXception('Tag must be in %s' % str(_COLLECTION_TAGS)) return _getJson('stock/market/collection/' + tag + '?collectionName=' + collectionName, token, version)
def collectionsDF(tag, query, token='', version=''): '''Returns an array of quote objects for a given collection type. Currently supported collection types are sector, tag, and list https://iexcloud.io/docs/api/#collections Args: tag (string); Sector, Tag, or List collectionName (string); Associated name for tag token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(collections(tag, query, token, version)) _toDatetime(df) _reindex(df, 'symbol') return df
def company(symbol, token='', version=''): '''Company reference data https://iexcloud.io/docs/api/#company Updates at 4am and 5am UTC every day Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/company', token, version)
def _companyToDF(c, token='', version=''): '''internal''' df = pd.io.json.json_normalize(c) _toDatetime(df) _reindex(df, 'symbol') return df
def companyDF(symbol, token='', version=''): '''Company reference data https://iexcloud.io/docs/api/#company Updates at 4am and 5am UTC every day Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' c = company(symbol, token, version) df = _companyToDF(c) return df
def delayedQuote(symbol, token='', version=''): '''This returns the 15 minute delayed market quote. https://iexcloud.io/docs/api/#delayed-quote 15min delayed 4:30am - 8pm ET M-F when market is open Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/delayed-quote', token, version)
def delayedQuoteDF(symbol, token='', version=''): '''This returns the 15 minute delayed market quote. https://iexcloud.io/docs/api/#delayed-quote 15min delayed 4:30am - 8pm ET M-F when market is open Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.io.json.json_normalize(delayedQuote(symbol, token, version)) _toDatetime(df) _reindex(df, 'symbol') return df
def dividends(symbol, timeframe='ytd', token='', version=''): '''Dividend history https://iexcloud.io/docs/api/#dividends Updated at 9am UTC every day Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) if timeframe not in _TIMEFRAME_DIVSPLIT: raise PyEXception('Range must be in %s' % str(_TIMEFRAME_DIVSPLIT)) return _getJson('stock/' + symbol + '/dividends/' + timeframe, token, version)
def _dividendsToDF(d): '''internal''' df = pd.DataFrame(d) _toDatetime(df) _reindex(df, 'exDate') return df
def dividendsDF(symbol, timeframe='ytd', token='', version=''): '''Dividend history https://iexcloud.io/docs/api/#dividends Updated at 9am UTC every day Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' d = dividends(symbol, timeframe, token, version) df = _dividendsToDF(d) return df
def earnings(symbol, token='', version=''): '''Earnings data for a given company including the actual EPS, consensus, and fiscal period. Earnings are available quarterly (last 4 quarters) and annually (last 4 years). https://iexcloud.io/docs/api/#earnings Updates at 9am, 11am, 12pm UTC every day Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/earnings', token, version)
def _earningsToDF(e): '''internal''' if e: df = pd.io.json.json_normalize(e, 'earnings', 'symbol') _toDatetime(df) _reindex(df, 'EPSReportDate') else: df = pd.DataFrame() return df
def earningsDF(symbol, token='', version=''): '''Earnings data for a given company including the actual EPS, consensus, and fiscal period. Earnings are available quarterly (last 4 quarters) and annually (last 4 years). https://iexcloud.io/docs/api/#earnings Updates at 9am, 11am, 12pm UTC every day Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' e = earnings(symbol, token, version) df = _earningsToDF(e) return df
def earningsTodayDF(token='', version=''): '''Returns earnings that will be reported today as two arrays: before the open bto and after market close amc. Each array contains an object with all keys from earnings, a quote object, and a headline key. https://iexcloud.io/docs/api/#earnings-today Updates at 9am, 11am, 12pm UTC daily Args: token (string); Access token version (string); API version Returns: DataFrame: result ''' x = earningsToday(token, version) z = [] for k in x: ds = x[k] for d in ds: d['when'] = k z.extend(ds) df = pd.io.json.json_normalize(z) if not df.empty: df.drop_duplicates(inplace=True) _toDatetime(df) _reindex(df, 'symbol') return df
def spread(symbol, token='', version=''): '''This returns an array of effective spread, eligible volume, and price improvement of a stock, by market. Unlike volume-by-venue, this will only return a venue if effective spread is not ‘N/A’. Values are sorted in descending order by effectiveSpread. Lower effectiveSpread and higher priceImprovement values are generally considered optimal. Effective spread is designed to measure marketable orders executed in relation to the market center’s quoted spread and takes into account hidden and midpoint liquidity available at each market center. Effective Spread is calculated by using eligible trade prices recorded to the consolidated tape and comparing those trade prices to the National Best Bid and Offer (“NBBO”) at the time of the execution. View the data disclaimer at the bottom of the stocks app for more information about how these values are calculated. https://iexcloud.io/docs/api/#earnings-today 8am ET M-F Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/effective-spread', token, version)
def spreadDF(symbol, token='', version=''): '''This returns an array of effective spread, eligible volume, and price improvement of a stock, by market. Unlike volume-by-venue, this will only return a venue if effective spread is not ‘N/A’. Values are sorted in descending order by effectiveSpread. Lower effectiveSpread and higher priceImprovement values are generally considered optimal. Effective spread is designed to measure marketable orders executed in relation to the market center’s quoted spread and takes into account hidden and midpoint liquidity available at each market center. Effective Spread is calculated by using eligible trade prices recorded to the consolidated tape and comparing those trade prices to the National Best Bid and Offer (“NBBO”) at the time of the execution. View the data disclaimer at the bottom of the stocks app for more information about how these values are calculated. https://iexcloud.io/docs/api/#earnings-today 8am ET M-F Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(spread(symbol, token, version)) _toDatetime(df) _reindex(df, 'venue') return df
def estimates(symbol, token='', version=''): '''Provides the latest consensus estimate for the next fiscal period https://iexcloud.io/docs/api/#estimates Updates at 9am, 11am, 12pm UTC every day Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/estimates', token, version)
def estimatesDF(symbol, token='', version=''): '''Provides the latest consensus estimate for the next fiscal period https://iexcloud.io/docs/api/#estimates Updates at 9am, 11am, 12pm UTC every day Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' f = estimates(symbol, token, version) df = _estimatesToDF(f) return df
def financials(symbol, token='', version=''): '''Pulls income statement, balance sheet, and cash flow data from the four most recent reported quarters. https://iexcloud.io/docs/api/#financials Updates at 8am, 9am UTC daily Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/financials', token, version)
def _financialsToDF(f): '''internal''' if f: df = pd.io.json.json_normalize(f, 'financials', 'symbol') _toDatetime(df) _reindex(df, 'reportDate') else: df = pd.DataFrame() return df
def financialsDF(symbol, token='', version=''): '''Pulls income statement, balance sheet, and cash flow data from the four most recent reported quarters. https://iexcloud.io/docs/api/#financials Updates at 8am, 9am UTC daily Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' f = financials(symbol, token, version) df = _financialsToDF(f) return df
def incomeStatement(symbol, token='', version=''): '''Pulls income statement data. Available quarterly (4 quarters) or annually (4 years). https://iexcloud.io/docs/api/#income-statement Updates at 8am, 9am UTC daily Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/income', token, version)
def incomeStatementDF(symbol, token='', version=''): '''Pulls income statement data. Available quarterly (4 quarters) or annually (4 years). https://iexcloud.io/docs/api/#income-statement Updates at 8am, 9am UTC daily Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' val = incomeStatement(symbol, token, version) df = pd.io.json.json_normalize(val, 'income', 'symbol') _toDatetime(df) _reindex(df, 'reportDate') return df
def ipoTodayDF(token='', version=''): '''This returns a list of upcoming or today IPOs scheduled for the current and next month. The response is split into two structures: rawData and viewData. rawData represents all available data for an IPO. viewData represents data structured for display to a user. https://iexcloud.io/docs/api/#ipo-calendar 10am, 10:30am UTC daily Args: token (string); Access token version (string); API version Returns: DataFrame: result ''' val = ipoToday(token, version) if val: df = pd.io.json.json_normalize(val, 'rawData') _toDatetime(df) _reindex(df, 'symbol') else: df = pd.DataFrame() return df
def ipoUpcomingDF(token='', version=''): '''This returns a list of upcoming or today IPOs scheduled for the current and next month. The response is split into two structures: rawData and viewData. rawData represents all available data for an IPO. viewData represents data structured for display to a user. https://iexcloud.io/docs/api/#ipo-calendar 10am, 10:30am UTC daily Args: token (string); Access token version (string); API version Returns: DataFrame: result ''' val = ipoUpcoming(token, version) if val: df = pd.io.json.json_normalize(val, 'rawData') _toDatetime(df) _reindex(df, 'symbol') else: df = pd.DataFrame() return df
def keyStats(symbol, token='', version=''): '''Key Stats about company https://iexcloud.io/docs/api/#key-stats 8am, 9am ET Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/stats', token, version)
def _statsToDF(s): '''internal''' if s: df = pd.io.json.json_normalize(s) _toDatetime(df) _reindex(df, 'symbol') else: df = pd.DataFrame() return df
def keyStatsDF(symbol, token='', version=''): '''Key Stats about company https://iexcloud.io/docs/api/#key-stats 8am, 9am ET Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' s = keyStats(symbol, token, version) df = _statsToDF(s) return df
def largestTrades(symbol, token='', version=''): '''This returns 15 minute delayed, last sale eligible trades. https://iexcloud.io/docs/api/#largest-trades 9:30-4pm ET M-F during regular market hours Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/largest-trades', token, version)
def largestTradesDF(symbol, token='', version=''): '''This returns 15 minute delayed, last sale eligible trades. https://iexcloud.io/docs/api/#largest-trades 9:30-4pm ET M-F during regular market hours Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(largestTrades(symbol, token, version)) _toDatetime(df) _reindex(df, 'time') return df
def list(option='mostactive', token='', version=''): '''Returns an array of quotes for the top 10 symbols in a specified list. https://iexcloud.io/docs/api/#list Updated intraday Args: option (string); Option to query token (string); Access token version (string); API version Returns: dict: result ''' if option not in _LIST_OPTIONS: raise PyEXception('Option must be in %s' % str(_LIST_OPTIONS)) return _getJson('stock/market/list/' + option, token, version)
def listDF(option='mostactive', token='', version=''): '''Returns an array of quotes for the top 10 symbols in a specified list. https://iexcloud.io/docs/api/#list Updated intraday Args: option (string); Option to query token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(list(option, token, version)) _toDatetime(df) _reindex(df, 'symbol') return df
def logo(symbol, token='', version=''): '''This is a helper function, but the google APIs url is standardized. https://iexcloud.io/docs/api/#logo 8am UTC daily Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/logo', token, version)
def logoPNG(symbol, token='', version=''): '''This is a helper function, but the google APIs url is standardized. https://iexcloud.io/docs/api/#logo 8am UTC daily Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: image: result as png ''' _raiseIfNotStr(symbol) response = requests.get(logo(symbol, token, version)['url']) return ImageP.open(BytesIO(response.content))
def logoNotebook(symbol, token='', version=''): '''This is a helper function, but the google APIs url is standardized. https://iexcloud.io/docs/api/#logo 8am UTC daily Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: image: result ''' _raiseIfNotStr(symbol) url = logo(symbol, token, version)['url'] return ImageI(url=url)
def news(symbol, count=10, token='', version=''): '''News about company https://iexcloud.io/docs/api/#news Continuous Args: symbol (string); Ticker to request count (int): limit number of results token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/news/last/' + str(count), token, version)
def _newsToDF(n): '''internal''' df = pd.DataFrame(n) _toDatetime(df) _reindex(df, 'datetime') return df
def newsDF(symbol, count=10, token='', version=''): '''News about company https://iexcloud.io/docs/api/#news Continuous Args: symbol (string); Ticker to request count (int): limit number of results token (string); Access token version (string); API version Returns: DataFrame: result ''' n = news(symbol, count, token, version) df = _newsToDF(n) return df
def marketNewsDF(count=10, token='', version=''): '''News about market https://iexcloud.io/docs/api/#news Continuous Args: count (int): limit number of results token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(marketNews(count, token, version)) _toDatetime(df) _reindex(df, 'datetime') return df
def ohlc(symbol, token='', version=''): '''Returns the official open and close for a give symbol. https://iexcloud.io/docs/api/#news 9:30am-5pm ET Mon-Fri Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/ohlc', token, version)
def ohlcDF(symbol, token='', version=''): '''Returns the official open and close for a give symbol. https://iexcloud.io/docs/api/#news 9:30am-5pm ET Mon-Fri Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' o = ohlc(symbol, token, version) if o: df = pd.io.json.json_normalize(o) _toDatetime(df) else: df = pd.DataFrame() return df
def marketOhlcDF(token='', version=''): '''Returns the official open and close for whole market. https://iexcloud.io/docs/api/#news 9:30am-5pm ET Mon-Fri Args: token (string); Access token version (string); API version Returns: DataFrame: result ''' x = marketOhlc(token, version) data = [] for key in x: data.append(x[key]) data[-1]['symbol'] = key df = pd.io.json.json_normalize(data) _toDatetime(df) _reindex(df, 'symbol') return df
def peers(symbol, token='', version=''): '''Peers of ticker https://iexcloud.io/docs/api/#peers 8am UTC daily Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/peers', token, version)
def _peersToDF(p): '''internal''' df = pd.DataFrame(p, columns=['symbol']) _toDatetime(df) _reindex(df, 'symbol') df['peer'] = df.index return df
def peersDF(symbol, token='', version=''): '''Peers of ticker https://iexcloud.io/docs/api/#peers 8am UTC daily Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' p = peers(symbol, token, version) df = _peersToDF(p) return df
def yesterday(symbol, token='', version=''): '''This returns previous day adjusted price data for one or more stocks https://iexcloud.io/docs/api/#previous-day-prices Available after 4am ET Tue-Sat Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/previous', token, version)
def yesterdayDF(symbol, token='', version=''): '''This returns previous day adjusted price data for one or more stocks https://iexcloud.io/docs/api/#previous-day-prices Available after 4am ET Tue-Sat Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' y = yesterday(symbol, token, version) if y: df = pd.io.json.json_normalize(y) _toDatetime(df) _reindex(df, 'symbol') else: df = pd.DataFrame() return df
def marketYesterdayDF(token='', version=''): '''This returns previous day adjusted price data for whole market https://iexcloud.io/docs/api/#previous-day-prices Available after 4am ET Tue-Sat Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' x = marketYesterday(token, version) data = [] for key in x: data.append(x[key]) data[-1]['symbol'] = key df = pd.DataFrame(data) _toDatetime(df) _reindex(df, 'symbol') return df
def price(symbol, token='', version=''): '''Price of ticker https://iexcloud.io/docs/api/#price 4:30am-8pm ET Mon-Fri Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/price', token, version)
def priceDF(symbol, token='', version=''): '''Price of ticker https://iexcloud.io/docs/api/#price 4:30am-8pm ET Mon-Fri Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.io.json.json_normalize({'price': price(symbol, token, version)}) _toDatetime(df) return df
def priceTarget(symbol, token='', version=''): '''Provides the latest avg, high, and low analyst price target for a symbol. https://iexcloud.io/docs/api/#price-target Updates at 10am, 11am, 12pm UTC every day Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/price-target', token, version)
def priceTargetDF(symbol, token='', version=''): '''Provides the latest avg, high, and low analyst price target for a symbol. https://iexcloud.io/docs/api/#price-target Updates at 10am, 11am, 12pm UTC every day Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.io.json.json_normalize(priceTarget(symbol, token, version)) _toDatetime(df) return df
def quote(symbol, token='', version=''): '''Get quote for ticker https://iexcloud.io/docs/api/#quote 4:30am-8pm ET Mon-Fri Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/quote', token, version)
def quoteDF(symbol, token='', version=''): '''Get quote for ticker https://iexcloud.io/docs/api/#quote 4:30am-8pm ET Mon-Fri Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' q = quote(symbol, token, version) if q: df = pd.io.json.json_normalize(q) _toDatetime(df) _reindex(df, 'symbol') else: df = pd.DataFrame() return df
def relevant(symbol, token='', version=''): '''Same as peers https://iexcloud.io/docs/api/#relevant Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/relevant', token, version)
def relevantDF(symbol, token='', version=''): '''Same as peers https://iexcloud.io/docs/api/#relevant Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(relevant(symbol, token, version)) _toDatetime(df) return df
def sectorPerformanceDF(token='', version=''): '''This returns an array of each sector and performance for the current trading day. Performance is based on each sector ETF. https://iexcloud.io/docs/api/#sector-performance 8am-5pm ET Mon-Fri Args: token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(sectorPerformance(token, version)) _toDatetime(df) _reindex(df, 'name') return df
def _splitsToDF(s): '''internal''' df = pd.DataFrame(s) _toDatetime(df) _reindex(df, 'exDate') return df
def splitsDF(symbol, timeframe='ytd', token='', version=''): '''Stock split history https://iexcloud.io/docs/api/#splits Updated at 9am UTC every day Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' s = splits(symbol, timeframe, token, version) df = _splitsToDF(s) return df
def volumeByVenue(symbol, token='', version=''): '''This returns 15 minute delayed and 30 day average consolidated volume percentage of a stock, by market. This call will always return 13 values, and will be sorted in ascending order by current day trading volume percentage. https://iexcloud.io/docs/api/#volume-by-venue Updated during regular market hours 9:30am-4pm ET Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) return _getJson('stock/' + symbol + '/volume-by-venue', token, version)
def volumeByVenueDF(symbol, token='', version=''): '''This returns 15 minute delayed and 30 day average consolidated volume percentage of a stock, by market. This call will always return 13 values, and will be sorted in ascending order by current day trading volume percentage. https://iexcloud.io/docs/api/#volume-by-venue Updated during regular market hours 9:30am-4pm ET Args: symbol (string); Ticker to request token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(volumeByVenue(symbol, token, version)) _toDatetime(df) _reindex(df, 'venue') return df
def threshold(date=None, token='', version=''): '''The following are IEX-listed securities that have an aggregate fail to deliver position for five consecutive settlement days at a registered clearing agency, totaling 10,000 shares or more and equal to at least 0.5% of the issuer’s total shares outstanding (i.e., “threshold securities”). The report data will be published to the IEX website daily at 8:30 p.m. ET with data for that trading day. https://iexcloud.io/docs/api/#listed-regulation-sho-threshold-securities-list-in-dev Args: date (datetime); Effective Datetime token (string); Access token version (string); API version Returns: dict: result ''' if date: date = _strOrDate(date) return _getJson('stock/market/threshold-securities/' + date, token, version) return _getJson('stock/market/threshold-securities', token, version)
def thresholdDF(date=None, token='', version=''): '''The following are IEX-listed securities that have an aggregate fail to deliver position for five consecutive settlement days at a registered clearing agency, totaling 10,000 shares or more and equal to at least 0.5% of the issuer’s total shares outstanding (i.e., “threshold securities”). The report data will be published to the IEX website daily at 8:30 p.m. ET with data for that trading day. https://iexcloud.io/docs/api/#listed-regulation-sho-threshold-securities-list-in-dev Args: date (datetime); Effective Datetime token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(threshold(date, token, version)) _toDatetime(df) return df
def shortInterest(symbol, date=None, token='', version=''): '''The consolidated market short interest positions in all IEX-listed securities are included in the IEX Short Interest Report. The report data will be published daily at 4:00pm ET. https://iexcloud.io/docs/api/#listed-short-interest-list-in-dev Args: symbol (string); Ticker to request date (datetime); Effective Datetime token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) if date: date = _strOrDate(date) return _getJson('stock/' + symbol + '/short-interest/' + date, token, version) return _getJson('stock/' + symbol + '/short-interest', token, version)
def shortInterestDF(symbol, date=None, token='', version=''): '''The consolidated market short interest positions in all IEX-listed securities are included in the IEX Short Interest Report. The report data will be published daily at 4:00pm ET. https://iexcloud.io/docs/api/#listed-short-interest-list-in-dev Args: symbol (string); Ticker to request date (datetime); Effective Datetime token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(shortInterest(symbol, date, token, version)) _toDatetime(df) return df
def marketShortInterest(date=None, token='', version=''): '''The consolidated market short interest positions in all IEX-listed securities are included in the IEX Short Interest Report. The report data will be published daily at 4:00pm ET. https://iexcloud.io/docs/api/#listed-short-interest-list-in-dev Args: date (datetime); Effective Datetime token (string); Access token version (string); API version Returns: dict: result ''' if date: date = _strOrDate(date) return _getJson('stock/market/short-interest/' + date, token, version) return _getJson('stock/market/short-interest', token, version)
def marketShortInterestDF(date=None, token='', version=''): '''The consolidated market short interest positions in all IEX-listed securities are included in the IEX Short Interest Report. The report data will be published daily at 4:00pm ET. https://iexcloud.io/docs/api/#listed-short-interest-list-in-dev Args: date (datetime); Effective Datetime token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(marketShortInterest(date, token, version)) _toDatetime(df) return df
def topsSSE(symbols=None, on_data=None, token='', version=''): '''TOPS provides IEX’s aggregated best quoted bid and offer position in near real time for all securities on IEX’s displayed limit order book. TOPS is ideal for developers needing both quote and trade data. https://iexcloud.io/docs/api/#tops Args: symbols (string); Tickers to request on_data (function): Callback on data token (string); Access token version (string); API version ''' return _runSSE('tops', symbols, on_data, token, version)
def lastSSE(symbols=None, on_data=None, token='', version=''): '''Last provides trade data for executions on IEX. It is a near real time, intraday API that provides IEX last sale price, size and time. Last is ideal for developers that need a lightweight stock quote. https://iexcloud.io/docs/api/#last Args: symbols (string); Tickers to request on_data (function): Callback on data token (string); Access token version (string); API version ''' return _runSSE('last', symbols, on_data, token, version)
def deepSSE(symbols=None, channels=None, on_data=None, token='', version=''): '''DEEP is used to receive real-time depth of book quotations direct from IEX. The depth of book quotations received via DEEP provide an aggregated size of resting displayed orders at a price and side, and do not indicate the size or number of individual orders at any price level. Non-displayed orders and non-displayed portions of reserve orders are not represented in DEEP. DEEP also provides last trade price and size information. Trades resulting from either displayed or non-displayed orders matching on IEX will be reported. Routed executions will not be reported. https://iexcloud.io/docs/api/#deep Args: symbols (string); Tickers to request on_data (function): Callback on data token (string); Access token version (string); API version ''' symbols = _strCommaSeparatedString(symbols) channels = channels or [] if isinstance(channels, str): if channels not in DeepChannelsSSE.options(): raise PyEXception('Channel not recognized: %s', type(channels)) channels = [channels] elif isinstance(channels, DeepChannelsSSE): channels = [channels.value] elif isinstance(channels, list): for i, c in enumerate(channels): if isinstance(c, DeepChannelsSSE): channels[i] = c.value elif not isinstance(c, str) or isinstance(c, str) and c not in DeepChannelsSSE.options(): raise PyEXception('Channel not recognized: %s', c) channels = _strCommaSeparatedString(channels) return _streamSSE(_SSE_DEEP_URL_PREFIX.format(symbols=symbols, channels=channels, token=token, version=version), on_data)
def tradesSSE(symbols=None, on_data=None, token='', version=''): '''Trade report messages are sent when an order on the IEX Order Book is executed in whole or in part. DEEP sends a Trade report message for every individual fill. https://iexcloud.io/docs/api/#deep-trades Args: symbols (string); Tickers to request on_data (function): Callback on data token (string); Access token version (string); API version ''' symbols = _strCommaSeparatedString(symbols) return _streamSSE(_SSE_DEEP_URL_PREFIX.format(symbols=symbols, channels='trades', token=token, version=version), on_data)
def auctionSSE(symbols=None, on_data=None, token='', version=''): '''DEEP broadcasts an Auction Information Message every one second between the Lock-in Time and the auction match for Opening and Closing Auctions, and during the Display Only Period for IPO, Halt, and Volatility Auctions. Only IEX listed securities are eligible for IEX Auctions. https://iexcloud.io/docs/api/#deep-auction Args: symbols (string); Tickers to request on_data (function): Callback on data token (string); Access token version (string); API version ''' return _runSSE('auction', symbols, on_data, token, version)
def bookSSE(symbols=None, on_data=None, token='', version=''): '''Book shows IEX’s bids and asks for given symbols. https://iexcloud.io/docs/api/#deep-book Args: symbols (string); Tickers to request on_data (function): Callback on data token (string); Access token version (string); API version ''' return _runSSE('book', symbols, on_data, token, version)
def opHaltStatusSSE(symbols=None, on_data=None, token='', version=''): '''The Exchange may suspend trading of one or more securities on IEX for operational reasons and indicates such operational halt using the Operational halt status message. IEX disseminates a full pre-market spin of Operational halt status messages indicating the operational halt status of all securities. In the spin, IEX will send out an Operational Halt Message with “N” (Not operationally halted on IEX) for all securities that are eligible for trading at the start of the Pre-Market Session. If a security is absent from the dissemination, firms should assume that the security is being treated as operationally halted in the IEX Trading System at the start of the Pre-Market Session. After the pre-market spin, IEX will use the Operational halt status message to relay changes in operational halt status for an individual security. https://iexcloud.io/docs/api/#deep-operational-halt-status Args: symbols (string); Tickers to request on_data (function): Callback on data token (string); Access token version (string); API version ''' return _runSSE('op-halt-status', symbols, on_data, token, version)
def officialPriceSSE(symbols=None, on_data=None, token='', version=''): '''The Official Price message is used to disseminate the IEX Official Opening and Closing Prices. These messages will be provided only for IEX Listed Securities. https://iexcloud.io/docs/api/#deep-official-price Args: symbols (string); Tickers to request on_data (function): Callback on data token (string); Access token version (string); API version ''' return _runSSE('official-price', symbols, on_data, token, version)
def securityEventSSE(symbols=None, on_data=None, token='', version=''): '''The Security event message is used to indicate events that apply to a security. A Security event message will be sent whenever such event occurs https://iexcloud.io/docs/api/#deep-security-event Args: symbols (string); Tickers to request on_data (function): Callback on data token (string); Access token version (string); API version ''' return _runSSE('security-event', symbols, on_data, token, version)
def ssrStatusSSE(symbols=None, on_data=None, token='', version=''): '''In association with Rule 201 of Regulation SHO, the Short Sale Price Test Message is used to indicate when a short sale price test restriction is in effect for a security. IEX disseminates a full pre-market spin of Short sale price test status messages indicating the Rule 201 status of all securities. After the pre-market spin, IEX will use the Short sale price test status message in the event of an intraday status change. The IEX Trading System will process orders based on the latest short sale price test restriction status. https://iexcloud.io/docs/api/#deep-short-sale-price-test-status Args: symbols (string); Tickers to request on_data (function): Callback on data token (string); Access token version (string); API version ''' return _runSSE('ssr-status', symbols, on_data, token, version)
def systemEventSSE(symbols=None, on_data=None, token='', version=''): '''The System event message is used to indicate events that apply to the market or the data feed. There will be a single message disseminated per channel for each System Event type within a given trading session. https://iexcloud.io/docs/api/#deep-system-event Args: symbols (string); Tickers to request on_data (function): Callback on data token (string); Access token version (string); API version ''' return _runSSE('system-event', symbols, on_data, token, version)
def tradeBreaksSSE(symbols=None, on_data=None, token='', version=''): '''Trade report messages are sent when an order on the IEX Order Book is executed in whole or in part. DEEP sends a Trade report message for every individual fill. https://iexcloud.io/docs/api/#deep-trades Args: symbols (string); Tickers to request on_data (function): Callback on data token (string); Access token version (string); API version ''' return _runSSE('trade-breaks', symbols, on_data, token, version)
def tradingStatusSSE(symbols=None, on_data=None, token='', version=''): '''The Trading status message is used to indicate the current trading status of a security. For IEX-listed securities, IEX acts as the primary market and has the authority to institute a trading halt or trading pause in a security due to news dissemination or regulatory reasons. For non-IEX-listed securities, IEX abides by any regulatory trading halts and trading pauses instituted by the primary or listing market, as applicable. IEX disseminates a full pre-market spin of Trading status messages indicating the trading status of all securities. In the spin, IEX will send out a Trading status message with “T” (Trading) for all securities that are eligible for trading at the start of the Pre-Market Session. If a security is absent from the dissemination, firms should assume that the security is being treated as operationally halted in the IEX Trading System. After the pre-market spin, IEX will use the Trading status message to relay changes in trading status for an individual security. Messages will be sent when a security is: Halted Paused* Released into an Order Acceptance Period* Released for trading *The paused and released into an Order Acceptance Period status will be disseminated for IEX-listed securities only. Trading pauses on non-IEX-listed securities will be treated simply as a halt. https://iexcloud.io/docs/api/#deep-trading-status Args: symbols (string); Tickers to request on_data (function): Callback on data token (string); Access token version (string); API version ''' return _runSSE('trading-status', symbols, on_data, token, version)
def cryptoDF(token='', version=''): '''This will return an array of quotes for all Cryptocurrencies supported by the IEX API. Each element is a standard quote object with four additional keys. https://iexcloud.io/docs/api/#crypto Args: token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(crypto(token, version)) _toDatetime(df) _reindex(df, 'symbol') return df
def sentiment(symbol, type='daily', date=None, token='', version=''): '''This endpoint provides social sentiment data from StockTwits. Data can be viewed as a daily value, or by minute for a given date. https://iexcloud.io/docs/api/#social-sentiment Continuous Args: symbol (string); Ticker to request type (string); 'daily' or 'minute' date (string); date in YYYYMMDD or datetime token (string); Access token version (string); API version Returns: dict: result ''' _raiseIfNotStr(symbol) if date: date = _strOrDate(date) return _getJson('stock/{symbol}/sentiment/{type}/{date}'.format(symbol=symbol, type=type, date=date), token, version) return _getJson('stock/{symbol}/sentiment/{type}/'.format(symbol=symbol, type=type), token, version)
def sentimentDF(symbol, type='daily', date=None, token='', version=''): '''This endpoint provides social sentiment data from StockTwits. Data can be viewed as a daily value, or by minute for a given date. https://iexcloud.io/docs/api/#social-sentiment Continuous Args: symbol (string); Ticker to request type (string); 'daily' or 'minute' date (string); date in YYYYMMDD or datetime token (string); Access token version (string); API version Returns: DataFrame: result ''' ret = sentiment(symbol, type, date, token, version) if type == 'daiy': ret = [ret] df = pd.DataFrame(ret) _toDatetime(df) return df
def statsDF(token='', version=''): '''https://iexcloud.io/docs/api/#stats-intraday Args: token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(stats(token, version)) _toDatetime(df) return df
def recentDF(token='', version=''): '''https://iexcloud.io/docs/api/#stats-recent Args: token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(recent(token, version)) _toDatetime(df) _reindex(df, 'date') return df
def recordsDF(token='', version=''): '''https://iexcloud.io/docs/api/#stats-records Args: token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(records(token, version)) _toDatetime(df) return df
def summary(date=None, token='', version=''): '''https://iexcloud.io/docs/api/#stats-historical-summary Args: token (string); Access token version (string); API version Returns: dict: result ''' if date: if isinstance(date, str): return _getJson('stats/historical?date=' + date, token, version) elif isinstance(date, datetime): return _getJson('stats/historical?date=' + date.strftime('%Y%m'), token, version) else: raise PyEXception("Can't handle type : %s" % str(type(date)), token, version) return _getJson('stats/historical', token, version)
def summaryDF(date=None, token='', version=''): '''https://iexcloud.io/docs/api/#stats-historical-summary Args: token (string); Access token version (string); API version Returns: DataFrame: result ''' df = pd.DataFrame(summary(date, token, version)) _toDatetime(df) return df