43 lines
1.1 KiB
Python
Executable File
43 lines
1.1 KiB
Python
Executable File
import os, sys, json, datetime
|
|
|
|
pair = sys.argv[1]
|
|
|
|
def load_old_long(pair):
|
|
#Load old_long info
|
|
try:
|
|
with open(f"../status/{pair}.oldlong") as f:
|
|
return json.load(f)
|
|
except Exception as e:
|
|
print(e)
|
|
return None
|
|
|
|
def load_old_long_from_status(pair):
|
|
#Load old_long info
|
|
try:
|
|
with open(f"../status/{pair}.status") as f:
|
|
return json.load(f)["old_long"]
|
|
except Exception as e:
|
|
print(e)
|
|
return None
|
|
|
|
old_long = load_old_long(pair)
|
|
if old_long is None:
|
|
old_long = load_old_long_from_status(pair)
|
|
if old_long is None:
|
|
sys.exit(0)
|
|
|
|
#Get time of switch to unix time
|
|
old_date = old_long["datetime"][1:11]
|
|
time_of_switch = datetime.datetime.strptime(old_date,"%Y/%m/%d").timestamp()
|
|
|
|
#Calculate profits
|
|
total = 0
|
|
with open(f"{pair}.profits") as csvfile:
|
|
for x in csvfile:
|
|
[date,amount,_] = x.split(",")
|
|
time_of_profit = datetime.datetime.strptime(date,"%Y-%m-%d").timestamp()
|
|
if time_of_profit>=time_of_switch:
|
|
total += float(amount)
|
|
|
|
print(f"Profits since {old_date}: {round(total,2)}")
|