code.vegaprotocol.io/vega@v0.79.0/datanode/gateway/graphql/new_market_resolver.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package gql
    17  
    18  import (
    19  	"context"
    20  	"errors"
    21  	"strconv"
    22  
    23  	"code.vegaprotocol.io/vega/libs/ptr"
    24  	types "code.vegaprotocol.io/vega/protos/vega"
    25  )
    26  
    27  type newMarketResolver VegaResolverRoot
    28  
    29  func (r *newMarketResolver) EnableTxReordering(ctx context.Context, obj *types.NewMarket) (bool, error) {
    30  	return obj.Changes.EnableTransactionReordering, nil
    31  }
    32  
    33  func (r *newMarketResolver) TickSize(_ context.Context, obj *types.NewMarket) (string, error) {
    34  	return obj.Changes.TickSize, nil
    35  }
    36  
    37  func (r *newMarketResolver) Instrument(_ context.Context, obj *types.NewMarket) (*types.InstrumentConfiguration, error) {
    38  	return obj.Changes.Instrument, nil
    39  }
    40  
    41  func (r *newMarketResolver) DecimalPlaces(_ context.Context, obj *types.NewMarket) (int, error) {
    42  	return int(obj.Changes.DecimalPlaces), nil
    43  }
    44  
    45  func (r *newMarketResolver) PriceMonitoringParameters(_ context.Context, obj *types.NewMarket) (*PriceMonitoringParameters, error) {
    46  	triggers := make([]*PriceMonitoringTrigger, len(obj.Changes.PriceMonitoringParameters.Triggers))
    47  	for i, t := range obj.Changes.PriceMonitoringParameters.Triggers {
    48  		probability, err := strconv.ParseFloat(t.Probability, 64)
    49  		if err != nil {
    50  			return nil, err
    51  		}
    52  		triggers[i] = &PriceMonitoringTrigger{
    53  			HorizonSecs:          int(t.Horizon),
    54  			Probability:          probability,
    55  			AuctionExtensionSecs: int(t.AuctionExtension),
    56  		}
    57  	}
    58  	return &PriceMonitoringParameters{Triggers: triggers}, nil
    59  }
    60  
    61  func (r *newMarketResolver) LiquidityMonitoringParameters(_ context.Context, obj *types.NewMarket) (*LiquidityMonitoringParameters, error) {
    62  	params := obj.Changes.LiquidityMonitoringParameters
    63  	if params == nil {
    64  		return nil, nil
    65  	}
    66  
    67  	lmp := &LiquidityMonitoringParameters{}
    68  
    69  	if params.TargetStakeParameters != nil {
    70  		lmp.TargetStakeParameters = &TargetStakeParameters{
    71  			TimeWindow:    int(params.TargetStakeParameters.TimeWindow),
    72  			ScalingFactor: params.TargetStakeParameters.ScalingFactor,
    73  		}
    74  	}
    75  	return lmp, nil
    76  }
    77  
    78  func (r *newMarketResolver) PositionDecimalPlaces(_ context.Context, obj *types.NewMarket) (int, error) {
    79  	return int(obj.Changes.PositionDecimalPlaces), nil
    80  }
    81  
    82  func (r *newMarketResolver) LinearSlippageFactor(_ context.Context, obj *types.NewMarket) (string, error) {
    83  	return obj.Changes.LinearSlippageFactor, nil
    84  }
    85  
    86  func (r *newMarketResolver) QuadraticSlippageFactor(_ context.Context, obj *types.NewMarket) (string, error) {
    87  	return obj.Changes.QuadraticSlippageFactor, nil
    88  }
    89  
    90  func (r *newMarketResolver) RiskParameters(_ context.Context, obj *types.NewMarket) (RiskModel, error) {
    91  	switch rm := obj.Changes.RiskParameters.(type) {
    92  	case *types.NewMarketConfiguration_LogNormal:
    93  		return rm.LogNormal, nil
    94  	case *types.NewMarketConfiguration_Simple:
    95  		return rm.Simple, nil
    96  	default:
    97  		return nil, errors.New("invalid risk model")
    98  	}
    99  }
   100  
   101  func (r *newMarketResolver) Metadata(_ context.Context, obj *types.NewMarket) ([]string, error) {
   102  	return obj.Changes.Metadata, nil
   103  }
   104  
   105  func (r *newMarketResolver) SuccessorConfiguration(ctx context.Context, obj *types.NewMarket) (*types.SuccessorConfiguration, error) {
   106  	return obj.Changes.Successor, nil
   107  }
   108  
   109  func (r *newMarketResolver) LiquiditySLAParameters(ctx context.Context, obj *types.NewMarket) (*types.LiquiditySLAParameters, error) {
   110  	return obj.Changes.LiquiditySlaParameters, nil
   111  }
   112  
   113  func (r *newMarketResolver) LiquidityFeeSettings(ctx context.Context, obj *types.NewMarket) (*types.LiquidityFeeSettings, error) {
   114  	return obj.Changes.LiquidityFeeSettings, nil
   115  }
   116  
   117  func (r *newMarketResolver) LiquidationStrategy(ctx context.Context, obj *types.NewMarket) (*types.LiquidationStrategy, error) {
   118  	return obj.Changes.LiquidationStrategy, nil
   119  }
   120  
   121  func (r *newMarketResolver) MarkPriceConfiguration(ctx context.Context, obj *types.NewMarket) (*types.CompositePriceConfiguration, error) {
   122  	return obj.Changes.MarkPriceConfiguration, nil
   123  }
   124  
   125  func (r *newMarketResolver) AllowedEmptyAMMLevels(ctx context.Context, obj *types.NewMarket) (*int, error) {
   126  	v := obj.Changes.AllowedEmptyAmmLevels
   127  	if v == nil {
   128  		return nil, nil
   129  	}
   130  	return ptr.From(int(*obj.Changes.AllowedEmptyAmmLevels)), nil
   131  }