Skip to content

Commit

Permalink
Merge branch 'develop' into 10858-auction-state-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
wwestgarth committed Mar 11, 2024
2 parents 392cb07 + fa67296 commit 3588003
Show file tree
Hide file tree
Showing 195 changed files with 1,474 additions and 2,672 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- [10392](https://github.com/vegaprotocol/vega/issues/10392) - Integrate mark price with price monitoring.
- [10845](https://github.com/vegaprotocol/vega/issues/10845) - Remove price monitoring trigger staleness check.
- [10810](https://github.com/vegaprotocol/vega/issues/10810) - Do not update mark price from book during auctions.
- [10754](https://github.com/vegaprotocol/vega/issues/10754) - Simplify margin calculation (remove order book slippage).

### 🐛 Fixes

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 @@ -315,6 +315,7 @@ type CommonMarket interface {
BlockEnd(context.Context)
BeginBlock(context.Context)
UpdateMarketState(ctx context.Context, changes *types.MarketStateUpdateConfiguration) error
GetFillPrice(volume uint64, side types.Side) (*num.Uint, error)

IsOpeningAuction() bool

Expand Down
7 changes: 7 additions & 0 deletions core/execution/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1931,3 +1931,10 @@ func (e *Engine) UpdateMarginMode(ctx context.Context, party, marketID string, m

return market.UpdateMarginMode(ctx, party, marginMode, marginFactor)
}

func (e *Engine) GetFillPriceForMarket(marketID string, volume uint64, side types.Side) (*num.Uint, error) {
if mkt, ok := e.allMarkets[marketID]; ok {
return mkt.GetFillPrice(volume, side)
}
return nil, types.ErrInvalidMarketID
}
4 changes: 4 additions & 0 deletions core/execution/future/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -4956,3 +4956,7 @@ func (m *Market) emitPartyMarginModeUpdated(ctx context.Context, party string, m

m.broker.Send(events.NewPartyMarginModeUpdatedEvent(ctx, e))
}

func (m *Market) GetFillPrice(volume uint64, side types.Side) (*num.Uint, error) {
return m.matching.GetFillPrice(volume, side)
}
4 changes: 4 additions & 0 deletions core/execution/spot/market_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,7 @@ func (m *Market) GetState() *types.ExecSpotMarket {
func (m *Market) GetNewStateProviders() []types.StateProvider {
return []types.StateProvider{m.matching, m.tsCalc, m.orderHoldingTracker, m.liquidityEngine.V2StateProvider()}
}

func (m *Market) GetFillPrice(volume uint64, side types.Side) (*num.Uint, error) {
return m.matching.GetFillPrice(volume, side)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: Distressed parties should not have general balance left
Given time is updated to "2020-10-16T00:00:00Z"
And the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params |
| ETH/DEC20 | ETH | ETH | default-simple-risk-model-3 | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 1e6 | 1e6 | default-futures |
| ETH/DEC20 | ETH | ETH | default-simple-risk-model-3 | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 0.25 | 0 | default-futures |
And the following network parameters are set:
| name | value |
| market.auction.minimumDuration | 1 |
Expand Down Expand Up @@ -66,8 +66,8 @@ Feature: Distressed parties should not have general balance left

Then the parties should have the following account balances:
| party | asset | market id | margin | general |
| party4 | ETH | ETH/DEC20 | 360 | 9999999999640 |
| party5 | ETH | ETH/DEC20 | 372 | 9999999999528 |
| party4 | ETH | ETH/DEC20 | 420 | 9999999999580 |
| party5 | ETH | ETH/DEC20 | 432 | 9999999999468 |
Then the parties submit the following liquidity provision:
| id | party | market id | commitment amount | fee | lp type |
| lp2 | party3 | ETH/DEC20 | 20000 | 0.1 | submission |
Expand Down Expand Up @@ -126,8 +126,8 @@ Feature: Distressed parties should not have general balance left

And the parties should have the following account balances:
| party | asset | market id | margin | general |
| party3 | ETH | ETH/DEC20 | 3152 | 1040 |
| party4 | ETH | ETH/DEC20 | 160 | 9999999999640 |
| party3 | ETH | ETH/DEC20 | 3254 | 938 |
| party4 | ETH | ETH/DEC20 | 504 | 9999999999296 |

## Now let's increase the mark price so party3 gets distressed
When the parties place the following orders "1" blocks apart:
Expand All @@ -138,4 +138,4 @@ Feature: Distressed parties should not have general balance left

And the parties should have the following account balances:
| party | asset | market id | margin | general |
| party3 | ETH | ETH/DEC20 | 4899 | 0 |
| party3 | ETH | ETH/DEC20 | 4617 | 0 |
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Feature: Test party accounts
Background:
Given the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params |
| ETH/DEC19 | ETH | ETH | default-simple-risk-model-3 | default-margin-calculator | 0 | default-none | default-none | default-eth-for-future | 1e6 | 1e6 | default-futures |
| GBPUSD/DEC19 | USD | VUSD | default-simple-risk-model-3 | default-margin-calculator | 0 | default-none | default-none | default-usd-for-future | 1e6 | 1e6 | default-futures |
| ETH/DEC19 | ETH | ETH | default-simple-risk-model-3 | default-margin-calculator | 0 | default-none | default-none | default-eth-for-future | 0.25 | 0 | default-futures |
| GBPUSD/DEC19 | USD | VUSD | default-simple-risk-model-3 | default-margin-calculator | 0 | default-none | default-none | default-usd-for-future | 0.25 | 0 | default-futures |

Scenario: a party is added to the system. A general account is created for each asset
Given the parties deposit on asset's general account the following amount:
Expand Down
2 changes: 1 addition & 1 deletion core/integration/features/auctions/0043-MKTL-010.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Feature: Ensure the markets expire if they cannot leave opening auction within t
| market.auction.maximumDuration | 100s |
And the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | decimal places | linear slippage factor | quadratic slippage factor | sla params | is passed |
| ETH/DEC20 | ETH | ETH | my-simple-risk-model | default-margin-calculator | 5 | my-fees-config | default-none | default-eth-for-future | 2 | 1e6 | 1e6 | default-futures | true |
| ETH/DEC20 | ETH | ETH | my-simple-risk-model | default-margin-calculator | 5 | my-fees-config | default-none | default-eth-for-future | 2 | 0.25 | 0 | default-futures | true |

@Expires
Scenario: Covers 0043-MKTL-010
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Feature: Set up a market, with an opening auction, then uncross the book. Make s
| 0.004 | 0.001 |
And the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | decimal places | linear slippage factor | quadratic slippage factor | sla params |
| ETH/DEC20 | ETH | ETH | my-simple-risk-model | default-margin-calculator | 1 | my-fees-config | default-none | default-eth-for-future | 2 | 1e6 | 1e6 | default-futures |
| ETH/DEC20 | ETH | ETH | my-simple-risk-model | default-margin-calculator | 1 | my-fees-config | default-none | default-eth-for-future | 2 | 0.25 | 0 | default-futures |
And the following network parameters are set:
| name | value |
| limits.markets.maxPeggedOrders | 2 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Set up a market, with an opening auction, then uncross the book. Make s
| 0.004 | 0.001 |
And the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params |
| ETH/DEC20 | ETH | ETH | my-simple-risk-model | default-margin-calculator | 1 | my-fees-config | default-none | default-eth-for-future | 1e6 | 1e6 | default-futures |
| ETH/DEC20 | ETH | ETH | my-simple-risk-model | default-margin-calculator | 1 | my-fees-config | default-none | default-eth-for-future | 0.25 | 0 | default-futures |
And the following network parameters are set:
| name | value |
| limits.markets.maxPeggedOrders | 2 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Feature: Test for issue 5460
| 43200 | 0.9999999 | 60 |
And the markets:
| id | quote name | asset | liquidity monitoring | risk model | margin calculator | auction duration | fees | price monitoring | data source config | decimal places | position decimal places | linear slippage factor | quadratic slippage factor | sla params |
| ETH/DEC21 | ETH | ETH | lqm-params | log-normal-risk-model-1 | default-margin-calculator | 10 | fees-config-1 | price-monitoring-1 | default-eth-for-future | 5 | 5 | 1e6 | 1e6 | default-futures |
| ETH/DEC21 | ETH | ETH | lqm-params | log-normal-risk-model-1 | default-margin-calculator | 10 | fees-config-1 | price-monitoring-1 | default-eth-for-future | 5 | 5 | 0.25 | 0 | default-futures |
And the parties deposit on asset's general account the following amount:
| party | asset | amount |
| party0 | ETH | 100000000000000 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: Set up a market, with an opening auction, then uncross the book in pres

And the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params |
| ETH/DEC19 | BTC | BTC | default-simple-risk-model-4 | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 1e6 | 1e6 | default-futures |
| ETH/DEC19 | BTC | BTC | default-simple-risk-model-4 | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 0.25 | 0 | default-futures |

Scenario: Set up opening auction with wash trades and uncross
# setup accounts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Set up a market, create indiciative price different to actual opening a
| 0.1 | 0.1 | 2 | -3 | 0.2 |
Given the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params |
| ETH/DEC19 | BTC | BTC | my-simple-risk-model | default-margin-calculator | 5 | default-none | default-basic | default-eth-for-future | 1e6 | 1e6 | default-futures |
| ETH/DEC19 | BTC | BTC | my-simple-risk-model | default-margin-calculator | 5 | default-none | default-basic | default-eth-for-future | 0.25 | 0 | default-futures |
And the following network parameters are set:
| name | value |
| market.auction.minimumDuration | 5 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: Set up a market, create indiciative price different to actual opening a

Given the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params |
| ETH/DEC19 | BTC | BTC | default-log-normal-risk-model | default-margin-calculator | 8 | default-none | default-basic | default-eth-for-future | 1e6 | 1e6 | default-futures |
| ETH/DEC19 | BTC | BTC | default-log-normal-risk-model | default-margin-calculator | 8 | default-none | default-basic | default-eth-for-future | 0.25 | 0 | default-futures |
And the following network parameters are set:
| name | value |
| market.auction.minimumDuration | 8 |
Expand Down
36 changes: 12 additions & 24 deletions core/integration/features/auctions/opening-auction-price.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Set up a market, create indiciative price different to actual opening a
| 0.1 | 0.1 | 2 | -3 | 0.2 |
Given the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params |
| ETH/DEC19 | BTC | BTC | my-simple-risk-model | default-margin-calculator | 5 | default-none | default-basic | default-eth-for-future | 1e6 | 1e6 | default-futures |
| ETH/DEC19 | BTC | BTC | my-simple-risk-model | default-margin-calculator | 5 | default-none | default-basic | default-eth-for-future | 0.25 | 0 | default-futures |
And the following network parameters are set:
| name | value |
| market.auction.minimumDuration | 5 |
Expand Down Expand Up @@ -104,15 +104,11 @@ Feature: Set up a market, create indiciative price different to actual opening a
| buy | 5900 | 16 |
| buy | 1000 | 1 |

# party2_maintenance:= 8*10000*0.1 + 8*max(0, 6100-10000) = 8000 + 0 = 8000
# party2_maintenance:= 8*10000*(0.1+0.25) = 28000
And the parties should have the following margin levels:
| party | market id | maintenance | search | initial | release |
| party2 | ETH/DEC19 | 8000 | 8800 | 9600 | 11200 |
| party1 | ETH/DEC19 | 45900 | 50490 | 55080 | 64260 |
Then the parties should have the following account balances:
| party | asset | market id | margin | general |
| party2 | BTC | ETH/DEC19 | 9600 | 99990400 |
| party1 | BTC | ETH/DEC19 | 55080 | 99944920 |
| party | market id | maintenance |
| party2 | ETH/DEC19 | 28000 |
| party1 | ETH/DEC19 | 31500 |
And the market data for the market "ETH/DEC19" should be:
| mark price | trading mode | horizon | min bound | max bound | ref price |
| 10000 | TRADING_MODE_CONTINUOUS | 5 | 9997 | 10002 | 10000 |
Expand Down Expand Up @@ -178,13 +174,9 @@ Feature: Set up a market, create indiciative price different to actual opening a

When the network moves ahead "1" blocks
Then the parties should have the following margin levels:
| party | market id | maintenance | initial |
| party2 | ETH/DEC19 | 8000 | 9600 |
| party | market id | maintenance |
| party2 | ETH/DEC19 | 28000 |

And the parties should have the following account balances:
| party | asset | market id | margin | general |
| party2 | BTC | ETH/DEC19 | 9600 | 99990400 |
| party1 | BTC | ETH/DEC19 | 48960 | 99951040 |
And the market data for the market "ETH/DEC19" should be:
| mark price | trading mode | horizon | min bound | max bound | ref price |
| 10000 | TRADING_MODE_CONTINUOUS | 5 | 9997 | 10002 | 10000 |
Expand Down Expand Up @@ -264,13 +256,9 @@ Feature: Set up a market, create indiciative price different to actual opening a

When the network moves ahead "1" blocks
Then the parties should have the following margin levels:
| party | market id | maintenance | initial |
| party2 | ETH/DEC19 | 8000 | 9600 |
| party1 | ETH/DEC19 | 45900 | 55080 |
And the parties should have the following account balances:
| party | asset | market id | margin | general |
| party2 | BTC | ETH/DEC19 | 9600 | 99990400 |
| party1 | BTC | ETH/DEC19 | 55080 | 99944920 |
| party | market id | maintenance |
| party2 | ETH/DEC19 | 28000 |
| party1 | ETH/DEC19 | 31500 |
Then the parties should have the following profit and loss:
| party | volume | unrealised pnl | realised pnl |
| party2 | -8 | 0 | 0 |
Expand Down Expand Up @@ -363,8 +351,8 @@ Feature: Set up a market, create indiciative price different to actual opening a
When the network moves ahead "1" blocks
Then the parties should have the following account balances:
| party | asset | market id | margin | general |
| party2 | BTC | ETH/DEC19 | 9600 | 99990400 |
| party1 | BTC | ETH/DEC19 | 42840 | 99957160 |
| party2 | BTC | ETH/DEC19 | 33600 | 99966400 |
| party1 | BTC | ETH/DEC19 | 29400 | 99970600 |
And the market data for the market "ETH/DEC19" should be:
| mark price | trading mode | horizon | min bound | max bound | ref price |
| 10000 | TRADING_MODE_CONTINUOUS | 5 | 9997 | 10002 | 10000 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: Set up a market, with an opening auction, then uncross the book

Given the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params |
| ETH/DEC19 | BTC | BTC | default-simple-risk-model-4 | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 1e6 | 1e6 | default-futures |
| ETH/DEC19 | BTC | BTC | default-simple-risk-model-4 | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 0.25 | 0 | default-futures |
And the parties deposit on asset's general account the following amount:
| party | asset | amount |
| party1 | BTC | 100000000 |
Expand Down Expand Up @@ -70,8 +70,8 @@ Feature: Set up a market, with an opening auction, then uncross the book
| party2 | t2-s-3 | STATUS_FILLED |
Then the parties should have the following account balances:
| party | asset | market id | margin | general |
| party2 | BTC | ETH/DEC19 | 9600 | 39080 |
| party1 | BTC | ETH/DEC19 | 48960 | 1280 |
| party2 | BTC | ETH/DEC19 | 33600 | 15080 |
| party1 | BTC | ETH/DEC19 | 33600 | 16640 |

Scenario: Uncross auction via order amendment
When the parties place the following orders:
Expand Down

0 comments on commit 3588003

Please sign in to comment.