diff --git a/core/management/commands/scheduling.py b/core/management/commands/scheduling.py index b668816..88f17b3 100644 --- a/core/management/commands/scheduling.py +++ b/core/management/commands/scheduling.py @@ -2,6 +2,7 @@ import asyncio from apscheduler.schedulers.asyncio import AsyncIOScheduler from django.core.management.base import BaseCommand +from pyotp import TOTP from core.clients.aggregators.nordigen import NordigenClient from core.clients.platforms.agora import AgoraClient @@ -62,6 +63,43 @@ async def withdrawal_job(group=None): title="Your withdrawal is ready!", ) + if not checks["total_profit_in_xmr"] >= 0: + return + + total_withdrawal = sum(collapsed.values()) + if checks["total_xmr_agora"] < total_withdrawal: + await sendmsg( + group.user, + ( + f"Attempting to withdraw {total_withdrawal}, but you only have" + f" {checks['total_xmr_agora']} in your Agora wallet." + ), + title="Withdrawal failed", + ) + continue + if group.platforms.count() != 1: + raise Exception("You can only have one platform per group") + + platform = group.platforms.first() + # run = await AgoraClient(platform) + otp_code = TOTP(platform.otp_token).now() + + for wallet, amount in collapsed.items(): + print("ITER SEND", wallet, amount) + cast = { + "address": wallet.address, + "amount": amount, + "password": platform.password, + "otp": otp_code, + } + + print("CAST ADDRESS", cast["address"]) + print("CAST AMOUNT", cast["amount"]) + print("CAST OTP TRUNCATED BY 2", cast["otp"][-2]) + + # sent = await run.call("wallet_send_xmr", **cast) + # print("SENT", sent) + async def aggregator_job(): aggregators = Aggregator.objects.filter(enabled=True)