47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from mixins.views import ObjectRead
|
|
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
|
|
from core.util import logs
|
|
from core.views.helpers import synchronize_async_helper
|
|
|
|
log = logs.get_logger(__name__)
|
|
|
|
|
|
class Profit(LoginRequiredMixin, OTPRequiredMixin, ObjectRead):
|
|
context_object_name_singular = "profit"
|
|
context_object_name = "profit"
|
|
|
|
def get_object(self, **kwargs):
|
|
res = synchronize_async_helper(
|
|
money.check_all(
|
|
user=self.request.user, nordigen=NordigenClient, agora=AgoraClient
|
|
)
|
|
)
|
|
for key in res.keys():
|
|
if type(res[key]) != str:
|
|
res[key] = round(res[key], 2)
|
|
results = {
|
|
"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"],
|
|
"Profit in XMR": res["total_profit_in_xmr"],
|
|
"Remaining before withdrawal": res["total_remaining"],
|
|
"Total (without open trades)": res["total_usd"],
|
|
"Profit (without open trades)": res["profit"],
|
|
"Profit (without open trades) in XMR": res["profit_in_xmr"],
|
|
"Remaining before withdrawal (without open trades)": res["remaining"],
|
|
"Base balance required": res["total_base_usd"],
|
|
"Amount above base balance to trigger withdrawal": res[
|
|
"total_withdrawal_limit"
|
|
],
|
|
"Withdrawal trigger": res["withdraw_threshold"],
|
|
}
|
|
|
|
return results
|