def get_names(self, stocks): temp = rs.get_instruments_by_symbols(stocks) names = [] for t in temp: if t is not None: names.append(t.get('name')) return names
def test_instruments(self): quote = r.get_instruments_by_symbols(self.single_stock) assert (len(quote) == 1) assert (quote[0]['symbol'] == self.single_stock) quote = quote[0] assert ('id' in quote) assert isinstance(quote["id"], str) assert ('url' in quote) assert isinstance(quote["url"], str) assert ('quote' in quote) assert isinstance(quote["quote"], str) assert ('fundamentals' in quote) assert isinstance(quote["fundamentals"], str) assert ('splits' in quote) assert isinstance(quote["splits"], str) assert ('state' in quote) assert isinstance(quote["state"], str) assert ('market' in quote) assert isinstance(quote["market"], str) assert ('simple_name' in quote) assert isinstance(quote["simple_name"], str) assert ('name' in quote) assert isinstance(quote["name"], str) assert ('tradeable' in quote) assert isinstance(quote["tradeable"], bool) assert ('tradability' in quote) assert isinstance(quote["tradability"], str) assert ('symbol' in quote) assert isinstance(quote["symbol"], str) assert ('bloomberg_unique' in quote) assert isinstance(quote["bloomberg_unique"], str) assert ('margin_initial_ratio' in quote) assert isinstance(quote["margin_initial_ratio"], float) assert ('maintenance_ratio' in quote) assert isinstance(quote["maintenance_ratio"], float) assert ('country' in quote) assert isinstance(quote["country"], str) assert ('day_trade_ratio' in quote) assert isinstance(quote["day_trade_ratio"], float) assert ('list_date' in quote) assert isinstance(quote["list_date"], str) assert ('min_tick_size' in quote) assert ('type' in quote) assert isinstance(quote["type"], str) assert ('tradable_chain_id' in quote) assert isinstance(quote["tradable_chain_id"], str) assert ('rhs_tradability' in quote) assert isinstance(quote["rhs_tradability"], str) assert ('fractional_tradability' in quote) assert isinstance(quote["fractional_tradability"], str) assert ('default_collar_fraction' in quote) assert isinstance(quote["default_collar_fraction"], float) # more_quotes = r.get_fundamentals(self.list_stocks, info=None) assert (len(more_quotes) == len(self.list_stocks)) # fake_quotes = r.get_fundamentals(self.fake_stocks, info=None) assert (len(fake_quotes) == 1) assert (fake_quotes[0] == None)
def get_stock(cls, symbol=None, url=None): if symbol: __instrument_data = get_instruments_by_symbols(symbol) elif id: __instrument_data = get_instrument_by_url(url) else: raise exceptions.MissingParameter return cls(**__instrument_data)
def ask_security(ac_name: str) -> Tuple[str, str]: """ Asks the user for the symbol of a security to add and returns the security's id and name. """ sec_sym: str = ask_user_input( "\t\tEnter the symbol for the new {} security: ".format(ac_name) ) instrument: Dict[str, Any] = r.get_instruments_by_symbols([sec_sym])[0] return (instrument["id"], instrument["name"])
def get_position_creation_date(symbol, holdings_data): """Returns the time at which we bought a certain stock in our portfolio Args: symbol(str): Symbol of the stock that we are trying to figure out when it was bought holdings_data(dict): dict returned by r.get_current_positions() Returns: A string containing the date and time the stock was bought, or "Not found" otherwise """ instrument = r.get_instruments_by_symbols(symbol) url = instrument[0].get('url') for dict in holdings_data: if (dict.get('instrument') == url): return dict.get('created_at') return "Not found"
def get_portfolio_symbols(): """ Returns: the symbol for each stock in your portfolio as a list of strings """ symbols = [] holdings_data = ['AAPL'] #r.get_current_positions() for item in holdings_data: if not item: continue instrument_data = r.get_instrument_by_url( r.get_instruments_by_symbols(item)[0]['url']) symbol = instrument_data['symbol'] symbols.append(symbol) return symbols
def printStockLists(listName): # Break up the dictionary text into an array listText = lists[listName].split('-') # Join the split array with spaces and make it title case listText = " ".join(listText).title() print(f"Pulling up today's {listText}...") search = robin.get_all_stocks_from_market_tag(lists[listName]) searchResultList = [] for item in search: searchResultList.append(item['symbol']) searchResultStocks = robin.get_instruments_by_symbols(searchResultList) print("\n-----------------------") print(f"{listText}".center(22)) print("-----------------------\n") printStocks(searchResultStocks)
def five_year_check(stockTicker): """Figure out if a stock has risen or been created within the last five years. Args: stockTicker(str): Symbol of the stock we're querying Returns: True if the stock's current price is higher than it was five years ago, or the stock IPO'd within the last five years False otherwise """ instrument = r.get_instruments_by_symbols(stockTicker) list_date = instrument[0].get("list_date") if ((pd.Timestamp("now") - pd.to_datetime(list_date)) < pd.Timedelta("5 Y")): return True fiveyear = r.get_historicals(stockTicker, span='5year', bounds='regular') closingPrices = [] for item in fiveyear: closingPrices.append(float(item['close_price'])) recent_price = closingPrices[len(closingPrices) - 1] oldest_price = closingPrices[0] return (recent_price > oldest_price)
def test_instruments(self): quote = r.get_instruments_by_symbols(self.single_stock) self.assertEqual(len(quote), 1) self.assertEqual(quote[0]['symbol'], self.single_stock) quote = quote[0] self.assertIn('id', quote) self.assertIn('url', quote) self.assertIn('quote', quote) self.assertIn('fundamentals', quote) self.assertIn('splits', quote) self.assertIn('state', quote) self.assertIn('market', quote) self.assertIn('simple_name', quote) self.assertIn('name', quote) self.assertIn('tradeable', quote) self.assertIn('tradability', quote) self.assertIn('symbol', quote) self.assertIn('bloomberg_unique', quote) self.assertIn('margin_initial_ratio', quote) self.assertIn('maintenance_ratio', quote) self.assertIn('country', quote) self.assertIn('day_trade_ratio', quote) self.assertIn('list_date', quote) self.assertIn('min_tick_size', quote) self.assertIn('type', quote) self.assertIn('tradable_chain_id', quote) self.assertIn('rhs_tradability', quote) self.assertIn('fractional_tradability', quote) self.assertIn('default_collar_fraction', quote) # more_quotes = r.get_fundamentals(self.list_stocks, info=None) self.assertEqual(len(more_quotes), len(self.list_stocks)) # fake_quotes = r.get_fundamentals(self.fake_stocks, info=None) self.assertEqual(len(fake_quotes), 1) self.assertEqual(fake_quotes[0], None)
print(f'this is all the items in list2: {list2}') print() print(f'this is the last item in list2: {last_item_list2}') print() # testing the 2nd 14 min period in SOLO's trading day on 11/27 if list2[1] < -70: #and open positions is null and open orders is null print('this would execute a trade on robinhood') lat_ask = r.get_latest_price('SOLO', priceType='ask_price', includeExtendedHours=True) # if r.get_all_open_stock_orders(): # r.order_buy_limit('SOLO', quantity, limitPrice, timeInForce='gtc', extendedHours=False) solo_lat_ask = float( r.get_latest_price('PLUG', priceType='ask_price', includeExtendedHours=True)[0]) solo_inst_url = r.get_instruments_by_symbols('PLUG')[0]['url'] for position in r.get_all_positions(): if position['instrument'] == solo_inst_url: solo_avg_buy = float(position['average_buy_price']) print('this is the current price diff') print(solo_lat_ask - solo_avg_buy) # print(dir(r))