dex-services
dex-services copied to clipboard
Approximate economic viability contstraint
We can approximate the economic viability constraint by checking the traded amounts in the transitive orders against connected OWL limit prices. We would then discard any transitive orders that do not satisfy these constraints.
Instead of discarding transitive orders, should we reduce all direct orders that would not be matchable due to that constraint in a pre-processing step? I'm worried that if we ignored transitive orders, we might fill parts of larger orders which in their entirety could lead to better prices.
E.g. consider the transitive order A->C via A->B->C. If B->C doesn't have enough volume to be economically viable we should only ignore this part and not the complete transitive order A->B->C as the other part (A->B) could still be used in a transitive order (e.g. A->B->D->C).
I'm worried that if we ignored transitive orders, we might fill parts of larger orders which in their entirety could lead to better prices.
My hope is that this won't be too much of an issue, since we are failing to satisfy the economic viability constraint then the amounts should be small. So the larger part of the order will still be available. If it isn't, then this transitive order would have only been able to fulfill a small amount of the full buy amount and is unlikely to affect the final price estimate (unless it is the proverbial last drop in the bucket)...
E.g. consider the transitive order [...]
...But this is a great suggestion! I think this can be done fairly easily with the current model.
I thought about this a bunch, and I think the best way to implement this would be the same way we implemented the rounding buffer, so outside the pricegraph
and in the price estimator. This would require computing price estimates for all tokens on every orderbook update and create the Pricegraph
with orders that are filtered to be economically viable.
The implementation would be fairly straight forward:
- Compute the min trade amount for each token:
- Compute the min average fee
m
(using the existingEconomicViability
component). - Compute the price estimate
p
for a token (using the exisitngPricegraph::estimate_token_price
API). - The minimum trade amount is
2000 * p * m / 1e18
(I think)
- Compute the min average fee
- Create a
Pricegraph
instance filtering out all orders witheffective_remaining_sell_amount < min_trade_amount
. - Use the above
Pricegraph
created in the previous step to compute the price estimate with an added check that thesell_amount
used for the price estimate is> min_trade_amount
(returningNone
if it isn't).