예제 #1
0
 def test_quotes(self):
     quote = r.get_quotes(self.single_stock, info=None)
     self.assertEqual(len(quote), 1)
     quote = quote[0]
     self.assertEqual(quote['symbol'], self.single_stock)
     self.assertIn('ask_price', quote)
     self.assertIn('ask_size', quote)
     self.assertIn('bid_price', quote)
     self.assertIn('bid_size', quote)
     self.assertIn('last_trade_price', quote)
     self.assertIn('last_extended_hours_trade_price', quote)
     self.assertIn('previous_close', quote)
     self.assertIn('adjusted_previous_close', quote)
     self.assertIn('previous_close_date', quote)
     self.assertIn('symbol', quote)
     self.assertIn('trading_halted', quote)
     self.assertIn('has_traded', quote)
     self.assertIn('last_trade_price_source', quote)
     self.assertIn('updated_at', quote)
     self.assertIn('instrument', quote)
     #
     more_quotes = r.get_quotes(self.list_stocks, info=None)
     self.assertEqual(len(more_quotes), len(self.list_stocks))
     #
     fake_quotes = r.get_quotes(self.fake_stocks, info=None)
     self.assertEqual(len(fake_quotes), 1)
     self.assertEqual(fake_quotes[0], None)
예제 #2
0
 def test_quotes(self):
     quote = r.get_quotes(self.single_stock, info=None)
     assert (len(quote) == 1)
     quote = quote[0]
     assert (quote['symbol'] == self.single_stock)
     assert ('ask_price' in quote)
     assert ('ask_size' in quote)
     assert ('bid_price' in quote)
     assert ('bid_size' in quote)
     assert ('last_trade_price' in quote)
     assert ('last_extended_hours_trade_price' in quote)
     assert ('previous_close' in quote)
     assert ('adjusted_previous_close' in quote)
     assert ('previous_close_date' in quote)
     assert ('symbol' in quote)
     assert ('trading_halted' in quote)
     assert ('has_traded' in quote)
     assert ('last_trade_price_source' in quote)
     assert ('updated_at' in quote)
     assert ('instrument' in quote)
     #
     more_quotes = r.get_quotes(self.list_stocks, info=None)
     assert (len(more_quotes) == len(self.list_stocks))
     #
     fake_quotes = r.get_quotes(self.fake_stocks, info=None)
     assert (len(fake_quotes) == 1)
     assert (fake_quotes[0] == None)
예제 #3
0
def watchlist():
    print("Getting quotes for watchlist")
    with open('watchlist')as f:
        symbols = f.read().splitlines()
    quotes = rh.get_quotes(symbols)
    for qte in quotes:
        ui.success("{}| {}".format(qte['symbol'], qte['ask_price']))
예제 #4
0
def pc(stock):
    """Generates and formats stock prices based on if market is open or in after-hours.

    :param stock: {1-5} character stock-ticker
    :return: [String] formatted output of price check.
    """
    quote = r.get_quotes(stock)[0]
    curr = '{:.2f}'.format(round(float(quote['last_trade_price']), 2))
    prev = '{:.2f}'.format(round(float(quote['adjusted_previous_close']), 2))
    perc1 = grabPercent(float(curr), float(prev))

    if cal.getDay() < 5 and 9 <= cal.getEstHour() < 16 and not (
            cal.getEstHour() == 9 and cal.getMinute() < 30):
        low, high = grabIntradayHL(stock)
        res = '{:<6}{:^8}{:>7}{:>2}{:>6}{:>11}'.format(
            stock.upper() + ':', '$' + str(curr), perc1, '|', 'L: ' + str(low),
            'H: ' + str(high)) + '\n'
        perc1 = evaluatePercent(float(curr), float(prev), perc1)
        return res, perc1
    elif quote['last_extended_hours_trade_price']:
        ah = '{:.2f}'.format(
            round(float(quote['last_extended_hours_trade_price']), 2))
        perc2 = grabPercent(float(ah), float(curr))
        res = '{:<6}{:^8}{:>7}{:>2}{:>6}{:>9}'.format(
            stock.upper() + ':', '$' + str(curr), perc1, '|',
            'AH: $' + str(ah), perc2) + '\n'
        perc2 = evaluatePercent(float(ah), float(prev), perc2)
        return res, perc2
    else:
        res = '{:<6}{:^8}{:>7}'.format(stock.upper() + ':', '$' + str(curr),
                                       perc1) + '\n'
        perc1 = evaluatePercent(float(curr), float(prev), perc1)
        return res, perc1
    def get_current_price(self):
        rh.login(self.user, self.password)
        quotes = rh.get_quotes(self.symbol)

        sym = self.symbol
        b = np.zeros(len(sym))

        quotes = rh.get_quotes(self.symbol)

        df1 = pd.DataFrame({'Quote': sym, 'Curr_price': b}, index=np.arange(len(sym)))

        for idx, quote in enumerate(quotes):
            curr_price = quote['ask_price']
            df1.loc[df1.Quote == sym[idx], 'Curr_price'] = curr_price
            print("{} | {}".format(quote['symbol'], quote['ask_price']))

        return df1
예제 #6
0
def watchlist():
    print('\nGetting quotes for watchlist....\n')
    
    with open('watchlist') as f:
        symbols = f.read().splitlines()

    quotes = rh.get_quotes(symbols)

    for quote in quotes:
        ui.success(quote)
        ui.bar()
