From 3ff4d512a4fb0874e1993ffbaafabf00c8132b6f Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 24 Feb 2022 23:44:10 +0000 Subject: [PATCH] Store cheat output in ES --- handler/agora.py | 19 +++++++++++++++++++ handler/transactions.py | 1 + 2 files changed, 20 insertions(+) diff --git a/handler/agora.py b/handler/agora.py index 609bece..cdc3d75 100644 --- a/handler/agora.py +++ b/handler/agora.py @@ -378,6 +378,7 @@ class Agora(object): ads = self.money.lookup_rates(ads_list, rates=rates) if not ads: continue + self.write_to_es_ads("ads", ads) if currency in public_ads: for ad in list(ads): if ad not in public_ads[currency]: @@ -387,6 +388,24 @@ class Agora(object): 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): """ Slow ad equation update utilising exponential backoff in order to guarantee all ads are updated. diff --git a/handler/transactions.py b/handler/transactions.py index 451bdce..1fc98ef 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -60,6 +60,7 @@ class Transactions(object): self.lc_es_checks = LoopingCall(self.run_checks_in_thread) delay = int(settings.ES.RefreshSec) self.lc_es_checks.start(delay) + self.agora.es = self.es # TODO: write tests then refactor, this is terribly complicated! def transaction(self, data):