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