Thornode: new trade_limit property

This commit is contained in:
The MMGen Project 2026-10-08 13:12:03 +00:00
commit cef8ed21e1
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 13 additions and 13 deletions

View file

@ -51,7 +51,7 @@ class Thornode:
else:
self.data = self.rpc.get_quote(self.tx.send_asset, self.tx.recv_asset, self.in_amt)
async def format_quote(self, trade_limit, *, deduct_est_fee=False):
async def format_quote(self, *, deduct_est_fee=False):
from ....util import make_timestr, ymsg
from ....util2 import format_elapsed_hr
from ....color import blue, green, cyan, pink, orange, redbg, yelbg, grnbg
@ -66,9 +66,9 @@ class Thornode:
if tx.proto.has_usr_fee:
gas_unit = d['gas_rate_units']
if trade_limit:
if self.trade_limit:
from . import ExpInt4
tl_int = ExpInt4(trade_limit.to_unit('satoshi'))
tl_int = ExpInt4(self.trade_limit.to_unit('satoshi'))
tl_uniamt = UniAmt(tl_int.trunc, from_unit='satoshi')
ratio = float(tl_uniamt / out_amt)
direction = 'ABOVE' if ratio > 1 else 'below'
@ -137,6 +137,14 @@ class Thornode:
Slippage: {pink(slip_pct_disp)}
"""
@property
def trade_limit(self):
match self.tx.swap_cfg.trade_limit:
case UniAmt(): # can’t use positional arg here (not supported by Decimal)
return self.tx.swap_cfg.trade_limit
case float(x):
return UniAmt(int(self.data['expected_amount_out']), from_unit='satoshi') * x
@property
def inbound_address(self):
addr = self.data['inbound_address']

View file

@ -184,13 +184,6 @@ class NewSwap(New):
self.recv_proto.coin_addr(self.swap_proto_mod.Memo.parse(memo).address),
trade_limit = trade_limit)
def get_trade_limit(self, qd):
match self.swap_cfg.trade_limit:
case UniAmt(): # can’t use positional arg here (not supported by Decimal)
return self.swap_cfg.trade_limit
case float(x):
return UniAmt(int(qd.data['expected_amount_out']), from_unit='satoshi') * x
async def update_vault_output(self, amt, *, deduct_est_fee=False):
qd = self.swap_proto_mod.rpc_client(self, amt)
@ -204,8 +197,7 @@ class NewSwap(New):
self.cfg._util.qmsg('OK')
self.swap_quote_refresh_time = time.time()
await self.set_gas(to_addr=qd.router if self.is_token else None)
trade_limit = self.get_trade_limit(qd)
msg(await qd.format_quote(trade_limit, deduct_est_fee=deduct_est_fee))
msg(await qd.format_quote(deduct_est_fee=deduct_est_fee))
ch = get_char('Press ‘r’ to refresh quote, any other key to continue: ')
msg('')
if ch not in 'Rr':
@ -213,6 +205,6 @@ class NewSwap(New):
self.swap_quote_expiry = qd.data['expiry']
self.update_vault_addr(qd)
self.update_data_output(trade_limit)
self.update_data_output(qd.trade_limit)
self.quote_data = qd
return qd.rel_fee_hint