2023-03-11 00:21:58 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
2023-03-11 11:51:19 +00:00
|
|
|
from mixins.views import ObjectRead
|
2023-03-11 00:21:58 +00:00
|
|
|
from two_factor.views.mixins import OTPRequiredMixin
|
|
|
|
|
|
|
|
from core.clients.aggregators.nordigen import NordigenClient
|
|
|
|
from core.clients.platforms.agora import AgoraClient
|
|
|
|
from core.lib.money import money
|
2023-03-11 11:51:19 +00:00
|
|
|
from core.util import logs
|
2023-03-11 00:21:58 +00:00
|
|
|
from core.views.helpers import synchronize_async_helper
|
|
|
|
|
|
|
|
log = logs.get_logger(__name__)
|
|
|
|
|
2023-03-11 11:51:19 +00:00
|
|
|
|
2023-03-11 00:21:58 +00:00
|
|
|
class Profit(LoginRequiredMixin, OTPRequiredMixin, ObjectRead):
|
|
|
|
context_object_name_singular = "profit"
|
|
|
|
context_object_name = "profit"
|
2023-03-11 11:45:24 +00:00
|
|
|
page_title = "Profit info (USD)"
|
2023-03-11 00:21:58 +00:00
|
|
|
# detail_template = "partials/profit-info.html"
|
|
|
|
|
|
|
|
def get_object(self, **kwargs):
|
2023-03-11 11:51:19 +00:00
|
|
|
res = synchronize_async_helper(
|
|
|
|
money.check_all(
|
|
|
|
user=self.request.user, nordigen=NordigenClient, agora=AgoraClient
|
|
|
|
)
|
|
|
|
)
|
2023-03-11 11:45:24 +00:00
|
|
|
print("RES", res)
|
2023-03-11 00:21:58 +00:00
|
|
|
results = {
|
2023-03-11 11:45:24 +00:00
|
|
|
"Bank balance total": res["total_sinks_usd"],
|
|
|
|
"Platform balance total": res["total_usd_agora"],
|
|
|
|
"Open trade value": res["open_trade_value"],
|
|
|
|
"Total": res["total_with_trades"],
|
|
|
|
"Profit": res["total_profit"],
|
|
|
|
"Remaining before withdrawal": res["total_remaining"],
|
|
|
|
"Total (without open trades)": res["total_usd"],
|
|
|
|
"Profit (without open trades)": res["profit"],
|
|
|
|
"Remaining before withdrawal (without open trades)": res["remaining"],
|
|
|
|
"Base balance required": res["total_base_usd"],
|
2023-03-11 11:51:19 +00:00
|
|
|
"Amount above base balance to trigger withdrawal": res[
|
|
|
|
"total_withdrawal_limit"
|
|
|
|
],
|
2023-03-11 11:45:24 +00:00
|
|
|
"Withdrawal trigger": res["withdraw_threshold"],
|
2023-03-11 00:21:58 +00:00
|
|
|
}
|
2023-03-11 11:51:19 +00:00
|
|
|
return results
|