-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2227 from ranaroussi/dev
sync dev -> Sphinx docs
- Loading branch information
Showing
31 changed files
with
1,209 additions
and
868 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import yfinance as yf | ||
|
||
EUROPE = yf.Market("EUROPE") | ||
|
||
status = EUROPE.status | ||
summary = EUROPE.summary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
===================== | ||
Market Summary | ||
===================== | ||
.. currentmodule:: yfinance | ||
Class | ||
------------ | ||
The `Market` class, allows you to access market data in a Pythonic way. | ||
.. autosummary:: | ||
:toctree: api/ | ||
Market | ||
|
||
Market Sample Code | ||
-------------------------- | ||
The `Market` class, allows you to access market summary data in a Pythonic way. | ||
.. literalinclude:: examples/market.py | ||
:language: python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
========================= | ||
Screener & Query | ||
========================= | ||
|
||
.. currentmodule:: yfinance | ||
|
||
Query Market Data | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
The `Sector` and `Industry` modules allow you to access the sector and industry information. | ||
|
||
.. autosummary:: | ||
:toctree: api/ | ||
|
||
EquityQuery | ||
FundQuery | ||
screen | ||
|
||
.. seealso:: | ||
:attr:`EquityQuery.valid_fields <yfinance.EquityQuery.valid_fields>` | ||
supported operand values for query | ||
:attr:`EquityQuery.valid_values <yfinance.EquityQuery.valid_values>` | ||
supported `EQ query operand parameters` | ||
:attr:`EquityQuery.valid_fields <yfinance.EquityQuery.valid_fields>` | ||
supported operand values for query | ||
:attr:`EquityQuery.valid_values <yfinance.EquityQuery.valid_values>` | ||
supported `EQ query operand parameters` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,153 +1,38 @@ | ||
import unittest | ||
from unittest.mock import patch, MagicMock | ||
from yfinance.const import PREDEFINED_SCREENER_BODY_MAP | ||
from yfinance.screener.screener import Screener | ||
from yfinance.screener.screener_query import EquityQuery | ||
from yfinance.screener.screener import screen | ||
from yfinance.screener.query import EquityQuery | ||
|
||
|
||
class TestScreener(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(self): | ||
self.screener = Screener() | ||
self.query = EquityQuery('gt',['eodprice',3]) | ||
|
||
def test_set_default_body(self): | ||
result = self.screener.set_default_body(self.query) | ||
|
||
self.assertEqual(self.screener.body['offset'], 0) | ||
self.assertEqual(self.screener.body['size'], 100) | ||
self.assertEqual(self.screener.body['sortField'], 'ticker') | ||
self.assertEqual(self.screener.body['sortType'], 'desc') | ||
self.assertEqual(self.screener.body['quoteType'], 'equity') | ||
self.assertEqual(self.screener.body['query'], self.query.to_dict()) | ||
self.assertEqual(self.screener.body['userId'], '') | ||
self.assertEqual(self.screener.body['userIdType'], 'guid') | ||
self.assertEqual(self.screener, result) | ||
|
||
def test_set_predefined_body(self): | ||
k = 'most_actives' | ||
result = self.screener.set_predefined_body(k) | ||
self.assertEqual(self.screener.body, PREDEFINED_SCREENER_BODY_MAP[k]) | ||
self.assertEqual(self.screener, result) | ||
|
||
def test_set_predefined_body_invalid_key(self): | ||
with self.assertRaises(ValueError): | ||
self.screener.set_predefined_body('invalid_key') | ||
|
||
def test_set_body(self): | ||
body = { | ||
"offset": 0, | ||
"size": 100, | ||
"sortField": "ticker", | ||
"sortType": "desc", | ||
"quoteType": "equity", | ||
"query": self.query.to_dict(), | ||
"userId": "", | ||
"userIdType": "guid" | ||
} | ||
result = self.screener.set_body(body) | ||
|
||
self.assertEqual(self.screener.body, body) | ||
self.assertEqual(self.screener, result) | ||
|
||
def test_set_body_missing_keys(self): | ||
body = { | ||
"offset": 0, | ||
"size": 100, | ||
"sortField": "ticker", | ||
"sortType": "desc", | ||
"quoteType": "equity" | ||
} | ||
with self.assertRaises(ValueError): | ||
self.screener.set_body(body) | ||
|
||
def test_set_body_extra_keys(self): | ||
body = { | ||
"offset": 0, | ||
"size": 100, | ||
"sortField": "ticker", | ||
"sortType": "desc", | ||
"quoteType": "equity", | ||
"query": self.query.to_dict(), | ||
"userId": "", | ||
"userIdType": "guid", | ||
"extraKey": "extraValue" | ||
} | ||
with self.assertRaises(ValueError): | ||
self.screener.set_body(body) | ||
|
||
def test_patch_body(self): | ||
initial_body = { | ||
"offset": 0, | ||
"size": 100, | ||
"sortField": "ticker", | ||
"sortType": "desc", | ||
"quoteType": "equity", | ||
"query": self.query.to_dict(), | ||
"userId": "", | ||
"userIdType": "guid" | ||
} | ||
self.screener.set_body(initial_body) | ||
patch_values = {"size": 50} | ||
result = self.screener.patch_body(patch_values) | ||
|
||
self.assertEqual(self.screener.body['size'], 50) | ||
self.assertEqual(self.screener.body['query'], self.query.to_dict()) | ||
self.assertEqual(self.screener, result) | ||
|
||
def test_patch_body_extra_keys(self): | ||
initial_body = { | ||
"offset": 0, | ||
"size": 100, | ||
"sortField": "ticker", | ||
"sortType": "desc", | ||
"quoteType": "equity", | ||
"query": self.query.to_dict(), | ||
"userId": "", | ||
"userIdType": "guid" | ||
} | ||
self.screener.set_body(initial_body) | ||
patch_values = {"extraKey": "extraValue"} | ||
with self.assertRaises(ValueError): | ||
self.screener.patch_body(patch_values) | ||
self.predefined = 'aggressive_small_caps' | ||
|
||
@patch('yfinance.screener.screener.YfData.post') | ||
def test_set_large_size_in_body(self, mock_post): | ||
body = { | ||
"offset": 0, | ||
"size": 251, # yahoo limits at 250 | ||
"sortField": "ticker", | ||
"sortType": "desc", | ||
"quoteType": "equity", | ||
"query": self.query.to_dict(), | ||
"userId": "", | ||
"userIdType": "guid" | ||
} | ||
|
||
with self.assertRaises(ValueError): | ||
self.screener.set_body(body).response | ||
screen(self.query, size=251) | ||
|
||
@patch('yfinance.screener.screener.YfData.post') | ||
def test_fetch(self, mock_post): | ||
@patch('yfinance.data.YfData.post') | ||
def test_fetch_query(self, mock_post): | ||
mock_response = MagicMock() | ||
mock_response.json.return_value = {'finance': {'result': [{}]}} | ||
mock_response.json.return_value = {'finance': {'result': [{'key': 'value'}]}} | ||
mock_post.return_value = mock_response | ||
|
||
self.screener.set_default_body(self.query) | ||
response = self.screener._fetch() | ||
|
||
self.assertEqual(response, {'finance': {'result': [{}]}}) | ||
response = screen(self.query) | ||
self.assertEqual(response, {'key': 'value'}) | ||
|
||
@patch('yfinance.screener.screener.YfData.post') | ||
def test_fetch_and_parse(self, mock_post): | ||
@patch('yfinance.data.YfData.get') | ||
def test_fetch_predefined(self, mock_get): | ||
mock_response = MagicMock() | ||
mock_response.json.return_value = {'finance': {'result': [{'key': 'value'}]}} | ||
mock_post.return_value = mock_response | ||
mock_get.return_value = mock_response | ||
|
||
self.screener.set_default_body(self.query) | ||
self.screener._fetch_and_parse() | ||
self.assertEqual(self.screener.response, {'key': 'value'}) | ||
response = screen(self.predefined) | ||
self.assertEqual(response, {'key': 'value'}) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.