Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: return all the price monitoring bounds + add active field #11213

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
### 🛠 Improvements

- [11209](https://github.com/vegaprotocol/vega/issues/11209) - Publish ongoing games data.
- [11196](https://github.com/vegaprotocol/vega/issues/11196) - Add an active field in the price monitoring bounds payload.

### 🐛 Fixes

Expand Down Expand Up @@ -110,6 +111,7 @@
- [10374](https://github.com/vegaprotocol/vega/issues/10374) - Add transfer ID to recurring governance transfer ledger entries.
- [11221](https://github.com/vegaprotocol/vega/issues/11221) - Fix for `totalRewardsEarned` being twice the `rewardEarned`.


## 0.75.0

### 🚨 Breaking changes
Expand Down
1 change: 1 addition & 0 deletions core/execution/common/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type PriceMonitor interface {
CheckPrice(ctx context.Context, as price.AuctionState, price *num.Uint, persistent bool, recordInHistory bool) bool
ResetPriceHistory(price *num.Uint)
GetCurrentBounds() []*types.PriceMonitoringBounds
GetBounds() []*types.PriceMonitoringBounds
SetMinDuration(d time.Duration)
GetValidPriceRange() (num.WrappedDecimal, num.WrappedDecimal)
// Snapshot
Expand Down
2 changes: 1 addition & 1 deletion core/execution/future/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ func (m *Market) GetMarketData() types.MarketData {
} else {
targetStake = m.getTargetStake().String()
}
bounds := m.pMonitor.GetCurrentBounds()
bounds := m.pMonitor.GetBounds()
for _, b := range bounds {
b.MaxValidPrice = m.priceToMarketPrecision(b.MaxValidPrice) // effictively floors this
b.MinValidPrice = m.priceToMarketPrecision(b.MinValidPrice)
Expand Down
15 changes: 14 additions & 1 deletion core/execution/future/market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3353,7 +3353,20 @@ func TestPriceMonitoringBoundsInGetMarketData(t *testing.T) {
auctionEndTime := openEnd.Add(time.Duration(t1.AuctionExtension) * time.Second)
require.Equal(t, auctionEndTime.UnixNano(), auctionEnd) // In auction
require.Equal(t, types.MarketStateSuspended, tm.market.State())
require.Equal(t, 1, len(md.PriceMonitoringBounds))
// 2 in total
require.Equal(t, 2, len(md.PriceMonitoringBounds))
active, triggerd := 0, 0
for _, v := range md.PriceMonitoringBounds {
if v.Active {
active++
continue
}
triggerd++
}
// 1 active
require.Equal(t, 1, active)
// 1 triggered
require.Equal(t, 1, triggerd)

tm.now = auctionEndTime
closed := tm.market.OnTick(vegacontext.WithTraceID(context.Background(), vgcrypto.RandomHash()), auctionEndTime)
Expand Down
2 changes: 1 addition & 1 deletion core/execution/spot/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (m *Market) GetMarketData() types.MarketData {
}

targetStake := m.getTargetStake().String()
bounds := m.pMonitor.GetCurrentBounds()
bounds := m.pMonitor.GetBounds()
for _, b := range bounds {
b.MaxValidPrice = m.priceToMarketPrecision(b.MaxValidPrice) // effictively floors this
b.MinValidPrice = m.priceToMarketPrecision(b.MinValidPrice)
Expand Down
26 changes: 26 additions & 0 deletions core/monitor/price/pricemonitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,32 @@ func (e *Engine) GetCurrentBounds() []*types.PriceMonitoringBounds {
return ret
}

// GetBounds returns a list of valid price ranges per price monitoring trigger. Note these are subject to change as the time progresses.
func (e *Engine) GetBounds() []*types.PriceMonitoringBounds {
priceRanges := e.getCurrentPriceRanges(false)
ret := make([]*types.PriceMonitoringBounds, 0, len(priceRanges))
for ind, pr := range priceRanges {
ret = append(ret,
&types.PriceMonitoringBounds{
MinValidPrice: pr.MinPrice.Representation(),
MaxValidPrice: pr.MaxPrice.Representation(),
Trigger: e.bounds[ind].Trigger,
ReferencePrice: pr.ReferencePrice,
Active: e.bounds[ind].Active,
})
}

sort.SliceStable(ret,
func(i, j int) bool {
if ret[i].Trigger.Horizon == ret[j].Trigger.Horizon {
return ret[i].Trigger.Probability.LessThan(ret[j].Trigger.Probability)
}
return ret[i].Trigger.Horizon < ret[j].Trigger.Horizon
})

return ret
}

func (e *Engine) OnTimeUpdate(now time.Time) {
e.recordTimeChange(now)
}
Expand Down
3 changes: 3 additions & 0 deletions core/types/pricemonitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type PriceMonitoringBounds struct {
MaxValidPrice *num.Uint
Trigger *PriceMonitoringTrigger
ReferencePrice num.Decimal
Active bool
}

func (p PriceMonitoringBounds) String() string {
Expand Down Expand Up @@ -145,6 +146,7 @@ func (p PriceMonitoringBounds) IntoProto() *proto.PriceMonitoringBounds {
MaxValidPrice: num.UintToString(p.MaxValidPrice),
Trigger: trigger,
ReferencePrice: p.ReferencePrice.BigInt().String(),
Active: p.Active,
}
}

Expand All @@ -165,6 +167,7 @@ func PriceMonitoringBoundsFromProto(pr *proto.PriceMonitoringBounds) (*PriceMoni
MinValidPrice: minValid,
MaxValidPrice: maxValid,
ReferencePrice: refPrice,
Active: pr.Active,
}
if pr.Trigger != nil {
p.Trigger = PriceMonitoringTriggerFromProto(pr.Trigger)
Expand Down
2 changes: 1 addition & 1 deletion datanode/entities/marketdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func priceMonitoringBoundsMatches(bounds, other []*types.PriceMonitoringBounds)

if bound.MinValidPrice != other[i].MinValidPrice ||
bound.MaxValidPrice != other[i].MaxValidPrice ||
bound.ReferencePrice != other[i].ReferencePrice {
bound.ReferencePrice != other[i].ReferencePrice || bound.Active != other[i].Active {
return false
}

Expand Down
55 changes: 55 additions & 0 deletions datanode/gateway/graphql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions datanode/gateway/graphql/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions datanode/gateway/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,8 @@ type PriceMonitoringBounds {
trigger: PriceMonitoringTrigger!
"Reference price used to calculate the valid price range"
referencePrice: String!
"Has this bound been triggered yet or is it still active"
active: Boolean
}

"TargetStakeParameters contains parameters used in target stake calculation"
Expand Down
2 changes: 2 additions & 0 deletions protos/sources/vega/vega.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,8 @@ message PriceMonitoringBounds {
PriceMonitoringTrigger trigger = 3;
// Reference price used to calculate the valid price range. This field is an unsigned integer scaled to the market's decimal places.
string reference_price = 4;
// Has this bound been triggered yet or is it still active.
bool active = 5;
}

// Represents Vega domain specific error information over gRPC/Protobuf
Expand Down
Loading
Loading