-
Notifications
You must be signed in to change notification settings - Fork 19
/
market_ext.go
70 lines (62 loc) · 1.89 KB
/
market_ext.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
package vega
import (
"errors"
fmt "fmt"
"strconv"
)
var (
ErrNilTradableInstrument = errors.New("nil tradable instrument")
ErrNilInstrument = errors.New("nil instrument")
ErrNilProduct = errors.New("nil product")
ErrUnknownAsset = errors.New("unknown asset")
)
func (m *Market) GetAsset() (string, error) {
if m.TradableInstrument == nil {
return "", ErrNilTradableInstrument
}
if m.TradableInstrument.Instrument == nil {
return "", ErrNilInstrument
}
if m.TradableInstrument.Instrument.Product == nil {
return "", ErrNilProduct
}
switch pimpl := m.TradableInstrument.Instrument.Product.(type) {
case *Instrument_Future:
return pimpl.Future.SettlementAsset, nil
case *Instrument_Perpetual:
return pimpl.Perpetual.SettlementAsset, nil
case *Instrument_Spot:
return pimpl.Spot.QuoteAsset, nil
default:
return "", ErrUnknownAsset
}
}
func (p *PriceMonitoringTrigger) Validate() error {
if !(p.Horizon > 0) {
return fmt.Errorf("invalid field Triggers.Horizon: value '%v' must be greater than '0'", p.Horizon)
}
probability, err := strconv.ParseFloat(p.Probability, 64)
if err != nil {
return fmt.Errorf("invalid field Triggers.Probability: value '%v' must be numeric and between 0 and 1", p.Probability)
}
if !(probability > 0) {
return fmt.Errorf("invalid field Triggers.Probability: value '%v' must be strictly greater than '0'", p.Probability)
}
if !(probability < 1) {
return fmt.Errorf("invalid field Triggers.Probability: value '%v' must be strictly lower than '1'", p.Probability)
}
if !(p.AuctionExtension > 0) {
return fmt.Errorf("invalid field Triggers.AuctionExtension: value '%v' must be greater than '0'", p.AuctionExtension)
}
return nil
}
func (p *PriceMonitoringParameters) Validate() error {
for _, item := range p.Triggers {
if item != nil {
if err := item.Validate(); err != nil {
return err
}
}
}
return nil
}