40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from two_factor.views.mixins import OTPRequiredMixin
|
|
|
|
from core.exchanges import GenericAPIError
|
|
from core.models import Account
|
|
from core.util import logs
|
|
from core.views import ObjectList
|
|
|
|
log = logs.get_logger(__name__)
|
|
|
|
|
|
class Profit(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
|
|
list_template = "partials/profit-list.html"
|
|
page_title = "Profit by account"
|
|
page_subtitle = None
|
|
|
|
context_object_name_singular = "profit"
|
|
context_object_name = "profit"
|
|
|
|
list_url_name = "profit"
|
|
list_url_args = ["type"]
|
|
|
|
def get_queryset(self, **kwargs):
|
|
items = []
|
|
accounts = Account.objects.filter(user=self.request.user)
|
|
for account in accounts:
|
|
try:
|
|
details = account.client.get_account()
|
|
item = {
|
|
"account": account,
|
|
"pl": float(details["pl"]),
|
|
"unrealizedPL": float(details["unrealizedPL"]),
|
|
"balance": details["balance"],
|
|
"currency": details["currency"],
|
|
}
|
|
items.append(item)
|
|
except GenericAPIError:
|
|
continue
|
|
return items
|