Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--dry-run",
                        help="dry-run mode",
                        action="store_true",
                        default=True)
    args = parser.parse_args()
    if args.verbosity:
        print("dry-run enabled")

    ruser = os.environ("RH_USER")
    rpass = os.environ("RH_PASS")

    login = robinhood.login(ruser, rpass)
    profile = robinhood.build_user_profile()
    watchlist = folio.watchlist_symbols()
    portfolio = folio.portfolio_symbols()
    holdings = folio.modified_holdings()

    sells = find.sells(portfolio)
    for sym in sells:
        transact.sell(sym, holdings, dry_run=args.dry_run)

    buys = find.buys(watchlist, portfolio)
    if args.dry_run:
        transact.buy(buys, profile, holdings, dry_run=args.dry_run)
Exemplo n.º 2
0
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.
    """
    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)
    if (len(sells) > 0):
        update_trade_history(sells, holdings_data, "tradehistory.txt")
    print("----- Scan over -----\n")
    if debug:
        print("----- DEBUG MODE -----\n")
Exemplo n.º 3
0
 def __getAvailableCash(self):
     self.__available_cash = float(rs.build_user_profile()["cash"])