Skip to content

Commit

Permalink
more explicit function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
jonfung-dydx committed Apr 30, 2024
1 parent 5b1a471 commit cec38f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 8 additions & 1 deletion protocol/x/clob/memclob/memclob.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,15 @@ func (m *MemClobPriceTimePriority) mustUpdateMemclobStateWithMatches(
internalOperation := m.operationsToPropose.MustAddMatchToOperationsQueue(takerOrder, makerFillWithOrders)
// If orderbook updates are on, send an orderbook update with the fill to grpc streams.
if m.generateOrderbookUpdates {
// Collect all maker orders.
makerOrders := lib.MapSlice(
makerFillWithOrders,
func(mfwo types.MakerFillWithOrder) types.Order {
return mfwo.Order
},
)
clobMatch := internalOperation.GetMatch()
orderbookMatchFill := m.GenerateStreamOrderbookFill(ctx, *clobMatch, takerOrder, makerFillWithOrders)
orderbookMatchFill := m.GenerateStreamOrderbookFill(ctx, *clobMatch, takerOrder, makerOrders)
m.clobKeeper.SendOrderbookFillUpdates(ctx, []types.StreamOrderbookFill{orderbookMatchFill})
}

Expand Down
12 changes: 5 additions & 7 deletions protocol/x/clob/memclob/memclob_grpc_streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,25 @@ func (m *MemClobPriceTimePriority) GenerateStreamOrderbookFill(
ctx sdk.Context,
clobMatch types.ClobMatch,
takerOrder types.MatchableOrder,
makerFillWithOrders []types.MakerFillWithOrder,
makerOrders []types.Order,
) types.StreamOrderbookFill {
ordersInClobMatch := []types.Order{}
fillAmounts := []uint32{}

for _, makerFillWithOrder := range makerFillWithOrders {
ordersInClobMatch = append(ordersInClobMatch, makerFillWithOrder.Order)
fillAmount := m.GetOrderFilledAmount(ctx, makerFillWithOrder.Order.OrderId)
for _, makerOrder := range makerOrders {
fillAmount := m.GetOrderFilledAmount(ctx, makerOrder.OrderId)
fillAmounts = append(fillAmounts, uint32(fillAmount))
}
// If taker order is not a liquidation order, has to be a regular
// taker order. Add the taker order to the orders array.
if !takerOrder.IsLiquidation() {
order := takerOrder.MustGetOrder()
ordersInClobMatch = append(ordersInClobMatch, order)
makerOrders = append(makerOrders, order)
fillAmount := m.GetOrderFilledAmount(ctx, order.OrderId)
fillAmounts = append(fillAmounts, uint32(fillAmount))
}
return types.StreamOrderbookFill{
ClobMatch: &clobMatch,
Orders: ordersInClobMatch,
Orders: makerOrders,
FillAmounts: fillAmounts,
}
}
Expand Down

0 comments on commit cec38f7

Please sign in to comment.