Skip to content

Commit e0fdd58

Browse files
authored
Merge pull request #2410 from ranaroussi/dev
sync dev -> main
2 parents 4ecd6a6 + 1ed7c39 commit e0fdd58

33 files changed

+1164
-435
lines changed

doc/source/advanced/config.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
******
2+
Config
3+
******
4+
5+
`yfinance` has a new global config for sharing common values.
6+
7+
Proxy
8+
-----
9+
10+
Set proxy once in config, affects all yfinance data fetches.
11+
12+
.. code-block:: python
13+
14+
import yfinance as yf
15+
yf.set_config(proxy="PROXY_SERVER")

doc/source/advanced/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ Advanced
66
:maxdepth: 2
77

88
logging
9-
proxy
9+
config
1010
caching
1111
multi_level_columns

doc/source/advanced/proxy.rst

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import yfinance as yf
2+
3+
# Get All
4+
all = yf.Lookup("AAPL").all
5+
all = yf.Lookup("AAPL").get_all(count=100)
6+
7+
# Get Stocks
8+
stock = yf.Lookup("AAPL").stock
9+
stock = yf.Lookup("AAPL").get_stock(count=100)
10+
11+
# Get Mutual Funds
12+
mutualfund = yf.Lookup("AAPL").mutualfund
13+
mutualfund = yf.Lookup("AAPL").get_mutualfund(count=100)
14+
15+
# Get ETFs
16+
etf = yf.Lookup("AAPL").etf
17+
etf = yf.Lookup("AAPL").get_etf(count=100)
18+
19+
# Get Indices
20+
index = yf.Lookup("AAPL").index
21+
index = yf.Lookup("AAPL").get_index(count=100)
22+
23+
# Get Futures
24+
future = yf.Lookup("AAPL").future
25+
future = yf.Lookup("AAPL").get_future(count=100)
26+
27+
# Get Currencies
28+
currency = yf.Lookup("AAPL").currency
29+
currency = yf.Lookup("AAPL").get_currency(count=100)
30+
31+
# Get Cryptocurrencies
32+
cryptocurrency = yf.Lookup("AAPL").cryptocurrency
33+
cryptocurrency = yf.Lookup("AAPL").get_cryptocurrency(count=100)

doc/source/reference/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The following are the publicly available classes, and functions exposed by the `
1818
- :attr:`Market <yfinance.Market>`: Class for accessing market summary.
1919
- :attr:`download <yfinance.download>`: Function to download market data for multiple tickers.
2020
- :attr:`Search <yfinance.Search>`: Class for accessing search results.
21+
- :attr:`Lookup <yfinance.Lookup>`: Class for looking up tickers.
2122
- :attr:`Sector <yfinance.Sector>`: Domain class for accessing sector information.
2223
- :attr:`Industry <yfinance.Industry>`: Domain class for accessing industry information.
2324
- :attr:`Market <yfinance.Market>`: Class for accessing market status & summary.
@@ -39,6 +40,7 @@ The following are the publicly available classes, and functions exposed by the `
3940
yfinance.analysis
4041
yfinance.market
4142
yfinance.search
43+
yfinance.lookup
4244
yfinance.sector_industry
4345
yfinance.screener
4446
yfinance.functions

doc/source/reference/yfinance.search.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
=====================
2-
Search & News
2+
Search & Lookup
33
=====================
44

55
.. currentmodule:: yfinance
@@ -14,9 +14,21 @@ The `Search` module, allows you to access search data in a Pythonic way.
1414

1515
Search
1616

17-
Search Sample Code
17+
The `Lookup` module, allows you to look up tickers in a Pythonic way.
18+
19+
.. autosummary::
20+
:toctree: api/
21+
22+
Lookup
23+
24+
Sample Code
1825
------------------
1926
The `Search` module, allows you to access search data in a Pythonic way.
2027

2128
.. literalinclude:: examples/search.py
2229
:language: python
30+
31+
The `Lookup` module, allows you to look up tickers in a Pythonic way.
32+
33+
.. literalinclude:: examples/lookup.py
34+
:language: python

