code.vegaprotocol.io/vega@v0.79.0/datanode/gateway/graphql/tradable_update_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  	"strconv"
    21  
    22  	types "code.vegaprotocol.io/vega/protos/vega"
    23  )
    24  
    25  type tradeUpdateResolver VegaResolverRoot
    26  
    27  func (r *tradeUpdateResolver) Size(ctx context.Context, obj *types.Trade) (string, error) {
    28  	return strconv.FormatUint(obj.Size, 10), nil
    29  }
    30  
    31  func (r *tradeUpdateResolver) CreatedAt(ctx context.Context, obj *types.Trade) (int64, error) {
    32  	return obj.Timestamp, nil
    33  }
    34  
    35  func (r *tradeUpdateResolver) BuyerID(ctx context.Context, obj *types.Trade) (string, error) {
    36  	return obj.Buyer, nil
    37  }
    38  
    39  func (r *tradeUpdateResolver) SellerID(ctx context.Context, obj *types.Trade) (string, error) {
    40  	return obj.Seller, nil
    41  }
    42  
    43  func (r *tradeUpdateResolver) SellerAuctionBatch(ctx context.Context, obj *types.Trade) (*int, error) {
    44  	i := int(obj.SellerAuctionBatch)
    45  	return &i, nil
    46  }
    47  
    48  func (r *tradeUpdateResolver) BuyerAuctionBatch(ctx context.Context, obj *types.Trade) (*int, error) {
    49  	i := int(obj.BuyerAuctionBatch)
    50  	return &i, nil
    51  }
    52  
    53  func (r *tradeUpdateResolver) BuyerFee(ctx context.Context, obj *types.Trade) (*TradeFee, error) {
    54  	fee := TradeFee{
    55  		MakerFee:          "0",
    56  		InfrastructureFee: "0",
    57  		LiquidityFee:      "0",
    58  	}
    59  	if obj.BuyerFee != nil {
    60  		fee.MakerFee = obj.BuyerFee.MakerFee
    61  		fee.InfrastructureFee = obj.BuyerFee.InfrastructureFee
    62  		fee.LiquidityFee = obj.BuyerFee.LiquidityFee
    63  	}
    64  	return &fee, nil
    65  }
    66  
    67  func (r *tradeUpdateResolver) SellerFee(ctx context.Context, obj *types.Trade) (*TradeFee, error) {
    68  	fee := TradeFee{
    69  		MakerFee:          "0",
    70  		InfrastructureFee: "0",
    71  		LiquidityFee:      "0",
    72  	}
    73  	if obj.SellerFee != nil {
    74  		fee.MakerFee = obj.SellerFee.MakerFee
    75  		fee.InfrastructureFee = obj.SellerFee.InfrastructureFee
    76  		fee.LiquidityFee = obj.SellerFee.LiquidityFee
    77  	}
    78  	return &fee, nil
    79  }