import sqlite3 import os import sys import json import datetime pair = sys.argv[1].replace("/","") #Connect to db connection = sqlite3.connect("../profits/profits_database.db") cursor = connection.cursor() #Load old_long info try: with open(f"../status/{pair}.oldlong") as f: old_long = json.load(f) except Exception as e: print(e) print("No old_long file") os._exit(0) #Get time of switch to unix time old_date = old_long["datetime"][1:11] linux_time = datetime.datetime.strptime(old_date,"%Y/%m/%d").timestamp() #Query database query = f"""SELECT pair, SUM(amount) AS total_profit FROM profits_table WHERE timestamp >= '{linux_time}' GROUP BY pair;""" cursor.execute(query) query_result = cursor.fetchall() #Calculate profits total = 0 for item in query_result: if item[0].replace("/","")==pair: total = item[1] print(f"Profits since switch ({old_date}): {round(total,2)}") print(f"Profit needed to cover expenses: {round(old_long['quote_spent'],2)}") print(f"Difference: {round(old_long['quote_spent']-total,2)}") try: with open(f"../status/{pair}.status") as f: status_file = json.load(f) except Exception as e: print(e) print("No status file") os._exit(0) print(f"Old long price: {old_long['tp_price']}") print(f"Current price: {status_file['price']}")