Fix how min and max are used in transactions
This commit is contained in:
parent
e4e88ac301
commit
158b452167
|
@ -72,6 +72,8 @@ class Transactions(object):
|
||||||
event = data["event"]
|
event = data["event"]
|
||||||
ts = data["timestamp"]
|
ts = data["timestamp"]
|
||||||
|
|
||||||
|
if "data" not in data:
|
||||||
|
return
|
||||||
inside = data["data"]
|
inside = data["data"]
|
||||||
|
|
||||||
txid = inside["id"]
|
txid = inside["id"]
|
||||||
|
@ -152,10 +154,8 @@ class Transactions(object):
|
||||||
"description": description,
|
"description": description,
|
||||||
"valid": 0, # All checks passed and we can release escrow?
|
"valid": 0, # All checks passed and we can release escrow?
|
||||||
}
|
}
|
||||||
|
|
||||||
self.log.info("Transaction processed: {formatted}", formatted=dumps(to_store, indent=2))
|
self.log.info("Transaction processed: {formatted}", formatted=dumps(to_store, indent=2))
|
||||||
self.irc.sendmsg(f"AUTO Incoming transaction: {amount}{currency} ({reference}) - {state} - {description}")
|
self.irc.sendmsg(f"AUTO Incoming transaction: {amount}{currency} ({reference}) - {state} - {description}")
|
||||||
|
|
||||||
# Partial reference implementation
|
# Partial reference implementation
|
||||||
# Account for silly people not removing the default string
|
# Account for silly people not removing the default string
|
||||||
# Split the reference into parts
|
# Split the reference into parts
|
||||||
|
@ -230,14 +230,14 @@ class Transactions(object):
|
||||||
if looked_up_without_reference:
|
if looked_up_without_reference:
|
||||||
return
|
return
|
||||||
# If the amount does not match exactly, get the min and max values for our given acceptable margins for trades
|
# If the amount does not match exactly, get the min and max values for our given acceptable margins for trades
|
||||||
min_amount, max_amount = self.money.get_acceptable_margins(currency, amount)
|
min_amount, max_amount = self.money.get_acceptable_margins(currency, stored_trade["amount"])
|
||||||
self.log.info(
|
self.log.info(
|
||||||
"Amount does not match exactly, trying with margins: min: {min_amount} / max: {max_amount}",
|
"Amount does not match exactly, trying with margins: min: {min_amount} / max: {max_amount}",
|
||||||
min_amount=min_amount,
|
min_amount=min_amount,
|
||||||
max_amount=max_amount,
|
max_amount=max_amount,
|
||||||
)
|
)
|
||||||
self.irc.sendmsg(f"Amount does not match exactly, trying with margins: min: {min_amount} / max: {max_amount}")
|
self.irc.sendmsg(f"Amount does not match exactly, trying with margins: min: {min_amount} / max: {max_amount}")
|
||||||
if not min_amount < stored_trade["amount"] < max_amount:
|
if not min_amount < amount < max_amount:
|
||||||
self.log.info(
|
self.log.info(
|
||||||
"Amount mismatch - not in margins: {amount} (min: {min_amount} / max: {max_amount}",
|
"Amount mismatch - not in margins: {amount} (min: {min_amount} / max: {max_amount}",
|
||||||
amount=stored_trade["amount"],
|
amount=stored_trade["amount"],
|
||||||
|
@ -562,33 +562,6 @@ class Transactions(object):
|
||||||
self.write_to_es("get_remaining", cast_es)
|
self.write_to_es("get_remaining", cast_es)
|
||||||
return remaining
|
return remaining
|
||||||
|
|
||||||
# TODO: move to money
|
|
||||||
def get_profit(self, trades=False):
|
|
||||||
"""
|
|
||||||
Check how much total profit we have made.
|
|
||||||
:return: profit in USD
|
|
||||||
:rtype: float
|
|
||||||
"""
|
|
||||||
total_usd = self.get_total_usd()
|
|
||||||
if not total_usd:
|
|
||||||
return False
|
|
||||||
if trades:
|
|
||||||
trades_usd = self.get_open_trades_usd()
|
|
||||||
total_usd += trades_usd
|
|
||||||
|
|
||||||
profit = total_usd - float(settings.Money.BaseUSD)
|
|
||||||
if trades:
|
|
||||||
cast_es = {
|
|
||||||
"profit_trades_usd": profit,
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
cast_es = {
|
|
||||||
"profit_usd": profit,
|
|
||||||
}
|
|
||||||
|
|
||||||
self.write_to_es("get_profit", cast_es)
|
|
||||||
return profit
|
|
||||||
|
|
||||||
def get_open_trades_usd(self):
|
def get_open_trades_usd(self):
|
||||||
"""
|
"""
|
||||||
Get total value of open trades in USD.
|
Get total value of open trades in USD.
|
||||||
|
|
Loading…
Reference in New Issue