westonplatter / fast_arrow

(no longer maintained) A simple yet robust (stock+options) API client for Robinhood
MIT License
127 stars 37 forks source link

Option chain response does not include requested ticker. #99

Closed mauera closed 4 years ago

mauera commented 4 years ago

The following code, intended to get an option chain for 'ROKU' returns an error as shown below:

from fast_arrow import Stock, OptionChain, Option, OptionOrder from fast_arrow_auth import Client

client = Client(username='username', password='password') symb = 'ROKU' stock = Stock.fetch(client, symb) stockid = stock['id']

everything is fine until this point

chain = OptionChain.fetch(client, stockid, symb)

----------- Error Message -------------- Traceback (most recent call last): File "", line 1, in File "C:\path\fast_arrow\resources\option_chain.py", line 19, in fetch return results[0] IndexError: list index out of range


If I go into the function and look for the url request portion of the code..the response returns 750 ticker chains but does not include 'ROKU'. It seems to be returning only a portion of the available option chains. Also, the parameters for OptionChain.fetch() do not seem to 'pre-filter' the response at all...so if this is an avenue for troubleshooting this problem I can try adding new parameters to the request.

Is there are a possible fix for this? Thanks.

westonplatter commented 4 years ago

@mauera see updated option chain example from #101

westonplatter commented 4 years ago

@mauera closing this issue since the updated example (ie, examples/option_chain.py) runs successfully on my machine. If it's still not working for you, please reopen the issue.

mauera commented 4 years ago

Hi Weston, Thank you very much for attending to this issue. Did you recently remove the Stock.fetch() method? I am getting this error now while I try to load the stock to get the id:

stock = Stock.fetch(robinx, symb) optionid = stock['id']

DeprecatedWarning: fetch is deprecated as of 1.0.0 and will be removed in 1.1. Use 'StockMarketdata.quote_by_symbol' Traceback (most recent call last): File "", line 1, in File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\deprecation.py", line 247, in _inner return function(*args, **kwargs) File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\fast_arrow\resources\stock.py", line 21, in fetch raise ApiDoesNotSupportError(message) fast_arrow.exceptions.ApiDoesNotSupportError: Robinhood API seems to not support this endpoint. Use fast_arrow.StockMarketdata.quote_by_symbol

I'm assuming there is now a new method to get the stock id / option; chain. I will investigate further. Thank you again.

On Mon, Sep 23, 2019 at 10:53 AM Weston Platter notifications@github.com wrote:

Closed #99 https://github.com/westonplatter/fast_arrow/issues/99.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/westonplatter/fast_arrow/issues/99?email_source=notifications&email_token=AAFGQ4FW6D7BDIOKLFFUFO3QLDX7TA5CNFSM4IY36I3KYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOTZBMZXY#event-2655177951, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFGQ4DNTN76OPIIAXIGYP3QLDX7TANCNFSM4IY36I3A .

-- V/R, Allen Mauer

westonplatter commented 4 years ago

@mauera kinda yes. The Robinhood's API endpoint is not responsive, so I had to get the stock_id a different way. See the code in https://github.com/westonplatter/fast_arrow/blob/master/examples/option_chain.py.

Specifically, the stock_id can be acquired via

symbol = "TLT"
md = StockMarketdata.quote_by_symbol(client, symbol)
stock_id = md["instrument"].split("/")[-2]
mauera commented 4 years ago

Thank you.

Sent from Mail for Windows 10

