price trigger fixes
This commit is contained in:
@@ -223,7 +223,7 @@ async def input_amount_is_sufficient(order, token_balance):
|
||||
if price is None:
|
||||
return token_balance > 0 # we don't know the price so we allow any nonzero amount to be sufficient
|
||||
pool = await get_pool(order.pool_address)
|
||||
price *= dec(10) ** dec(-pool['decimals'])
|
||||
price *= dec(10) ** -pool['decimals']
|
||||
inverted = order.order.tokenIn != pool['base']
|
||||
minimum = dec(order.min_fill_amount)*price if inverted else dec(order.min_fill_amount)/price
|
||||
log.debug(f'order minimum amount is {order.min_fill_amount} '+ ("input" if order.amount_is_input else f"output @ {price} = {minimum} ")+f'< {token_balance} balance')
|
||||
@@ -323,23 +323,21 @@ class PriceLineTrigger (Trigger):
|
||||
by_pool: dict[str,set['PriceLineTrigger']] = defaultdict(set)
|
||||
|
||||
@staticmethod
|
||||
def create(tk: TrancheKey, scale: dec, inverted: bool, price: dec, line: Line, is_min: bool, is_barrier: bool):
|
||||
def create(tk: TrancheKey, inverted: bool, price: dec, line: Line, is_min: bool, is_barrier: bool):
|
||||
if line.intercept == 0 and line.slope == 0:
|
||||
return None # no constraint (deactivated)
|
||||
return PriceLineTrigger(tk, scale, inverted, line, is_min, is_barrier, price)
|
||||
return PriceLineTrigger(tk, inverted, line, is_min, is_barrier, price)
|
||||
|
||||
def __init__(self, tk: TrancheKey, scale: dec, inverted: bool, line: Line, is_min: bool, is_barrier: bool, price_now: dec):
|
||||
def __init__(self, tk: TrancheKey, inverted: bool, line: Line, is_min: bool, is_barrier: bool, price_now: dec):
|
||||
if is_barrier:
|
||||
log.warning('Barriers not supported')
|
||||
value_now = line.intercept + line.slope * current_clock.get().timestamp
|
||||
price_now = float(price_now)
|
||||
if inverted:
|
||||
price_now = 1/price_now
|
||||
price_now *= scale
|
||||
activated = value_now < price_now if is_min else value_now > price_now
|
||||
log.debug(f'initial price line {value_now} {"<" if is_min else ">"} {price_now} {activated}')
|
||||
super().__init__(3 if is_min else 4, tk, activated)
|
||||
self.scale = scale
|
||||
self.inverted = inverted
|
||||
self.line = line
|
||||
self.is_min = is_min
|
||||
@@ -376,7 +374,7 @@ class PriceLineTrigger (Trigger):
|
||||
PriceLineTrigger.y.append(price)
|
||||
PriceLineTrigger.m.append(self.line.slope)
|
||||
PriceLineTrigger.b.append(self.line.intercept)
|
||||
PriceLineTrigger.sign.append(1 if (self.is_min != self.inverted) else -1)
|
||||
PriceLineTrigger.sign.append(1 if self.is_min else -1)
|
||||
PriceLineTrigger.triggers.append(self)
|
||||
PriceLineTrigger.triggers_set.add(self)
|
||||
else:
|
||||
@@ -459,14 +457,11 @@ class TrancheTrigger:
|
||||
else:
|
||||
# tranche minLine and maxLine are relative to the pool and will be flipped from the orderspec if the
|
||||
# order is buying the base and selling the quote.
|
||||
price = pool_prices[pool['address']]
|
||||
scale = 10 ** -pool['decimals']
|
||||
price = pool_prices[pool['address']] * dec(10) ** -pool['decimals']
|
||||
inverted = order.order.tokenIn != pool['base']
|
||||
assert inverted and order.order.tokenIn == pool['quote'] or not inverted and order.order.tokenIn == pool['base']
|
||||
min_trigger = PriceLineTrigger.create(tk, scale, inverted, price, tranche.minLine, True,
|
||||
tranche.minIsBarrier)
|
||||
max_trigger = PriceLineTrigger.create(tk, scale, inverted, price, tranche.maxLine, False,
|
||||
tranche.maxIsBarrier)
|
||||
min_trigger = PriceLineTrigger.create(tk, inverted, price, tranche.minLine, True, tranche.minIsBarrier)
|
||||
max_trigger = PriceLineTrigger.create(tk, inverted, price, tranche.maxLine, False, tranche.maxIsBarrier)
|
||||
return TrancheTrigger(order, tk, balance_trigger, activation_trigger, expiration_trigger, min_trigger, max_trigger)
|
||||
|
||||
def __init__(self, order: Order, tk: TrancheKey,
|
||||
|
||||
Reference in New Issue
Block a user