Added status and PnL

This commit is contained in:
2025-05-19 15:45:30 +03:00
parent 1314f566fb
commit e9d10af8da
7 changed files with 91 additions and 21 deletions

View File

@ -1,8 +1,52 @@
import options
import time
from datetime import datetime
import re
from random import randint
async def getLevels(amount, highPrice, lowPrice, roundDecimals):
startTime = None
def setStartTime():
startTime = time.time()
def getPnL(pair):
PnL = 0.0
with open("tradingLog.log", "r") as f:
lines = f.readlines()
logEntries = []
for i in lines:
# Get timestamp + message tuples
t = re.match(r"(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}) - (.+)", i)
if t:
timestamp_str, message = t.groups()
timestamp = datetime.strptime(timestamp_str, "%Y-%m-%d %H:%M:%S,%f")
logEntries.append((timestamp, message.strip()))
strategyStartTime = None
for timestamp, message in logEntries:
if message == f"Starting strategy with {pair}":
strategyStartTime = timestamp
if not strategyStartTime:
print(f"No 'Starting strategy' found for pair {pair}")
return 0.0
totalPnL = 0.0
pattern = re.compile(
rf"(Long|Short) order on {re.escape(pair)} level .*? filled with P&L (-?\d+\.?\d*) and qty .*"
)
for timestamp, message in logEntries:
if timestamp >= strategyStartTime:
match = pattern.search(message)
if match:
t = float(match.group(2))
totalPnL += t
return totalPnL
def getLevels(amount, highPrice, lowPrice, roundDecimals):
# Returns array of prices from low to high for each level
levels = []
delta = (highPrice - lowPrice)/amount