def add_ticker(args=None): if args is None: args = [] do_verbose = is_verbose(args) do_forced = if_present_pop(args, FLAG_FORCE) if len(args) < 2: print("ERROR: Please provide a ticker and a ticker class to add") return 1 new_ticker = args[0] print('Received ticker: ' + new_ticker) ticker = Ticker.get_ticker(new_ticker) # check if the ticker exists at all, and if it does, if the name field has been set if not do_forced: if ticker is not None and ticker[1] is not None: print( 'The ticker "%s - %s" is already present in the database. No need to add again. Exiting.' % (ticker[0], ticker[1])) return 0 if do_forced: print('Doing forced update for this ticker\'s metadata...') is_fund = if_present_pop(args, FLAG_FUND) is_stock = if_present_pop(args, FLAG_STOCK) if not is_fund and not is_stock: print( 'ERROR: Could not determine if the ticker is an ETF or a stock. Please use the --fund or --stock flags to' ) print(' indicate which it is and retry.') return 1 # then nicely ask AlphaVantage about the ticker (don't do this too often) retrieved_json = retrieve_ticker_meta(new_ticker) if retrieved_json is None: # retrieve_ticker_meta does the common logging for us return 1 # insert the ticker and asset class into the database if it wasn't there already if ticker is None: Ticker.insert_new_ticker(new_ticker, Ticker.STOCK if is_stock else Ticker.FUND) do_ticker_update(new_ticker, retrieved_json) print('Successfully added %s to the database!' % (new_ticker, )) if do_verbose: TickerWrapper.get(new_ticker).pretty_print() return 0
def remove_ticker(args): """ Update the provided ticker if it already exists """ if args is None: args = [] if len(args) < 1: print("ERROR: Please provide a ticker to remove") return 1 test_ticker = args[0] print('Removing ticker: %s' % test_ticker) found_t = Ticker.get_ticker(test_ticker) if found_t is None: print("Ticker %s is not in the database. Nothing to do. Exiting." % test_ticker) return 0 Ticker.delete_ticker(test_ticker) print("Ticker %s successfully deleted!" % test_ticker) return 0
def get_likely_subject_stock(sorted_bow): for word in sorted_bow: primary_search = re.search('^\$[A-Z]{1,5}$', word) if primary_search is not None and not any( word in not_ticker for not_ticker in NOT_TICKER_LIST): match_result = primary_search.group(0).strip() t = Ticker() result = t.get_ticker(match_result.upper().replace('$', '')) if result is not None: return result secondary_search = re.search('^[A-Z]{2,4}$', word) if secondary_search is not None and not any( word in not_ticker for not_ticker in NOT_TICKER_LIST): match_result = secondary_search.group(0).strip() t = Ticker() result = t.get_ticker(match_result.upper()) if result is not None: return result
from api.local_stocks.Ticker import Ticker from client.util.html.ListBuilder import ListBuilder from client.Reporter import Reporter t = Ticker() stocks = t.get_n_stocks(n=10) values = [] for stock in stocks: values.append(stock[0] + ' - ' + stock[1]) r = Reporter() r.set_title('Sample Stock List Report') r.set_body(ListBuilder(values, list_header="Stock tickers").compile()) r.compile()
from api.local_stocks.Ticker import Ticker from client.util.html.TableBuilder import TableBuilder from client.Reporter import Reporter t = Ticker() acb = t.get_stock('ACB') hexo = t.get_stock('HEXO') tlry = t.get_stock('TLRY') values = [acb[:3], hexo[:3], tlry[:3]] r = Reporter() r.set_title('Sample Stock Report') r.set_body( TableBuilder(['Ticker', 'Company Name', 'Description'], values).compile()) r.compile()
submissions = reddit.get_hot('wallstreetbets', limit=1000) # loop through and try to pick out tickers tickers_found = {} for sub in range(0, len(submissions['title'])): title = submissions['title'][sub] self_text = submissions['body'][sub] url = submissions['url'][sub] score = submissions['score'][sub] match = re.search('[A-Z]{2,4}', title + self_text) if match is not None: ticker = match.group(0).strip() # if we get a match, verify that it's a real ticker t = Ticker() result = t.get_ticker(ticker) if result is None: continue # if it is, write down information about the ticker and how many times we've seen it if ticker in tickers_found: tickers_found[ticker]['count'] += 1 tickers_found[ticker]['links'].append(url) tickers_found[ticker]['titles'].append(title) tickers_found[ticker]['score'].append(score) else: tickers_found[ticker] = { 'count': 1, 'links': [submissions['url'][sub]], 'titles': [title],
def get(ticker): db_ticker = Ticker().get_ticker(ticker) if db_ticker is None: return None return TickerWrapper(db_ticker)
from api.local_stocks.Ticker import Ticker t = Ticker.get_ticker('VIX') print(t)