-
Notifications
You must be signed in to change notification settings - Fork 84
/
perpetuals.go
68 lines (58 loc) · 1.85 KB
/
perpetuals.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
59
60
61
62
63
64
65
66
67
68
package perpetuals
import (
"github.com/dydxprotocol/v4-chain/protocol/dtypes"
perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types"
)
type PerpetualModifierOption func(cp *perptypes.Perpetual)
func WithId(id uint32) PerpetualModifierOption {
return func(cp *perptypes.Perpetual) {
cp.Params.Id = id
}
}
func WithMarketId(id uint32) PerpetualModifierOption {
return func(cp *perptypes.Perpetual) {
cp.Params.MarketId = id
}
}
func WithPerpetual(perp perptypes.Perpetual) PerpetualModifierOption {
return func(cp *perptypes.Perpetual) {
cp.Params = perp.Params
}
}
func WithTicker(ticker string) PerpetualModifierOption {
return func(cp *perptypes.Perpetual) {
cp.Params.Ticker = ticker
}
}
func WithLiquidityTier(liquidityTier uint32) PerpetualModifierOption {
return func(cp *perptypes.Perpetual) {
cp.Params.LiquidityTier = liquidityTier
}
}
// GeneratePerpetual returns a `Perpetual` object set to default values.
// Passing in `PerpetualModifierOption` methods alters the value of the `Perpetual` returned.
// It will start with the default, valid `Perpetual` value defined within the method
// and make the requested modifications before returning the object.
//
// Example usage:
// `GeneratePerpetual(WithId(10))`
// This will start with the default `Perpetual` object defined within the method and
// return the newly-created object after overriding the values of
// `Id` to 10.
func GeneratePerpetual(optionalModifications ...PerpetualModifierOption) *perptypes.Perpetual {
perpetual := &perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Id: 0,
Ticker: "BTC-USD",
MarketId: 0,
AtomicResolution: -8,
DefaultFundingPpm: 0,
LiquidityTier: 0,
},
FundingIndex: dtypes.ZeroInt(),
}
for _, opt := range optionalModifications {
opt(perpetual)
}
return perpetual
}