Code Monkey home page Code Monkey logo

wallstreet's Introduction

Wallstreet: Real time Stock and Option tools

Wallstreet is a Python 3 library for monitoring and analyzing real time Stock and Option data. Quotes are provided from the Google Finance API. Wallstreet requires minimal input from the user, it uses available online data to calculate option greeks and even scrapes the US Treasury website to get the current risk free rate.

Usage

Stocks:

from wallstreet import Stock, Call, Put

>>> s = Stock('AAPL')
>>> s.price
96.44
>>> s.price
96.48
>>> s.change
-0.35
>>> s.last_trade
'21 Jan 2016 13:32:12'

Options:

>>> g = Call('GOOG', d=12, m=2, y=2016, strike=700)
>>> g.price
38.2
>>> g.implied_volatility()
0.49222968442691889
>>> g.delta()
0.56522039722040063
>>> g.vega()
0.685034827159825
>>> g.underlying.price
706.59

Alternative construction:

>>> g = Call('GOOG', d=12, m=2, y=2016)
>>> g
Call(ticker=GOOG, expiration='12-02-2016')
>>> g.strikes
(580, 610, 620, 630, 640, 650, 660, 670, 680, 690, 697.5, 700, 702.5, 707.5, 710, 712.5, 715, 720, ...)
>>> g.set_strike(712.5)
>>> g
Call(ticker=GOOG, expiration='12-02-2016', strike=712.5)

or

>>> g = Put("GOOG")
'No options listed for given date, using 22-01-2016 instead'
>>> g.expirations
['22-01-2016', '29-01-2016', '05-02-2016', '12-02-2016', '19-02-2016', '26-02-2016', '04-03-2016', ...]
>>> g
Put(ticker=GOOG, expiration='22-01-2016')

Yahoo Finance Support (keep in mind that YF quotes might be delayed):

>>> apple = Stock('AAPL', source='yahoo')
>>> call = Call('AAPL', strike=apple.price, source='yahoo')
No options listed for given date, using '26-05-2017' instead
No option for given strike, using 155 instead

Download historical data (requires pandas)

s = Stock('BTC-USD')
>>> df = s.historical(days_back=30, frequency='d')
>>> df
         Date          Open          High           Low         Close     Adj Close      Volume
0  2019-07-10  12567.019531  13183.730469  11569.940430  12099.120117  12099.120117  1554955347
1  2019-07-11  12099.120117  12099.910156  11002.389648  11343.120117  11343.120117  1185222449
2  2019-07-12  11343.120117  11931.910156  11096.610352  11797.370117  11797.370117   647690095
3  2019-07-13  11797.370117  11835.870117  10827.530273  11363.969727  11363.969727   668325183
4  2019-07-14  11363.969727  11447.919922  10118.849609  10204.410156  10204.410156   814667763
5  2019-07-15  10204.410156  11070.179688   9877.019531  10850.259766  10850.259766   965178341
6  2019-07-16  10850.259766  11025.759766   9366.820313   9423.440430   9423.440430  1140137759
7  2019-07-17   9423.440430   9982.240234   9086.509766   9696.150391   9696.150391   965256823
8  2019-07-18   9696.150391  10776.540039   9292.610352  10638.349609  10638.349609  1033842556
9  2019-07-19  10638.349609  10757.410156  10135.160156  10532.940430  10532.940430   658190962
10 2019-07-20  10532.940430  11094.320313  10379.190430  10759.419922  10759.419922   608954333
11 2019-07-21  10759.419922  10833.990234  10329.889648  10586.709961  10586.709961   405339891
12 2019-07-22  10586.709961  10676.599609  10072.070313  10325.870117  10325.870117   524442852
13 2019-07-23  10325.870117  10328.440430   9820.610352   9854.150391   9854.150391   529438124
14 2019-07-24   9854.150391   9920.540039   9535.780273   9772.139648   9772.139648   531611909
15 2019-07-25   9772.139648  10184.429688   9744.700195   9882.429688   9882.429688   403576364
16 2019-07-26   9882.429688   9890.049805   9668.519531   9847.450195   9847.450195   312717110
17 2019-07-27   9847.450195  10202.950195   9310.469727   9478.320313   9478.320313   512612117
18 2019-07-28   9478.320313   9591.519531   9135.639648   9531.769531   9531.769531   267243770
19 2019-07-29   9531.769531   9717.690430   9386.900391   9506.929688   9506.929688   299936368
20 2019-07-30   9506.929688   9749.530273   9391.780273   9595.519531   9595.519531   276402322
21 2019-07-31   9595.519531  10123.940430   9581.599609  10089.250000  10089.250000   416343142
22 2019-08-01  10089.250000  10488.809570   9890.490234  10409.790039  10409.790039   442037342
23 2019-08-02  10409.790039  10666.639648  10340.820313  10528.990234  10528.990234   463688251
24 2019-08-03  10528.990234  10915.000000  10509.349609  10820.410156  10820.410156   367536516
25 2019-08-04  10820.410156  11074.950195  10572.240234  10978.910156  10978.910156   431699306
26 2019-08-05  10978.910156  11945.379883  10978.889648  11807.959961  11807.959961   870917186
27 2019-08-06  11807.959961  12316.849609  11224.099609  11467.099609  11467.099609   949534020
28 2019-08-07  11467.099609  12138.549805  11393.980469  11974.280273  11974.280273   834719365
29 2019-08-08  11974.280273  12042.870117  11498.040039  11982.799805  11982.799805   588463519
30 2019-08-09  11983.620117  12027.570313  11674.059570  11810.679688  11810.679688   366160288

