Implement more detailed link group withdrawal simulations
This commit is contained in:
@@ -5,21 +5,67 @@ from django.core.management.base import BaseCommand
|
||||
|
||||
from core.clients.aggregators.nordigen import NordigenClient
|
||||
from core.clients.platforms.agora import AgoraClient
|
||||
from core.models import INTERVAL_CHOICES, Aggregator, Platform
|
||||
from core.lib.money import Money
|
||||
from core.lib.notify import sendmsg
|
||||
from core.models import INTERVAL_CHOICES, Aggregator, LinkGroup, Platform, Requisition
|
||||
from core.util import logs
|
||||
|
||||
log = logs.get_logger("scheduling")
|
||||
|
||||
INTERVAL_AGGREGATOR = 10
|
||||
INTERVAL_WITHDRAWAL = 7200
|
||||
|
||||
INTERVALS_PLATFORM = [x[0] for x in INTERVAL_CHOICES]
|
||||
|
||||
|
||||
async def withdrawal_job(group=None):
|
||||
money = Money()
|
||||
if group is not None:
|
||||
groups = [group]
|
||||
else:
|
||||
groups = LinkGroup.objects.filter(enabled=True)
|
||||
for group in groups:
|
||||
checks = await money.check_all(
|
||||
user=group.user, nordigen=NordigenClient, agora=AgoraClient
|
||||
)
|
||||
aggregators = Aggregator.objects.filter(
|
||||
user=group.user,
|
||||
link_group=group,
|
||||
)
|
||||
platforms = Platform.objects.filter(
|
||||
user=group.user,
|
||||
link_group=group,
|
||||
)
|
||||
requisitions = Requisition.objects.filter(
|
||||
user=group.user,
|
||||
aggregator__in=aggregators,
|
||||
)
|
||||
pay_list = money.get_pay_list(
|
||||
group,
|
||||
requisitions,
|
||||
platforms,
|
||||
group.user,
|
||||
checks["total_profit"],
|
||||
)
|
||||
collapsed = money.collapse_pay_list(pay_list)
|
||||
if any(collapsed.values()):
|
||||
message = ""
|
||||
print("COLLAPSED", collapsed)
|
||||
for wallet, amount in collapsed.items():
|
||||
print("ITER", wallet, amount)
|
||||
message += f"{wallet}: {amount}\n"
|
||||
print("MESSAGE", message)
|
||||
await sendmsg(
|
||||
group.user,
|
||||
message,
|
||||
title="Your withdrawal is ready!",
|
||||
)
|
||||
|
||||
|
||||
async def aggregator_job():
|
||||
aggregators = Aggregator.objects.filter(enabled=True)
|
||||
for aggregator in aggregators:
|
||||
open_trade_currencies = aggregator.trades_currencies
|
||||
log.debug(f"Currencies of open trades: {open_trade_currencies}")
|
||||
if aggregator.service == "nordigen":
|
||||
instance = None
|
||||
if aggregator.fetch_accounts is True:
|
||||
@@ -74,6 +120,10 @@ class Command(BaseCommand):
|
||||
|
||||
log.debug(f"Scheduling {INTERVAL_AGGREGATOR} second aggregator job")
|
||||
scheduler.add_job(aggregator_job, "interval", seconds=INTERVAL_AGGREGATOR)
|
||||
|
||||
log.debug(f"Scheduling {INTERVAL_WITHDRAWAL} second withdrawal job")
|
||||
scheduler.add_job(withdrawal_job, "interval", seconds=INTERVAL_WITHDRAWAL)
|
||||
|
||||
for interval in INTERVALS_PLATFORM:
|
||||
if interval == 0:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user