Ejemplo n.º 1
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']))
Ejemplo n.º 2
0
def buy(quantity, symbol, limit):
    if limit is not None:
        ui.success("buying {} of {} at {}".format(quantity, symbol, limit))
        result = rh.order_buy_limit(symbol, quantity, limit)
    else:
        ui.success("buying {} of {}".format(quantity, symbol))
        result = rh.order_buy_market(symbol, quantity)
Ejemplo n.º 3
0
def owns_spy():
    try:
        spy_position = Client.held_positions[symbol]
        ui.success(spy_position)
        return True
    except KeyError:
        return False
Ejemplo n.º 4
0
def sell(quantity, symbol, limit):
    if limit is not None:
        ui.success(f"\nSelling {quantity} of {symbol} at ${limit}\n")
        result = rh.order_sell_limit(symbol, quantity, limit)
    else:
        ui.success(f'\nSelling {quantity} of {symbol} at market price....\n')
        result = rh.order_sell_market(symbol, quantity)
    ui.chec_ref(result)
Ejemplo n.º 5
0
def crypto_history(symbol, interval, span):
    ui.success(f'\nGetting {interval} stock historicals for {symbol} for the past {span}....\n')
    result = rh.get_crypto_historicals(symbol, interval, span)

    for i in result:
        for x in i:
            ui.success(f'{x}: {i[x]}')
        ui.bar()
Ejemplo n.º 6
0
def buy_doge(amount):
    ui.success(f'Ordering ${amount} of DOGE....\n')
    # Doge error workaround
    price = float(rh.get_crypto_quote('DOGE').get('ask_price'))
    shares = round(amount/price, 0)
    result = rh.order_buy_crypto_by_quantity('DOGE', shares)

    ui.chec_ref(result)
Ejemplo n.º 7
0
def info(fetch):
    print(f'\nFetching {fetch}....\n')
    result = rh.load_account_profile()

    if fetch is not None:
        ui.success(result[fetch])
    else:
        ui.success(result)
Ejemplo n.º 8
0
def buy(quantity, symbol, limit):
    if limit is not None:
        ui.success(f"Bying {quantity} of {symbol} at ${limit}")
        result = rh.order_buy_limit(symbol, quantity, limit)
    else:
        ui.success(f'Bying {quantity} of {symbol} at market price....\n')
        result = rh.order_buy_market(symbol, quantity)

    ui.chec_ref(result)
Ejemplo n.º 9
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()
Ejemplo n.º 10
0
    def trade_on_fear_and_greed(self, current_fear_greed_index):

        investors_are_greedy = current_fear_greed_index >= fear_greed.sell_threshold
        investors_are_fearful = current_fear_greed_index <= fear_greed.buy_threshold
        owns_spy = fear_greed.owns_spy()
        current_date_time = datetime.now().strftime("%m/%d/%Y %H:%M:%S")

        if investors_are_greedy and owns_spy:
            # Sell entire SPY position
            price = fear_greed.get_sell_equity_amount()
            result = rh.order_sell_fractional_by_price(fear_greed.symbol,
                                                       price,
                                                       extendedHours=True,
                                                       timeInForce="gfd")

            if result is not None and 'account' in result.keys():
                TradeHistory.update_trade_history(fear_greed.algo,
                                                  current_fear_greed_index,
                                                  fear_greed.symbol, price,
                                                  "sell", current_date_time,
                                                  Client.current_user_id)
            else:
                ui.error(result)
        elif investors_are_fearful and not owns_spy:
            # Buy initial SPY investment or the last sold equity
            price = fear_greed.get_buy_equity_amount(
                TradeHistory.trade_history['trades'])
            result = rh.order_buy_fractional_by_price(fear_greed.symbol,
                                                      price,
                                                      extendedHours=True,
                                                      timeInForce="gfd")

            if result is not None and 'account' in result.keys():
                TradeHistory.update_trade_history(fear_greed.algo,
                                                  current_fear_greed_index,
                                                  fear_greed.symbol, price,
                                                  "buy", current_date_time,
                                                  Client.current_user_id)
            else:
                ui.error(result)
        else:
            # Skip SPY trade because there is not yet a significant fear or greed value
            skipped_dict = {
                "algo": fear_greed.algo,
                "index": current_fear_greed_index,
                "action": "skipped",
                "date": current_date_time,
                "price": "N/A",
                "symbol": "N/A",
                "user_id": Client.current_user_id
            }
            ui.success(skipped_dict)
            return
Ejemplo n.º 11
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()
Ejemplo n.º 12
0
def get_s_r(df):
    '''Loops through DF to determine and return clear support and resistance lines'''
    s = np.mean(df['high'] - df['low'])

    levels = []

    for i in range(2, df.shape[0] - 2):
        if is_support(df, i):
            l = df['low'][i]

            if np.sum([abs(l - x) < s for x in levels]) == 0:
                levels.append((i, l))
                ui.success(f'{l} | SUPPORT')

        elif is_resistance(df, i):
            l = df['high'][i]

            if np.sum([abs(l - x) < s for x in levels]) == 0:
                levels.append((i, l))

                ui.error(f'{l} | RESISTANCE')
Ejemplo n.º 13
0
def sell(quantity, symbol, limit):
    if limit is not None:
        ui.success("Selling {} quantity of {} at {}".format(quantity, symbol, limit))
        result = rh.order_buy_limit(symbol, quantity, limit)
    else:
        ui.success("Selling {} quantity of {} at market price".format(quantity, symbol))
        result = rh.order_sell_market(symbol, quantity)
    ui.success(result)
