예제 #1
0
def get_holdings():
    my_stocks = r.build_holdings()
    my_options = r.options.get_open_option_positions()
    dicts = []
    for option in my_options:
        link = option['option']
        value = requests.get(link).json()
        option.update(value)
        dicts.append(option)
    for option_position in dicts:
        underlying = option_position['chain_symbol']
        strike = option_position['strike_price']
        expiration = option_position['expiration_date']
        contract_type = option_position['type']
        quantity = option_position['quantity']
        average_price = option_position['average_price']
        mark = ((float(option_position['min_ticks']['above_tick']) +
                 float(option_position['min_ticks']['above_tick'])) / 2) * 100
        month = expiration.split("-")[1]
        day = expiration.split("-")[2]
        year = expiration.split("-")[0]
        symbol = underlying + "_" + month + day + year[2:] + contract_type[
            0].upper() + format_number(strike)
        name = look_up[month] + " " + day + " " + year + " " + format_number(
            strike) + " " + contract_type
        my_stocks[symbol] = {
            "type": "option",
            "quantity": quantity,
            "average_buy_price": average_price,
            "name": name,
            "equity": mark
        }
    return my_stocks
def rs_current_price(tick):

    my_stocks = rs.build_holdings()
    value = my_stocks[tick]
    rs_price_dict.update({tick: float(value["price"])})
    print(value["price"], "\n")

    return
def tickers():

    my_tickers_list = []
    my_stocks = rs.build_holdings()
    for key, value in my_stocks.items():
        my_tickers_list.append(key)
    print(my_tickers_list, "\n")

    return my_tickers_list
예제 #4
0
def get_equity_data():
    """Displays a pie chart of your portfolio holdings
    """
    holdings_data = r.build_holdings()
    equity_data = {}
    for key, value in holdings_data.items():
        equity_data[key] = {}
        equity_data[key][name] = value.get('name')
        equity_data[key][percentage] = value.get("percentage")
        equity_data[key][type]
    fig1, ax1 = plt.subplots()
    ax1.pie(equities, labels=labels, autopct='%1.1f%%',
            shadow=True, startangle=90)
    ax1.axis('equal')
    plt.show()
예제 #5
0
def modified_holdings():
    """ Retrieves the same dictionary as robinhood.build_holdings, but includes data about
        when the stock was purchased, which is useful for the read_trade_history() method
        in tradingstats.py

    Returns:
        the same dict from robinhood.build_holdings, but with an extra key-value pair for each
        position you have, which is 'bought_at': (the time the stock was purchased)
    """
    holdings = robinhood.build_holdings()
    holdings_data = robinhood.open_stock_positions()
    for symbol, _ in holdings.items():
        bought_at = position_creation_date(symbol, holdings_data)
        bought_at = str(pandas.to_datetime(bought_at))
        holdings[symbol].update({'bought_at': bought_at})
    return holdings
예제 #6
0
def create_holdings_table():
    print("Getting holdings data...")

    holdings = r.build_holdings()  # get the holdings
    data = []  # list to hold stock data

    print("Transforming data...")

    # Loop through stocks
    for name, stats in holdings.items():
        stock = {"name": name}  # initialize name/value
        stock = {**stock, **stats}  # merge stats dict with stocks
        data.append(stock)  # append to data list

    # Write to Excel
    helper.create_excel(data, 'holdings')
def build_portfolio():
    # Get my portfolio info
    my_stocks = rb.build_holdings()
    myStocks = my_stocks.items()
    return myStocks
예제 #8
0
def get_holdings():
    my_stocks = r.build_holdings()
    for key, value in my_stocks.items():
        print(key, value)
예제 #9
0
def get_profile_data(username):
    holdings = rh.build_holdings()
    return get_stocks_as_percent(holdings)
예제 #10
0
 def returnHoldings(self):
     return rs.build_holdings()