query patch

This commit is contained in:
Nicolás Sánchez 2025-05-17 18:51:11 -03:00
parent 1a62e483ae
commit 415f74fe3e
1 changed files with 12 additions and 12 deletions

View File

@ -84,13 +84,13 @@ def profit_report():
ORDER BY year_month_utc3;""") ORDER BY year_month_utc3;""")
last_n_months_rows = cursor.fetchall() last_n_months_rows = cursor.fetchall()
#Yearly totals #Yearly totals
cursor.execute("""SELECT strftime('%Y', timestamp, 'unixepoch', '-3 hours') AS year_utc3, # cursor.execute("""SELECT strftime('%Y', timestamp, 'unixepoch', '-3 hours') AS year_utc3,
SUM(amount) AS total_amount # SUM(amount) AS total_amount
FROM profits_table # FROM profits_table
WHERE strftime('%s', 'now') - timestamp <= 24 * 365 * 60 * 60 -- 365 days in seconds # WHERE strftime('%s', 'now') - timestamp <= 24 * 365 * 60 * 60 -- 365 days in seconds
GROUP BY year_utc3 # GROUP BY year_utc3
ORDER BY year_utc3;""") # ORDER BY year_utc3;""")
yearly_totals = cursor.fetchall() # yearly_totals = cursor.fetchall()
#Per exchange #Per exchange
cursor.execute("""SELECT cursor.execute("""SELECT
exchange_name, exchange_name,
@ -213,10 +213,10 @@ def daily_and_monthly_totals():
start_of_day_unix = int(time.mktime(start_of_day.timetuple())) start_of_day_unix = int(time.mktime(start_of_day.timetuple()))
start_of_month_unix = int(time.mktime(start_of_month.timetuple())) start_of_month_unix = int(time.mktime(start_of_month.timetuple()))
query = f"""SELECT * FROM profits_table query = """SELECT * FROM profits_table
WHERE timestamp >= {start_of_month_unix} WHERE timestamp >= ?
ORDER BY timestamp DESC;""" ORDER BY timestamp DESC;"""
cursor.execute(query) cursor.execute(query, (start_of_month_unix,))
query_result = cursor.fetchall() query_result = cursor.fetchall()
connection.close() connection.close()
@ -283,7 +283,7 @@ def query_monthly_totals(pair=None):
for item in query_result: for item in query_result:
result[item[0]] = item[1] result[item[0]] = item[1]
else: else:
query = f"""SELECT pair, strftime('%Y-%m', datetime(timestamp, 'unixepoch', '-3 hours')) AS month, query = """SELECT pair, strftime('%Y-%m', datetime(timestamp, 'unixepoch', '-3 hours')) AS month,
SUM(amount) AS total_profit SUM(amount) AS total_profit
FROM profits_table FROM profits_table
GROUP BY pair, month;""" GROUP BY pair, month;"""
@ -302,7 +302,7 @@ def last_n_deals(n):
''' '''
connection = sqlite3.connect(profits_database) connection = sqlite3.connect(profits_database)
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute(f"SELECT * FROM profits_table ORDER BY timestamp DESC LIMIT ?",(n,)) cursor.execute("SELECT * FROM profits_table ORDER BY timestamp DESC LIMIT ?",(n,))
result = cursor.fetchall() result = cursor.fetchall()
connection.close() connection.close()