From: Weston Platter Sent: Monday, September 23, 2019 11:04 AM To: westonplatter/fast_arrow Cc: mauera; Mention Subject: Re: [westonplatter/fast_arrow] Option chain response does not includerequested ticker. (#99)

@mauera kinda yes. The Robinhood's API endpoint is not responsive, so I had to get the stock_id a different way. See the code in https://github.com/westonplatter/fast_arrow/blob/master/examples/option_chain.py. Specifically, the stock_id can be acquired via symbol = "TLT" md = StockMarketdata.quote_by_symbol(client, symbol) stock_id = md["instrument"].split("/")[-2] — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

mauera commented 4 years ago

Ugh....still getting this:

Traceback (most recent call last): File "", line 9, in File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\fast_arrow\resources\option_chain.py", line 19, in fetch return results[0] IndexError: list index out of range

On Mon, Sep 23, 2019 at 10:57 AM Allen Mauer mauera@gmail.com wrote:

Hi Weston, Thank you very much for attending to this issue. Did you recently remove the Stock.fetch() method? I am getting this error now while I try to load the stock to get the id:

stock = Stock.fetch(robinx, symb) optionid = stock['id']

DeprecatedWarning: fetch is deprecated as of 1.0.0 and will be removed in 1.1. Use 'StockMarketdata.quote_by_symbol' Traceback (most recent call last): File "", line 1, in File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\deprecation.py", line 247, in _inner return function(*args, **kwargs) File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\fast_arrow\resources\stock.py", line 21, in fetch raise ApiDoesNotSupportError(message) fast_arrow.exceptions.ApiDoesNotSupportError: Robinhood API seems to not support this endpoint. Use fast_arrow.StockMarketdata.quote_by_symbol

I'm assuming there is now a new method to get the stock id / option; chain. I will investigate further. Thank you again.

On Mon, Sep 23, 2019 at 10:53 AM Weston Platter notifications@github.com wrote:

Closed #99 https://github.com/westonplatter/fast_arrow/issues/99.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/westonplatter/fast_arrow/issues/99?email_source=notifications&email_token=AAFGQ4FW6D7BDIOKLFFUFO3QLDX7TA5CNFSM4IY36I3KYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOTZBMZXY#event-2655177951, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFGQ4DNTN76OPIIAXIGYP3QLDX7TANCNFSM4IY36I3A .

-- V/R, Allen Mauer

-- V/R, Allen Mauer

mauera commented 4 years ago

symbol = "TLT" md = StockMarketdata.quote_by_symbol(robinx, symbol)

#

get the TLT option chain info

# stock_id = md["instrument"].split("/")[-2] option_chain = OptionChain.fetch(robinx, stock_id, symbol) option_chain_id = option_chain["id"] expiration_dates = option_chain['expiration_dates']

On Mon, Sep 23, 2019 at 11:09 AM Allen Mauer mauera@gmail.com wrote:

Ugh....still getting this:

Traceback (most recent call last): File "", line 9, in File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\fast_arrow\resources\option_chain.py", line 19, in fetch return results[0] IndexError: list index out of range

On Mon, Sep 23, 2019 at 10:57 AM Allen Mauer mauera@gmail.com wrote:

Hi Weston, Thank you very much for attending to this issue. Did you recently remove the Stock.fetch() method? I am getting this error now while I try to load the stock to get the id:

stock = Stock.fetch(robinx, symb) optionid = stock['id']

DeprecatedWarning: fetch is deprecated as of 1.0.0 and will be removed in 1.1. Use 'StockMarketdata.quote_by_symbol' Traceback (most recent call last): File "", line 1, in File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\deprecation.py", line 247, in _inner return function(*args, **kwargs) File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\fast_arrow\resources\stock.py", line 21, in fetch raise ApiDoesNotSupportError(message) fast_arrow.exceptions.ApiDoesNotSupportError: Robinhood API seems to not support this endpoint. Use fast_arrow.StockMarketdata.quote_by_symbol

I'm assuming there is now a new method to get the stock id / option; chain. I will investigate further. Thank you again.

On Mon, Sep 23, 2019 at 10:53 AM Weston Platter notifications@github.com wrote:

Closed #99 https://github.com/westonplatter/fast_arrow/issues/99.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/westonplatter/fast_arrow/issues/99?email_source=notifications&email_token=AAFGQ4FW6D7BDIOKLFFUFO3QLDX7TA5CNFSM4IY36I3KYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOTZBMZXY#event-2655177951, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFGQ4DNTN76OPIIAXIGYP3QLDX7TANCNFSM4IY36I3A .

-- V/R, Allen Mauer

-- V/R, Allen Mauer

-- V/R, Allen Mauer

mauera commented 4 years ago

But this exact code works on your machine?

On Mon, Sep 23, 2019 at 11:09 AM Allen Mauer mauera@gmail.com wrote:

symbol = "TLT" md = StockMarketdata.quote_by_symbol(robinx, symbol)

#

get the TLT option chain info

# stock_id = md["instrument"].split("/")[-2] option_chain = OptionChain.fetch(robinx, stock_id, symbol) option_chain_id = option_chain["id"] expiration_dates = option_chain['expiration_dates']

On Mon, Sep 23, 2019 at 11:09 AM Allen Mauer mauera@gmail.com wrote:

Ugh....still getting this:

Traceback (most recent call last): File "", line 9, in File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\fast_arrow\resources\option_chain.py", line 19, in fetch return results[0] IndexError: list index out of range

On Mon, Sep 23, 2019 at 10:57 AM Allen Mauer mauera@gmail.com wrote:

Hi Weston, Thank you very much for attending to this issue. Did you recently remove the Stock.fetch() method? I am getting this error now while I try to load the stock to get the id:

stock = Stock.fetch(robinx, symb) optionid = stock['id']

DeprecatedWarning: fetch is deprecated as of 1.0.0 and will be removed in 1.1. Use 'StockMarketdata.quote_by_symbol' Traceback (most recent call last): File "", line 1, in File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\deprecation.py", line 247, in _inner return function(*args, **kwargs) File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\fast_arrow\resources\stock.py", line 21, in fetch raise ApiDoesNotSupportError(message) fast_arrow.exceptions.ApiDoesNotSupportError: Robinhood API seems to not support this endpoint. Use fast_arrow.StockMarketdata.quote_by_symbol

I'm assuming there is now a new method to get the stock id / option; chain. I will investigate further. Thank you again.

On Mon, Sep 23, 2019 at 10:53 AM Weston Platter < notifications@github.com> wrote:

Closed #99 https://github.com/westonplatter/fast_arrow/issues/99.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/westonplatter/fast_arrow/issues/99?email_source=notifications&email_token=AAFGQ4FW6D7BDIOKLFFUFO3QLDX7TA5CNFSM4IY36I3KYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOTZBMZXY#event-2655177951, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFGQ4DNTN76OPIIAXIGYP3QLDX7TANCNFSM4IY36I3A .

-- V/R, Allen Mauer

-- V/R, Allen Mauer

-- V/R, Allen Mauer

-- V/R, Allen Mauer

mauera commented 4 years ago

I am authenticated, I can verify that...I am getting information back just this particular line of code does not include the symbol in the results.

On Mon, Sep 23, 2019 at 11:12 AM Allen Mauer mauera@gmail.com wrote:

But this exact code works on your machine?

On Mon, Sep 23, 2019 at 11:09 AM Allen Mauer mauera@gmail.com wrote:

symbol = "TLT" md = StockMarketdata.quote_by_symbol(robinx, symbol)

#

get the TLT option chain info

# stock_id = md["instrument"].split("/")[-2] option_chain = OptionChain.fetch(robinx, stock_id, symbol) option_chain_id = option_chain["id"] expiration_dates = option_chain['expiration_dates']

On Mon, Sep 23, 2019 at 11:09 AM Allen Mauer mauera@gmail.com wrote:

Ugh....still getting this:

Traceback (most recent call last): File "", line 9, in File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\fast_arrow\resources\option_chain.py", line 19, in fetch return results[0] IndexError: list index out of range

On Mon, Sep 23, 2019 at 10:57 AM Allen Mauer mauera@gmail.com wrote:

Hi Weston, Thank you very much for attending to this issue. Did you recently remove the Stock.fetch() method? I am getting this error now while I try to load the stock to get the id:

stock = Stock.fetch(robinx, symb) optionid = stock['id']

DeprecatedWarning: fetch is deprecated as of 1.0.0 and will be removed in 1.1. Use 'StockMarketdata.quote_by_symbol' Traceback (most recent call last): File "", line 1, in File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\deprecation.py", line 247, in _inner return function(*args, **kwargs) File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\fast_arrow\resources\stock.py", line 21, in fetch raise ApiDoesNotSupportError(message) fast_arrow.exceptions.ApiDoesNotSupportError: Robinhood API seems to not support this endpoint. Use fast_arrow.StockMarketdata.quote_by_symbol

I'm assuming there is now a new method to get the stock id / option; chain. I will investigate further. Thank you again.

On Mon, Sep 23, 2019 at 10:53 AM Weston Platter < notifications@github.com> wrote:

Closed #99 https://github.com/westonplatter/fast_arrow/issues/99.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/westonplatter/fast_arrow/issues/99?email_source=notifications&email_token=AAFGQ4FW6D7BDIOKLFFUFO3QLDX7TA5CNFSM4IY36I3KYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOTZBMZXY#event-2655177951, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFGQ4DNTN76OPIIAXIGYP3QLDX7TANCNFSM4IY36I3A .

-- V/R, Allen Mauer

-- V/R, Allen Mauer

-- V/R, Allen Mauer

-- V/R, Allen Mauer

-- V/R, Allen Mauer

mauera commented 4 years ago

https://api.robinhood.com/options/instruments/?chain_symbol=ROKU

This is the endpoint that returns the options.

On Mon, Sep 23, 2019 at 11:13 AM Allen Mauer mauera@gmail.com wrote:

I am authenticated, I can verify that...I am getting information back just this particular line of code does not include the symbol in the results.

On Mon, Sep 23, 2019 at 11:12 AM Allen Mauer mauera@gmail.com wrote:

But this exact code works on your machine?

On Mon, Sep 23, 2019 at 11:09 AM Allen Mauer mauera@gmail.com wrote:

symbol = "TLT" md = StockMarketdata.quote_by_symbol(robinx, symbol)

#

get the TLT option chain info

# stock_id = md["instrument"].split("/")[-2] option_chain = OptionChain.fetch(robinx, stock_id, symbol) option_chain_id = option_chain["id"] expiration_dates = option_chain['expiration_dates']

On Mon, Sep 23, 2019 at 11:09 AM Allen Mauer mauera@gmail.com wrote:

Ugh....still getting this:

Traceback (most recent call last): File "", line 9, in File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\fast_arrow\resources\option_chain.py", line 19, in fetch return results[0] IndexError: list index out of range

On Mon, Sep 23, 2019 at 10:57 AM Allen Mauer mauera@gmail.com wrote:

Hi Weston, Thank you very much for attending to this issue. Did you recently remove the Stock.fetch() method? I am getting this error now while I try to load the stock to get the id:

stock = Stock.fetch(robinx, symb) optionid = stock['id']

DeprecatedWarning: fetch is deprecated as of 1.0.0 and will be removed in 1.1. Use 'StockMarketdata.quote_by_symbol' Traceback (most recent call last): File "", line 1, in File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\deprecation.py", line 247, in _inner return function(*args, **kwargs) File "C:\Users\mauer\Dropbox\upWork\venv2\lib\site-packages\fast_arrow\resources\stock.py", line 21, in fetch raise ApiDoesNotSupportError(message) fast_arrow.exceptions.ApiDoesNotSupportError: Robinhood API seems to not support this endpoint. Use fast_arrow.StockMarketdata.quote_by_symbol

I'm assuming there is now a new method to get the stock id / option; chain. I will investigate further. Thank you again.

On Mon, Sep 23, 2019 at 10:53 AM Weston Platter < notifications@github.com> wrote:

Closed #99 https://github.com/westonplatter/fast_arrow/issues/99.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/westonplatter/fast_arrow/issues/99?email_source=notifications&email_token=AAFGQ4FW6D7BDIOKLFFUFO3QLDX7TA5CNFSM4IY36I3KYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOTZBMZXY#event-2655177951, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFGQ4DNTN76OPIIAXIGYP3QLDX7TANCNFSM4IY36I3A .

-- V/R, Allen Mauer

-- V/R, Allen Mauer

-- V/R, Allen Mauer

-- V/R, Allen Mauer

-- V/R, Allen Mauer

-- V/R, Allen Mauer

westonplatter commented 4 years ago

Running this script,

import configparser
import json
from fast_arrow import (
    Client,
    StockMarketdata,
    OptionChain,
    Option,
)

with open("fast_arrow_auth.json") as f:
    auth_data = json.loads(f.read())

client = Client(auth_data)

symbol = "ROKU"
md = StockMarketdata.quote_by_symbol(client, symbol)

stock_id = md["instrument"].split("/")[-2]
option_chain = OptionChain.fetch(client, stock_id, symbol)
option_chain_id = option_chain["id"]
expiration_dates = option_chain['expiration_dates']

next_3_expiration_dates = expiration_dates[0:3]

ops = Option.in_chain(client, option_chain_id, expiration_dates=next_3_expiration_dates)

ops = Option.mergein_marketdata_list(client, ops)

print(f"{len(ops)} options for {symbol} within {next_3_expiration_dates}")

Prints this out,

638 options for ROKU within ['2019-09-27', '2019-10-04', '2019-10-11']
mauera commented 4 years ago

Ok perfect. I was using the client function from fast-arrow-auth. Once I used it to generate a credentials.json file I could then use that with the other client method and no errors this time. So in my opinion, it was related to my method of authentication, although this is confusing to me...i accept the outcome :) Thanks

On Mon, Sep 23, 2019 at 11:44 AM Weston Platter notifications@github.com wrote:

Running this script,

import configparser import json from fast_arrow import ( Client, StockMarketdata, OptionChain, Option, )

with open("fast_arrow_auth.json") as f: auth_data = json.loads(f.read())

client = Client(auth_data)

symbol = "ROKU" md = StockMarketdata.quote_by_symbol(client, symbol)

stock_id = md["instrument"].split("/")[-2] option_chain = OptionChain.fetch(client, stock_id, symbol) option_chain_id = option_chain["id"] expiration_dates = option_chain['expiration_dates']

next_3_expiration_dates = expiration_dates[0:3]

ops = Option.in_chain(client, option_chain_id, expiration_dates=next_3_expiration_dates)

ops = Option.mergein_marketdata_list(client, ops)

print(f"{len(ops)} options for {symbol} within {next_3_expiration_dates}")

Prints this out,

638 options for ROKU within ['2019-09-27', '2019-10-04', '2019-10-11']

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/westonplatter/fast_arrow/issues/99?email_source=notifications&email_token=AAFGQ4GFFYX5PNPKS2TI2X3QLD57XA5CNFSM4IY36I3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7LVYRY#issuecomment-534207559, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFGQ4EDFBAAQ2FZYADW6E3QLD57XANCNFSM4IY36I3A .

-- V/R, Allen Mauer

westonplatter commented 4 years ago

welcome!