-
Notifications
You must be signed in to change notification settings - Fork 28
/
market.go
68 lines (60 loc) · 1.52 KB
/
market.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
package types
import (
"github.com/mrz1836/go-sanitize"
)
func NewMarket(
uid, creator string,
startTS, endTS uint64,
odds []*Odds,
meta string,
bookUID string,
status MarketStatus,
) Market {
return Market{
UID: uid,
Creator: creator,
StartTS: startTS,
EndTS: endTS,
Odds: odds,
Meta: sanitize.XSS(meta),
BookUID: bookUID,
Status: status,
}
}
// IsResolved returns true if the market is already resolved.
func (m *Market) IsResolved() bool {
return m.Status == MarketStatus_MARKET_STATUS_RESULT_DECLARED ||
m.Status == MarketStatus_MARKET_STATUS_CANCELED ||
m.Status == MarketStatus_MARKET_STATUS_ABORTED
}
// IsUpdateAllowed returns true if updating the market is allowed.
func (m *Market) IsUpdateAllowed() bool {
return m.isActiveOrInactive()
}
// IsResolveAllowed returns true if resolving the market is allowed.
func (m *Market) IsResolveAllowed() bool {
return m.isActiveOrInactive()
}
func (m *Market) isActiveOrInactive() bool {
return m.Status == MarketStatus_MARKET_STATUS_ACTIVE ||
m.Status == MarketStatus_MARKET_STATUS_INACTIVE
}
// HasOdds determine if the input odds uid is present in
// the market odds or not.
func (m *Market) HasOdds(oddsUID string) bool {
for _, o := range m.Odds {
if oddsUID == o.UID {
return true
}
}
return false
}
// OddsUIDS get list of odd uids
// This ensures that we loop over the odds in a non random order
func (m *Market) OddsUIDS() []string {
var odds []string
for _, odd := range m.Odds {
odds = append(odds, odd.UID)
}
return odds
}