KomodoPlatform / komodo-defi-framework

This is the official Komodo DeFi Framework repository
https://komodoplatform.com/en/docs/komodo-defi-framework/
104 stars 94 forks source link

reduce volume of open orders after match #1012

Open cipig opened 3 years ago

cipig commented 3 years ago

A maker can post multiple orders with an aggregated volume that is higher than his balance, eg if his balance of KOIN is 10, he can post one sell order with volume 5, and a second one with volume 9. If a taker matches the first order with volume 5 and tries to match the second one too shortly after, the second swap will fail with maker_swap:321] !check_balance_for_maker_swap check_balance:76] Not enough KOIN for swap

Here is an example:

fc60629f-968d-4b11-b4b7-c25d60e5d9f2 | 2021-07-09 10:15:46 | KMD        | DIMI       |
0590bef2-dc89-4320-a33e-98499ef5d6b8 | 2021-07-09 10:17:00 | KMD        | DIMI       | NegotiateFailed

25292c13-a7df-4e6b-9aca-c5f9749f0b05 | 2021-07-09 10:32:01 | KMD        | DIMI       |
11cbe174-0298-4ea4-ab88-03181501c0e7 | 2021-07-09 10:32:13 | KMD        | DIMI       | NegotiateFailed 

3a22822b-b4ee-4de3-9687-d2e1cc23048a | 2021-07-09 10:44:15 | KMD        | DIMI       |
bdf65ba0-74f1-425c-82d3-6ad859a0ad1d | 2021-07-09 10:44:22 | KMD        | DIMI       | NegotiateFailed

https://dexapi.cipig.net/public/error.php?uuid=11cbe174-0298-4ea4-ab88-03181501c0e7

Would it be possible to reduce the max_volume of all open orders after a match if the remaining balance would not be sufficient? Simply cancelling those orders would also be OK. This is not a big issue though, since NegotiateFailed does not lead to a ban any more and i also changed my bot to avoid such situations, but would be nice to have.

artemii235 commented 3 years ago

Thanks for creating the issue! Yes, it's possible, I think we will do this in the near future.

cipig commented 2 years ago

this one looks fixed to me created sell order for 4 GRS (balance was 12), it didn't match and was converted to a maker order then i found a better offer and sold all 12 GRS to that one... after order matched and GRS were sent out, the first order (sell 4 GRS) was cancelled am i missing something? if not, we can close this

sergeyboyko0791 commented 2 years ago

If I understand the source issue correctly, we haven't improved the app to reduce max_vol/cancel orders as soon as the order has matched. I think the following problem is not gone away:

If a taker matches the first order with volume 5 and tries to match the second one too shortly after, the second swap will fail with

cipig commented 2 months ago

If I understand the source issue correctly, we haven't improved the app to reduce max_vol/cancel orders as soon as the order has matched. I think the following problem is not gone away:

If a taker matches the first order with volume 5 and tries to match the second one too shortly after, the second swap will fail with

see https://github.com/KomodoPlatform/komodo-defi-framework/issues/732#issuecomment-2248032734 i guess the problem there comes from multiple swaps with same coin (eg LTC) running in parallel... if the volume of other orders (also on other pairs, but with same coin like LTC) is not reduced (only necessary if remaining LTC balance is not enough to cover the second swap too) when first LTC order is matched, then it can lead to this kind of failed swaps

EDIT: i fear it can still happen, even if we would reduce volume of all open orders after a match... eg when i/my bot calls setprice again (after volume was reduced) and uses the actual balance to determine the volume of the order... if that balance includes LTC that was already "reserved" for a running swap (even if not yet sent, nor confirmed), then the volume of the order will be too high and can lead to such failed swaps... so we can only avoid them completely if my_balance (or a new call, only for this purpose) shows only balance that is available for orders/swaps (so balance minus everything that is already reserved for a swap)