def get_symbols(): company_list = iex.get_available_symbols(session = cache_session) company_info = {} for company in company_list: company_info[company['symbol']] = company['name'] return company_info
def run(self, dispatcher, tracker, domain): company_x = tracker.get_slot('company') start_time = tracker.get_slot('start_time') end_time = tracker.get_slot('end_time') pattern = re.compile(r'\.|-|/') start_x = re.split(pattern, start_time) end_x = re.split(pattern, end_time) start = datetime(int(start_x[0]), int(start_x[1]), int(start_x[2])) end = datetime(int(end_x[0]), int(end_x[1]), int(end_x[2])) symbols = get_available_symbols() for i in range(len(symbols)): if company_x.lower() in symbols[i]["name"].lower(): company = symbols[i]["symbol"] f = get_historical_data(company, start, end, output_format='pandas') plt.plot(f["close"]) plt.title('Time series chart for {}'.format(company)) fig1 = plt.gcf() plt.draw() fig1.savefig("1.jpg", dpi=100) dispatcher.utter_template("utter_plot", tracker) plt.show() return [ SlotSet('company', company), SlotSet('start_time', start), SlotSet('end_time', end) ]
def get_stock_names(): l = get_available_symbols() names = set() for d in l: names.add(d['symbol'].lower()) return names
def _fetch_all_iex_tickers(self): columns = ['symbol', 'name'] df = pd.DataFrame(get_available_symbols()) df = df[df.isEnabled == True] df = df[df.type != 'crypto'] df = df[df.name != 'NASDAQ TEST STOCK'] df = df.set_index('iexId') return df[columns]
def getNewestTickers(): ''' Will retrieve all tickers available through current API. Returns tickers as a list. This function is innefficient, so only call it when you need to update your ticker list. ''' symbolJsonList = iex.get_available_symbols(output_format='pandas') listOfTickers = list(map(utils.extractTicker, symbolJsonList)) return listOfTickers
def iex_symbols(): markets = get_available_symbols(output_format='pandas') e = get_exchange('IEX') for m in markets: try: Market.create(symbol=m['symbol'], name=m['name'], market_type=m['type'], exchange=e, enabled=m['isEnabled']) print(colored.green(m)) except IntegrityError: DB.rollback() except Exception as err: print(colored.red(err)) DB.rollback()
def run(self, dispatcher, tracker, domain): company_x = tracker.get_slot('company') symbols = get_available_symbols() for i in range(len(symbols)): if company_x.lower() in symbols[i]["name"].lower(): company = symbols[i]["symbol"] companyobj = Stock(company) price = companyobj.get_price() response = """{} shares is {} currently.""".format(company, price) dispatcher.utter_message(response) return [SlotSet('company', company)]
def exec_database_actions(args): if args.rebuild_database and args.database_uri.startswith('sqlite://'): file = args.database_uri[len('sqlite://'):] file = file[1:] if file[:2] == '//' else file if os.path.isfile(file): if not DatabaseClient.is_sqlite_db(file): raise RuntimeError( 'Unable to continue with rebuilding database. ' 'The {} file seems to be invalid sqlite db'.format(file)) os.remove(file) manager = Manager(db_uri=args.database_uri) # Populate initial sectors sectors = { sector['name']: [] for sector in MarketSectorPerformanceReader().fetch() } processed = total = 0 sys.stdout.write('Loading data into {} database\n'.format( args.database_uri)) for symbol in get_available_symbols(): # Only parse cs and et types (common stock and ETFs) if symbol['type'] == 'cs' or symbol['type'] == 'et': company = Stock(symbol['symbol'], output_format='json').get_company() manager.create_iex_company(company) processed += 1 if processed % 25 == 0: sys.stdout.write('.') sys.stdout.flush() total += 1 if total % 1000 == 0: sys.stdout.write('[{} of {}]\n'.format(processed, total)) if total == 2500: break if total % 1000 != 0: sys.stdout.write('[{} of {}]\n'.format(processed, total)) sys.stdout.write('{} of {} records loaded to {} database\n'.format( processed, total, args.database_uri)) sys.stdout.flush()
def run(self, dispatcher, tracker, domain): company_x = tracker.get_slot('company') time = tracker.get_slot('time') symbols = get_available_symbols() for i in range(len(symbols)): if company_x.lower() in symbols[i]["name"].lower(): company = symbols[i]["symbol"] pattern = re.compile(r'\.|-|/') end_x = re.split(pattern, time) end = datetime(int(end_x[0]), int(end_x[1]), int(end_x[2])) #start = end - timedelta(1) end_date = end.strftime('%Y-%m-%d') f = get_historical_data(company, end, end, output_format="pandas") volume = f.loc[end_date]["volume"] response = """{}'s volume is {} on {}""".format(company, volume, time) dispatcher.utter_message(response) return [SlotSet('company', company), SlotSet('time', time)]
def getAllCompanyInfo(self, fromDB=False, dynamo=None): # Get the company information either from the DB or from IEX -- Should only need to IEX once companyInformation = {} if fromDB: # Retrieve from dynamo -- scan should work table = dynamo.Table('StockHeadlines') companyInformation = table.scan()['Items'] else: # Get all the indices that the IEX finance API can server companyData = get_available_symbols() # Set up the company's information object for company in companyData: # Only include company values -- not dividends, crypto, ect if company['type'] == 'cs': companyInformation[company['symbol']] = company['name'] return companyInformation
def getDividendYields(self): symbols = [s['symbol'] for s in get_available_symbols()] dividendStocks = {} batchIndex = 0 maxBatch = 99 while (batchIndex < len(symbols)): slicedSymbols = symbols[batchIndex:batchIndex + maxBatch] stocks = Stock(slicedSymbols) stats = stocks.get_key_stats() quote = stocks.get_quote() companiesInfo = stocks.get_company() for symbol in slicedSymbols: dividendStats = {} try: if (stats[symbol]['dividendYield'] and stats[symbol]['dividendRate'] and companiesInfo[symbol]['issueType'] and companiesInfo[symbol]['issueType'] == "cs" and companiesInfo[symbol]['sector'] != 'Financial Services' and quote[symbol]['sector'] == 'Industrials'): dividendStats['Dividend Yield'] = stats[symbol][ 'dividendYield'] dividendStats['Dividend Rate'] = stats[symbol][ 'dividendRate'] dividendStocks[symbol] = dividendStats except: continue batchIndex += maxBatch print(len(dividendStocks)) df = pd.DataFrame.from_dict(dividendStocks).T df = df.sort_values('Dividend Yield') print(df)
def parse_args(): # # get symbol metadata # available_symbols = [ s['symbol'] for s in iex.get_available_symbols() if s['type'] in ['cs', 'etf'] ] # these symbols cause an exception in the API request and I don't # care enough to figure out if I should care about this exception # at the moment ... FIXME # available_symbols.remove('ALL-C*') # available_symbols.remove('ARNC-') # available_symbols.remove('BNGO') # available_symbols.remove('CMCTP') # available_symbols.remove('DTLA-') # available_symbols.remove('BNBUSDT') if len(sys.argv) == 2: requested_symbols = pd.read_csv(sys.argv[1]).Symbol.values elif len(sys.argv) == 1: requested_symbols = available_symbols else: # FIXME help raise ValueError() # # check availability # missing_symbols = set(requested_symbols) - set(available_symbols) if missing_symbols: print('Missing symbols {} from database. Skipping ...'.format( ','.join(missing_symbols))) requested_symbols = list(set(requested_symbols) - missing_symbols) return requested_symbols
def _load_stock_symbols(self): self.logger.info(f'Downloading stock symbols.') df = pd.DataFrame(iexfinance.get_available_symbols()) self.stocks = list(df[df.isEnabled == True]['symbol'])
try: keyStats = stock.get_key_stats() if (stock.get_price() < 5): return -1,-1,-1 df_hist = get_historical_data(ticker, start=start, end=now, output_format='pandas') dma50 = keyStats['day50MovingAvg'] dma10 = df_hist.tail(10)['close'].mean() dma20 = df_hist.tail(20)['close'].mean() except: return -1,-1,-1 return dma10, dma20, dma50 listOfTickers = get_available_symbols(output_format='pandas') df = pd.DataFrame(listOfTickers) df = df.loc[df['type'] == 'cs'] df = df.head(numberOfStocks) for i,r in df['symbol'].iteritems(): print("Getting Averages for "+r+"\n") dma10, dma20, dma50 = get_ma(r) if dma10 == -1 or dma20 == -1 or dma50 == -1: continue else: analyze(dma10, dma20, dma50, r) print("Major List:") print(masterlist)
def list_symbols(): return [symbol['symbol'] for symbol in iexfinance.get_available_symbols()]
def test_get_available_symbols(self): d = get_available_symbols() assert isinstance(d, list) assert isinstance(d[0], dict)
return -1, -1, -1 df_hist = get_historical_data(ticker, start=start, end=now, output_format='pandas') dma50 = keyStats['day50MovingAvg'] dma10 = df_hist.tail(10)['close'].mean() dma20 = df_hist.tail(20)['close'].mean() except: return -1, -1, -1 return dma10, dma20, dma50 listOfTickers = get_available_symbols(output_format='pandas') df = pd.DataFrame(listOfTickers) df = df.loc[df['type'] == 'cs'] df = df.head(numberOfStocks) for i, r in df['symbol'].iteritems(): print("Getting Averages for " + r + "\n") dma10, dma20, dma50 = get_ma(r) if dma10 == -1 or dma20 == -1 or dma50 == -1: continue else: analyze(dma10, dma20, dma50, r) print("Major List:") print(masterlist) print("Minor List")
import iexfinance import pandas as pd import datetime all_symbols = [stock['symbol'] for stock in iexfinance.get_available_symbols()] volumes = {} data = iexfinance.get_historical_data('FB', datetime.datetime(2018, 4, 29), datetime.datetime(2018, 4, 30)) volume = list(list(data.values())[0].values())[0]['volume'] iexfinance.Stock('FB') for i in range(0, len(all_symbols), 99): print('{}/{}'.format(i, len(all_symbols))) stock = iexfinance.Stock(all_symbols[i:i + 99]) volumes.update(stock.get_volume()) volumes.update( iexfinance.Stock(all_symbols[-(len(all_symbols) % 99):]).get_volume()) volumes = pd.Series(volumes) volumes.sort_values(inplace=True, ascending=False) volumes = volumes.iloc[:1000] volumes.to_csv('out.csv')
from datetime import date from iexfinance import get_stats_intraday from iexfinance import get_available_symbols import pandas as pd #import datetime # Set Date Variables todays_date = str(date.today()) todays_timestamp = str(datetime.today()) yesterdays_date = str(date.today() - timedelta(days=1)) start = datetime(2018,8,1) end = todays_date # Get List of ticker symbols - creates a dictionary full_ticker_info_dict = get_available_symbols(output_format='pandas')[450:500] # Creates a list from the items in the dictionary ticker_symbol_list = [d['symbol'] for d in full_ticker_info_dict] ticker_name_list = [d['name'] for d in full_ticker_info_dict] ticker_date_list = [d['date'] for d in full_ticker_info_dict] ticker_isEnabled_list = [d['isEnabled'] for d in full_ticker_info_dict] ticker_type_list = [d['type'] for d in full_ticker_info_dict] ticker_id_list = [d['iexId'] for d in full_ticker_info_dict] # Gets number of stocks number_of_stocks = len(ticker_symbol_list) print("There are a total of {} stocks".format(number_of_stocks)) # Creates a list of indicies for blank or otherwise specified values in each respective list
def symbol_load(): global avai_symbol stocks = get_available_symbols() for stock in stocks: avai_symbol.append(stock['symbol']) print('Symbols successfully loaded.')
def import_data(self): self.download() stock_list = pd.read_csv("stock_list.csv") os.remove("stock_list.csv") stocks = pd.DataFrame(get_available_symbols(output_format='pandas')) stocks = stocks.loc[stocks['type'] == 'cs'] stocks = stocks.merge(stock_list, how='inner', left_on='symbol', right_on='Symbol') #Plainly filter list to reduce further analysis load stocks = stocks.loc[(stocks['MarketCap'] > 0) & stocks['MarketCap'].notnull()] stocks = stocks.loc[stocks['Industry'].notnull()] stocks = stocks.loc[(stocks['LastSale'] > .25) & (stocks['LastSale'] <= 5.0)] #add columns to df that we will go through and fill for analysis stocks['profitMargin'] = Series([]) stocks['day50MovingAvg'] = Series([]) stocks['beta'] = Series([]) stocks['avg_daily_change_30'] = Series([]) stocks['avg_change_over_time_30'] = Series([]) stocks['avg_daily_change_5'] = Series([]) stocks['avg_change_over_time_5'] = Series([]) stocks['last_change_percent'] = Series([]) stocks['avg_close_30'] = Series([]) stocks['std_close_30'] = Series([]) stocks['avg_close_5'] = Series([]) stocks['std_close_5'] = Series([]) stocks['avg_volume_30'] = Series([]) stocks['avg_volume_5'] = Series([]) stocks['last_volume'] = Series([]) stocks['shortRatio'] = Series([]) stocks.reset_index(inplace=True, drop=True) print(stocks.head(), stocks.info()) for index, row in stocks.iterrows(): #print (index, row) #Pause so api doesn't kick us out if index % 7 == 0 and index != 0: print("Waiting 3 seconds") time.sleep(3) stock = Stock(str(row['symbol'])) stock_stats = pd.DataFrame(stock.get_key_stats(), index=[0]) #Five day timeseries avg for values stock_book = pd.DataFrame( stock.get_time_series(output_format='pandas')) stock_book_3 = stock_book.tail(3) #Close to real time #stock_quote = pd.DataFrame(stock.get_quote(), index=[0]) #print (stock_move.head(), stock_move.info()) #print (stock_stats) print(index) #print (stock_stats) stock_stats = stock_stats[[ 'profitMargin', 'day50MovingAvg', 'beta', 'shortRatio' ]] stocks.loc[index, 'profitMargin'] = stock_stats.iloc[0]['profitMargin'] stocks.loc[ index, 'day50MovingAvg'] = stock_stats.iloc[0]['day50MovingAvg'] stocks.loc[index, 'beta'] = stock_stats.iloc[0]['beta'] stocks.loc[index, 'shortRatio'] = stock_stats.iloc[0]['shortRatio'] stocks.loc[ index, 'avg_daily_change_30'] = stock_book['changePercent'].mean() stocks.loc[index, 'avg_change_over_time_30'] = stock_book[ 'changeOverTime'].mean() stocks.loc[ index, 'avg_daily_change_5'] = stock_book_3['changePercent'].mean() stocks.loc[index, 'avg_change_over_time_5'] = stock_book_3[ 'changeOverTime'].mean() stocks.loc[index, 'last_change_percent'] = stock_book.loc[ len(stock_book) - 1, 'changePercent'] stocks.loc[index, 'avg_close_30'] = stock_book['close'].mean() stocks.loc[index, 'std_close_30'] = stock_book['close'].std() stocks.loc[index, 'avg_close_5'] = stock_book_3['close'].mean() stocks.loc[index, 'std_close_5'] = stock_book_3['close'].std() stocks.loc[index, 'avg_volume_30'] = stock_book['volume'].mean() stocks.loc[index, 'avg_volume_5'] = stock_book_3['volume'].mean() stocks.loc[index, 'last_volume'] = stock_book.loc[len(stock_book) - 1, 'volume'] #if index > 50: #break stocks.to_csv('stocks_before_filter.csv') stocks = stocks.loc[ (stocks['LastSale'] < (stocks['avg_close_30'] - (1.40 * stocks['std_close_30']))) & (stocks['LastSale'] >= (stocks['avg_close_30'] - (2.00 * stocks['std_close_30'])))] stocks = stocks.loc[((stocks['avg_volume_5'] / stocks['avg_volume_30']) > 1.02)] stocks.sort_values('shortRatio', inplace=True) stocks.reset_index(inplace=True, drop=True) #print (stocks.head(20),stocks.info()) stocks.to_csv('stocklist.csv') return (stocks)