-
Notifications
You must be signed in to change notification settings - Fork 19
/
new_market_resolver.go
118 lines (97 loc) · 4.25 KB
/
new_market_resolver.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (C) 2023 Gobalsky Labs Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package gql
import (
"context"
"errors"
"strconv"
types "code.vegaprotocol.io/vega/protos/vega"
)
type newMarketResolver VegaResolverRoot
func (r *newMarketResolver) TickSize(_ context.Context, obj *types.NewMarket) (string, error) {
return obj.Changes.TickSize, nil
}
func (r *newMarketResolver) Instrument(_ context.Context, obj *types.NewMarket) (*types.InstrumentConfiguration, error) {
return obj.Changes.Instrument, nil
}
func (r *newMarketResolver) DecimalPlaces(_ context.Context, obj *types.NewMarket) (int, error) {
return int(obj.Changes.DecimalPlaces), nil
}
func (r *newMarketResolver) PriceMonitoringParameters(_ context.Context, obj *types.NewMarket) (*PriceMonitoringParameters, error) {
triggers := make([]*PriceMonitoringTrigger, len(obj.Changes.PriceMonitoringParameters.Triggers))
for i, t := range obj.Changes.PriceMonitoringParameters.Triggers {
probability, err := strconv.ParseFloat(t.Probability, 64)
if err != nil {
return nil, err
}
triggers[i] = &PriceMonitoringTrigger{
HorizonSecs: int(t.Horizon),
Probability: probability,
AuctionExtensionSecs: int(t.AuctionExtension),
}
}
return &PriceMonitoringParameters{Triggers: triggers}, nil
}
func (r *newMarketResolver) LiquidityMonitoringParameters(_ context.Context, obj *types.NewMarket) (*LiquidityMonitoringParameters, error) {
params := obj.Changes.LiquidityMonitoringParameters
if params == nil {
return nil, nil
}
lmp := &LiquidityMonitoringParameters{}
if params.TargetStakeParameters != nil {
lmp.TargetStakeParameters = &TargetStakeParameters{
TimeWindow: int(params.TargetStakeParameters.TimeWindow),
ScalingFactor: params.TargetStakeParameters.ScalingFactor,
}
}
return lmp, nil
}
func (r *newMarketResolver) PositionDecimalPlaces(_ context.Context, obj *types.NewMarket) (int, error) {
return int(obj.Changes.PositionDecimalPlaces), nil
}
func (r *newMarketResolver) LinearSlippageFactor(_ context.Context, obj *types.NewMarket) (string, error) {
return obj.Changes.LinearSlippageFactor, nil
}
func (r *newMarketResolver) QuadraticSlippageFactor(_ context.Context, obj *types.NewMarket) (string, error) {
return obj.Changes.QuadraticSlippageFactor, nil
}
func (r *newMarketResolver) RiskParameters(_ context.Context, obj *types.NewMarket) (RiskModel, error) {
switch rm := obj.Changes.RiskParameters.(type) {
case *types.NewMarketConfiguration_LogNormal:
return rm.LogNormal, nil
case *types.NewMarketConfiguration_Simple:
return rm.Simple, nil
default:
return nil, errors.New("invalid risk model")
}
}
func (r *newMarketResolver) Metadata(_ context.Context, obj *types.NewMarket) ([]string, error) {
return obj.Changes.Metadata, nil
}
func (r *newMarketResolver) SuccessorConfiguration(ctx context.Context, obj *types.NewMarket) (*types.SuccessorConfiguration, error) {
return obj.Changes.Successor, nil
}
func (r *newMarketResolver) LiquiditySLAParameters(ctx context.Context, obj *types.NewMarket) (*types.LiquiditySLAParameters, error) {
return obj.Changes.LiquiditySlaParameters, nil
}
func (r *newMarketResolver) LiquidityFeeSettings(ctx context.Context, obj *types.NewMarket) (*types.LiquidityFeeSettings, error) {
return obj.Changes.LiquidityFeeSettings, nil
}
func (r *newMarketResolver) LiquidationStrategy(ctx context.Context, obj *types.NewMarket) (*types.LiquidationStrategy, error) {
return obj.Changes.LiquidationStrategy, nil
}
func (r *newMarketResolver) MarkPriceConfiguration(ctx context.Context, obj *types.NewMarket) (*types.CompositePriceConfiguration, error) {
return obj.Changes.MarkPriceConfiguration, nil
}