Log more things into ES
This commit is contained in:
parent
dfe02f557c
commit
df195d968c
|
@ -7,16 +7,16 @@ from random import choices
|
|||
from string import ascii_uppercase
|
||||
from elasticsearch import Elasticsearch
|
||||
from datetime import datetime
|
||||
|
||||
# TODO: secure ES traffic properly
|
||||
import urllib3
|
||||
urllib3.disable_warnings()
|
||||
|
||||
# Project imports
|
||||
from settings import settings
|
||||
from db import r
|
||||
from util import convert
|
||||
|
||||
# TODO: secure ES traffic properly
|
||||
urllib3.disable_warnings()
|
||||
|
||||
|
||||
class Transactions(object):
|
||||
"""
|
||||
|
@ -33,7 +33,7 @@ class Transactions(object):
|
|||
f"https://{settings.ES.Host}:9200",
|
||||
verify_certs=False,
|
||||
basic_auth=(settings.ES.Username, settings.ES.Pass),
|
||||
#ssl_assert_fingerprint=("6b264fd2fd107d45652d8add1750a8a78f424542e13b056d0548173006260710"),
|
||||
# ssl_assert_fingerprint=("6b264fd2fd107d45652d8add1750a8a78f424542e13b056d0548173006260710"),
|
||||
ca_certs="certs/ca.crt",
|
||||
)
|
||||
|
||||
|
@ -433,6 +433,18 @@ class Transactions(object):
|
|||
# Add it all up
|
||||
total_usd_agora = total_usd_agora_xmr + total_usd_agora_btc
|
||||
total_usd = total_usd_agora + total_usd_revolut
|
||||
cast_es = {
|
||||
"price_usd": total_usd,
|
||||
"total_usd_agora_xmr": total_usd_agora_xmr,
|
||||
"total_usd_agora_btc": total_usd_agora_btc,
|
||||
"total_xmr_agora": total_xmr_agora,
|
||||
"total_btc_agora": total_btc_agora,
|
||||
"xmr_usd": xmr_usd["monero"]["usd"],
|
||||
"btc_usd": btc_usd["bitcoin"]["usd"],
|
||||
"total_usd_revolut": total_usd_revolut,
|
||||
"total_usd_agora": total_usd_agora,
|
||||
}
|
||||
self.write_to_es("get_total_usd", cast_es)
|
||||
return total_usd
|
||||
|
||||
# TODO: possibly refactor this into smaller functions which don't return as much stuff
|
||||
|
@ -484,22 +496,27 @@ class Transactions(object):
|
|||
(total_usd_agora_xmr, total_usd_agora_btc), # Total USD balance in only Agora
|
||||
(total_xmr_agora, total_btc_agora),
|
||||
) # Total XMR and BTC balance in Agora
|
||||
self.write_to_es("total", cast)
|
||||
|
||||
cast_es = {
|
||||
"price_sek": price_sek,
|
||||
"price_usd": price_usd,
|
||||
"price_gbp": price_gbp,
|
||||
"total_usd_agora_xmr": total_usd_agora_xmr,
|
||||
"total_usd_agora_btc": total_usd_agora_btc,
|
||||
"total_xmr_agora": total_xmr_agora,
|
||||
"total_btc_agora": total_btc_agora,
|
||||
"xmr_usd": xmr_usd["monero"]["usd"],
|
||||
"btc_usd": btc_usd["bitcoin"]["usd"],
|
||||
"total_usd_revolut": total_usd_revolut,
|
||||
"total_usd_agora": total_usd_agora,
|
||||
}
|
||||
self.write_to_es("get_total", cast_es)
|
||||
return cast
|
||||
|
||||
def write_to_es(self, msgtype, cast):
|
||||
cast_remap = {
|
||||
"type": msgtype,
|
||||
"price_sek": cast[0][0],
|
||||
"price_usd": cast[0][1],
|
||||
"price_gbp": cast[0][2],
|
||||
"total_usd_agora_xmr": cast[1][0],
|
||||
"total_usd_agora_btc": cast[1][1],
|
||||
"total_xmr_agora": cast[2][0],
|
||||
"total_btc_agora": cast[2][1],
|
||||
"ts": str(datetime.now().isoformat()),
|
||||
}
|
||||
self.es.index(index=settings.ES.Index, document=cast_remap)
|
||||
cast["type"] = msgtype
|
||||
cast["ts"] = str(datetime.now().isoformat())
|
||||
self.es.index(index=settings.ES.Index, document=cast)
|
||||
|
||||
def get_remaining(self):
|
||||
"""
|
||||
|
@ -513,7 +530,10 @@ class Transactions(object):
|
|||
|
||||
withdraw_threshold = float(settings.Money.BaseUSD) + float(settings.Money.WithdrawLimit)
|
||||
remaining = withdraw_threshold - total_usd
|
||||
|
||||
cast_es = {
|
||||
"remaining_usd": remaining,
|
||||
}
|
||||
self.write_to_es("get_remaining", cast_es)
|
||||
return remaining
|
||||
|
||||
# TODO: move to money
|
||||
|
@ -531,6 +551,10 @@ class Transactions(object):
|
|||
total_usd += trades_usd
|
||||
|
||||
profit = total_usd - float(settings.Money.BaseUSD)
|
||||
cast_es = {
|
||||
"profit_usd": profit,
|
||||
}
|
||||
self.write_to_es("get_profit", cast_es)
|
||||
return profit
|
||||
|
||||
def get_open_trades_usd(self):
|
||||
|
@ -556,6 +580,11 @@ class Transactions(object):
|
|||
rate = rates[currency]
|
||||
amount_usd = float(amount) / rate
|
||||
cumul_usd += amount_usd
|
||||
|
||||
cast_es = {
|
||||
"trades_usd": cumul_usd,
|
||||
}
|
||||
self.write_to_es("get_open_trades_usd", cast_es)
|
||||
return cumul_usd
|
||||
|
||||
def get_total_remaining(self):
|
||||
|
@ -571,6 +600,11 @@ class Transactions(object):
|
|||
total_usd += total_trades_usd
|
||||
withdraw_threshold = float(settings.Money.BaseUSD) + float(settings.Money.WithdrawLimit)
|
||||
remaining = withdraw_threshold - total_usd
|
||||
|
||||
cast_es = {
|
||||
"total_remaining_usd": remaining,
|
||||
}
|
||||
self.write_to_es("get_total_remaining", cast_es)
|
||||
return remaining
|
||||
|
||||
def get_total_with_trades(self):
|
||||
|
@ -578,4 +612,9 @@ class Transactions(object):
|
|||
if not total_usd:
|
||||
return False
|
||||
total_trades_usd = self.get_open_trades_usd()
|
||||
return total_usd + total_trades_usd
|
||||
total_with_trades = total_usd + total_trades_usd
|
||||
cast_es = {
|
||||
"total_with_trades": total_with_trades,
|
||||
}
|
||||
self.write_to_es("get_total_with_trades", cast_es)
|
||||
return total_with_trades
|
||||
|
|
Loading…
Reference in New Issue