Libraries refactor and add some sinks #4

Closed
m wants to merge 136 commits from library-refactor into master
2 changed files with 20 additions and 0 deletions
Showing only changes of commit 6dd11bbfa5 - Show all commits

View File

@ -378,6 +378,7 @@ class Agora(object):
ads = self.money.lookup_rates(ads_list, rates=rates) ads = self.money.lookup_rates(ads_list, rates=rates)
if not ads: if not ads:
continue continue
self.write_to_es_ads("ads", ads)
if currency in public_ads: if currency in public_ads:
for ad in list(ads): for ad in list(ads):
if ad not in public_ads[currency]: if ad not in public_ads[currency]:
@ -387,6 +388,24 @@ class Agora(object):
return public_ads return public_ads
def write_to_es_ads(self, msgtype, ads):
if settings.ES.Enabled == "1":
for ad in ads:
cast = {
"id": ad[0],
"username": ad[1],
"price": ad[2],
"provider": ad[3],
"asset": ad[4],
"currency": ad[5],
"margin": ad[6],
}
cast["type"] = msgtype
cast["ts"] = str(datetime.now().isoformat())
cast["xtype"] = "platorm"
cast["market"] = "agora"
self.es.index(index=settings.ES.MetaIndex, document=cast)
def slow_ad_update(self, ads): def slow_ad_update(self, ads):
""" """
Slow ad equation update utilising exponential backoff in order to guarantee all ads are updated. Slow ad equation update utilising exponential backoff in order to guarantee all ads are updated.

View File

@ -60,6 +60,7 @@ class Transactions(object):
self.lc_es_checks = LoopingCall(self.run_checks_in_thread) self.lc_es_checks = LoopingCall(self.run_checks_in_thread)
delay = int(settings.ES.RefreshSec) delay = int(settings.ES.RefreshSec)
self.lc_es_checks.start(delay) self.lc_es_checks.start(delay)
self.agora.es = self.es
# TODO: write tests then refactor, this is terribly complicated! # TODO: write tests then refactor, this is terribly complicated!
def transaction(self, data): def transaction(self, data):