DCAv2/profits/profits_that_day.py

27 lines
693 B
Python

'''
Returns the profits of a certain day, grouped by pair.
Usage: python3 profits_that_day.py YYYY-MM-DD
'''
import sqlite3
import sys
try:
date = sys.argv[1]
except Exception as e:
print(e)
print("Usage: python3 profits_that_day.py YYYY-MM-DD")
sys.exit()
#Connect to db
connection = sqlite3.connect("profits_database.db")
cursor = connection.cursor()
query = f"SELECT strftime('%Y-%m-%d', timestamp, 'unixepoch', '-3 hours') AS day_utc3, SUM(amount) AS total_amount FROM profits_table GROUP BY day_utc3 ORDER BY day_utc3;"
cursor.execute(query)
result = cursor.fetchall()
for item in result:
if item[0]==date:
print(f"Profits on {date}: {round(item[1],2)}")