restoring from backup
This commit is contained in:
119
main.py
Normal file
119
main.py
Normal file
@@ -0,0 +1,119 @@
|
||||
|
||||
import functions
|
||||
import config
|
||||
|
||||
while True:
|
||||
|
||||
# ------------------------------------------- #
|
||||
# PART 1: Updating the notion trades database #
|
||||
# ------------------------------------------- #
|
||||
# Fetches the list of all trades stored in notion
|
||||
print("Fetching Data from Notion...", end=" ", flush=True)
|
||||
trades = functions.fetch_format_notion_trades(config.notion_db_id_trades)
|
||||
|
||||
# Generates a list with unique tickers and no duplicates to reduce workload for the yfinance api
|
||||
print("Creating a list of unique tickers...", end=" ", flush=True)
|
||||
tickers = functions.filter_list_of_tickers(trades)
|
||||
|
||||
# Fetches & formats the complete history per ticker from yfinance
|
||||
print("Fetching & formating yfinance data", end="", flush=True)
|
||||
yf_data = functions.fetch_format_yf_data(tickers)
|
||||
|
||||
# Calculates & stores a history per trade
|
||||
print("Calculating the history per trade...", end=" ", flush=True)
|
||||
history_per_trade = functions.calc_history_per_trade(trades, yf_data)
|
||||
|
||||
# Configuration dependent execution:
|
||||
if config.update_notion == True:
|
||||
|
||||
# Selects the most current values from the history per trade and overwrites them in the "trades" feteched from notion
|
||||
print("Selecting the most current values...", end=" ", flush=True)
|
||||
trades = functions.select_current_value_per_trade(trades, history_per_trade)
|
||||
|
||||
# Updates the values in the notion database
|
||||
print("Updating the notion trades database", end="", flush=True)
|
||||
functions.push_notion_trades_update(trades)
|
||||
|
||||
|
||||
# ------------------------------------------------ #
|
||||
# PART 2: Updating the notion investments database #
|
||||
# ------------------------------------------------ #
|
||||
# Fetches the list of entries in the investment-overview database stored in notion
|
||||
print("Fetching & formating notion investments...", end=" ", flush=True)
|
||||
investments = functions.fetch_format_notion_investments(config.notion_db_id_investments)
|
||||
|
||||
# Calculates & stores a history per ticker AND a total across all tickers indexed by the ticker name
|
||||
print("Calculating history per ticker...", end=" ", flush=True)
|
||||
history_per_ticker = functions.calc_history_per_ticker(history_per_trade, tickers, trades)
|
||||
|
||||
# Configuration dependent execution:
|
||||
if config.update_notion == True:
|
||||
|
||||
# Selects the most current values from the history per ticker and overwrites them in the "investments" feteched from notion
|
||||
print("Calculating current value per ticker...", end=" ", flush=True)
|
||||
investments = functions.select_current_value_per_ticker(investments, history_per_ticker)
|
||||
|
||||
# Updates the values in the notion database
|
||||
print("Updating the notion ticker database", end="", flush=True)
|
||||
functions.push_notion_investment_update(investments)
|
||||
|
||||
|
||||
# --------------------------------- #
|
||||
# PART 3: Updating the TRMNL Screen #
|
||||
# --------------------------------- #
|
||||
|
||||
# Configuration dependent execution:
|
||||
if config.update_TRMNL == True:
|
||||
|
||||
# Creates a list containing one date per week
|
||||
print("Creating a list with one entry per week...", end=" ", flush=True)
|
||||
list_filtered_dates = functions.create_list_filtered_dates(trades, config.trmnl_granularity)
|
||||
|
||||
# Filter a weekly snapshot from the history per ticker
|
||||
print("Filtering the history per ticker to weekly values...", end=" ", flush=True)
|
||||
history_per_ticker_filtered = functions.filter_history_by_list(history_per_ticker, list_filtered_dates)
|
||||
|
||||
# Prepare a new TRMNL update
|
||||
print("Constructing a TERMNL update object...", end=" ", flush=True)
|
||||
trmnl_update_object = functions.prep_trmnl_chart_udpate(
|
||||
history_per_ticker_filtered,
|
||||
series_to_show_1="total",
|
||||
data_to_show_1="current_value",
|
||||
series_to_show_2="DBPG.DE",
|
||||
data_to_show_2="current_value"
|
||||
)
|
||||
|
||||
# Push the update to TRMNL
|
||||
print("Updating a TERMNL screen...", end=" ", flush=True)
|
||||
functions.push_trmnl_update_chart(trmnl_update_object, config.trmnl_url_chart_1, config.trmnl_headers)
|
||||
|
||||
# Prepare a new TRMNL update
|
||||
print("Constructing a TERMNL update object...", end=" ", flush=True)
|
||||
trmnl_update_object = functions.prep_trmnl_chart_udpate(
|
||||
history_per_ticker_filtered,
|
||||
series_to_show_1="total",
|
||||
data_to_show_1="current_irr",
|
||||
series_to_show_2="DBPG.DE",
|
||||
data_to_show_2="current_irr"
|
||||
)
|
||||
|
||||
# Push the update to TRMNL
|
||||
print("Updating a TERMNL screen...", end=" ", flush=True)
|
||||
functions.push_trmnl_update_chart(trmnl_update_object, config.trmnl_url_chart_2, config.trmnl_headers)
|
||||
|
||||
# --------------------------- #
|
||||
# PART 4: Cool off and repeat #
|
||||
# --------------------------- #
|
||||
# Logging
|
||||
print("Completed cycle at: {}".format(functions.datetime.datetime.now()))
|
||||
print("Waiting a few minutes before the next execution")
|
||||
print("---------------------------------------------------------------------------")
|
||||
|
||||
# Clear variables
|
||||
trades = {}
|
||||
yf_data = {}
|
||||
history_per_trade = {}
|
||||
tickers = []
|
||||
|
||||
# Wait for api-cooldown
|
||||
functions.time.sleep(config.programm_cooldown_time * 60)
|
||||
Reference in New Issue
Block a user