-
Notifications
You must be signed in to change notification settings - Fork 85
/
matches.go
58 lines (50 loc) · 1.78 KB
/
matches.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package types
import (
"math/big"
"github.com/dydxprotocol/v4-chain/protocol/lib"
satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types"
)
// MakerFillWithOrder represents the filled amount of a matched maker order,
// along with the `Order` representing the matched maker order.
type MakerFillWithOrder struct {
MakerFill
// The `Order` representing the matched maker order.
Order Order
}
// MakerFillsWithOrderToMakerFills converts a slice of `MakerFillWithOrder` to a
// slice of `MakerFill`.
func MakerFillsWithOrderToMakerFills(mfos []MakerFillWithOrder) []MakerFill {
mfs := make([]MakerFill, len(mfos))
for i, mf := range mfos {
mfs[i] = mf.MakerFill
}
return mfs
}
// GetMakerSubaccountIds gets a list of SubaccountIds belonging to subaccounts which placed the maker orders
// in the Fills property of this MatchOrdersNew object.
func (m *MatchOrders) GetMakerSubaccountIds() []satypes.SubaccountId {
return lib.MapSlice(
m.Fills,
func(fill MakerFill) satypes.SubaccountId {
return fill.MakerOrderId.SubaccountId
},
)
}
// GetMakerSubaccountIds gets a list of SubaccountIds belonging to subaccounts which placed the maker orders
// in the Fills property of this MatchPerpetualLiquidationNew object.
func (m *MatchPerpetualLiquidation) GetMakerSubaccountIds() []satypes.SubaccountId {
return lib.MapSlice(
m.Fills,
func(fill MakerFill) satypes.SubaccountId {
return fill.MakerOrderId.SubaccountId
},
)
}
// GetTotalFilledQuantums gets the total filled quantums from a MatchPerpetualDeleveraging match.
func (m *MatchPerpetualDeleveraging) GetTotalFilledQuantums() *big.Int {
totalQuantums := big.NewInt(0)
for _, fill := range m.GetFills() {
totalQuantums.Add(totalQuantums, new(big.Int).SetUint64(fill.GetFillAmount()))
}
return totalQuantums
}