Implement more payout management
This commit is contained in:
@@ -8,7 +8,14 @@ from core.clients.aggregators.nordigen import NordigenClient
|
||||
from core.clients.platforms.agora import AgoraClient
|
||||
from core.lib.money import Money
|
||||
from core.lib.notify import sendmsg
|
||||
from core.models import INTERVAL_CHOICES, Aggregator, LinkGroup, Platform, Requisition
|
||||
from core.models import (
|
||||
INTERVAL_CHOICES,
|
||||
Aggregator,
|
||||
LinkGroup,
|
||||
Payout,
|
||||
Platform,
|
||||
Requisition,
|
||||
)
|
||||
from core.util import logs
|
||||
|
||||
log = logs.get_logger("scheduling")
|
||||
@@ -29,6 +36,16 @@ async def withdrawal_job(group=None):
|
||||
checks = await money.check_all(
|
||||
link_group=group, nordigen=NordigenClient, agora=AgoraClient
|
||||
)
|
||||
|
||||
if checks["total_remaining"] > 0:
|
||||
# More than 0 remaining, so we can't withdraw
|
||||
await sendmsg(
|
||||
group.user,
|
||||
f"{checks['total_remaining']} left until you can withdraw.",
|
||||
title="Balance update",
|
||||
)
|
||||
continue
|
||||
|
||||
print("CHECKS", checks)
|
||||
aggregators = Aggregator.objects.filter(
|
||||
user=group.user,
|
||||
@@ -63,8 +80,10 @@ async def withdrawal_job(group=None):
|
||||
title="Your withdrawal is ready!",
|
||||
)
|
||||
|
||||
if not checks["total_profit_in_xmr"] >= 0:
|
||||
return
|
||||
# TODO: UNCOMMENT
|
||||
# COMMENTED FOR TESTING
|
||||
# if not checks["total_profit_in_xmr"] >= 0:
|
||||
# return
|
||||
|
||||
total_withdrawal = sum(collapsed.values())
|
||||
if checks["total_xmr_agora"] < total_withdrawal:
|
||||
@@ -84,21 +103,38 @@ async def withdrawal_job(group=None):
|
||||
# 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,
|
||||
}
|
||||
for wallet, pay_list_iter in pay_list.items():
|
||||
for amount, reason in pay_list_iter:
|
||||
print("ITER", wallet, pay_list_iter)
|
||||
print("ITER SENT", wallet, amount, reason)
|
||||
|
||||
print("CAST ADDRESS", cast["address"])
|
||||
print("CAST AMOUNT", cast["amount"])
|
||||
print("CAST OTP TRUNCATED BY 2", cast["otp"][-2])
|
||||
# for wallet, amount in collapsed.items():
|
||||
print("ITER SEND", wallet, amount)
|
||||
cast = {
|
||||
"address": wallet.address,
|
||||
"amount": amount,
|
||||
"password": platform.password,
|
||||
"otp": otp_code,
|
||||
}
|
||||
|
||||
# sent = await run.call("wallet_send_xmr", **cast)
|
||||
# print("SENT", sent)
|
||||
print("CAST ADDRESS", cast["address"])
|
||||
print("CAST AMOUNT", cast["amount"])
|
||||
print("CAST OTP TRUNCATED BY 2", cast["otp"][-2])
|
||||
|
||||
# TODO: UNCOMMENT
|
||||
# sent = await run.call("wallet_send_xmr", **cast)
|
||||
# print("SENT", sent)
|
||||
|
||||
payout = Payout.objects.create( # noqa
|
||||
user=group.user,
|
||||
wallet=wallet,
|
||||
amount=amount,
|
||||
description=reason,
|
||||
)
|
||||
|
||||
# TODO: UNCOMMENT
|
||||
# payout.response = sent
|
||||
# payout.save()
|
||||
|
||||
|
||||
async def aggregator_job():
|
||||
|
||||
Reference in New Issue
Block a user