Run balance checks intermittently
This commit is contained in:
parent
4f24417417
commit
18ef7a0350
|
@ -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…
Reference in New Issue