jmfernandes / robin_stocks

This is a library to use with Robinhood Financial App. It currently supports trading crypto-currencies, options, and stocks. In addition, it can be used to get real time ticker information, assess the performance of your portfolio, and can also get tax documents, total dividends paid, and more. More info at
http://www.robin-stocks.com
MIT License
1.74k stars 467 forks source link

Option buy orders erroring out with Max retries exceeded with url #386

Open skumar7777 opened 1 year ago

skumar7777 commented 1 year ago

For every order through r.order_buy_option_limit, the resulting error code is

HTTPSConnectionPool(host='api.robinhood.com', port=443): Max retries exceeded with url: /instruments/?symbol=QQQ (Caused by SSLError(SSLError(1, '[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2548)')))

Checked code repeatedly, there is no retries of /instruments/?symbol=QQQ

Order submission works correctly in python shell. I have pip installed 3.0.1

skumar7777 commented 1 year ago

I have updated requests to 2.31. Immediately after the r.order_buy_option_limit call, other calls like r.get_all_option_orders() work correctly.

def place_order(tran_type, symbol, expiry, strike, option_type, price, qty):
    print("place_order", tran_type, symbol, expiry, strike, option_type, price, qty)
    try:
        if tran_type == 'buy':
            print("Sending order to Robinhood...", r.__path__) # PATH IS CORRECT
            ordData = r.order_buy_option_limit("open", "debit", price, symbol, qty, expiry, strike, option_type, "gtc") # FAILS
                        # I tried putting in a print as first statement in the def order_buy_option_limit under orders.py, does not print
            print("RH Order submitted...")
        else:
            ordData = r.order_sell_option_limit("close", "credit", price, symbol, qty, expiry, strike, option_type, "gtc")
    except Exception as e:
        print(e)
        allOrds = r.get_all_option_orders()
        print(allOrds)                                    # WORKS CORRECTLY!
        return None
    return ordData

In orders.py,

@login_required
def order_buy_option_limit(positionEffect, creditOrDebit, price, symbol, quantity, expirationDate, strike, optionType='both', timeInForce='gtc', account_number=None, jsonify=True):
    """ Removed code comments for ease of reading, below print does not PRINT! 
    print("In r.order_buy_option_limit", load_account_profile(account_number=account_number, info='url'))
    try:
        symbol = symbol.upper().strip()
    except AttributeError as message:
        print(message, file=get_output())
        return None
...
...
skumar7777 commented 1 year ago

Only thing I can see is that the calls occur from another thread than the one opening the robinhood connection. Can it make a difference?