code.vegaprotocol.io/vega@v0.79.0/protos/vega/market_ext.go (about) 1 package vega 2 3 import ( 4 "errors" 5 fmt "fmt" 6 "strconv" 7 ) 8 9 var ( 10 ErrNilTradableInstrument = errors.New("nil tradable instrument") 11 ErrNilInstrument = errors.New("nil instrument") 12 ErrNilProduct = errors.New("nil product") 13 ErrUnknownAsset = errors.New("unknown asset") 14 ) 15 16 func (m *Market) GetAsset() (string, error) { 17 if m.TradableInstrument == nil { 18 return "", ErrNilTradableInstrument 19 } 20 if m.TradableInstrument.Instrument == nil { 21 return "", ErrNilInstrument 22 } 23 if m.TradableInstrument.Instrument.Product == nil { 24 return "", ErrNilProduct 25 } 26 27 switch pimpl := m.TradableInstrument.Instrument.Product.(type) { 28 case *Instrument_Future: 29 return pimpl.Future.SettlementAsset, nil 30 case *Instrument_Perpetual: 31 return pimpl.Perpetual.SettlementAsset, nil 32 case *Instrument_Spot: 33 return pimpl.Spot.QuoteAsset, nil 34 default: 35 return "", ErrUnknownAsset 36 } 37 } 38 39 func (p *PriceMonitoringTrigger) Validate() error { 40 if !(p.Horizon > 0) { 41 return fmt.Errorf("invalid field Triggers.Horizon: value '%v' must be greater than '0'", p.Horizon) 42 } 43 44 probability, err := strconv.ParseFloat(p.Probability, 64) 45 if err != nil { 46 return fmt.Errorf("invalid field Triggers.Probability: value '%v' must be numeric and between 0 and 1", p.Probability) 47 } 48 49 if !(probability > 0) { 50 return fmt.Errorf("invalid field Triggers.Probability: value '%v' must be strictly greater than '0'", p.Probability) 51 } 52 if !(probability < 1) { 53 return fmt.Errorf("invalid field Triggers.Probability: value '%v' must be strictly lower than '1'", p.Probability) 54 } 55 if !(p.AuctionExtension > 0) { 56 return fmt.Errorf("invalid field Triggers.AuctionExtension: value '%v' must be greater than '0'", p.AuctionExtension) 57 } 58 return nil 59 } 60 61 func (p *PriceMonitoringParameters) Validate() error { 62 for _, item := range p.Triggers { 63 if item != nil { 64 if err := item.Validate(); err != nil { 65 return err 66 } 67 } 68 } 69 return nil 70 }