예제 #7
0
def get_lines(symbol, interval, span):
    ui.success(f'\nGetting {interval} stock historicals for {symbol} for the past {span}....\n')
    result = rh.get_stock_historicals(symbol, interval, span)

    price = rh.get_quotes(symbol)[0]['last_extended_hours_trade_price']

    ui.bar()
    print(f"Value: {price}")
    ui.bar()
    df = funcs.make_df(result)
    funcs.get_s_r(df)
    ui.bar()
예제 #8
0
def validateTicker(stock):
    """Validates user input. If it is allowed, return True and add it to the stocks_mentioned dict.

    :param stock:
    :return:
    """
    if not re.match(r'\b[a-zA-Z]{1,5}\b', stock) or not r.get_quotes(stock)[0]:
        return False
    else:
        stocks_mentioned[stock.upper()] = stocks_mentioned.get(
            stock.upper(), 0) + 1
        return True
예제 #9
0
def grabSimplePrice(stock):
    """Grabs a simple float price. If AH, use the extended hours price instead.

    :param stock:
    :return:
    """
    quote = r.get_quotes(stock)[0]

    if quote['last_extended_hours_trade_price']:
        return '{:.2f}'.format(
            round(float(quote['last_extended_hours_trade_price']), 2))
    else:
        return '{:.2f}'.format(round(float(quote['last_trade_price']), 2))
def quote(symbols):
    quotes = rh.get_quotes(symbols)
    for quote in quotes:
        robinhood_ui.success("{} | {}".format(quote['symbol'], quote['ask_price']))
예제 #11
0
db = client['robinhood_options']

ticker = sys.argv[1]
if ticker is None:
    print('ticker not entered on commandline')
    exit(code=404)
today = datetime.now().strftime('%m/%d/%Y, %H:%M:%S')
print('{0}\t{1}'.format(ticker, today))
chains = r.get_chains(ticker)
expiration_dates = chains['expiration_dates']
for expiration_date in expiration_dates:
    try:
        stock_options = r.find_options_for_stock_by_expiration(
            ticker, expiration_date)
        df = pd.DataFrame(stock_options)
        quotes = r.get_quotes(ticker)
        df['ticker_last_trade_price'] = quotes[0]['last_trade_price']
        df['ticker_updated_at'] = quotes[0]['updated_at']
        df['_id'] = df['expiration_date'] + '_' + df[
            'strike_price'] + '_' + df['ticker_updated_at'] + '_' + df['type']

        data_dict = df.to_dict(orient='records')

        try:
            db[ticker].insert_many(data_dict)
        except pymongo.errors.DuplicateKeyError as e:
            print(e.error_document)
        except Exception as ee:
            print(ee)
    except Exceptions as ee:
        print(ee)
예제 #12
0
import os
import robin_stocks as r
import configparser
config = configparser.RawConfigParser()
configFilePath = '/Users/philipmassey/.tokens/robinhood.cfg'
config.read(configFilePath)
print(list(config.items()))
rhuser = config.get('login', 'user')
rhpwd = config.get('login', 'pwd')
print(rhuser,rhpwd)
login = r.login(rhuser,rhpwd)


client = MongoClient()
db = client['robinhood_options']
symbol='NET'
print(r.get_quotes(symbol)[0]['last_trade_price'])
print(r.get_quotes(symbol)[0]['updated_at'])
symbol = 'HD'
expiration_dates = r.get_chains(symbol)['expiration_dates']
print(expiration_dates)
expirationDate = expiration_dates[0]
volume_limit = 0
print('running')
optionData = r.find_options_for_list_of_stocks_by_expiration_date([symbol], expirationDate=expirationDate,optionType='call')
dfoptions = pd.DataFrame((filter(lambda x:x['volume']>volume_limit,optionData)))
dfstrikes = dfoptions[['strike_price','volume']].sort_values(by='volume', ascending=False)
strike_prices = [i for i in enumerate(dfstrikes[0:5].strike_price)]
print(strike_prices)
예제 #13
0
def quote(symbols):
    quotes = rh.get_quotes(symbols)
    # print(quotes)

    for quote in quotes:
        print("{}|{}".format(quote['symbol'], quote['ask_price']))
예제 #14
0
 def test_quotes(self):
     profile_info = r.get_quotes('spy')
     assert profile_info
예제 #15
0
def quote(symbols):
    quotes = rh.get_quotes(symbols)

    for quote in quotes:
        ui.success(f"\n{quote['symbol']} | {quote['last_extended_hours_trade_price']}\n")
예제 #16
0
def quote(symbols):
    quotes = rh.get_quotes(symbols)
    print(quotes)
    for qte in quotes:
        ui.success("{}| {}".format(qte['symbol'], qte['ask_price']))
예제 #17
0
def watchlist():
    with open('watchlist') as file:
        symbols = file.read().split()
        quotes = rh.get_quotes(symbols)
        for stock_quote in quotes:
            print("{} | {}".format(stock_quote["symbol"], stock_quote["ask_price"]))
def watchlist():
    with open('watchlist') as f:
        symbols = f.read().splitlines()

    quotes = rh.get_quotes(symbols)
    print(quotes)
예제 #19
0
    def currentPrices(self):
        symbol = self.symbol
        data = r.get_quotes(symbol)

        for item in data:
            return item
예제 #20
0
def quote(symbols):
    for symbol in symbols:
        print("Getting stock quote for: {}".format(symbol))
    quotes = rh.get_quotes(symbols)
    for stock_quote in quotes:
        print("{} | {}".format(stock_quote["symbol"], stock_quote["ask_price"]))