Only check transactions when we have a trade and make the fetch less efficient to throttle requests more
This commit is contained in:
parent
da5d1badd8
commit
7e7b145b04
|
@ -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
|
||||
|
|
|
@ -224,6 +224,31 @@ class Aggregator(models.Model):
|
|||
return None
|
||||
return transaction
|
||||
|
||||
@property
|
||||
def trades(self):
|
||||
"""
|
||||
Get all trades for the platforms of this aggregator's link group.
|
||||
"""
|
||||
trades = []
|
||||
for platform in self.platforms:
|
||||
platform_trades = platform.trades
|
||||
for trade in platform_trades:
|
||||
trades.append(trade)
|
||||
|
||||
return trades
|
||||
|
||||
@property
|
||||
def trades_currencies(self):
|
||||
"""
|
||||
Get all the trade fiat currencies.
|
||||
"""
|
||||
currencies = []
|
||||
for trade in self.trades:
|
||||
if trade.currency not in currencies:
|
||||
currencies.append(trade.currency)
|
||||
|
||||
return currencies
|
||||
|
||||
|
||||
class Wallet(models.Model):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue