Beispiel #1
0
    def get_current_positions(self):
        data = r.get_open_stock_positions()

        holdings = list()
        for item in data:
            item['symbol'] = r.get_symbol_by_url(item['instrument'])

            # Returns current_price object for a give symbol
            helperFunction = Helpers(item['symbol'])
            currentData = helperFunction.currentPrices()

            current_equity = float(item['quantity']) * float(
                currentData['ask_price'])
            price_paid = float(item['quantity']) * float(
                item['average_buy_price'])

            singleHolding = {
                "symbol": item['symbol'],
                "quantity": item['quantity'],
                "current_price": currentData['ask_price'],
                "average_buy_price": item['average_buy_price'],
                "price_paid": round(price_paid, 2),
                "current_equity": round(current_equity, 2),
                "profit": round(float(current_equity) - float(price_paid), 2)
            }

            holdings.append(singleHolding)

        return holdings
Beispiel #2
0
def get_options(all_options, max_date, latest_price):
    options = []
    for option in all_options:
        y, m, d = option['expiration_date'].split('-')
        try:
            if datetime.date(int(y), int(m), int(d)) <= max_date:
                temp = r.get_option_market_data_by_id(option['id'])[0]
                temp['expiration_date'] = option['expiration_date']
                temp['strike_price'] = option['strike_price']
                temp['last_trade_price'] = latest_price
                if float(temp['last_trade_price']) - float(
                        temp['strike_price']) > 0:
                    temp['money'] = 'ITM'
                else:
                    temp['money'] = 'OTM'
                options.append(temp)
        except TypeError as message:
            print('for options in all options {}: o man'.format(message))
        except IndexError as message:
            print('{} for {} {} {}'.format(message,
                                           r.get_symbol_by_url(option['url']),
                                           option['expiration_date'],
                                           option['type']))

    return options
Beispiel #3
0
 def test_symbol_by_url(self):
     symbol = r.get_symbol_by_url(self.instrument)
     assert (symbol == self.single_stock)
     fake_symbol = r.get_symbol_by_url(self.fake_instrument)
     assert (fake_symbol == '')
Beispiel #4
0
print('getting all stock orders...\n')
orders = r.get_all_stock_orders()

tickers_list = []
shares_list = []
avg_price_list = []
dates_list = []

for i in range(len(orders)):
    # Exclude failed orders
    if orders[i]['state'] != 'filled':
        continue

    # Get stock ticker associated with the order
    instrument = orders[i]['instrument']
    symbol = r.get_symbol_by_url(instrument)
    tickers_list.append(symbol)

    shares = orders[i]['cumulative_quantity']
    # We want shares to be negative if the order was a sell
    if orders[i]['side'] == 'sell':
        shares_list.append(float(shares) * -1)
    else:
        shares_list.append(float(shares))

    avg_price = orders[i]['average_price']
    avg_price_list.append(float(avg_price))

    date_object = datetime.strptime(orders[i]['created_at'],
                                    '%Y-%m-%dT%H:%M:%S.%fZ').date()
    dates_list.append(date_object)
Beispiel #5
0
 def test_symbol_by_url(self):
     symbol = r.get_symbol_by_url(self.instrument)
     self.assertEqual(symbol, self.single_stock)
     fake_symbol = r.get_symbol_by_url(self.fake_instrument)
     self.assertEqual(fake_symbol, '')
def getSymbolFromOrder(order):
    return r.get_symbol_by_url(getOrder(order)['instrument'])
Beispiel #7
0
def get_watchlist_symbols():
    return list(map(lambda x: r.get_symbol_by_url(x['instrument']), watchlist))
Beispiel #8
0
 def __get_stock_from_positions_list(ticker, list):
     for stock in list:
         if robin_stocks.get_symbol_by_url(stock['instrument']) == ticker:
             return stock
Beispiel #9
0
def URL2SYM(url):
    return r.get_symbol_by_url(url)
Beispiel #10
0
def getStockPositions():
    positions_data = rs.get_open_stock_positions()
    for item in positions_data:
        item['symbol'] = rs.get_symbol_by_url(item['instrument'])
        print(item['symbols'])