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

View File

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

View File

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