rate limit untested impl
This commit is contained in:
@@ -3,20 +3,19 @@ import itertools
|
|||||||
import logging
|
import logging
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from web3.exceptions import LogTopicError, MismatchedABI
|
|
||||||
from web3.types import EventData
|
from web3.types import EventData
|
||||||
|
|
||||||
from dexorder import current_pub, db, from_timestamp, minutely
|
from dexorder import current_pub, db, from_timestamp, minutely
|
||||||
from dexorder.base.chain import current_chain, current_clock, Mockchain
|
from dexorder.base.chain import current_chain, current_clock
|
||||||
from dexorder.base.order import TrancheExecutionRequest, TrancheKey, ExecutionRequest, new_tranche_execution_request, \
|
from dexorder.base.order import TrancheExecutionRequest, TrancheKey, ExecutionRequest, new_tranche_execution_request, \
|
||||||
OrderKey
|
OrderKey
|
||||||
from dexorder.base.orderlib import SwapOrderState
|
from dexorder.base.orderlib import SwapOrderState
|
||||||
from dexorder.blocks import get_block_timestamp
|
from dexorder.blocks import get_block_timestamp
|
||||||
from dexorder.blockstate.fork import current_fork
|
from dexorder.blockstate.fork import current_fork
|
||||||
from dexorder.contract import ERC20, ContractProxy, get_contract_event
|
from dexorder.contract import ERC20
|
||||||
from dexorder.contract.dexorder import vault_address, VaultContract, get_factory_contract
|
from dexorder.contract.dexorder import vault_address, VaultContract, get_factory_contract
|
||||||
from dexorder.database.model.transaction import TransactionJob
|
from dexorder.database.model.transaction import TransactionJob
|
||||||
from dexorder.logics import logics, get_logic_version
|
from dexorder.logics import get_logic_version
|
||||||
from dexorder.ohlc import ohlcs, recent_ohlcs
|
from dexorder.ohlc import ohlcs, recent_ohlcs
|
||||||
from dexorder.order.orderstate import Order
|
from dexorder.order.orderstate import Order
|
||||||
from dexorder.order.triggers import OrderTriggers, price_triggers, time_triggers, \
|
from dexorder.order.triggers import OrderTriggers, price_triggers, time_triggers, \
|
||||||
@@ -71,11 +70,13 @@ def handle_swap_filled(event: EventData):
|
|||||||
tranche_index = args['trancheIndex']
|
tranche_index = args['trancheIndex']
|
||||||
amount_in = args['amountIn']
|
amount_in = args['amountIn']
|
||||||
amount_out = args['amountOut']
|
amount_out = args['amountOut']
|
||||||
|
next_execution_time = args['nextExecutionTime']
|
||||||
try:
|
try:
|
||||||
order: Order = Order.of(vault, order_index)
|
order: Order = Order.of(vault, order_index)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
log.warning(f'DexorderSwapFilled IGNORED due to missing order {vault} {order_index}')
|
log.warning(f'DexorderSwapFilled IGNORED due to missing order {vault} {order_index}')
|
||||||
return
|
return
|
||||||
|
order.status.trancheActivationTime[tranche_index] = next_execution_time # update rate limit
|
||||||
try:
|
try:
|
||||||
triggers = OrderTriggers.instances[order.key]
|
triggers = OrderTriggers.instances[order.key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|||||||
@@ -142,6 +142,9 @@ class Order:
|
|||||||
def tranche_remaining(self, tranche_index: int):
|
def tranche_remaining(self, tranche_index: int):
|
||||||
return self.tranche_amounts[tranche_index] - self.tranche_filled(tranche_index)
|
return self.tranche_amounts[tranche_index] - self.tranche_filled(tranche_index)
|
||||||
|
|
||||||
|
def activation_time(self, tranche_index: int):
|
||||||
|
return self.status.trancheActivationTime[tranche_index]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def filled(self):
|
def filled(self):
|
||||||
return self.filled_in if self.amount_is_input else self.filled_out
|
return self.filled_in if self.amount_is_input else self.filled_out
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ from collections import defaultdict
|
|||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
from typing import Callable, Optional, Union, Awaitable
|
from typing import Callable, Optional, Union, Awaitable
|
||||||
|
|
||||||
from dexorder.blockstate import BlockSet, BlockDict
|
|
||||||
from dexorder.base.orderlib import SwapOrderState, PriceProof, DISTANT_FUTURE, DISTANT_PAST
|
from dexorder.base.orderlib import SwapOrderState, PriceProof, DISTANT_FUTURE, DISTANT_PAST
|
||||||
|
from dexorder.blockstate import BlockSet, BlockDict
|
||||||
from dexorder.util import defaultdictk
|
from dexorder.util import defaultdictk
|
||||||
from .orderstate import Order
|
from .orderstate import Order
|
||||||
from .. import dec, order_log
|
from .. import dec, order_log, now, timestamp, from_timestamp
|
||||||
from ..base.chain import current_clock
|
from ..base.chain import current_clock
|
||||||
from ..base.order import OrderKey, TrancheKey, ExecutionRequest
|
from ..base.order import OrderKey, TrancheKey, ExecutionRequest
|
||||||
from ..pools import ensure_pool_price, pool_prices, get_pool
|
from ..pools import ensure_pool_price, pool_prices, get_pool
|
||||||
@@ -161,6 +161,10 @@ class TrancheTrigger:
|
|||||||
if self.closed:
|
if self.closed:
|
||||||
log.debug(f'price trigger ignored because trigger status is {self.status}')
|
log.debug(f'price trigger ignored because trigger status is {self.status}')
|
||||||
return
|
return
|
||||||
|
activation_time = self.order.activation_time(self.tk.tranche_index)
|
||||||
|
if activation_time != 0 and timestamp() < activation_time:
|
||||||
|
log.debug(f'{self.tk} is rate limited until {from_timestamp(activation_time)}')
|
||||||
|
return # rate limited
|
||||||
# log.debug(f'price trigger {cur}')
|
# log.debug(f'price trigger {cur}')
|
||||||
addr = pool_address(self.order.order)
|
addr = pool_address(self.order.order)
|
||||||
pool = await get_pool(addr)
|
pool = await get_pool(addr)
|
||||||
@@ -175,6 +179,7 @@ class TrancheTrigger:
|
|||||||
if cur is None or not self.has_line_constraint or all(await asyncio.gather(
|
if cur is None or not self.has_line_constraint or all(await asyncio.gather(
|
||||||
line_passes(self.min_line_constraint, True, cur),
|
line_passes(self.min_line_constraint, True, cur),
|
||||||
line_passes(self.max_line_constraint, False, cur))):
|
line_passes(self.max_line_constraint, False, cur))):
|
||||||
|
# setting active_tranches[] with a PriceProof causes an execute() invocation
|
||||||
active_tranches[self.tk] = PriceProof(0) # todo PriceProof
|
active_tranches[self.tk] = PriceProof(0) # todo PriceProof
|
||||||
|
|
||||||
def fill(self, _amount_in, _amount_out ):
|
def fill(self, _amount_in, _amount_out ):
|
||||||
|
|||||||
Reference in New Issue
Block a user