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.69k stars 459 forks source link

find_options_for_list_of_stocks_by_expiration_date fails to run sometimes #67

Open boi-led-egg opened 4 years ago

boi-led-egg commented 4 years ago

Sometimes, for some stocks find_options_for_list_of_stocks_by_expiration_date function would fail. For example:

import robin_stocks as rs
rs.login('<email>', '<password>')
o = rs.find_options_for_list_of_stocks_by_expiration_date(['JPM'], expirationDate='2019-11-22', optionType='call')

Result:

$ python robin_stocks_test.py 
Found Additional pages.
Loading page 2 ...
Loading page 3 ...
Loading page 4 ...
Loading page 5 ...
Loading page 6 ...
401 Client Error: Unauthorized for url: https://api.robinhood.com/marketdata/options/35f92590-b047-4a7a-8256-30e470da4c48/
Traceback (most recent call last):
  File "robin_stocks_test.py", line 4, in <module>
    optionType='call')
  File "/home/garm/projects/trader/venv/lib/python3.6/site-packages/robin_stocks/options.py", line 263, in find_options_for_list_of_stocks_by_expiration_date
    item.update(marketData)
TypeError: 'NoneType' object is not iterable

It would work on one day, but not the other. Would work with other symbols just fine. I have robin-stocks==0.9.9.5, Python 3.6.8 right now.

boi-led-egg commented 4 years ago

A small update with more info. I dug into the code, specifically https://github.com/jmfernandes/robin_stocks/blob/master/robin_stocks/options.py#L262 added print(item) before get_option_market_data_by_id(where it fails inside) Also added skipping the cycle if that request was unsuccessful, to see what other items look like. Here's what a failed item looks like:

  "issue_date": "1987-01-12",
  "tradability": "tradable",
  "strike_price": "150.0000",
  "state": "active",
  "url": "https://api.robinhood.com/options/instruments/35f92590-b047-4a7a-8256-30e470da4c48/",
  "expiration_date": "2019-11-22",
  "created_at": "2019-11-20T01:05:50.822956Z",
  "chain_id": "9b27bd90-041d-4994-8934-4fac29c00ceb",
  "updated_at": "2019-11-20T01:05:50.822964Z",
  "rhs_tradability": "untradable",
  "type": "call",
  "chain_symbol": "JPM",
  "min_ticks": {
    "cutoff_price": "3.00",
    "below_tick": "0.01",
    "above_tick": "0.05"
  },
  "id": "35f92590-b047-4a7a-8256-30e470da4c48"
}

All other were successful, they had item like this:

{
  "issue_date": "1987-01-12",
  "tradability": "tradable",
  "strike_price": "149.0000",
  "state": "active",
  "url": "https://api.robinhood.com/options/instruments/0903ac21-6d94-455a-b74d-c3372638aef9/",
  "expiration_date": "2019-11-22",
  "created_at": "2019-11-12T01:04:31.785395Z",
  "chain_id": "9b27bd90-041d-4994-8934-4fac29c00ceb",
  "updated_at": "2019-11-12T01:04:31.785402Z",
  "rhs_tradability": "untradable",
  "type": "call",
  "chain_symbol": "JPM",
  "min_ticks": {
    "cutoff_price": "3.00",
    "below_tick": "0.01",
    "above_tick": "0.05"
  },
  "id": "0903ac21-6d94-455a-b74d-c3372638aef9"
}

The failed one has "updated_at": "2019-11-20T01:05:50.822964Z", all others have this much older. I live in Pacific Time zone, and it's Nov 19, 23:28 right now. I guess that time is UTC. Don't know if it can cause any troubles, but that's the only significant difference in input data.

boi-led-egg commented 4 years ago

Oh, and this is what RobinHood itself showing for this option(strike price 150) https://drive.google.com/open?id=1cfLvnGVx33kfwO6ipKBnu0RqoXpHXfH3 Not much.

jmfernandes commented 4 years ago

Thanks for bringing this to my attention. Will look into it.

stephen-nguyen commented 4 years ago

Has there been any fix to this? I'm running into the same issue. Do I just need to run my code in the morning or something?

jmfernandes commented 4 years ago

@stephen-nguyen do you still get this error when using the new find_options_by_expiration() function?

Monil1601 commented 3 years ago

@stephen-nguyen do you still get this error when using the new find_options_by_expiration() function?

I'm still getting the error