added 'by pair' functionality

This commit is contained in:
Nicolás Sánchez 2024-11-29 12:03:44 -03:00
parent 6a0eedf7d6
commit 285a3b6de0
1 changed files with 8 additions and 2 deletions

View File

@ -4,14 +4,20 @@ import sqlite3
try:
amount_of_deals = sys.argv[1]
pair = None
if len(sys.argv) > 2:
pair = sys.argv[2]
except Exception as e:
print(e)
print("Usage: python3 last_n_deals.py int")
print("Usage: python3 last_n_deals.py int <pair>")
sys.exit()
connection = sqlite3.connect('profits_database.db')
cursor = connection.cursor()
cursor.execute(f'SELECT * FROM profits_table ORDER BY timestamp DESC LIMIT {amount_of_deals}')
extra_query = ""
if pair:
extra_query = f"WHERE pair = '{pair}'"
cursor.execute(f'SELECT * FROM profits_table {extra_query} ORDER BY timestamp DESC LIMIT ?', (amount_of_deals,))
deals = cursor.fetchall()
connection.close()