Skip to content

Commit

Permalink
feat: return all the price monitoring bounds + add active field
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Letang <[email protected]>
  • Loading branch information
jeremyletang committed Apr 29, 2024
1 parent 8de5aa7 commit 94a8dd8
Show file tree
Hide file tree
Showing 13 changed files with 1,063 additions and 947 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- [11143](https://github.com/vegaprotocol/vega/issues/11143) - Add support for new asset proposal in batch governance proposal
- [11182](https://github.com/vegaprotocol/vega/issues/11182) - Remove reduce only restriction on spot markets stop orders.
- [11153](https://github.com/vegaprotocol/vega/issues/11153) - Add check on start-up that bridge `RPC-endpoints` are functional.
- [11196](https://github.com/vegaprotocol/vega/issues/11196) - Add an active field in the price monitoring bounds payload.

### 🐛 Fixes

Expand Down Expand Up @@ -79,9 +80,9 @@
- [11159](https://github.com/vegaprotocol/vega/issues/11159) - Reject stop orders with size override position for spot product.
- [11161](https://github.com/vegaprotocol/vega/issues/11161) - Add validation for time in force GFA in stop order submission.
- [11177](https://github.com/vegaprotocol/vega/issues/11177) - Adjust the formulas for reduced position to the spec update and fix handling of closed out position.
- [11193](https://github.com/vegaprotocol/vega/issues/11193) - Fix loading of liquidation strategy from proto with missing data.
- [11200](https://github.com/vegaprotocol/vega/issues/11200) - Make sure a party can afford the trades before they are submitted to the book.
- [11205](https://github.com/vegaprotocol/vega/issues/11205) - Evaluate transfer interval correctly.
- [11193](https://github.com/vegaprotocol/vega/issues/11193) - Fix loading of liquidation strategy from proto with missing data.
- [11200](https://github.com/vegaprotocol/vega/issues/11200) - Make sure a party can afford the trades before they are submitted to the book.
- [11205](https://github.com/vegaprotocol/vega/issues/11205) - Evaluate transfer interval correctly.
## 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 @@ -2473,6 +2473,8 @@ type PriceMonitoringBounds {
trigger: PriceMonitoringTrigger!
"Reference price used to calculate the valid price range"
referencePrice: String!
"Has this bound been triggered yet or is 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 still active.
bool active = 5;
}

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

0 comments on commit 94a8dd8

Please sign in to comment.