BitShares Forum

Main => General Discussion => Topic started by: biophil on April 10, 2015, 10:35:01 pm

Title: The market engine is not matching shorts properly
Post by: biophil on April 10, 2015, 10:35:01 pm
Right now, there are bids for BitUSD above the feed price. The feed price is about 211, the highest bid is 225. To test the market, I shorted BitUSD with 1000 BTS of collateral, and was able to borrow 2.3637 BitUSD. Now in my margin order it says I have about 1500 BTS, which means the proceeds of my short order were about 500 BTS. THAT IS THE WRONG AMOUNT!! I should have been matched with the highest bid and gotten the 225 price, but as you can calculate (500/2.3637), I only got the 211 price. I'm guessing I matched one of the many expired shorts.

I know the devs aren't allowed to talk to us anymore or some such insane bullshit, but is there anybody out there who knows how to get a fix for this in the pipeline? Thanks.
Title: Re: The market engine is not matching shorts properly
Post by: bytemaster on April 10, 2015, 10:49:40 pm
There are a ton of market order fixes that have been heavily tested in the current DEV shares release.   Those fixes will migrate to BTS soon.   

In the mean time we have the issue that the expired orders are not being properly displayed in the GUI and the LIMIT prices are not properly included.   bitsharesblocks.com seems to do it properly.
Title: Re: The market engine is not matching shorts properly
Post by: Riverhead on April 11, 2015, 12:41:05 am

Is that what's happening here? Those shorts aren't really there? My bot is very low on bitUSD can I can't seem to buy more.

Code: [Select]
     BIDS (* Short, + Relative, - Relative Limit)                            |                                   ASKS                                 
TOTAL                     QUANTITY                                     PRICE | PRICE                                        QUANTITY                     TOTAL   COLLATERAL
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1.1250 USD                250.00000 BTS                   0.004500000000 USD*| 0.004444344444 USD                  132,000.00000 BTS              586.6534 USD
444.4444 USD              100,000.00000 BTS               0.004444444444 USD*| 0.004651162791 USD                   10,750.00000 BTS               50.0000 USD
Title: Re: The market engine is not matching shorts properly
Post by: toast on April 11, 2015, 03:09:59 am
Not only are shorts not getting matched, normal sells that match only fill one order but keep the other on the book!
Title: Re: The market engine is not matching shorts properly
Post by: svk on April 11, 2015, 06:45:57 am
At the moment we seem to have simple buy orders not getting matched with shorts either, see the screenshot below for the current state in my wallet:

(http://i.imgur.com/SBnlZbuh.png) (http://imgur.com/SBnlZbu)
Title: Re: The market engine is not matching shorts properly
Post by: pc on April 11, 2015, 07:29:34 am
This is a known bug: https://github.com/BitShares/bitshares/issues/1495

The problem here is that the huge volume of expired BitUSD shorts have a call price that's close to the feed price, and shorts with a limit above the call price are skipped in the order matching. Also, the engine tries to match covers before regular orders. So when the engine get to match your regular offer, the matching short will already have been skipped.
Title: Re: The market engine is not matching shorts properly
Post by: Riverhead on April 11, 2015, 10:52:11 am
This is a known bug: https://github.com/BitShares/bitshares/issues/1495 (https://github.com/BitShares/bitshares/issues/1495)

The problem here is that the huge volume of expired BitUSD shorts have a call price that's close to the feed price, and shorts with a limit above the call price are skipped in the order matching. Also, the engine tries to match covers before regular orders. So when the engine get to match your regular offer, the matching short will already have been skipped.

Thank you PC. That is a perfect explanation. So it seems the long and, er, short of it is currently it's not possible to acquire bitUSD?
Title: Re: The market engine is not matching shorts properly
Post by: pc on April 11, 2015, 12:56:26 pm
So it seems the long and, er, short of it is currently it's not possible to acquire bitUSD?

It is possible to buy bitUSD from regular sellers, but not from shorts.

It is also possible to short bitUSD at the feed price by either setting no limit or a limit above ~.0047 USD/BTS. These shorts will be eaten up immediately by the margin calls, so it is not possible to self-short.
Title: Re: The market engine is not matching shorts properly
Post by: svk on April 11, 2015, 01:02:23 pm
So it seems the long and, er, short of it is currently it's not possible to acquire bitUSD?

It is possible to buy bitUSD from regular sellers, but not from shorts.

It is also possible to short bitUSD at the feed price by either setting no limit or a limit above ~.0047 USD/BTS. These shorts will be eaten up immediately by the margin calls, so it is not possible to self-short.

That doesn't seem to be the case either, there's currently a short wall of 354 bitUSD for sale (no limit or below the limit), and several thousand bitUSD worth of cover orders that are not eating into this short wall. Is the single BUY order at 226 BTS/bitUSD blocking the other trades from happening?

Another picture to help the explanation:

(http://i.imgur.com/pPPbSyWh.png) (http://imgur.com/pPPbSyW)

If what you say is true, shouldn't the expired margin calls (in yellow) be matched with the short wall (first entry in blue in the SELL table)?
Title: Re: The market engine is not matching shorts properly
Post by: zerosum on April 11, 2015, 01:36:06 pm
In what world this belongs to the trading sub section?

PS
Sorry for not checking each illogical subsection before posting this  https://bitsharestalk.org/index.php/topic,15170.msg201296.html#msg201296
Title: Re: The market engine is not matching shorts properly
Post by: pc on April 11, 2015, 03:02:12 pm
It is possible to buy bitUSD from regular sellers, but not from shorts.

It is also possible to short bitUSD at the feed price by either setting no limit or a limit above ~.0047 USD/BTS. These shorts will be eaten up immediately by the margin calls, so it is not possible to self-short.

That doesn't seem to be the case either, there's currently a short wall of 354 bitUSD for sale (no limit or below the limit), and several thousand bitUSD worth of cover orders that are not eating into this short wall. Is the single BUY order at 226 BTS/bitUSD blocking the other trades from happening?

All shorts have a limit below .004652 USD/BTS. It doesn't matter if that limit is above or below the feed. The bug is triggered because the margin call with the highest priority has a limit of 0.00469622149801484 which is greater than the limit of the shorts and therefore causes the shorts to be skipped.
Title: Re: The market engine is not matching shorts properly
Post by: arhag on April 11, 2015, 09:10:29 pm
(http://i.imgur.com/pPPbSyWh.png) (http://imgur.com/pPPbSyW)

Shouldn't your buy table also have entries at 10% above the feed price for the margin-called orders?

Also I think it would look much better if you coalesced orders at the same price together. That means there shouldn't be more than at most two yellow items (one for expired cover orders and one for margin-called cover orders). If a user wants to a see a more detailed break down than that, they always could click the "Margin Orders" button (which I think is misleading and should instead be labelled "Cover Orders").
Title: Re: The market engine is not matching shorts properly
Post by: svk on April 11, 2015, 09:50:12 pm


(http://i.imgur.com/pPPbSyWh.png) (http://imgur.com/pPPbSyW)

Shouldn't your buy table also have entries at 10% above the feed price for the margin-called orders?

Also I think it would look much better if you coalesced orders at the same price together. That means there shouldn't be more than at most two yellow items (one for expired cover orders and one for margin-called cover orders). If a user wants to a see a more detailed break down than that, they always could click the "Margin Orders" button (which I think is misleading and should instead be labelled "Cover Orders").

You're right I could sum them, those are all expired orders actually, I forgot about the margin called orders. I was under the impression the 10% above price was a bug, isn't it? Expired orders should be at the feed price though right?
Title: Re: The market engine is not matching shorts properly
Post by: arhag on April 11, 2015, 09:55:11 pm
You're right I could sum them, those are all expired orders actually, I forgot about the margin called orders. I was under the impression the 10% above price was a bug, isn't it? Expired orders should be at the feed price though right?

The bug was that expired cover orders had a limit price at 10% above the price feed when it was supposed to be at the price feed. However, margin call cover orders should have a price limit 10% above the price feed.

Title: Re: The market engine is not matching shorts properly
Post by: svk on April 12, 2015, 08:20:40 am
You're right I could sum them, those are all expired orders actually, I forgot about the margin called orders. I was under the impression the 10% above price was a bug, isn't it? Expired orders should be at the feed price though right?

The bug was that expired cover orders had a limit price at 10% above the price feed when it was supposed to be at the price feed. However, margin call cover orders should have a price limit 10% above the price feed.

Thanks for the clarifications, I've worked some more on the wallet this morning and I believe I have it right this time. One thing that I'm unsure about is, what happens to a margin called order that expires before getting filled? Does it stay at +10% price, or does it revert to the feed price? I suppose it's the former, but unfortunately there's no way for me to distinguish between a call that had previously been margin called but is now expired..

Here's a screenie from bitBTC which currently has expired and forced margin calls at the top of the books:

(http://i.imgur.com/eJCQ818h.png) (http://imgur.com/eJCQ818)

FYI atm bitUSD as of right now still has an invisible buy order of 1275.55 bitUSD at 243.4266 BTS/bitUSD, and the expired orders make up a whopping 186944 bitUSD at 221.29 BTS/bitUSD. At least this makes the whole trading action make a lot more sense, what was missing from my understanding was the forced margin calls at +10% which were invisible in the client.
Title: Re: The market engine is not matching shorts properly
Post by: svk on April 12, 2015, 08:55:24 am
Another question about the mechanics, what happens to a short that gets margin called, but before it fills the call price drops below the margin call price? Does it remain a forced cover, or does it revert to normal status and wait for either another margin call or the expiration date?
Title: Re: The market engine is not matching shorts properly
Post by: pc on April 12, 2015, 11:28:18 am
With the current market engine, it reverts to normal status. I suppose the new engine will behave in the same way.
Title: Re: The market engine is not matching shorts properly
Post by: Shentist on April 12, 2015, 09:01:09 pm
wow,

so a matching bug again. i hope it will get fixed soon. This costs not only me money, but will not get new people in BitShares.
Title: Re: The market engine is not matching shorts properly
Post by: svk on April 13, 2015, 12:52:51 pm
With the current market engine, it reverts to normal status. I suppose the new engine will behave in the same way.

Another question: does an expired cover that later gets margin called execute at call price or call price + 10%? In other words, is the priority on expiry or on margin?
Title: Re: The market engine is not matching shorts properly
Post by: sudo on July 31, 2015, 09:41:44 am
With the current market engine, it reverts to normal status. I suppose the new engine will behave in the same way.

Another question: does an expired cover that later gets margin called execute at call price or call price + 10%? In other words, is the priority on expiry or on margin?

I am curious too