tests/test_cache.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
python -m unittest tests.cache.TestCache
99
1010
"""
11-
from unittest import TestSuite
12-
1311
from tests.context import yfinance as yf
1412

1513
import unittest
@@ -48,46 +46,5 @@ def test_setTzCacheLocation(self):
4846
self.assertTrue(os.path.exists(os.path.join(self.tempCacheDir.name, "tkr-tz.db")))
4947

5048

51-
class TestCacheNoPermission(unittest.TestCase):
52-
@classmethod
53-
def setUpClass(cls):
54-
if os.name == "nt": # Windows
55-
cls.cache_path = "C:\\Windows\\System32\\yf-cache"
56-
else: # Unix/Linux/MacOS
57-
# Use a writable directory
58-
cls.cache_path = "/yf-cache"
59-
yf.set_tz_cache_location(cls.cache_path)
60-
61-
def test_tzCacheRootStore(self):
62-
# Test that if cache path in read-only filesystem, no exception.
63-
tkr = 'AMZN'
64-
tz1 = "America/New_York"
65-
66-
# During attempt to store, will discover cannot write
67-
yf.cache.get_tz_cache().store(tkr, tz1)
68-
69-
# Handling the store failure replaces cache with a dummy
70-
cache = yf.cache.get_tz_cache()
71-
self.assertTrue(cache.dummy)
72-
cache.store(tkr, tz1)
73-
74-
def test_tzCacheRootLookup(self):
75-
# Test that if cache path in read-only filesystem, no exception.
76-
tkr = 'AMZN'
77-
# During attempt to lookup, will discover cannot write
78-
yf.cache.get_tz_cache().lookup(tkr)
79-
80-
# Handling the lookup failure replaces cache with a dummy
81-
cache = yf.cache.get_tz_cache()
82-
self.assertTrue(cache.dummy)
83-
cache.lookup(tkr)
84-
85-
def suite():
86-
ts: TestSuite = unittest.TestSuite()
87-
ts.addTest(TestCache('Test cache'))
88-
ts.addTest(TestCacheNoPermission('Test cache no permission'))
89-
return ts
90-
91-
9249
if __name__ == '__main__':
9350
unittest.main()

tests/test_cache_noperms.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
Tests for cache
3+
4+
To run all tests in suite from commandline:
5+
python -m unittest tests.cache
6+
7+
Specific test class:
8+
python -m unittest tests.cache.TestCache
9+
10+
"""
11+
from tests.context import yfinance as yf
12+
13+
import unittest
14+
import os
15+
16+
17+
class TestCacheNoPermission(unittest.TestCase):
18+
@classmethod
19+
def setUpClass(cls):
20+
if os.name == "nt": # Windows
21+
cls.cache_path = "C:\\Windows\\System32\\yf-cache"
22+
else: # Unix/Linux/MacOS
23+
# Use a writable directory
24+
cls.cache_path = "/yf-cache"
25+
yf.set_tz_cache_location(cls.cache_path)
26+
27+
def test_tzCacheRootStore(self):
28+
# Test that if cache path in read-only filesystem, no exception.
29+
tkr = 'AMZN'
30+
tz1 = "America/New_York"
31+
32+
# During attempt to store, will discover cannot write
33+
yf.cache.get_tz_cache().store(tkr, tz1)
34+
35+
# Handling the store failure replaces cache with a dummy
36+
cache = yf.cache.get_tz_cache()
37+
self.assertTrue(cache.dummy)
38+
cache.store(tkr, tz1)
39+
40+
def test_tzCacheRootLookup(self):
41+
# Test that if cache path in read-only filesystem, no exception.
42+
tkr = 'AMZN'
43+
# During attempt to lookup, will discover cannot write
44+
yf.cache.get_tz_cache().lookup(tkr)
45+
46+
# Handling the lookup failure replaces cache with a dummy
47+
cache = yf.cache.get_tz_cache()
48+
self.assertTrue(cache.dummy)
49+
cache.lookup(tkr)
50+
51+
if __name__ == '__main__':
52+
unittest.main()

tests/test_lookup.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import unittest
2+
3+
import pandas as pd
4+
5+
from tests.context import yfinance as yf, session_gbl
6+
7+
8+
class TestLookup(unittest.TestCase):
9+
def setUp(self):
10+
self.query = "A" # Generic query to make sure all lookup types are returned
11+
self.lookup = yf.Lookup(query=self.query, session=session_gbl)
12+
13+
def test_get_all(self):
14+
result = self.lookup.get_all(count=5)
15+
16+
self.assertIsInstance(result, pd.DataFrame)
17+
self.assertEqual(len(result), 5)
18+
19+
def test_get_stock(self):
20+
result = self.lookup.get_stock(count=5)
21+
22+
self.assertIsInstance(result, pd.DataFrame)
23+
self.assertEqual(len(result), 5)
24+
25+
def test_get_mutualfund(self):
26+
result = self.lookup.get_mutualfund(count=5)
27+
28+
self.assertIsInstance(result, pd.DataFrame)
29+
self.assertEqual(len(result), 5)
30+
31+
def test_get_etf(self):
32+
result = self.lookup.get_etf(count=5)
33+
34+
self.assertIsInstance(result, pd.DataFrame)
35+
self.assertEqual(len(result), 5)
36+
37+
def test_get_index(self):
38+
result = self.lookup.get_index(count=5)
39+
40+
self.assertIsInstance(result, pd.DataFrame)
41+
self.assertEqual(len(result), 5)
42+
43+
def test_get_future(self):
44+
result = self.lookup.get_future(count=5)
45+
46+
self.assertIsInstance(result, pd.DataFrame)
47+
self.assertEqual(len(result), 5)
48+
49+
def test_get_currency(self):
50+
result = self.lookup.get_currency(count=5)
51+
52+
self.assertIsInstance(result, pd.DataFrame)
53+
self.assertEqual(len(result), 5)
54+
55+
def test_get_cryptocurrency(self):
56+
result = self.lookup.get_cryptocurrency(count=5)
57+
58+
self.assertIsInstance(result, pd.DataFrame)
59+
self.assertEqual(len(result), 5)
60+
61+
def test_large_all(self):
62+
result = self.lookup.get_all(count=1000)
63+
64+
self.assertIsInstance(result, pd.DataFrame)
65+
self.assertEqual(len(result), 1000)
66+
67+
68+
if __name__ == "__main__":
69+
unittest.main()

tests/test_prices.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_duplicatingHourly(self):
6666
tkrs = ["IMP.JO", "BHG.JO", "SSW.JO", "BP.L", "INTC"]
6767
for tkr in tkrs:
6868
dat = yf.Ticker(tkr, session=self.session)
69-
tz = dat._get_ticker_tz(proxy=None, timeout=None)
69+
tz = dat._get_ticker_tz(timeout=None)
7070

7171
dt_utc = _pd.Timestamp.utcnow()
7272
dt = dt_utc.astimezone(_tz.timezone(tz))
@@ -86,7 +86,7 @@ def test_duplicatingDaily(self):
8686
test_run = False
8787
for tkr in tkrs:
8888
dat = yf.Ticker(tkr, session=self.session)
89-
tz = dat._get_ticker_tz(proxy=None, timeout=None)
89+
tz = dat._get_ticker_tz(timeout=None)
9090

9191
dt_utc = _pd.Timestamp.utcnow()
9292
dt = dt_utc.astimezone(_tz.timezone(tz))
@@ -112,7 +112,7 @@ def test_duplicatingWeekly(self):
112112
test_run = False
113113
for tkr in tkrs:
114114
dat = yf.Ticker(tkr, session=self.session)
115-
tz = dat._get_ticker_tz(proxy=None, timeout=None)
115+
tz = dat._get_ticker_tz(timeout=None)
116116

117117
dt = _tz.timezone(tz).localize(_dt.datetime.now())
118118
if dt.date().weekday() not in [1, 2, 3, 4]:

0 commit comments

Comments
 (0)