Skip to content

Commit

Permalink
Refactor order structures
Browse files Browse the repository at this point in the history
  • Loading branch information
lumos42 committed Sep 15, 2023
1 parent 01bd9d5 commit c353ed6
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 67 deletions.
2 changes: 1 addition & 1 deletion plugin/evm/limit_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func (lop *limitOrderProcesser) UpdateLastPremiumFractionFromStorage() {
}
}

orderMap := lop.memoryDb.GetOrderBookData().OrderMap
orderMap := lop.memoryDb.GetOrderBookData().Orders
for orderHash, order := range orderMap {
if order.FilledBaseAssetQuantity.CmpAbs(order.BaseAssetQuantity) > 0 {
log.Info("Order map cleanup - deleting order", "hash", orderHash.String(), "baseAssetQuantity", order.BaseAssetQuantity, "filledBaseAssetQuantity", order.FilledBaseAssetQuantity)
Expand Down
24 changes: 12 additions & 12 deletions plugin/evm/orderbook/contract_events_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,24 +263,24 @@ func (cep *ContractEventsProcessor) handleIOCOrderBookEvent(event *types.Log) {
}
orderId := event.Topics[2]
if !removed {
order := IOCOrder{}
order.DecodeFromRawOrder(args["order"])
limitOrder := Order{
iocOrder := IOCOrder{}
iocOrder.DecodeFromRawOrder(args["order"])
order := Order{
Id: orderId,
Market: Market(order.AmmIndex.Int64()),
PositionType: getPositionTypeBasedOnBaseAssetQuantity(order.BaseAssetQuantity),
Market: Market(iocOrder.AmmIndex.Int64()),
PositionType: getPositionTypeBasedOnBaseAssetQuantity(iocOrder.BaseAssetQuantity),
Trader: getAddressFromTopicHash(event.Topics[1]),
BaseAssetQuantity: order.BaseAssetQuantity,
BaseAssetQuantity: iocOrder.BaseAssetQuantity,
FilledBaseAssetQuantity: big.NewInt(0),
Price: order.Price,
RawOrder: &order,
Salt: order.Salt,
ReduceOnly: order.ReduceOnly,
Price: iocOrder.Price,
RawOrder: &iocOrder,
Salt: iocOrder.Salt,
ReduceOnly: iocOrder.ReduceOnly,
BlockNumber: big.NewInt(int64(event.BlockNumber)),
OrderType: IOCOrderType,
}
log.Info("IOCOrder/OrderPlaced", "order", limitOrder, "number", event.BlockNumber)
cep.database.Add(&limitOrder)
log.Info("IOCOrder/OrderPlaced", "order", order, "number", event.BlockNumber)
cep.database.Add(&order)
} else {
log.Info("IOCOrder/OrderPlaced removed", "orderId", orderId.String(), "block", event.BlockHash.String(), "number", event.BlockNumber)
cep.database.Delete(orderId)
Expand Down
Loading

0 comments on commit c353ed6

Please sign in to comment.