code.vegaprotocol.io/vega@v0.79.0/datanode/gateway/graphql/mark_price_configuration_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  
    21  	"code.vegaprotocol.io/vega/protos/vega"
    22  	types "code.vegaprotocol.io/vega/protos/vega"
    23  )
    24  
    25  type compositePriceConfigurationResolver VegaResolverRoot
    26  
    27  func (*compositePriceConfigurationResolver) MarkPriceSourceWeights(ctx context.Context, obj *vega.CompositePriceConfiguration) ([]string, error) {
    28  	if obj == nil {
    29  		return []string{}, nil
    30  	}
    31  	return obj.SourceWeights, nil
    32  }
    33  
    34  func (*compositePriceConfigurationResolver) MarkPriceSourceStalenessTolerance(ctx context.Context, obj *vega.CompositePriceConfiguration) ([]string, error) {
    35  	if obj == nil {
    36  		return []string{}, nil
    37  	}
    38  	return obj.SourceStalenessTolerance, nil
    39  }
    40  
    41  func (*compositePriceConfigurationResolver) CompositePriceType(ctx context.Context, obj *vega.CompositePriceConfiguration) (CompositePriceType, error) {
    42  	if obj == nil {
    43  		return CompositePriceTypeCompositePriceTypeLastTrade, nil
    44  	}
    45  	if obj.CompositePriceType == types.CompositePriceType_COMPOSITE_PRICE_TYPE_WEIGHTED {
    46  		return CompositePriceTypeCompositePriceTypeWeighted, nil
    47  	} else if obj.CompositePriceType == types.CompositePriceType_COMPOSITE_PRICE_TYPE_MEDIAN {
    48  		return CompositePriceTypeCompositePriceTypeMedian, nil
    49  	} else {
    50  		return CompositePriceTypeCompositePriceTypeLastTrade, nil
    51  	}
    52  }
    53  
    54  func (*compositePriceConfigurationResolver) DecayPower(ctx context.Context, obj *vega.CompositePriceConfiguration) (int, error) {
    55  	if obj == nil {
    56  		return 0, nil
    57  	}
    58  	return int(obj.DecayPower), nil
    59  }
    60  
    61  func (*compositePriceConfigurationResolver) DataSourcesSpecBinding(ctx context.Context, obj *vega.CompositePriceConfiguration) ([]*SpecBindingForCompositePrice, error) {
    62  	if obj == nil || obj.DataSourcesSpecBinding == nil {
    63  		return nil, nil
    64  	}
    65  	binding := make([]*SpecBindingForCompositePrice, 0, len(obj.DataSourcesSpecBinding))
    66  	for _, sbfcp := range obj.DataSourcesSpecBinding {
    67  		binding = append(binding, &SpecBindingForCompositePrice{
    68  			PriceSourceProperty: sbfcp.PriceSourceProperty,
    69  		})
    70  	}
    71  	return binding, nil
    72  }