37 lines
884 B
Python
37 lines
884 B
Python
'''
|
|
Usage: python3 profits_since_date.py BASE/QUOTE YYYY-MM-DD
|
|
'''
|
|
|
|
import sqlite3
|
|
import sys
|
|
import datetime
|
|
|
|
try:
|
|
pair = sys.argv[1].replace("/","")
|
|
since_date = sys.argv[2]
|
|
except Exception as e:
|
|
print(e)
|
|
print("Usage: python3 profits_since_date.py BASE/QUOTE YYYY-MM-DD")
|
|
sys.exit()
|
|
|
|
#Connect to db
|
|
connection = sqlite3.connect("../profits/profits_database.db")
|
|
cursor = connection.cursor()
|
|
|
|
linux_time = datetime.datetime.strptime(since_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 {since_date}: {round(total,2)}") |