def scan_stocks(): """ The main method. Sells stocks in your portfolio if their 50 day moving average crosses below the 200 day, and buys stocks in your watchlist if the opposite happens. ############################################################################################### WARNING: Comment out the sell_holdings and buy_holdings lines if you don't actually want to execute the trade. ############################################################################################### If you sell a stock, this updates tradehistory.txt with information about the position, how much you've earned/lost, etc. """ #Log in to Robinhood #Put your username and password in a config.py file in the same directory (see sample file) login = r.login(rh_username, rh_password) login_to_sms(rh_phone, 'tmobile') if debug: print("----- DEBUG MODE -----\n") print("----- Starting scan... -----\n") register_matplotlib_converters() watchlist_symbols = get_watchlist_symbols() portfolio_symbols = get_portfolio_symbols() holdings_data = get_modified_holdings() potential_buys = [] sells = [] print("Current Portfolio: " + str(portfolio_symbols) + "\n") print("Current Watchlist: " + str(watchlist_symbols) + "\n") print("----- Scanning portfolio for stocks to sell -----\n") for symbol in portfolio_symbols: cross = golden_cross(symbol, n1=50, n2=200, days=30, direction="below") if (cross == -1): sell_holdings(symbol, holdings_data) sells.append(symbol) profile_data = r.build_user_profile() print("\n----- Scanning watchlist for stocks to buy -----\n") for symbol in watchlist_symbols: if (symbol not in portfolio_symbols): cross = golden_cross(symbol, n1=50, n2=200, days=10, direction="above") if (cross == 1): potential_buys.append(symbol) if (len(potential_buys) > 0): buy_holdings(potential_buys, profile_data, holdings_data) else: send_text("Nothing to buy.") if (len(sells) > 0): update_trade_history(sells, holdings_data, "tradehistory.txt") else: send_text("Nothing to sell.") print("----- Scan over -----\n") server.quit() if debug: print("----- DEBUG MODE -----\n")
def RetrievePortfolio(self): try: # Pull down an update of the current holdings self.portfolio = rs.build_holdings() # Update the user profile self.profile = rs.build_user_profile() except Exception as e: raise StockAPIException(e)
def determineShareAmount(price=float): userProfile = rStocks.build_user_profile() userCashVal = userProfile.get('cash') userCash = float(userCashVal) fiftyPercent = userCash / 2 shareAmountVal = float(fiftyPercent) / float(price) shareAmount = str(int(shareAmountVal)) return shareAmount
def stockPriceAcceptable(price=float): userProfile = rStocks.build_user_profile() userCashVal = userProfile.get('cash') userCash = float(userCashVal) oneTwentieth = userCash / 20 if float(price) < float(oneTwentieth): return True else: return False
def scan_stocks(): """ The main method. Sells stocks in your portfolio if their 50 day moving average crosses below the 200 day, and buys stocks in your watchlist if the opposite happens. ############################################################################################### WARNING: Comment out the sell_holdings and buy_holdings lines if you don't actually want to execute the trade. ############################################################################################### If you sell a stock, this updates tradehistory.txt with information about the position, how much you've earned/lost, etc. """ print("----- Starting scan... -----\n") register_matplotlib_converters() watchlist_symbols = get_watchlist_symbols() portfolio_symbols = get_portfolio_symbols() holdings_data = get_modified_holdings() potential_buys = [] sells = [] print("Current Portfolio: " + str(portfolio_symbols) + "\n") print("Current Watchlist: " + str(watchlist_symbols) + "\n") print("----- Scanning portfolio for stocks to sell -----\n") for symbol in portfolio_symbols: cross = golden_cross(symbol, n1=50, n2=200, days=30, direction="below") if (cross == -1): sell_holdings(symbol, holdings_data) sells.append(symbol) profile_data = r.build_user_profile() print("\n----- Scanning watchlist for stocks to buy -----\n") for symbol in watchlist_symbols: if (symbol not in portfolio_symbols): cross = golden_cross(symbol, n1=50, n2=200, days=10, direction="above") if (cross == 1): potential_buys.append(symbol) if (len(potential_buys) > 0): buy_holdings(potential_buys, profile_data, holdings_data) if (len(sells) > 0): update_trade_history(sells, holdings_data, "tradehistory.txt") print("----- Scan over -----\n")
def generate_portfolio_summary(): r.login(username,password) d = r.build_holdings() d.update(r.build_user_profile()) return d
def scan_stocks(): """ The main method. Sells stocks in your portfolio if their 50 day moving average crosses below the 200 day, and buys stocks in your watchlist if the opposite happens. ############################################################################################### WARNING: Comment out the sell_holdings and buy_holdings lines if you don't actually want to execute the trade. ############################################################################################### If you sell a stock, this updates tradehistory.txt with information about the position, how much you've earned/lost, etc. """ print("----- Starting scan... -----\n") register_matplotlib_converters() watchlist_symbols = get_watchlist_symbols() watchlist_names = get_watchlist_names() portfolio_symbols = get_portfolio_symbols() holdings_data = get_modified_holdings() potential_buys = [] sells = [] print("Current Portfolio: " + str(portfolio_symbols) + "\n") # print("Current Watchlist Names: " + str(watchlist_names) + "\n") # print("Current Watchlist Tickers: " + str(watchlist_symbols) + "\n") print("----- Scanning portfolio for stocks to sell -----\n") for symbol in portfolio_symbols: cross = golden_cross(symbol, n1=5, n2=10, days=60, direction="below") if (cross == -1): print("----- Portfolio company " + str(symbol) + "has crossed and should be sold -----\n") answer = input("----- Would you like to sell your shares in " + str(symbol) + "? -----\n") # sell_holdings(symbol, holdings_data) sells.append(symbol) profile_data = r.build_user_profile() print("----- Scanning watchlist for stocks to buy -----\n") # Import watchlist since robinhood api doesn't seem to be working... # watchlist_symbols = ['BAC'] watchlist_file = 'real_estate_watchlist.txt' watchlist_data = read_watchlist(watchlist_file) watchlist_symbols = watchlist_data[1] for symbol in watchlist_symbols: if (symbol not in portfolio_symbols): cross = golden_cross(symbol, n1=10, n2=20, days=6, direction="above") if (cross == 1): potential_buys.append(symbol) if (len(potential_buys) > 0): print("\n----- There are: " + str(len(potential_buys)) + " potential buys in the watchlist -----\n") print(potential_buys) answer = input("\nWould you like to make a buy order (yes or no):") if answer == "yes": buy_holdings(potential_buys, profile_data, holdings_data) print("\n----- Buy order has been excecuted -----\n") elif answer == "no": print("\n----- Buy order has been terminated -----\n") else: print("\nPlease enter yes or no.") if (len(sells) > 0): update_trade_history(sells, holdings_data, "tradehistory.txt") print("----- Scan over -----\n")
import json import robin_stocks as r import robin_stocks.helper as helper import praw reddit = praw.Reddit(client_id='xxxxx', client_secret='xxxxx', user_agent='xxxxx', password='******', username='******') username = '******' password = '******' login = r.login(username, password, store_session=True) account = r.build_user_profile() def get_cutoff(max_option_price): # Get Stock List cash = float(account['cash']) half_cash = 0.5 * cash budget = min(cash, max_option_price) max_stock_price = max_option_price / 2 cutoff = min(half_cash, max_stock_price) print('Current buying power: ${0:.2f}'.format(cash)) print('Maximum option price: ${0:.2f}'.format(budget, 2)) print('Ticker price cutoff: ${0:.2f}'.format(cutoff, 2))
def getUserProfile(): return r.build_user_profile()
def getProfile(self): return self.masterFormat(robin_stocks.build_user_profile(), "profile")