Skip to content

Commit

Permalink
handle new trader
Browse files Browse the repository at this point in the history
  • Loading branch information
atvanguard committed Jan 18, 2024
1 parent 3f76459 commit 05e8d7f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion plugin/evm/orderbook/memory_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1289,10 +1289,21 @@ func (db *InMemoryDatabase) GetOrderValidationFields(orderId common.Hash, order
bidsHead = db.LongOrders[marketId][0].Price
}

availableMargin := big.NewInt(0)
if db.TraderMap[trader] != nil {
// backwards compatibility
if db.TraderMap[trader].Margin.Available == nil {
db.TraderMap[trader].Margin.Available = big.NewInt(0)
}
if db.TraderMap[trader].Margin.VirtualReserved == nil {
db.TraderMap[trader].Margin.Available = big.NewInt(0)
}
availableMargin = hu.Sub(db.TraderMap[trader].Margin.Available /* as fresh as the last matching engine run */, db.TraderMap[trader].Margin.VirtualReserved)
}
return OrderValidationFields{
Exists: false,
PosSize: posSize,
AvailableMargin: hu.Sub(db.TraderMap[trader].Margin.Available /* as fresh as the last matching engine run */, db.TraderMap[trader].Margin.VirtualReserved),
AvailableMargin: availableMargin,
AsksHead: asksHead,
BidsHead: bidsHead,
}
Expand Down

0 comments on commit 05e8d7f

Please sign in to comment.