Skip to content

Commit

Permalink
Merge pull request #15 from AramKoorn/hidden_files
Browse files Browse the repository at this point in the history
fix #14
  • Loading branch information
AramKoorn authored Nov 14, 2021
2 parents aa69254 + 9ce5bce commit 9e99cde
Show file tree
Hide file tree
Showing 18 changed files with 235 additions and 40 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']}
)
25 changes: 24 additions & 1 deletion tenbagger/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 5 additions & 15 deletions tenbagger/cli.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
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


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")
Expand Down Expand Up @@ -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

Expand All @@ -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']
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Empty file added tenbagger/configs/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions tenbagger/configs/environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"CURRENCY": "EUR",
"MAINPORTFOLIO": "my_portfolio",
"TELEGRAMID": ""
}
8 changes: 8 additions & 0 deletions tenbagger/configs/environment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Here you can specify your preferred environment.
# E.G. CURRENCY: "EUR"

CURRENCY: "EUR"
MAINPORTFOLIO: "my_portfolio"
TELEGRAMID: ""
TELEGRAMTOKEN: ""

22 changes: 22 additions & 0 deletions tenbagger/configs/portfolio.json
Original file line number Diff line number Diff line change
@@ -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
}
}

35 changes: 35 additions & 0 deletions tenbagger/configs/portfolio.yaml
Original file line number Diff line number Diff line change
@@ -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

7 changes: 7 additions & 0 deletions tenbagger/configs/staking.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"eth-usd": 0.0735,
"eth-eur": 0.0735,
"dot1-usd": 0.1313,
"dot1-eur": 0.1313,
"algo-eur": 0.06
}
5 changes: 5 additions & 0 deletions tenbagger/configs/staking.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eth-usd: 0.0735
eth-eur: 0.0735
dot1-usd: 0.1313
dot1-eur: 0.1313
algo-eur: 0.06
7 changes: 4 additions & 3 deletions tenbagger/src/portfolio/core.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions tenbagger/src/portfolio/crypto.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
9 changes: 1 addition & 8 deletions tenbagger/src/scripts/insiders.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)
46 changes: 46 additions & 0 deletions tenbagger/src/utils/builtin_utils.py
Original file line number Diff line number Diff line change
@@ -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)
36 changes: 34 additions & 2 deletions tenbagger/src/utils/utilities.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tenbagger/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.3"
__version__ = "0.8.1"
Loading

0 comments on commit 9e99cde

Please sign in to comment.