Port releasing trades to LBTC

This commit is contained in:
Mark Veidemanis 2022-04-15 14:42:12 +01:00
parent e5b7f29346
commit 05bdc5f1e3
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 39 additions and 15 deletions

View File

@ -385,12 +385,21 @@ class Transactions(util.Base):
self.ux.notify.notify_complete_trade(amount, currency) self.ux.notify.notify_complete_trade(amount, currency)
def release_funds(self, trade_id, reference): def release_funds(self, trade_id, reference):
stored_trade = self.get_ref(reference)
platform = stored_trade["subclass"]
logmessage = f"All checks passed, releasing funds for {trade_id} {reference}" logmessage = f"All checks passed, releasing funds for {trade_id} {reference}"
self.log.info(logmessage) self.log.info(logmessage)
self.irc.sendmsg(logmessage) self.irc.sendmsg(logmessage)
rtrn = self.agora.release_funds(trade_id) if platform == "agora":
release = self.agora.release_funds
post_message = self.agora.agora.contact_message_post
elif platform == "lbtc":
release = self.lbtc.release_funds
post_message = self.lbtc.lbtc.contact_message_post
rtrn = release(trade_id)
if rtrn["message"] == "OK": if rtrn["message"] == "OK":
self.agora.agora.contact_message_post(trade_id, "Thanks! Releasing now :)") post_message(trade_id, "Thanks! Releasing now :)")
else: else:
logmessage = f"Release funds unsuccessful: {rtrn['message']}" logmessage = f"Release funds unsuccessful: {rtrn['message']}"
self.log.error(logmessage) self.log.error(logmessage)
@ -465,8 +474,14 @@ class Transactions(util.Base):
r.hmset(f"trade.{reference}", to_store) r.hmset(f"trade.{reference}", to_store)
self.irc.sendmsg(f"Generated reference for {trade_id}: {reference}") self.irc.sendmsg(f"Generated reference for {trade_id}: {reference}")
self.ux.notify.notify_new_trade(amount, currency) self.ux.notify.notify_new_trade(amount, currency)
if settings.Agora.Send == "1": if subclass == "agora":
self.agora.agora.contact_message_post( send_setting = settings.Agora.Send
post_message = self.agora.agora.contact_message_post
elif subclass == "lbtc":
send_setting = settings.LocalBitcoins.Send
post_message = self.lbtc.lbtc.contact_message_post
if send_setting == "1":
post_message(
trade_id, trade_id,
f"Hi! When sending the payment please use reference code: {reference}", f"Hi! When sending the payment please use reference code: {reference}",
) )
@ -759,17 +774,7 @@ class Transactions(util.Base):
self.write_to_es("get_remaining", cast_es) self.write_to_es("get_remaining", cast_es)
return remaining return remaining
def get_open_trades_usd(self): def open_trades_usd_parse_dash(self, dash, rates):
"""
Get total value of open trades in USD.
:return: total trade value
:rtype: float
"""
dash = self.agora.wrap_dashboard()
if dash is False:
return False
rates = self.money.get_rates_all()
cumul_usd = 0 cumul_usd = 0
for contact_id, contact in dash.items(): for contact_id, contact in dash.items():
# We need created at in order to look up the historical prices # We need created at in order to look up the historical prices
@ -800,6 +805,25 @@ class Transactions(util.Base):
rate = rates[currency] rate = rates[currency]
amount_usd = float(amount) / rate amount_usd = float(amount) / rate
cumul_usd += amount_usd cumul_usd += amount_usd
return cumul_usd
def get_open_trades_usd(self):
"""
Get total value of open trades in USD.
:return: total trade value
:rtype: float
"""
dash_agora = self.agora.wrap_dashboard()
if dash_agora is False:
return False
dash_lbtc = self.lbtc.wrap_dashboard()
if dash_lbtc is False:
return False
rates = self.money.get_rates_all()
cumul_usd_agora = self.open_trades_usd_parse_dash(dash_agora, rates)
cumul_usd_lbtc = self.open_trades_usd_parse_dash(dash_lbtc, rates)
cumul_usd = cumul_usd_agora + cumul_usd_lbtc
cast_es = { cast_es = {
"trades_usd": cumul_usd, "trades_usd": cumul_usd,