Add initial balance to template and adjust PL calculation to use initial balance

This commit is contained in:
Mark Veidemanis 2023-01-11 20:43:11 +00:00
parent 9a69120695
commit 3f05553c71
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
3 changed files with 7 additions and 2 deletions

View File

@ -13,6 +13,7 @@
<th>name</th>
<th>exchange</th>
<th>currency</th>
<th>initial</th>
<th>API key</th>
<th>sandbox</th>
<th>enabled</th>
@ -25,6 +26,7 @@
<td>{{ item.name }}</td>
<td>{{ item.exchange }}</td>
<td>{{ item.currency }}</td>
<td>{{ item.initial_balance }}</td>
<td>{{ item.api_key }}</td>
<td>
{% if item.sandbox %}

View File

@ -23,6 +23,7 @@ class AccountInfo(LoginRequiredMixin, OTPRequiredMixin, ObjectRead):
"api_key",
"sandbox",
"supported_symbols",
"initial_balance",
# "instruments",
]

View File

@ -1,3 +1,5 @@
from decimal import Decimal as D
from django.contrib.auth.mixins import LoginRequiredMixin
from two_factor.views.mixins import OTPRequiredMixin
@ -29,8 +31,8 @@ class Profit(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
details = account.client.get_account()
item = {
"account": account,
"pl": float(details["pl"]),
"unrealizedPL": float(details["unrealizedPL"]),
"pl": D(account.initial_balance) - D(details["balance"]),
"unrealizedPL": D(details["unrealizedPL"]),
"balance": details["balance"],
"currency": details["currency"],
}