diff --git a/README.md b/README.md index 2b92556..fecde2b 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,25 @@ tenbagger -v ``` ## Getting Started -Add/modify a portfolio with +Configuration files are stored in the user's root folder. +Configure your portfolio + +```sh +vi ~/.tenbagger/portfolio.yaml +``` + +Configure staking rewards +```sh +vi ~/.tenbagger/staking.yaml ``` -tenbagger --configure +Configure preferred currency + +```sh +vi ~/.tenbagger/environment.yaml ``` -Alternatively, modify the portfolio.yaml in the user_data/portfolio/ folder. + +Alternatively, you can change the files in the ~/.tenbagger folder with your preferred text editor. ## Usage Real-time overview of portfolio. The portfolio automatically gets updated with the real-time stock/crypto prices while the app is running. The app can be closed by hitting q or CTRL+C. diff --git a/setup.py b/setup.py index 8435652..ad29647 100644 --- a/setup.py +++ b/setup.py @@ -48,5 +48,6 @@ install_requires=INSTALL_REQUIRES, extras_require=EXTRAS_REQUIRE, author='Aram Koorn', - packages=find_packages() + packages=find_packages(), + package_data={'tenbagger': ['configs/*.json']} ) diff --git a/tenbagger/__init__.py b/tenbagger/__init__.py index 58f3ace..5263f4f 100644 --- a/tenbagger/__init__.py +++ b/tenbagger/__init__.py @@ -1 +1,24 @@ -from .version import __version__ +from tenbagger.version import __version__ +from tenbagger.src.utils.builtin_utils import read_from_root, read_json, create_hidden_folder, write_json +import os +from pathlib import Path + + +CWD = os.getcwd() +DIRECTORY = os.path.dirname(os.path.abspath(__file__)) +os.chdir(DIRECTORY) +FILES = ['staking.json', "portfolio.json", "environment.json"] + +HOME_PATH = Path.home() +TENBAGGER_PATH = f'{HOME_PATH}/.tenbagger' +create_hidden_folder('tenbagger') +os.chdir(TENBAGGER_PATH) + +HIDDEN_FILES = os.listdir() # Get files in .tenbagger +for f in set(FILES) - set(HIDDEN_FILES): + os.chdir(DIRECTORY) + to_dump = read_json(f'configs/{f}') + os.chdir(TENBAGGER_PATH) + write_json(loc=f, data=to_dump) + +os.chdir(CWD) diff --git a/tenbagger/cli.py b/tenbagger/cli.py index b5a186e..bb2f06c 100644 --- a/tenbagger/cli.py +++ b/tenbagger/cli.py @@ -1,8 +1,7 @@ import argparse from tenbagger.version import __version__ -from tenbagger.src.utils.utilities import order_by_month, make_percentage +from tenbagger.src.utils.utilities import order_by_month, make_percentage, read_from_root from pyfiglet import Figlet -from tenbagger.src.configuration.configuration import Configuration import pandas as pd @@ -10,9 +9,6 @@ def main(): parser = argparse.ArgumentParser(description="CLI interface for Stock Data", epilog="Homepage: https://github.com/AramKoorn/TenBagger") - # Configure - parser.add_argument("--configure", action="store_true") - # Portfolio parser.add_argument("--portfolio") parser.add_argument("--ticker") @@ -59,10 +55,6 @@ def main(): account = algo.get_account_data(address=address) print(account) - if args.configure: - c = Configuration() - c.run_configuration() - if args.scenario: from tenbagger.src.passiveIncome.calculator import PassiveIncomeCalculator @@ -75,7 +67,7 @@ def main(): from tenbagger.src.utils.utilities import read_yaml from tenbagger.src.terminal.utils import TermPlots - portfolio = read_yaml('user_data/portfolio/portfolio.yaml')[args.dividend] + portfolio = read_from_root('portfolio.json')[args.dividend] df = DividendsPortfolio(portfolio).calculate() df = order_by_month(df.groupby(['month', 'year']).Dividends.sum().reset_index(), col='month') del df['year'] @@ -91,11 +83,10 @@ def main(): if args.notify: from tenbagger.src.notify.price_target import NotifyPriceTarget from tenbagger.src.notify.insider_activity import NotifyInsider - from tenbagger.src.utils.utilities import read_yaml # Read configs - port = list(read_yaml('user_data/portfolio/portfolio.yaml').keys()) - env = read_yaml('user_data/env/environment.yaml') + port = list(read_from_root('portfolio.json').keys()) + env = read_from_root('environment.json') NotifyInsider().notify_portfolio(port) NotifyPriceTarget().notify_high() @@ -106,7 +97,6 @@ def main(): # Clean this up from tenbagger.src.portfolio.core import Portfolio from tenbagger.src.terminal.utils import TermPlots - from tenbagger.src.utils.utilities import read_yaml from tenbagger.src.textui.apps.portfolio import OverviewPortfolio pd.set_option("expand_frame_repr", False) @@ -115,7 +105,7 @@ def main(): print(f.renderText('Portfolio')) # Read in ENV settings - env = read_yaml('user_data/env/environment.yaml') + env = read_from_root('environment.json') # Print out portfolio port = Portfolio(args.portfolio) diff --git a/tenbagger/configs/__init__.py b/tenbagger/configs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tenbagger/configs/environment.json b/tenbagger/configs/environment.json new file mode 100644 index 0000000..b4c10cb --- /dev/null +++ b/tenbagger/configs/environment.json @@ -0,0 +1,5 @@ +{ + "CURRENCY": "EUR", + "MAINPORTFOLIO": "my_portfolio", + "TELEGRAMID": "" +} diff --git a/tenbagger/configs/environment.yaml b/tenbagger/configs/environment.yaml new file mode 100644 index 0000000..843cd9b --- /dev/null +++ b/tenbagger/configs/environment.yaml @@ -0,0 +1,8 @@ +# Here you can specify your preferred environment. +# E.G. CURRENCY: "EUR" + +CURRENCY: "EUR" +MAINPORTFOLIO: "my_portfolio" +TELEGRAMID: "" +TELEGRAMTOKEN: "" + diff --git a/tenbagger/configs/portfolio.json b/tenbagger/configs/portfolio.json new file mode 100644 index 0000000..53126ef --- /dev/null +++ b/tenbagger/configs/portfolio.json @@ -0,0 +1,22 @@ +{ + "my_portfolio": + { + "ibm": 10, + "aapl": 20, + "eth-usd": 2 + }, + "WSB": + { + "wish": 1000, + "tsla": 100, + "shib-eur": 100000, + "nvda": 100, + "baba": 100, + "bb": 100, + "gme": 1000, + "amc": 1000, + "intc": 1000, + "eth-eur": 10 + } +} + diff --git a/tenbagger/configs/portfolio.yaml b/tenbagger/configs/portfolio.yaml new file mode 100644 index 0000000..ad9aa21 --- /dev/null +++ b/tenbagger/configs/portfolio.yaml @@ -0,0 +1,35 @@ +# This is an example of a portfolio that contains 10 ibm shares 20 appple shares +# and 2 ethereum tokens. +# +# This is an example. You can delete/modify this portfolio if you want. +my_portfolio: + ibm: 10 + aapl: 20 + eth-usd: 2 + +WSB: + wish: 1000 + tsla: 100 + shib-eur: 100000 + nvda: 100 + baba: 100 + bb: 100 + gme: 1000 + amc: 1000 + intc: 1000 + eth-eur: 10 + +# You can modify the current portfolio or add a new portfolio. Make sure that you use ticker +# symbols as listed on yahoo finance. for instance, if you want to add a portfolio called household_portfolio that contains 5 tesla shares: +household_portfolio: + TSLA : 5 + +# Some hypothetical portfolio containing stocks and crypto +hypothetical_portfolio: + algo-eur: 2500 + IBM: 10 + BTC-USD: 0.5 + AAPl: 2 + ETH-USD: 2 + TSLA: 10 + diff --git a/tenbagger/configs/staking.json b/tenbagger/configs/staking.json new file mode 100644 index 0000000..c001278 --- /dev/null +++ b/tenbagger/configs/staking.json @@ -0,0 +1,7 @@ +{ + "eth-usd": 0.0735, +"eth-eur": 0.0735, +"dot1-usd": 0.1313, +"dot1-eur": 0.1313, +"algo-eur": 0.06 +} diff --git a/tenbagger/configs/staking.yaml b/tenbagger/configs/staking.yaml new file mode 100644 index 0000000..3cc587c --- /dev/null +++ b/tenbagger/configs/staking.yaml @@ -0,0 +1,5 @@ +eth-usd: 0.0735 +eth-eur: 0.0735 +dot1-usd: 0.1313 +dot1-eur: 0.1313 +algo-eur: 0.06 diff --git a/tenbagger/src/portfolio/core.py b/tenbagger/src/portfolio/core.py index 2de2065..05ce113 100644 --- a/tenbagger/src/portfolio/core.py +++ b/tenbagger/src/portfolio/core.py @@ -1,4 +1,5 @@ -from tenbagger.src.utils.utilities import read_yaml, Ticker, make_percentage +from tenbagger.src.utils.utilities import Ticker +from tenbagger.src.utils.builtin_utils import read_from_root from tenbagger.src.portfolio.crypto import PortfolioCrypto import datetime import pandas as pd @@ -13,7 +14,7 @@ def __init__(self, name_port): super().__init__() self.name_port = name_port self.portfolio = self._select() - self.env = read_yaml('user_data/env/environment.yaml') + self.env = read_from_root('environment.json') self.tickers = {} self.c = CurrencyRates() self.ticker_info = {} @@ -52,7 +53,7 @@ def _select(self): if isinstance(self.name_port, dict): portfolio = self.name_port else: - portfolio = read_yaml('user_data/portfolio/portfolio.yaml')[self.name_port] + portfolio = read_from_root('portfolio.json')[self.name_port] return portfolio diff --git a/tenbagger/src/portfolio/crypto.py b/tenbagger/src/portfolio/crypto.py index 3b63f8a..8a8daf8 100644 --- a/tenbagger/src/portfolio/crypto.py +++ b/tenbagger/src/portfolio/crypto.py @@ -1,13 +1,12 @@ -from tenbagger.src.utils.utilities import read_yaml -import numpy as np +from tenbagger.src.utils.utilities import read_yaml, read_from_root import pandas as pd class PortfolioCrypto: def __init__(self): - self.apy = read_yaml('configs/staking.yaml') + self.apy = read_from_root('staking.json') - def staking_rewards(self, df : pd.DataFrame): + def staking_rewards(self, df: pd.DataFrame): df['staking_rewards'] = df.ticker.str.lower().map(self.apy) * df['value'] df['apy'] = df.ticker.str.lower().map(self.apy) diff --git a/tenbagger/src/scripts/insiders.py b/tenbagger/src/scripts/insiders.py index d93dd31..bddaeea 100644 --- a/tenbagger/src/scripts/insiders.py +++ b/tenbagger/src/scripts/insiders.py @@ -1,9 +1,4 @@ import pandas as pd -import datetime -import yaml - -def prGreen(skk): - print("\033[92m {}\033[00m" .format(skk)) def format_insiders(ticker): @@ -19,8 +14,6 @@ def format_insiders(ticker): if __name__ == "__main__": - with open(r'configs/ColorCodes.yaml') as file: - color_config = yaml.load(file, Loader=yaml.FullLoader) - ticker = 'IBM' df = format_insiders(ticker) + print(df) \ No newline at end of file diff --git a/tenbagger/src/utils/builtin_utils.py b/tenbagger/src/utils/builtin_utils.py new file mode 100644 index 0000000..a931695 --- /dev/null +++ b/tenbagger/src/utils/builtin_utils.py @@ -0,0 +1,46 @@ +import json +import os +from pathlib import Path +import logging + + +def read_json(loc : str): + ''' + + :param loc: path to file + :return: yaml converted to a dictionary + ''' + with open(loc) as f: + data = json.load(f) + + return data + + +def write_json(data, loc): + with open(loc, 'w') as json_file: + json.dump(data, json_file) + + +def read_from_root(file: str): + + cwd = os.getcwd() + home_path = str(Path.home()) + '/.tenbagger' + os.chdir(home_path) + + data = read_json(loc=file) + os.chdir(cwd) + return data + + +def create_hidden_folder(name: str): + + cwd = os.getcwd() + home_path = Path.home() + os.chdir(home_path) + + if os.path.exists(f".{name}"): + logging.info("Folder already exist") + return + + os.mkdir(f".{name}") + os.chdir(cwd) \ No newline at end of file diff --git a/tenbagger/src/utils/utilities.py b/tenbagger/src/utils/utilities.py index 1af0fd1..90c920a 100644 --- a/tenbagger/src/utils/utilities.py +++ b/tenbagger/src/utils/utilities.py @@ -1,12 +1,39 @@ import yfinance as yf import yaml -import numpy as np import datetime import pandas as pd -from bs4 import BeautifulSoup from requests import get import json +from pathlib import Path +import os +import logging import re +import json + + +def read_from_root(file: str): + + cwd = os.getcwd() + home_path = str(Path.home()) + '/.tenbagger' + os.chdir(home_path) + + dict = read_yaml(loc=file) + os.chdir(cwd) + return dict + + +def create_hidden_folder(name: str): + + cwd = os.getcwd() + home_path = Path.home() + os.chdir(home_path) + + if os.path.exists(f".{name}"): + logging.info("Folder already exist") + return + + os.mkdir(f".{name}") + os.chdir(cwd) def make_percentage(df: pd.DataFrame, value: str, groupby: str): @@ -157,6 +184,11 @@ def read_yaml(loc : str): return yaml.load(file, Loader=yaml.FullLoader) +def write_yaml(loc: str, dict): + with open(f'{loc}', 'w') as file: + yaml.dump(dict, file) + + def order_by_month(df, col): # Create mapping dictionary diff --git a/tenbagger/version.py b/tenbagger/version.py index 4910b9e..8088f75 100644 --- a/tenbagger/version.py +++ b/tenbagger/version.py @@ -1 +1 @@ -__version__ = "0.7.3" +__version__ = "0.8.1" diff --git a/test/utilities/test_utilities.py b/test/utilities/test_utilities.py index 28aa2e4..d36e777 100644 --- a/test/utilities/test_utilities.py +++ b/test/utilities/test_utilities.py @@ -1,7 +1,22 @@ -from tenbagger.src.utils.utilities import read_yaml, order_by_month, Ticker, make_percentage +from tenbagger.src.utils.utilities import read_from_root, read_yaml, Ticker, make_percentage, create_hidden_folder import pandas as pd import numpy as np from pandas._testing import assert_frame_equal +import os +from pathlib import Path + + +def test_create_hidden_folder(): + cwd = os.getcwd() + create_hidden_folder(name="test_folder") + + assert os.getcwd() == cwd + + os.chdir(str(Path.home())) + assert os.path.exists('.test_folder') + + os.rmdir('.test_folder') + assert not os.path.exists('.test_folder') def test_make_percentage(): @@ -14,7 +29,7 @@ def test_make_percentage(): def test_read_yaml(): - cfg = read_yaml('user_data/env/environment.yaml') + cfg = read_from_root('environment.json') assert "CURRENCY" in cfg.keys()