Installation

Simply

$ pip install wallstreet

Stock Attributes

  • ticker
  • price
  • id
  • exchange
  • last_trade
  • change (change in currency)
  • cp (percentage change)

Option Attributes and Methods

  • strike
  • expiration
  • underlying (underlying stock object)
  • ticker
  • bid
  • ask
  • price (option price)
  • id
  • exchange
  • change (in currency)
  • cp (percentage change)
  • volume
  • open_interest
  • code
  • expirations (list of possible expiration dates for option chain)
  • strikes (list of possible strike prices)
  • set_strike()
  • implied_volatility()
  • delta()
  • gamma()
  • vega()
  • theta()
  • rho()

wallstreet's People

Contributors

billjr99 avatar mcdallas avatar sorying avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wallstreet's Issues

wallstreet does not recognise source argument when using Put()

I want to analyze some option chains and data is not available using Google Finance. When I try to use Yahoo finance as a source I get the following error.

from wallstreet import Call, Put, Stock

put_premium = 0.32
underlying = Stock('P')
put_option = Put('P', d=16, m=6, y=2017, strike=8, source='yahoo')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-23-ecc5f3a5a2ce> in <module>()
      1 put_premium = 0.32
      2 underlying = Stock('P')
----> 3 put_option = Put('P', d=16, m=6, y=2017, strike=8, source='yahoo')

TypeError: __init__() got an unexpected keyword argument 'source'

My package version

wallstreet 0.1.5
Python version 3.6.0

ValueError when there is only call or only put in the most recent expiration date

jnj = wallstreet.Call("JNJ", source="yahoo")

gives this error:

ValueError: ('Possible expiration dates for this stock are:', ['13-04-2017', '21-04-2017', '05-05-2017', '12-05-2017', '19-05-2017', '26-05-2017', '16-06-2017', '21-07-2017', '20-10-2017', '19-01-2018', '15-06-2018', '18-01-2019'])

And that's because on expiration 13-04-2017, there is only put option, no call option. For the rest of the expiration dates, there are both calls and puts.
screen shot 2017-04-10 at 5 05 32 pm

Is there anyway to not throw ValueError, and instead find the nearest date that do have calls? Thanks!

Index Option Quotes

Were you ever able to get this to return Index Option Quotes?

For example:
g=Call('INDEXSP:.INX', d=20, m=10, y=2016, strike=2150)

Tried d=20 as well as 21
Tried INDEXSP, SPX, INDEXCBOE:SPX and a few other variations, but could not get index option data.

One issue is that it will return the same error message "No options listed for this stock." even if the date is incorrect - but I guess that you get a JSON object without a list of valid options and it does not tell you whether the expiry is valid or not - so can not fix that easily.

However, knowing the codes to get this API to show option data for SPX, RUT, NDX and other major indices will be very helpful.

Yahoo Finance update caused Stock.historical() not work

It seems Yahoo Finance website updated with some encryption in middle of Dec 2022. so the historical() in the Stock didn't work well now.

