|
|
|
@ -14,6 +14,7 @@ from .forms import NewTradeForm, ClosedTradeFilterForm, LoginForm |
|
|
|
import redis |
|
|
|
import redis |
|
|
|
import json |
|
|
|
import json |
|
|
|
import datetime |
|
|
|
import datetime |
|
|
|
|
|
|
|
import calendar |
|
|
|
|
|
|
|
|
|
|
|
def login_view(request): |
|
|
|
def login_view(request): |
|
|
|
if request.method == 'POST': |
|
|
|
if request.method == 'POST': |
|
|
|
@ -300,14 +301,41 @@ def performance(request): |
|
|
|
columns = {} |
|
|
|
columns = {} |
|
|
|
for account in all_accounts: |
|
|
|
for account in all_accounts: |
|
|
|
columns[account] = [] |
|
|
|
columns[account] = [] |
|
|
|
prev_day = None |
|
|
|
timeframe = request.GET.get('timeframe') |
|
|
|
for trade in closed_trades: |
|
|
|
if timeframe == 'daily': |
|
|
|
if prev_day != trade.exitTime.date(): |
|
|
|
prev_day = None |
|
|
|
prev_day = trade.exitTime.date() |
|
|
|
for trade in closed_trades: |
|
|
|
dates.append(prev_day) |
|
|
|
if prev_day != trade.exitTime.date(): |
|
|
|
for account in all_accounts: |
|
|
|
prev_day = trade.exitTime.date() |
|
|
|
columns[account].append(0) |
|
|
|
dates.append(prev_day) |
|
|
|
columns[trade.account][-1] += trade.profit |
|
|
|
for account in all_accounts: |
|
|
|
|
|
|
|
columns[account].append(0) |
|
|
|
|
|
|
|
columns[trade.account][-1] += trade.profit |
|
|
|
|
|
|
|
elif timeframe == 'weekly': |
|
|
|
|
|
|
|
epoch = datetime.date(1970, 1, 1) |
|
|
|
|
|
|
|
prev_week = None |
|
|
|
|
|
|
|
for trade in closed_trades: |
|
|
|
|
|
|
|
this_week = (trade.exitTime.date() - epoch).days // 7 |
|
|
|
|
|
|
|
if prev_week != this_week: |
|
|
|
|
|
|
|
prev_week = this_week |
|
|
|
|
|
|
|
week_end = epoch + datetime.timedelta(weeks=prev_week + 1) |
|
|
|
|
|
|
|
dates.append(week_end) |
|
|
|
|
|
|
|
for account in all_accounts: |
|
|
|
|
|
|
|
columns[account].append(0) |
|
|
|
|
|
|
|
columns[trade.account][-1] += trade.profit |
|
|
|
|
|
|
|
elif timeframe == 'monthly': |
|
|
|
|
|
|
|
epoch = datetime.date(1970, 1, 1) |
|
|
|
|
|
|
|
prev_month = None |
|
|
|
|
|
|
|
for trade in closed_trades: |
|
|
|
|
|
|
|
this_month = trade.exitTime.date().month |
|
|
|
|
|
|
|
if prev_month != this_month: |
|
|
|
|
|
|
|
prev_month = this_month |
|
|
|
|
|
|
|
this_date = trade.exitTime.date() |
|
|
|
|
|
|
|
month_end = datetime.date(this_date.year, this_date.month, calendar.monthrange(this_date.year, this_date.month)[1]) |
|
|
|
|
|
|
|
dates.append(month_end) |
|
|
|
|
|
|
|
for account in all_accounts: |
|
|
|
|
|
|
|
columns[account].append(0) |
|
|
|
|
|
|
|
columns[trade.account][-1] += trade.profit |
|
|
|
|
|
|
|
|
|
|
|
results = { 'total' : { 'pnl' : 0, 'profit' : 0, 'loss' : 0 } } |
|
|
|
results = { 'total' : { 'pnl' : 0, 'profit' : 0, 'loss' : 0 } } |
|
|
|
|
|
|
|
|
|
|
|
@ -333,6 +361,7 @@ def performance(request): |
|
|
|
'user' : request.user, |
|
|
|
'user' : request.user, |
|
|
|
'dates' : dates, |
|
|
|
'dates' : dates, |
|
|
|
'columns' : columns, |
|
|
|
'columns' : columns, |
|
|
|
'results' : results |
|
|
|
'results' : results, |
|
|
|
|
|
|
|
'timeframe' : timeframe |
|
|
|
} |
|
|
|
} |
|
|
|
return HttpResponse(template.render(context, request)) |
|
|
|
return HttpResponse(template.render(context, request)) |
|
|
|
|