Libraries refactor and add some sinks #4
|
@ -31,6 +31,7 @@ class Transactions(object):
|
|||
Set the logger.
|
||||
"""
|
||||
self.log = Logger("transactions")
|
||||
if settings.ES.Enabled == "1":
|
||||
self.es = Elasticsearch(
|
||||
f"https://{settings.ES.Host}:9200",
|
||||
verify_certs=False,
|
||||
|
@ -55,6 +56,7 @@ class Transactions(object):
|
|||
"""
|
||||
Set up the LoopingCalls to get the balance so we have data in ES.
|
||||
"""
|
||||
if settings.ES.Enabled == "1":
|
||||
self.lc_es_checks = LoopingCall(self.run_checks_in_thread)
|
||||
delay = int(settings.ES.RefreshSec)
|
||||
self.lc_es_checks.start(delay)
|
||||
|
@ -536,6 +538,7 @@ class Transactions(object):
|
|||
return cast
|
||||
|
||||
def write_to_es(self, msgtype, cast):
|
||||
if settings.ES.Enabled == "1":
|
||||
cast["type"] = msgtype
|
||||
cast["ts"] = str(datetime.now().isoformat())
|
||||
cast["xtype"] = "tx"
|
||||
|
@ -599,7 +602,25 @@ class Transactions(object):
|
|||
rates = self.agora.get_rates_all()
|
||||
cumul_usd = 0
|
||||
for contact_id, contact in dash.items():
|
||||
amount = contact["data"]["amount"]
|
||||
# We need created at in order to look up the historical prices
|
||||
created_at = contact["data"]["created_at"]
|
||||
|
||||
# Reformat the date how CoinGecko likes
|
||||
date_parsed = datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%S.%fZ")
|
||||
date_formatted = date_parsed.strftime("%d-%m-%Y")
|
||||
|
||||
# Get the historical rates for the right asset, extract the price
|
||||
asset = contact["data"]["advertisement"]["asset"]
|
||||
if asset == "XMR":
|
||||
amount_crypto = contact["data"]["amount_xmr"]
|
||||
history = self.agora.cg.get_coin_history_by_id(id="monero", date=date_formatted)
|
||||
crypto_usd = float(history["market_data"]["current_price"]["usd"])
|
||||
elif asset == "BTC":
|
||||
amount_crypto = contact["data"]["amount_btc"]
|
||||
history = self.agora.cg.get_coin_history_by_id(id="bitcoin", date=date_formatted)
|
||||
crypto_usd = float(history["market_data"]["current_price"]["usd"])
|
||||
# Convert crypto to fiat
|
||||
amount = float(amount_crypto) * crypto_usd
|
||||
currency = contact["data"]["currency"]
|
||||
if not contact["data"]["is_selling"]:
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue