code.vegaprotocol.io/vega@v0.79.0/core/execution/future/market_callbacks.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package future 17 18 import ( 19 "context" 20 "time" 21 22 "code.vegaprotocol.io/vega/core/events" 23 "code.vegaprotocol.io/vega/core/types" 24 "code.vegaprotocol.io/vega/libs/num" 25 ) 26 27 func (m *Market) OnMarketAMMMaxCalculationLevels(ctx context.Context, c *num.Uint) { 28 m.amm.OnMaxCalculationLevelsUpdate(ctx, c) 29 } 30 31 func (m *Market) OnAMMMinCommitmentQuantumUpdate(ctx context.Context, c *num.Uint) { 32 m.amm.OnMinCommitmentQuantumUpdate(ctx, c) 33 } 34 35 func (m *Market) OnMarketMinLpStakeQuantumMultipleUpdate(_ context.Context, d num.Decimal) { 36 m.liquidity.OnMinLPStakeQuantumMultiple(d) 37 } 38 39 func (m *Market) OnMarketMinProbabilityOfTradingLPOrdersUpdate(_ context.Context, d num.Decimal) { 40 m.liquidity.OnMinProbabilityOfTradingLPOrdersUpdate(d) 41 } 42 43 func (m *Market) OnMarginScalingFactorsUpdate(ctx context.Context, sf *types.ScalingFactors) error { 44 if err := m.risk.OnMarginScalingFactorsUpdate(sf); err != nil { 45 return err 46 } 47 48 // update our market definition, and dispatch update through the event bus 49 m.mkt.TradableInstrument.MarginCalculator.ScalingFactors = sf 50 m.broker.Send(events.NewMarketUpdatedEvent(ctx, *m.mkt)) 51 52 return nil 53 } 54 55 func (m *Market) OnFeeFactorsMakerFeeUpdate(ctx context.Context, d num.Decimal) { 56 m.fee.OnFeeFactorsMakerFeeUpdate(d) 57 m.mkt.Fees.Factors.MakerFee = d 58 m.broker.Send(events.NewMarketUpdatedEvent(ctx, *m.mkt)) 59 } 60 61 func (m *Market) OnFeeFactorsTreasuryFeeUpdate(ctx context.Context, d num.Decimal) { 62 m.fee.OnFeeFactorsTreasuryFeeUpdate(d) 63 m.mkt.Fees.Factors.TreasuryFee = d 64 m.broker.Send(events.NewMarketUpdatedEvent(ctx, *m.mkt)) 65 } 66 67 func (m *Market) OnFeeFactorsBuyBackFeeUpdate(ctx context.Context, d num.Decimal) { 68 m.fee.OnFeeFactorsBuyBackFeeUpdate(d) 69 m.mkt.Fees.Factors.BuyBackFee = d 70 m.broker.Send(events.NewMarketUpdatedEvent(ctx, *m.mkt)) 71 } 72 73 func (m *Market) OnFeeFactorsInfrastructureFeeUpdate(ctx context.Context, d num.Decimal) { 74 m.fee.OnFeeFactorsInfrastructureFeeUpdate(d) 75 m.mkt.Fees.Factors.InfrastructureFee = d 76 m.broker.Send(events.NewMarketUpdatedEvent(ctx, *m.mkt)) 77 } 78 79 func (m *Market) OnMinimalMarginQuantumMultipleUpdate(multiplier num.Decimal) error { 80 m.minMaintenanceMarginQuantumMultiplier = multiplier 81 return nil 82 } 83 84 func (m *Market) OnMarketValueWindowLengthUpdate(d time.Duration) { 85 m.marketValueWindowLength = d 86 } 87 88 func (m *Market) OnMarketTargetStakeTimeWindowUpdate(d time.Duration) { 89 m.tsCalc.UpdateTimeWindow(d) 90 } 91 92 func (m *Market) OnMarketTargetStakeScalingFactorUpdate(d num.Decimal) error { 93 return m.tsCalc.UpdateScalingFactor(d) 94 } 95 96 func (m *Market) OnMarketLiquidityMaximumLiquidityFeeFactorLevelUpdate(d num.Decimal) { 97 m.liquidity.OnMaximumLiquidityFeeFactorLevelUpdate(d) 98 } 99 100 func (m *Market) OnMarketProbabilityOfTradingTauScalingUpdate(_ context.Context, d num.Decimal) { 101 m.liquidity.OnProbabilityOfTradingTauScalingUpdate(d) 102 } 103 104 func (m *Market) OnMarketAuctionMinimumDurationUpdate(ctx context.Context, d time.Duration) { 105 m.pMonitor.SetMinDuration(d) 106 m.minDuration = d 107 evt := m.as.UpdateMinDuration(ctx, d) 108 // we were in an auction, and the duration of the auction was updated 109 if evt != nil { 110 m.broker.Send(evt) 111 } 112 } 113 114 func (m *Market) OnMarketAuctionMaximumDurationUpdate(ctx context.Context, d time.Duration) { 115 if m.mkt.State == types.MarketStatePending || m.mkt.State == types.MarketStateProposed { 116 m.as.UpdateMaxDuration(ctx, d) 117 } 118 } 119 120 func (m *Market) OnMarkPriceUpdateMaximumFrequency(ctx context.Context, d time.Duration) { 121 if !m.nextMTM.IsZero() { 122 m.nextMTM = m.nextMTM.Add(-m.mtmDelta) 123 } 124 m.nextMTM = m.nextMTM.Add(d) 125 m.mtmDelta = d 126 } 127 128 func (m *Market) OnInternalCompositePriceUpdateFrequency(ctx context.Context, d time.Duration) { 129 if !m.perp { 130 return 131 } 132 if !m.nextInternalCompositePriceCalc.IsZero() { 133 m.nextInternalCompositePriceCalc = m.nextInternalCompositePriceCalc.Add(-m.mtmDelta) 134 } 135 m.nextInternalCompositePriceCalc = m.nextInternalCompositePriceCalc.Add(d) 136 m.internalCompositePriceFrequency = d 137 } 138 139 func (m *Market) OnMarketPartiesMaximumStopOrdersUpdate(ctx context.Context, u *num.Uint) { 140 m.maxStopOrdersPerParties = u.Clone() 141 } 142 143 func (m *Market) OnMarketLiquidityV2BondPenaltyFactorUpdate(liquidityV2BondPenaltyFactor num.Decimal) { 144 m.bondPenaltyFactor = liquidityV2BondPenaltyFactor 145 146 m.liquidity.OnBondPenaltyFactorUpdate(liquidityV2BondPenaltyFactor) 147 } 148 149 func (m *Market) OnMarketLiquidityV2EarlyExitPenaltyUpdate(d num.Decimal) { 150 m.liquidity.OnEarlyExitPenalty(d) 151 } 152 153 func (m *Market) OnMarketLiquidityV2MaximumLiquidityFeeFactorLevelUpdate(d num.Decimal) { 154 m.liquidity.OnMaximumLiquidityFeeFactorLevelUpdate(d) 155 } 156 157 func (m *Market) OnMarketLiquidityV2SLANonPerformanceBondPenaltySlopeUpdate(d num.Decimal) { 158 m.liquidity.OnNonPerformanceBondPenaltySlopeUpdate(d) 159 } 160 161 func (m *Market) OnMarketLiquidityV2SLANonPerformanceBondPenaltyMaxUpdate(d num.Decimal) { 162 m.liquidity.OnNonPerformanceBondPenaltyMaxUpdate(d) 163 } 164 165 func (m *Market) OnMarketLiquidityV2StakeToCCYVolume(d num.Decimal) { 166 m.liquidity.OnStakeToCcyVolumeUpdate(d) 167 } 168 169 func (m *Market) OnMarketLiquidityV2ProvidersFeeCalculationTimeStep(d time.Duration) { 170 m.liquidity.OnProvidersFeeCalculationTimeStep(d) 171 } 172 173 func (m *Market) OnMarketLiquidityEquityLikeShareFeeFractionUpdate(d num.Decimal) { 174 m.liquidity.SetELSFeeFraction(d) 175 }