-
Notifications
You must be signed in to change notification settings - Fork 0
/
settle_market.go
76 lines (63 loc) · 1.91 KB
/
settle_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
69
70
71
72
73
74
75
76
package events
import (
"context"
"github.com/zeta-protocol/zeta/libs/num"
eventspb "github.com/zeta-protocol/zeta/protos/zeta/events/v1"
)
type SettleMarket struct {
*Base
marketID string
settledPrice *num.Uint
positionFactor num.Decimal
ts int64
}
func NewMarketSettled(ctx context.Context, marketID string, ts int64, settledPrice *num.Uint, positionFactor num.Decimal) *SettleMarket {
return &SettleMarket{
Base: newBase(ctx, SettleMarketEvent),
marketID: marketID,
settledPrice: settledPrice.Clone(),
positionFactor: positionFactor,
ts: ts,
}
}
func (m SettleMarket) MarketID() string {
return m.marketID
}
// PartyID will return an empty string as this is only required to satisfy an interface
// for identifying events that can affect positions in the data-node.
func (m SettleMarket) PartyID() string {
return ""
}
func (m SettleMarket) SettledPrice() *num.Uint {
return m.settledPrice.Clone()
}
func (m SettleMarket) PositionFactor() num.Decimal {
return m.positionFactor
}
func (m SettleMarket) Timestamp() int64 {
return m.ts
}
func (m SettleMarket) Proto() *eventspb.SettleMarket {
return &eventspb.SettleMarket{
MarketId: m.marketID,
Price: m.settledPrice.String(),
PositionFactor: m.positionFactor.String(),
}
}
func (m SettleMarket) StreamMessage() *eventspb.BusEvent {
p := m.Proto()
busEvent := newBusEventFromBase(m.Base)
busEvent.Event = &eventspb.BusEvent_SettleMarket{SettleMarket: p}
return busEvent
}
func SettleMarketEventFromStream(ctx context.Context, be *eventspb.BusEvent) *SettleMarket {
sm := be.GetSettleMarket()
smPrice, _ := num.UintFromString(sm.Price, 10)
positionFactor := num.MustDecimalFromString(sm.PositionFactor)
return &SettleMarket{
Base: newBaseFromBusEvent(ctx, SettleMarketEvent, be),
marketID: sm.MarketId,
settledPrice: smPrice,
positionFactor: positionFactor,
}
}