Ejemplo n.º 14
0
def sell(quantity, symbol, limit=None):
    content = open('config.json').read()
    config = json.loads(content)
    rh.login(config['username'], config['password'])
    
    if limit is not None:
        ui.success("Selling {} of {} at ${}".format(quantity, symbol, limit))
        result = rh.order_sell_limit(symbol, quantity, limit)
    else:
        ui.success("Selling  {} of {}".format(quantity, symbol))
        result = rh.order_sell_market(symbol, quantity)
    ui.success(result)

    if 'detail' in result:
        ui.error(result)
    else:
        ui.success(result)
Ejemplo n.º 15
0
def sell(quantity, symbol, limit):
    if limit is not None:
        ui.success("Selling {} of {} at {}".format(quantity, symbol, limit))
        result = rh.order_sell_limit(symbol, quantity, limit)
    else:
        # market order
        ui.success("Selling {} of {} at market price".format(quantity, symbol))
        result = rh.order_sell_market(symbol, quantity)
    if 'ref_id' in result:
        ui.success(result)
    else:
        ui.error(result)
Ejemplo n.º 16
0
def buy_crypto(symbol, amount):
    ui.success(f'Ordering ${amount} of {symbol}....\n')
    result = rh.order_buy_crypto_by_price(symbol, amount)
    ui.chec_ref(result)
Ejemplo n.º 17
0
def positions():
    result = rh.get_open_stock_positions()
    ui.success(result)
Ejemplo n.º 18
0
def day_trades():
    result = rh.get_day_trades()
    ui.success(len(result))
Ejemplo n.º 19
0
def quote(symbols):
    quotes = rh.get_quotes(symbols)
    print(quotes)
    for qte in quotes:
        ui.success("{}| {}".format(qte['symbol'], qte['ask_price']))
Ejemplo n.º 20
0
    def trade_on_macd(self):
        symbols = [
            "SE", "TTD", "DDOG", "SHOP", "SQ", "DRIP", "CHWY", "OSTK", "NET",
            "CHGG", "PINS", "DAL", "SNAP", "BABA", "NET", "IRBT", "MDB",
            "DKNG", "BYND", "GRUB", "SPOT", "GPS", "INO", "ENPH", "GOLD",
            "IDXX", "CRNC"
        ]

        restricted_stocks = ["AAPL", "WORK", "PLTR", "ROKU", "ETSY"]
        symbols = list(
            (Counter(symbols) - Counter(restricted_stocks)).elements())

        current_date_time = datetime.now().strftime("%m/%d/%Y %H:%M:%S")
        no_transactions = True
        for symbol in symbols:
            df = macd.create_df(symbol)
            df = macd.add_entry_for_today(symbol, df)
            # macd.plot_macd(df, symbol)

            action = macd.get_trade_action(df)
            if action == "buy" and not TradeHistory.already_holding_position(
                    symbol, macd.algo) and False:
                no_transactions = False
                # Buy initial investment or the last sold equity
                price = TradeHistory.get_buy_equity_amount(symbol, "macd")
                result = rh.order_buy_fractional_by_price(symbol,
                                                          price,
                                                          extendedHours=True,
                                                          timeInForce="gfd")
                if result is not None and 'account' in result.keys():
                    TradeHistory.update_trade_history(macd.algo, "N/A", symbol,
                                                      price, "buy",
                                                      current_date_time,
                                                      Client.current_user_id)
                else:
                    ui.error(result)
            elif action == "sell" and TradeHistory.already_holding_position(
                    symbol, macd.algo):
                # Sell entire position
                price = TradeHistory.get_sell_equity_amount(symbol, "macd")
                no_transactions = False
                result = rh.order_sell_fractional_by_price(symbol,
                                                           price,
                                                           extendedHours=True,
                                                           timeInForce="gfd")
                if result is not None and 'account' in result.keys():
                    TradeHistory.update_trade_history(macd.algo, "N/A", symbol,
                                                      price, "sell",
                                                      current_date_time,
                                                      Client.current_user_id)
                else:
                    ui.error(result)
            else:
                continue
        if no_transactions:
            skipped_dict = {
                "algo": macd.algo,
                "index": "N/A",
                "action": "skipped",
                "date": current_date_time,
                "price": "N/A",
                "symbol": "N/A",
                "user_id": Client.current_user_id
            }
            ui.success(skipped_dict)
Ejemplo n.º 21
0
def portfolio():
    print('Loading portfolio profile....')
    result = rh.load_portfolio_profile()
    ui.success(result)
Ejemplo n.º 22
0
def investments():
    print('\nLoading investment profile....\n')
    result = rh.load_investment_profile()
    ui.success(result)
Ejemplo n.º 23
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")
Ejemplo n.º 24
0
def buy_frac(amount, symbol):
    ui.success(f'\nBuying ${amount} of {symbol}....\n')
    result = rh.order_buy_fractional_by_price(symbol, amount)
    ui.chec_ref(result)
Ejemplo n.º 25
0
def crypto_quote(symbol):
    result = rh.get_crypto_quote(symbol)
    ui.success(result)
Ejemplo n.º 26
0
def ratings(symbol):
    ui.success(f'\nGet stock ratings for {symbol}....\n')
    result = rh.get_ratings(symbol)
    ui.success(result)
Ejemplo n.º 27
0
def get_earnings(symbol):
    result = rh.get_earnings(symbol)
    ui.success(result)
Ejemplo n.º 28
0
def holdings():
    result = rh.build_holdings()
    ui.success(result)
Ejemplo n.º 29
0
def notifications():
    result = rh.get_notifications()
    ui.success(result)
Ejemplo n.º 30
0
def all_positions():
    print('\nRetrieving all positions ever traded....\n')
    result = rh.get_all_positions()
    ui.success(result)