-
Notifications
You must be signed in to change notification settings - Fork 174
Bug in market engine / matching cover_orders #1315
Comments
@theoreticalbts Please check this in the new market engine. |
Is there an easy way to get the expiration date for a short position from the wallet? I'm using |
This is the proper behavior. We never force people to cover at less than 90% of the feed price. The order will sit there as expected until either the feed price falls or someone places a bid at 91% of the feed price. |
But the bid is 95% of the feed price. Why is it not used for covering? |
@theoreticalbts It looks like it should be part of the raw output of |
@pmconrad a suggestion: you could try to fix it yourself and submit a pull request (I believe you're a good enough developer). |
I'm certainly capable of providing a fix. But this is about fiddling with market logic, and I'm unsure about what is the correct way to fix this. IMHO get_next_bid should interleave bids and shorts ordered by execution price instead of simply preferring shorts when the next bid is below the feed. But AFAIK shorts are ordered by interest offered, which means we have conflicting goals here. And we might have to iterate through the shorts more than once, so the fix is really not so simple. |
I see... what is going on here. The short is selected... because it has the highest interest rate. |
First of all, @pmconrad you should be looking at develop branch. As part of my work implementing relative orders, I made additions to this code including substantial improvements to the logic merging various types of orders, see https://github.com/BitShares/bitshares/blob/18ac97f16b0da2aaad71ca2bf591441b51e03863/libraries/blockchain/market_engine.cpp#L626-830 The above comment generated some intense discussion. The fundamental issue is that you can have latent state changes -- i.e. feed updates change order semantics (whether the order executes and the price it executes at). For each order type, you want to be able to have a "best" order of that type, such that failing to match against that best order means no other order of that type can match. Now if latent updates change the ordering within a type (i.e. two orders Latent updates can change the ordering within the short order type. However, we can get around this by dividing shorts into "stuck" and "unstuck" categories. "Stuck" shorts execute at the price feed and are ordered based on interest rate. Unstuck shorts execute at their limit price and are ordered based on their limit price. Simply keep track of a list of stuck and unstuck shorts, and for every feed update, we only need to update shorts whose limit price the feed moved through. Which is likely small or zero. So basically we just have to add a bunch of database indices, and in the market engine have separate merge clauses for stuck and unstuck shorts. @bytemaster is currently working on implementing that. |
When sorting bids we need to create an index object of the form And then populate that index like so: bid => { price, 3, 0, owner } After sorting we can iterate through bids in order. In practice, we only need to maintain the index for short orders and we can "merge sort" just in time from the bid and relative bid databases. For Asks we have ask => { price, 3, 0, owner } Cover's are sorted by call price which is the "trigger price" and not the actual ask price. The actual ask price is the max( highest_bid_price, 0.9*feed ) if feed < call price, else max( highest_bid_price, feed ) if just expired. |
Glad to see this in the hands of experts. :-) |
There's another issue with covers. Don't know if the planned changes already cover it. There's currently a margin call on the BTC/BTS market that can't be covered:
Current feed price is 0.000033525036657829, i. e. it's below the limit. In my understanding, this margin call should be filled at the price feed or 10% below. (Upon closer examination it should be possible the fill the cover with an unlimited short and sufficient interest at exactly the feed price.) |
Don't know if this has been discussed somewhere yet: |
Failed to protect expired short orders by placing a short order with low limit_price and high interest rate. |
I would think that with the same interest rate the owner address comes into play. |
Had a look on the develop branch, it seems the refactoring of market engine is almost finished, so issue #1315 (comment) should have been fixed already. There is a TODO in the code which I think could be a issue: |
Could be.. I placed a USD short "BTS2yD2gQTnTrdUD2X7yZWLdh6pcYUJLKARh". Will see. //Edit: |
//EDIT: the comment below is incorrect. Just leave it here for reference. In develop branch, wouldn't this line skip the short orders with limit_price < feed_price, cause they never get matched with margin call orders? |
This is fixed by those last two patches, confirmed fixed by MC test. |
Suppose for example on the CNY/BTS market the feed price is 0.1 CNY per BTS, there is an open bid at 0.095 CNY/BTS and a short with a limit of 0.085 CNY/BTS. Now the expiration date of a cover_order passes. What I'd expect to happen (see https://bitsharestalk.org/index.php?topic=8390.msg178760#msg178760 ) is that the cover_order is filled by the bid. What actually happens is - nothing.
The reason:
The text was updated successfully, but these errors were encountered: