2021-05-26 19:51:30 -07:00
|
|
|
`stockquotes` is a simple Python module for collecting stock/ETF and mutual fund (see #2) quotes and
|
2020-04-20 07:09:04 -07:00
|
|
|
historical data from Yahoo! Finance. It's perfect for developers who can't
|
|
|
|
afford the (often high) prices charged by many stock data APIs.
|
|
|
|
|
2020-04-20 07:00:28 -07:00
|
|
|
# Requirements
|
2020-04-20 07:37:07 -07:00
|
|
|
* Python 3.5+
|
2020-04-20 07:00:28 -07:00
|
|
|
* Beautiful Soup 4
|
2020-04-20 07:09:04 -07:00
|
|
|
|
2020-04-20 07:00:28 -07:00
|
|
|
# Installation
|
2020-04-20 07:37:07 -07:00
|
|
|
|
2020-04-20 07:00:28 -07:00
|
|
|
pip3 install stockquotes
|
2020-04-20 07:09:04 -07:00
|
|
|
|
2020-04-20 07:00:28 -07:00
|
|
|
# Usage
|
|
|
|
First, import the `stockquotes` module.
|
|
|
|
|
|
|
|
import stockquotes
|
|
|
|
|
2020-04-20 07:09:04 -07:00
|
|
|
To get a stock quote, instantiate a `stockquotes.Stock` object. The only
|
|
|
|
parameter is the ticker symbol to look up.
|
2020-04-20 07:00:28 -07:00
|
|
|
|
|
|
|
kroger = stockquotes.Stock('KR')
|
|
|
|
|
|
|
|
## Basic data
|
2020-04-20 07:37:07 -07:00
|
|
|
To get the current price of a share, get the `Stock`'s `current_price`.
|
2020-04-20 07:00:28 -07:00
|
|
|
|
2020-11-16 07:30:23 -08:00
|
|
|
kroger_price = kroger.current_price
|
2020-04-20 07:00:28 -07:00
|
|
|
|
2020-04-20 07:37:07 -07:00
|
|
|
To get the day gain in dollars, get the `Stock`'s `increase_dollars`.
|
2020-04-20 07:00:28 -07:00
|
|
|
|
2020-11-16 07:30:23 -08:00
|
|
|
kroger_gain_dollars = kroger.increase_dollars
|
2020-04-20 07:00:28 -07:00
|
|
|
|
2020-04-20 07:37:07 -07:00
|
|
|
The same value as a percent is available in the `increase_percent` property. To
|
2020-04-20 07:09:04 -07:00
|
|
|
indicate losses, these values are negative.
|
2020-04-20 07:00:28 -07:00
|
|
|
|
|
|
|
## Historical data
|
2020-04-20 07:09:04 -07:00
|
|
|
The historical data for a stock can be accessed through the `Stock`'s
|
|
|
|
`historical` property. This is an array of `dict`s, with the first item
|
|
|
|
representing the most recent quote. The `dict`'s `date` property is a
|
|
|
|
`datetime` object representing the date the quote is from. `open` is the
|
|
|
|
opening price for that day. `high` and `low` are the high and low prices,
|
2020-04-20 07:37:07 -07:00
|
|
|
respectively, for that day. `close` and `adjusted_close` are the closing
|
|
|
|
price. The difference is that `adjClose` is adjusted for splits and
|
|
|
|
dividends, whereas `close` is adjusted only for splits. `volume` is the
|
|
|
|
stock's volume for that day.
|
2020-04-20 07:09:04 -07:00
|
|
|
|
|
|
|
Typically, this should give at least a month of data. Obviously, it gives less
|
|
|
|
for recent IPOs. Also, a known but unexplained bug causes it to only give two
|
|
|
|
days of data for some stocks.
|
|
|
|
|
2020-04-20 07:00:28 -07:00
|
|
|
# Exceptions
|
|
|
|
`stockquotes.StockDoesNotExistError` is raised when the stock does not exist.
|
2020-04-20 07:09:04 -07:00
|
|
|
|
|
|
|
`stockquotes.NetworkError` is raised when a connection to Yahoo! Finance
|
|
|
|
cannot be established.
|
|
|
|
|
2020-04-20 07:00:28 -07:00
|
|
|
# License
|
|
|
|
This is free and unencumbered software released into the public domain.
|
|
|
|
|
|
|
|
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
|
|
distribute this software, either in source code form or as a compiled
|
|
|
|
binary, for any purpose, commercial or non-commercial, and by any
|
|
|
|
means.
|
|
|
|
|
|
|
|
In jurisdictions that recognize copyright laws, the author or authors
|
|
|
|
of this software dedicate any and all copyright interest in the
|
|
|
|
software to the public domain. We make this dedication for the benefit
|
|
|
|
of the public at large and to the detriment of our heirs and
|
|
|
|
successors. We intend this dedication to be an overt act of
|
|
|
|
relinquishment in perpetuity of all present and future rights to this
|
|
|
|
software under copyright law.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
For more information, please refer to <https://unlicense.org/>
|