Skip to content

Conversation

buck54321
Copy link
Member

@buck54321 buck54321 commented Mar 23, 2022

I've been chasing down the residual orders in the front-end order book and depth chart. The orders that we see are zero-quantity orders that appear to be related to orders that are booked and unbooked on the same match cycle. In that case, we receive a book_order update followed by an unbook_order update. The book_order update contains a BookOrderNote with a zero-quantity order, because by the time the order.LimitOrder gets translated by BookRouter, the Remaining is already zero.

I still haven't figured this out. I've put feelers around to try to catch a zero-quantity book_order update with no subsequent unbook_order update, but I haven't seen one yet, even though I still see residual orders.

Oddly, these leftover orders only appear on the buy side.

This PR is here just to display a crude fix and for discussion. I've been banging my head against the wall on this one, and I need to switch gears.

The crude fix is to simply ignore zero-quantity orders in OrderBook.add. We already ignore unmatched unbook_order updates.

@chappjc
Copy link
Member

chappjc commented Mar 23, 2022

I swear @JoeGruffins just commented about cancel orders being a related issue, but I cannot find it.

Also might be related is that I often see 0 qty market buy orders in the table and I have a feeling they are not actually trade orders, but cancels that somehow got in. Something about the zero-values for an order and the flags for force, sell, etc.?

@chappjc
Copy link
Member

chappjc commented Mar 25, 2022

In testing the expiry PRs I put up, I managed to get a ghost buy order on the depth chart. I couldn't tell if it appeared after the match or when the revoke_order happened. Might try it again.

@buck54321
Copy link
Member Author

I've come back to this a couple of times to try to figure why this helps, and I still have no idea. But it does seem to prevent the issue for me.

@chappjc
Copy link
Member

chappjc commented Jun 18, 2022

I've been saving the loadbot go.sum update for #1656 if that's alright with you

@@ -23,6 +23,7 @@ export default class OrderBook {

/* add adds an order to the order book. */
add (ord: MiniOrder) {
if (ord.qtyAtomic === 0) return
Copy link
Member

@chappjc chappjc Jun 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I say let's go with it, but in the name of figuring this out, how bout a console log with info about the order, maybe just the whole json ord, to help figure out why it's here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of these.

Copy link
Member

@chappjc chappjc Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean it happens frequently or there are a lot of places in the code?
If it happens frequently, what are they? Cancels?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are orders that are booked, match partially (generating a update_remaining), then finish matching in the same epoch. By the time the update_remaining notification is generated by BookRouter, the order's Remaining value is 0. It's of little consequence in most places because an unbook_order notification is sent immediately after. I've put a little cache with a timer in place to make sure that the unbook_order comes through for every zero-qty order within a second or so, and they all do. But still for some reason, if not ignored, a zero-qty order will end up persisting on the book somehow, screwing up the chart.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to repro with something very similar. Two lot order on book, matches with 1 lot taker, hitting handleUpdateRemainingRoute (which could use an as RemainderUpdate I think), and following with a cancel in the same epoch hitting handleUnbookOrderRoute, so very similar to what you described. Still couldn't make this ord.qtyAtomic condition hit in this add function. 🤷‍♂️

@buck54321
Copy link
Member Author

You can watch loadbot trade on compound and enable the logger in the console.

enableLogger('zeroqty', true)

@buck54321 buck54321 marked this pull request as ready for review June 25, 2022 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants