From 9be1b992e6ee8a05ff0b6bbd96e2e73a19bf20bc Mon Sep 17 00:00:00 2001 From: BlueFox Date: Fri, 19 Jan 2024 20:20:02 +0100 Subject: [PATCH] Added some docs about using SimpleStockData as a library. Some small refactorings. --- README.md | 37 +++++++++++++++++-- SimpleStockData.py | 2 +- .../info_and_history_example.py | 4 +- 3 files changed, 36 insertions(+), 7 deletions(-) rename example1.py => examples/info_and_history_example.py (58%) diff --git a/README.md b/README.md index 980fc93..55807a0 100755 --- a/README.md +++ b/README.md @@ -55,12 +55,41 @@ pip3 install numpy pandas yfinance requests lxml ## 2. Usage -### 2.1 If used as a CLI: + +### 2.1 If used as a Module in Python (via `import`): + +If used as a module, all you have to do to access every share you own is +typing this: + +```python +from SimpleStockData import SSD +ssd1 = SSD(["EXAMPLE", "ANOTHER TICKER", "..."], "2011-11-11", "2022-02-22", "USD", "Close") +ssd2 = SSD(["EXAMPLE", "ANOTHER TICKER", "..."], "2011-11-11", "2022-02-22", "USD") # also working +ssd3 = SSD(ticker_list = ["EXAMPLE", "ANOTHER TICKER", "..."], period_start="2011-11-11", + period_end="2022-02-22", to_currency="USD", ohcl="Close") # again working +``` + +where... + +- `["EXAMPLE", "ANOTHER TICKER", "..."]` is a list of Ticker names (from Yahoo! finance) +- `2011-11-11` is the start date when accessing price history +- `2022-02-22` is the end date when accessing price history +- `USD` is the currency to convert to, later, when dumping history +- `Close` is **optional**. It specifies which price should be taken per day.
+ Valid values are: `High`, `Low`, `Open`, `Close` + +Then you can access the history of the stock just by calling the methods `get_info(index, [key]` +and `get_history(index, [interval="1d"], [convert=True]`. + +It's just that easy. + +--- +For more details, look into the [examples](examples) folder at this project's root. + +### 2.2 If used as a CLI: TODO; also mention the strange but working GBp thing -### 2.2 If used as a Module in Python (via `import`): -TODO; - +This feature is currently in progress and will soon be available. ## 3. Thanks to - [yfinance](https://pypi.org/project/yfinance/) - the library used in the background diff --git a/SimpleStockData.py b/SimpleStockData.py index de88b78..cc591a1 100755 --- a/SimpleStockData.py +++ b/SimpleStockData.py @@ -2,7 +2,7 @@ import yfinance as yf import pandas as pd -class SimpleStockData: +class SSD: def __init__(self, ticker_list: list, period_start: str, period_end: str, to_currency: str, ohcl: str = "Close"): """ :param period_start: diff --git a/example1.py b/examples/info_and_history_example.py similarity index 58% rename from example1.py rename to examples/info_and_history_example.py index 650ce01..e86db8d 100644 --- a/example1.py +++ b/examples/info_and_history_example.py @@ -1,6 +1,6 @@ -from SimpleStockData import SimpleStockData +from SimpleStockData import SSD -ssd = SimpleStockData(["RHM.DE", "BAS.DE", "AZN.L"], "2024-01-02", "2024-01-18", "EUR") +ssd = SSD(["RHM.DE", "BAS.DE", "AZN.L"], "2024-01-02", "2024-01-18", "EUR") print(ssd.get_info(0)) print(ssd.get_history(0))