Run balance checks intermittently

This commit is contained in:
Mark Veidemanis 2022-02-18 08:41:32 +00:00
parent 4f24417417
commit 18ef7a0350
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 21 additions and 0 deletions

View File

@ -1,5 +1,7 @@
# Twisted/Klein imports
from twisted.logger import Logger
from twisted.internet.task import LoopingCall
from twisted.internet.threads import deferToThread
# Other library imports
from json import dumps
@ -37,6 +39,25 @@ class Transactions(object):
ca_certs="certs/ca.crt",
)
def run_checks_in_thread(self):
"""
Run all the balance checks that output into ES in another thread.
"""
deferToThread(self.get_total)
deferToThread(self.get_remaining)
deferToThread(self.get_profit)
deferToThread(self.get_open_trades_usd)
deferToThread(self.get_total_remaining)
deferToThread(self.get_total_with_trades)
def setup_loops(self):
"""
Set up the LoopingCalls to get the balance so we have data in ES.
"""
self.lc_es_checks = LoopingCall(self.run_checks_in_thread)
delay = int(settings.ES.RefreshSec)
self.lc_es_checks.start(delay)
# TODO: write tests then refactor, this is terribly complicated!
def transaction(self, data):
"""