Python 3.10.8 (main, Nov 24 2022, 14:13:03) [GCC 11.2.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.6.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import wallstreet

In [2]: aapl = wallstreet.Stock("AAPL")

In [3]: aapl
Out[3]: Stock(ticker=AAPL, price=129.98)

In [4]: aapl.historical(7)

ValueError Traceback (most recent call last)
Cell In [4], line 1
----> 1 aapl.historical(7)

File ~/anaconda3/envs/py3a/lib/python3.10/site-packages/wallstreet/wallstreet.py:208, in Stock.historical(self, days_back, frequency)
207 def historical(self, days_back=30, frequency='d'):
--> 208 return YahooFinanceHistory(symbol=self.ticker, days_back=days_back, frequency=frequency).get_quote()

File ~/anaconda3/envs/py3a/lib/python3.10/site-packages/wallstreet/wallstreet.py:97, in YahooFinanceHistory.get_quote(self)
94 raise ImportError('This functionality requires pandas to be installed')
96 if not hasattr(self, 'crumb') or len(self.session.cookies) == 0:
---> 97 self.get_crumb()
98 now = datetime.utcnow()
99 dateto = int(now.timestamp())

File ~/anaconda3/envs/py3a/lib/python3.10/site-packages/wallstreet/wallstreet.py:86, in YahooFinanceHistory.get_crumb(self)
84 match = re.search(self.crumb_regex, response.text)
85 if not match:
---> 86 raise ValueError('Could not get crumb from Yahoo Finance')
87 else:
88 self.crumb = match.group(1)

ValueError: Could not get crumb from Yahoo Finance

In [5]:

Slow Response Time

Over the last four weeks, the response time to get Options data using Wallstreet is very slow. It takes almost on hour to get Call and Put values for a list of 8 stocks (AMZN, ABA, GOOGL, ISRG, NVDA, PCLN,SPY, and TSLA). Four weeks ago I could pull the data in about 5 minutes. I am not sure what changed in Yahoo Finance. Any suggestions or thoughts about how long this should take or how I can speed up the process?

Import Failure

The statement "import wallstreet" returns an error message.

" File "C:\Anaconda2\lib\site-packages\wallstreet\wallstreet.py", line 125
raise ValueError('Possible expiration dates for this stock are:', self.expirations) from None"

"No options listed for stock", but it exists in yahoo finance

First of all, thank you so much for this amazing library. It is really useful and easy to use.

I have noticed a problem that happens from time to time, a LookUp error in "normal" stocks. For example, as of now (Dec 1st) if you try to search for OTIS options...
E1  No OTIS options on Dic 1st
Sometimes yahoo finance doesn´t have options data (it happens especially with options on indices like ^SPX), but this is not the case this time:
E1  But they exists in YF

Do you know why this happens?

Thank you again for your great work

Inconsistent error messages when passing invalid tickers under default options

First of all, thank you for putting this API together. It's been fun becoming familiar with it. My use case for this is a bot where people are passing requests and some of them have been garbage requests for stock tickers that do not actually exist. The errors thrown by wallstreet.Stock have varied which surprised me. For example, Stock("XRP") will raise a KeyError, where Stock("RNDR") will raise an IndexError. I went to look into the code for Stock and found that no matter what I passed as an input, I could not trigger the LookupError on line 136 of wallstreet.py. It appears that the yahoo API returns status_code 200 for any successful request even if the stock does not exist.

Source='google' option fails

It appears that attempting to call any valid ticker with the source='google' option fails. Line 168 of wallstreet.py is a "catch all" exception that is resulting in a LookupError being thrown even when a valid symbol is passed. Just spending a few minutes trying to find the source on the issue leads me to believe that the response text from line 162 is html rather than something that json.loads() can parse.

ModuleNotFound error with options test file

I've installed wallstreet per the instructions with pip and everything seemed to go fine with no errors, but when I run the test files I get:

from wallstreet import wallstreet, blackandscholes ModuleNotFoundError: No module named 'wallstreet'

Ideas?

Index Quote issue

when trying to pull index options from yahoo im getting an error:
self.name = jayson['longName']
KeyError: 'longName'

The ticker is "^SPX" and the caret is causing the code to break. "SPY" or "MSFT" work very well.

scipy

When I installed and ran, it failed because there was no scipy.

I was able to pip3.5 install scipy but maybe it could be part of setup.py

Thanks !!

'bid' and 'ask' are often 0, in an inconsistent pattern

call = Call('SPY', d=18, m=12, y=2020)
print(call.strikes[30:40])

call.set_strike(211)
print(call.ask)
call.set_strike(212)
print(call.ask)
call.set_strike(213)
print(call.ask)

Output:

(205, 207, 208, 209, 210, 211, 212, 213, 214, 215)
0.0
79.43
0.0

This seems to happens mostly at night, when the market is closed.

SyntaxError: invalid syntax

Traceback (most recent call last):
File ".\main.py", line 6, in
from wallstreet import Stock, Call, Put
File "C:\Users\Vlessa.terceiro.windows-build-tools\python27\lib\site-packages\wallstreet_init_.py", line 1, in
from wallstreet.wallstreet import Stock, Call, Put
File "C:\Users\Vlessa.terceiro.windows-build-tools\python27\lib\site-packages\wallstreet\wallstreet.py", line 92
params = {'period1': datefrom, 'period2': dateto, 'interval': f'1{self.frequency}', 'events': 'history', 'crumb': self.crumb}

run code :

from wallstreet import Stock, Call, Put
s = Stock('AAPL')

issue simple usage of wallstreet

Hi Im having the following issue just by trying to create a Stock('GOOG'):


JSONDecodeError Traceback (most recent call last)
in ()
----> 1 s = ws.Stock('GOOG')

~\Anaconda3\lib\site-packages\wallstreet\wallstreet.py in init(self, quote, exchange)
45
46 jayson = r.text.replace('\n','')
---> 47 jayson = json.loads(jayson[2:])[0]
48
49 try:

~\Anaconda3\lib\json_init_.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
352 parse_int is None and parse_float is None and
353 parse_constant is None and object_pairs_hook is None and not kw):
--> 354 return _default_decoder.decode(s)
355 if cls is None:
356 cls = JSONDecoder

