Run balance checks intermittently

master
Mark Veidemanis 3 years ago
parent aad966feff
commit 3fdb728e04
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -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):
"""

Loading…
Cancel
Save