Keyword Arguments¶
Regular¶
asynchronous¶
- Description: When set to
True
, requests made to Yahoo Finance will be made asynchronously - Default:
False
- Type:
bool
Tip
Only necessary when you have more than one symbol
symbols = 'fb aapl amzn nflx goog'
Ticker(
symbols,
asynchronous=True
)
backoff_factor¶
- Description: A factor, in seconds, to apply between attempts after the second try
- Default:
0.3
- Implementation:
{backoff_factor} * (2 ** ({number of total retries} - 1))
- Example: If the backoff factor is 0.1, then
sleep()
will sleep for [0.0s, 0.2s, 0.4s, ...] between retries
Ticker(
'aapl',
backoff_factor=1
)
country¶
- Description: Alter the language, region, and corsDomain that each request utilizes as a query parameter.
- Default:
United States
Info
This functionality has not been thoroughly tested as far as comparing data returned for each country. You will see a difference, though, in the data returned from the news method:
View Countries
{
'france': {
'lang': 'fr-FR',
'region': 'FR',
'corsDomain': 'fr.finance.yahoo.com'
},
'india': {
'lang': 'en-IN',
'region': 'IN',
'corsDomain': 'in.finance.yahoo.com'
},
'hong kong': {
'lang': 'zh-Hant-HK',
'region': 'HK',
'corsDomain': 'hk.finance.yahoo.com'
},
'germany': {
'lang': 'de-DE',
'region': 'DE',
'corsDomain': 'de.finance.yahoo.com'
},
'canada': {
'lang': 'en-CA',
'region': 'CA',
'corsDomain': 'ca.finance.yahoo.com'
},
'spain': {
'lang': 'es-ES',
'region': 'ES',
'corsDomain': 'es.finance.yahoo.com'
},
'italy': {
'lang': 'it-IT',
'region': 'IT',
'corsDomain': 'it.finance.yahoo.com'
},
'united states': {
'lang': 'en-US',
'region': 'US',
'corsDomain': 'finance.yahoo.com'
},
'australia': {
'lang': 'en-AU',
'region': 'AU',
'corsDomain': 'au.finance.yahoo.com'
},
'united kingdom': {
'lang': 'en-GB',
'region': 'GB',
'corsDomain': 'uk.finance.yahoo.com'
},
'brazil': {
'lang': 'pt-BR',
'region': 'BR',
'corsDomain': 'br.financas.yahoo.com'
},
'new zealand': {
'lang': 'en-NZ',
'region': 'NZ',
'corsDomain': 'nz.finance.yahoo.com'
},
'singapore': {
'lang': 'en-SG',
'region': 'SG',
'corsDomain': 'sg.finance.yahoo.com'
},
'taiwan': {
'lang': 'zh-tw',
'region': 'TW',
'corsDomain': 'tw.finance.yahoo.com'
},
}
Ticker(
'aapl',
country='France'
)
formatted¶
- Description - When
formatted=True
, most numerical data from the API will be returned as a dictionary:When formatted is set to False, an internal method will return the value in the "raw" key."totalCash": { "raw": 94051000320 "fmt": "94.05B" "longFmt": "94,051,000,320" }
- Default -
False
- Type -
bool
Warning
When formatted=True
, all data will be returned as a dict
Ticker(
'aapl',
formatted=True
)
max_workers¶
- Description - Defines the number of workers used to make asynchronous requests.
- Default -
8
- Type -
int
Tip
This is only relevant when asynchronous=True
Ticker(
'aapl',
asynchronous=True,
max_workers=4
)
progress¶
- Description: - Show a progress bar when downloading data
- Default -
False
- Type -
bool
Ticker(
'aapl',
progress=True
)
proxies¶
- Description - Make each request with a proxy. Simply pass a dictionary, mapping URL schemes to the URL to the proxy.
- Default -
None
- Type -
dict
Tip
You can also configure proxies by setting the environment variables HTTP_PROXY
and HTTPS_PROXY
.
proxies = {
'http': 'http://10.10.1.10:3128',
'https': 'http://10.10.1.10:1080',
}
Ticker(
'aapl',
proxies=proxies
)
retry¶
- Description - Number of times to retry a failed request
- Default -
5
- Type -
int
Ticker(
'aapl',
retry=10
)
status_forcelist¶
- Description - A set of integer HTTP status codes that we should force a retry on.
- Default -
[429, 500, 502, 503, 504]
- Type -
list
Tip
This is especially useful when retrieving historical pricing data for a large amount of symbols. Currently, Yahoo Finance has been displaying 404 errors for mass download requests.
Ticker(
'aapl',
status_forcelist=[404, 429, 500, 502, 503, 504]
)
timeout¶
- Description - Stop waiting for a response after a given number of seconds
- Default -
5
- Type -
int
Note
This is not a time limit on the entire response download; rather, an exception is raised if the server has not issued a response for timeout seconds (more precisely, if no bytes have been received on the underlying socket for timeout seconds). If no timeout is specified explicitly, requests do not time out.
Ticker(
'aapl',
timeout=3
)
user_agent¶
- Description - A browser's user-agent string that is sent with the headers with each request.
- Default - Random selection from the list below:
USER_AGENT_LIST = [ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', ]
- Type -
str
Ticker(
'aapl',
user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
)
validate¶
- Description - Validate existence of symbols during instantiation. Invalid symbols will be dropped but you can view them through the
invalid_symbols
property. - Default -
False
- Type -
bool
from yahooquery import Ticker
symbols = 'fb facebook aapl apple amazon amzn netflix nflx goog alphabet'
t = Ticker(
symbols,
validate=True)
print(t.symbols)
['NFLX', 'GOOG', 'AAPL', 'FB', 'AMZN']
print(t.invalid_symbols)
['FACEBOOK', 'AMAZON', 'APPLE', 'NETFLIX', 'ALPHABET']
verify¶
- Description - Either a boolean, in which case it controls whether we verify the server’s TLS certificate, or a string, in which case it must be a path to a CA bundle to use.
- Default -
True
- Type -
bool
orstr
Ticker(
'aapl',
verify=False
)
Premium¶
username and password¶
- Description: If you're a subscriber to Yahoo Finance Premium, you'll be able to retrieve data available through that subscription. Simply pass your
username
andpassword
to theTicker
class
Note
Selenium is utilized to login to Yahoo. It should take around 15-20 seconds to login.
Tip
Set environment variables for your username and password as YF_USERNAME
and YF_PASSWORD
, respectively.
Ticker(
'aapl',
username='fake_username',
password='fake_password'
)
Advanced¶
crumb and session¶
- Description: Some requests to Yahoo Finance require a crumb to make the request. This is only utilized for advanced configuration
- Default:
None
- Type:
str
See the Advanced Section