~\Anaconda3\lib\json\decoder.py in decode(self, s, _w)
337
338 """
--> 339 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
340 end = _w(s, end).end()
341 if end != len(s):

~\Anaconda3\lib\json\decoder.py in raw_decode(self, s, idx)
355 obj, end = self.scan_once(s, idx)
356 except StopIteration as err:
--> 357 raise JSONDecodeError("Expecting value", s, err.value) from None
358 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Can someone help with that ?

Thanks.
Willian

Traceback on import

Getting this:

from wallstreet import Stock, Call, Put
Traceback (most recent call last):
File "", line 1, in
File "/Library/Python/2.7/site-packages/wallstreet/init.py", line 1, in
from wallstreet.wallstreet import Stock, Call, Put
File "/Library/Python/2.7/site-packages/wallstreet/wallstreet.py", line 196
raise ValueError('Possible expiration dates for this option are:', self.expirations) from None
^
SyntaxError: invalid syntax

Running:

sys.version
'2.7.10 (default, Oct 23 2015, 19:19:21) \n[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)]'

on a mac. Is 2.7 not supported? Thx.

Question: Google Finance API and Scipy

Hi mcdallas,

I have a question, on the description there's statement "provided from the Google Finance API"
Isn't the Google Finance API has been shut down?

is this library still work?

Thank you :)

error importing wallstreet package

Here is the error from simply importing. The 'pip install wallstreet' worked just fine.

PS C:\Users\larry\OneDrive\Documents\PythonProjects\options> python
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 16:30:00) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

from wallstreet import Stock, Call, Put
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\larry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\wallstreet_init_.py", line 1, in
from wallstreet.wallstreet import Stock, Call, Put
File "C:\Users\larry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\wallstreet\wallstreet.py", line 10, in
from wallstreet.blackandscholes import riskfree, BlackandScholes
File "C:\Users\larry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\wallstreet\blackandscholes.py", line 4, in
from scipy.interpolate import interp1d
File "C:\Users\larry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\scipy_init_.py", line 136, in
from . import distributor_init
File "C:\Users\larry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\scipy_distributor_init.py", line 61, in
WinDLL(os.path.abspath(filename))
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\ctypes_init
.py", line 364, in init
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

Error raised by query2.finance.yahoo.com

This example was working a couple of days ago. Today it is raising an error.

from wallstreet import Stock, Call, Put
s = Stock('AAPL')
Traceback (most recent call last):
File "", line 1, in
File "/Volumes/Backup/Users/......./anaconda3/lib/python3.7/site-packages/wallstreet/wallstreet.py", line 112, in init
self._yahoo(quote, exchange)
File "/Volumes/Backup/Users/......./anaconda3/lib/python3.7/site-packages/wallstreet/wallstreet.py", line 126, in _yahoo
r.raise_for_status()
File "/Volumes/Backup/Users/......./anaconda3/lib/python3.7/site-packages/requests/models.py", line 943, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://query2.finance.yahoo.com/v7/finance/options/AAPL

Google Finance Change

It appears that Google Finance has made another change in their API so Wallstreet is unable to find any stocks. I reloaded the Wallstreet module this morning but this didn't fix the issue. Is a change in work for Wlalstreet?

API change?

Ran below in the python 3.6 Conda container. Test isn't passing and seemed to work previously

s = Stock('GE',exchange='NYSE',source='google')
Traceback (most recent call last):
File "", line 1, in
File "/opt/conda/lib/python3.6/site-packages/wallstreet/wallstreet.py", line 66, in init
self._google(quote, exchange)
File "/opt/conda/lib/python3.6/site-packages/wallstreet/wallstreet.py", line 114, in _google
raise LookupError('Ticker symbol not found. Try adding the exchange parameter')

s = Stock('GE',exchange='NYSE',source='yahoo')
Traceback (most recent call last):
File "", line 1, in
File "/opt/conda/lib/python3.6/site-packages/wallstreet/wallstreet.py", line 68, in init
self._yahoo(quote, exchange)
File "/opt/conda/lib/python3.6/site-packages/wallstreet/wallstreet.py", line 80, in _yahoo
raise LookupError('Ticker symbol not found.')
LookupError: Ticker symbol not found.

Call(ticker) fails after multiple runs

In my application, I want to extract options data per minute for one of the tickers. What my python code does as of now is following:

g = Call(Ticker)
exp_dates = g.expiration_dates()
for each expiration date:
g = Call(Ticker, d, m, y)
dat = g.calls()
g = Put(Ticker, d, m, y)
dat = g.calls()
store cumulative data to database

However, after running this code successfully 3 times at 2 minute interval, the 4th time code fails with following error:
"raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)"
at g = Call(Ticker)

After an hour or so, the code starts working again. And again after 3 runs, it fails.

Please let me know if there is some limitation with wallstreet or it is something I am missing out.

Thanks in advance :)

Theta values on short duration options

I'm running into an issue where the theta values for short duration options are about 25-30% off of what I can see on my ThinkorSwim platform. The absolute value of the theta values should be larger generally than the method returns. The theta values are ok for options that are multiple months out however.

Is there volume for Stock()?

Probably Google doesn't provide it, so here goes a silly question: Will there be any change to get volume for Stock("TICK")? Otherwise thank you for the code, works smoothly.

Executin Error

I have been using Wallstreet successful for the last few months. This weekend, I started getting the following error message: LookupError('Ticker symbol not found. Try adding the exchange parameter')
LookupError: Ticker symbol not found. Try adding the exchange parameter. I haven't changed anything in my program including the stock symbols. Has something Wallstreet changed?

Numerous RuntimeWarning for internal procedures

Hello!

  1. In most of my cases by calling wallstreet_obj.delta() causes this warning:

C:\Program Files\Python38\lib\site-packages\wallstreet\blackandscholes.py:58: RuntimeWarning: divide by zero encountered in double_scalars
d1 = (log(S/K) + (r - q + (sigma**2)/2)T)/(sigmasqrt(T))

  1. also there is another annoying warning for this line:

wallstreet_obj.set_strike(float(str))

d:\Program Files\Python38\lib\site-packages\scipy\optimize\minpack.py:162: RuntimeWarning: The iteration is not making good progress, as measured by the
improvement from the last ten iterations.

Please check it out.

Regards.

risk free rate month2 missing

hi, maybe the yield webpage has changed but on the treasury webpage there is a month 2 yield which seems to be missing in the blackandscholes.py / riskfree function. Therefore all yields after month 1 have the yield of the following month

import error

After a successful pip install, when importing into python it immediately hits this error, the wedge points at "from" in the "from None".

Charles-Hsu-MacBook-Pro:~ Charles$ python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 26 2016, 12:10:39)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import wallstreet
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wallstreet/init.py", line 1, in
from wallstreet.wallstreet import Stock, Call, Put
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wallstreet/wallstreet.py", line 125
raise ValueError('Possible expiration dates for this stock are:', self.expirations) from None
^
SyntaxError: invalid syntax

.HTTPError exception

Hello there.

Calling by this:
opt_obj = Call('FB', d=17, m=4, y=2020 )

causes next error and script halt:

File "D:\WorkDir\script.py", line 62, in
opt_obj = ('FB', d=17, m=4, y=2020 )
File "с:\Program Files\Python38\Lib\site-packages\wallstreet\wallstreet.py", line 325, in init
super().init(quote, self.class.Option_type, **kw)
File "с:\Program Files\Python38\Lib\site-packages\wallstreet\wallstreet.py", line 218, in init
self._yahoo(quote, d, m, y)
File "с:\Program Files\Python38\Lib\site-packages\wallstreet\wallstreet.py", line 257, in _yahoo
r.raise_for_status()
File "с:\Program Files\Python38\Lib\site-packages\requests\models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)

requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: https://query2.finance.yahoo.com/v7/finance/options/FB?date=1587081600

I know, that's not because of your code, but need a solution.

Regards.

Is it possible to use Yahoo instead of Google?

Google Finance is somewhat spotty in terms of option data, and I'd like to use Yahoo instead. It seems from your code that Yahoo is supported, but not sure whether it works on current site, or what the correct flag is to change sources.

Getting a 403 Client Error for any request

Any stock, call, put requesting is returning with
403 Client Error: Forbidden for url: https://query2.finance.yahoo.com/v7/finance/options/[STOCK TICKER]

Anyone else seeing this or know of a workaround?

LookupError: Ticker symbol not found. Try adding the exchange parameter

Hi

this package seems very interesting, I tried using it with Stock with ticker MTCH

tried:
s = Stock('MTCH')

LookupError: Ticker symbol not found. Try adding the exchange parameter

s = Stock('MTCH',exchange="NASDAQ")

LookupError: Ticker symbol not found. Try adding the exchange parameter

s = Stock('MTCH',exchange="NASD")
LookupError: Ticker symbol not found. Try adding the exchange parameter

tried:
pip install --upgrade git+https://github.com/mcdallas/wallstreet.git

got the same error in all three cases

Issue with wallstreet module

I am trying to get Call and Put data for Options that I know exist for several stocks. I get the following data output using wallstreet 0.1.5: No options listed for given date, using 16-06-2017 instead. I am trying to get Call and Put option values for expiration dates of 19-05-2017 for AAPL and GOOGL. Can you help me extract this data using wallstreet?

Mutual funds not reporting properly

Google's mechanism to report mutual funds is a bit different, and the way it returns data sometimes has a ',}' that causes the json parser to hit an exception. Also, the keys are different from non-mutual funds. I used the hackery below to get past it, but you may want to do something more elegant:

try:
jayson = r.text.replace('\n', '')
# mutual funds have a ,} that messes up the json parser
jayson = jayson.replace(',}','}')
jayson = json.loads(jayson[2:])[0]
self.ticker = jayson['t']
except:
self.ticker = None

    if r.status_code == 400 or self.ticker != query.split(':')[-1]:
        raise LookupError('Ticker symbol not found. Try adding the exchange parameter')
    else:
        r.raise_for_status()

    self.id = jayson["id"]
    self.exchange = jayson['e']
    self._last_trade = None
    self.name = jayson['name']
    if self.exchange != 'MUTF':
        self._price = parse(jayson['l'])
        try:
            self.change = parse(jayson['c'])
            self.cp = parse(jayson['cp'])
        except ValueError:
            self.change = jayson['c']
            self.cp = jayson['cp']

        self.dy = parse(jayson.get('dy') or 0)/100
    else:
        self._price = parse(jayson['nav_prior'])
        try:
            self.change = parse(jayson['nav_c'])
            self.cp = parse(jayson['nav_cp'])
        except ValueError:
            self.change = jayson['nav_c']
            self.cp = jayson['nav_cp']
        self.dy = parse(jayson.get('yield_percent') or 0) / 100

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.