Only check transactions when we have a trade and make the fetch less efficient to throttle requests more
This commit is contained in:
@@ -18,23 +18,38 @@ INTERVALS_PLATFORM = [x[0] for x in INTERVAL_CHOICES]
|
||||
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 = await NordigenClient(aggregator)
|
||||
instance = None
|
||||
if aggregator.fetch_accounts is True:
|
||||
aggregator.account_info = {}
|
||||
aggregator.save()
|
||||
instance = await NordigenClient(aggregator)
|
||||
await instance.get_all_account_info(store=True)
|
||||
|
||||
fetch_tasks = []
|
||||
# fetch_tasks = []
|
||||
for bank, accounts in aggregator.account_info.items():
|
||||
for account in accounts:
|
||||
account_id = account["account_id"]
|
||||
requisition_id = account["requisition_id"]
|
||||
task = instance.get_transactions(
|
||||
log.debug(f"Polling currency {account['currency']}")
|
||||
if account["currency"] not in open_trade_currencies:
|
||||
log.debug(
|
||||
f"Skipping {account_id}, not in {open_trade_currencies}"
|
||||
)
|
||||
continue # Next account
|
||||
# Avoid hammering the API with new access token requests
|
||||
if instance is None:
|
||||
instance = await NordigenClient(aggregator)
|
||||
# task = instance.get_transactions(
|
||||
# account_id, req=requisition_id, process=True
|
||||
# )
|
||||
await instance.get_transactions(
|
||||
account_id, req=requisition_id, process=True
|
||||
)
|
||||
fetch_tasks.append(task)
|
||||
await asyncio.gather(*fetch_tasks)
|
||||
# fetch_tasks.append(task)
|
||||
# await asyncio.gather(*fetch_tasks)
|
||||
else:
|
||||
raise NotImplementedError(f"No such client library: {aggregator.service}")
|
||||
aggregator.fetch_accounts = False
|
||||
|
||||
Reference in New Issue
Block a user