Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing incorrect iterating order through sell price levels. #2294

Merged
merged 2 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions matching/orderbook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2640,6 +2640,46 @@ func TestOrderBook_IndicativePriceAndVolume8(t *testing.T) {
assert.Equal(t, len(cancels), 0)
}

func TestOrderBook_UncrossTest1(t *testing.T) {
market := "testOrderbook"
book := getTestOrderBook(t, market)
defer book.Finish()

logger := logging.NewTestLogger()
defer logger.Sync()

// Switch to auction mode
book.EnterAuction()

bo1 := getOrder(t, book, market, "BuyOrder01", types.Side_SIDE_BUY, 100, "party01", 5)
bo1.TimeInForce = types.Order_TIF_GFA
book.SubmitOrder(bo1)

so1 := getOrder(t, book, market, "SellOrder01", types.Side_SIDE_SELL, 100, "party02", 5)
so1.TimeInForce = types.Order_TIF_GFA
book.SubmitOrder(so1)

bo2 := getOrder(t, book, market, "BuyOrder02", types.Side_SIDE_BUY, 100, "party01", 5)
bo2.TimeInForce = types.Order_TIF_GFA
book.SubmitOrder(bo2)

so2 := getOrder(t, book, market, "SellOrder02", types.Side_SIDE_SELL, 101, "party02", 5)
so2.TimeInForce = types.Order_TIF_GFA
book.SubmitOrder(so2)

// Get indicative auction price and volume
price, volume, side := book.GetIndicativePriceAndVolume()
assert.Equal(t, price, uint64(100))
assert.Equal(t, volume, uint64(5))
assert.Equal(t, side, types.Side_SIDE_SELL)

// Leave auction and uncross the book
uncrossedOrders, cancels, err := book.LeaveAuction()
assert.Nil(t, err)
assert.Equal(t, len(uncrossedOrders), 1)
assert.Equal(t, len(cancels), 2)
}

// this is a test for issue 2060 to ensure we process FOK orders properly
func TestOrderBook_NetworkOrderSuccess(t *testing.T) {
market := "testOrderbook"
Expand Down
10 changes: 5 additions & 5 deletions matching/side.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ func (s *OrderBookSide) ExtractOrders(price, volume uint64) ([]*types.Order, err
}
}
} else {
for len(s.levels) > 0 {
pricelevel := s.levels[0]
for index := len(s.levels) - 1; index >= 0; index-- {
peterbarrow marked this conversation as resolved.
Show resolved Hide resolved
pricelevel := s.levels[index]
for _, order := range pricelevel.orders {
// Check the price is good and the total volume will not be exceeded
if order.Price <= price && totalVolume+order.Remaining <= volume {
Expand All @@ -193,9 +193,9 @@ func (s *OrderBookSide) ExtractOrders(price, volume uint64) ([]*types.Order, err
return nil, ErrInvalidVolume
}
}
// Erase this price level which will be the start of the slice
s.levels[0] = nil
s.levels = s.levels[1:len(s.levels)]
// Erase this price level which will be the end of the slice
s.levels[index] = nil
s.levels = s.levels[:len(s.levels)-1]

// Check if we have done enough
if totalVolume == volume {
Expand Down