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

Remove obsolete initial mark price network parameter #3041

Merged
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
5 changes: 0 additions & 5 deletions cmd/vega/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ func createDefaultMarkets(confpath string) ([]string, error) {
settlementAsset string
quoteName string
maturity time.Time
initialMarkPrice uint64
settlementValue uint64
sigma float64
riskAversionParameter float64
Expand All @@ -187,7 +186,6 @@ func createDefaultMarkets(confpath string) ([]string, error) {
quoteName: "VUSD",
settlementAsset: "VUSD",
maturity: time.Date(2020, 12, 31, 23, 59, 59, 0, time.UTC),
initialMarkPrice: 1410000,
settlementValue: 1500000,
riskAversionParameter: 0.001,
sigma: 1.5,
Expand All @@ -200,7 +198,6 @@ func createDefaultMarkets(confpath string) ([]string, error) {
quoteName: "VUSD",
settlementAsset: "VUSD",
maturity: time.Date(2020, 10, 30, 22, 59, 59, 0, time.UTC),
initialMarkPrice: 130000,
settlementValue: 126000,
riskAversionParameter: 0.01,
sigma: 0.09,
Expand All @@ -213,7 +210,6 @@ func createDefaultMarkets(confpath string) ([]string, error) {
quoteName: "BTC",
settlementAsset: "BTC",
maturity: time.Date(2020, 12, 31, 23, 59, 59, 0, time.UTC),
initialMarkPrice: 10000,
settlementValue: 98123,
riskAversionParameter: 0.001,
sigma: 2.0,
Expand Down Expand Up @@ -252,7 +248,6 @@ func createDefaultMarkets(confpath string) ([]string, error) {
"product:futures",
},
},
InitialMarkPrice: skel.initialMarkPrice,
Product: &proto.Instrument_Future{
Future: &proto.Future{
QuoteName: skel.quoteName,
Expand Down
40 changes: 38 additions & 2 deletions execution/margin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,52 @@ import (
)

func TestMargins(t *testing.T) {
party1 := "party1"
party1, party2, party3 := "party1", "party2", "party3"
now := time.Unix(10, 0)
closingAt := time.Unix(10000000000, 0)
tm := getTestMarket(t, now, closingAt, nil, nil)
price := uint64(100)
size := uint64(100)

addAccount(tm, party1)
addAccount(tm, party2)
addAccount(tm, party3)
tm.broker.EXPECT().Send(gomock.Any()).AnyTimes()

order1 := &types.Order{
Status: types.Order_STATUS_ACTIVE,
Type: types.Order_TYPE_LIMIT,
TimeInForce: types.Order_TIME_IN_FORCE_GTC,
Id: "someid12",
Side: types.Side_SIDE_BUY,
PartyId: party2,
MarketId: tm.market.GetID(),
Size: size,
Price: price,
Remaining: size,
CreatedAt: now.UnixNano(),
Reference: "party2-buy-order",
}
order2 := &types.Order{
Status: types.Order_STATUS_ACTIVE,
Type: types.Order_TYPE_LIMIT,
TimeInForce: types.Order_TIME_IN_FORCE_GTC,
Id: "someid123",
Side: types.Side_SIDE_SELL,
PartyId: party3,
MarketId: tm.market.GetID(),
Size: size,
Price: price,
Remaining: size,
CreatedAt: now.UnixNano(),
Reference: "party3-buy-order",
}
_, err := tm.market.SubmitOrder(context.TODO(), order1)
assert.NoError(t, err)
confirmation, err := tm.market.SubmitOrder(context.TODO(), order2)
assert.NoError(t, err)
assert.Equal(t, 1, len(confirmation.Trades))

orderBuy := &types.Order{
Status: types.Order_STATUS_ACTIVE,
Type: types.Order_TYPE_LIMIT,
Expand All @@ -37,7 +73,7 @@ func TestMargins(t *testing.T) {
Reference: "party1-buy-order",
}
// Create an order to amend
confirmation, err := tm.market.SubmitOrder(context.TODO(), orderBuy)
confirmation, err = tm.market.SubmitOrder(context.TODO(), orderBuy)
if !assert.NoError(t, err) {
t.Fatalf("Error: %v", err)
}
Expand Down
10 changes: 1 addition & 9 deletions execution/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ var (
ErrMarginCheckFailed = errors.New("margin check failed")
// ErrMarginCheckInsufficient signals that a margin had not enough funds
ErrMarginCheckInsufficient = errors.New("insufficient margin")
// ErrInvalidInitialMarkPrice signals that the initial mark price for a market is invalid
ErrInvalidInitialMarkPrice = errors.New("invalid initial mark price (mkprice <= 0)")
// ErrMissingGeneralAccountForParty ...
ErrMissingGeneralAccountForParty = errors.New("missing general account for party")
// ErrNotEnoughVolumeToZeroOutNetworkOrder ...
Expand Down Expand Up @@ -249,19 +247,14 @@ func NewMarket(
return nil, errors.Wrap(err, "unable to instantiate a new market")
}

if tradableInstrument.Instrument.InitialMarkPrice == 0 {
return nil, ErrInvalidInitialMarkPrice
}

closingAt, err := tradableInstrument.Instrument.GetMarketClosingTime()
if err != nil {
return nil, errors.Wrap(err, "unable to get market closing time")
}

// @TODO -> the raw auctionstate shouldn't be something exposed to the matching engine
// as far as matching goes: it's either an auction or not
book := matching.NewOrderBook(log, matchingConfig, mkt.Id,
tradableInstrument.Instrument.InitialMarkPrice, as.InAuction())
book := matching.NewOrderBook(log, matchingConfig, mkt.Id, as.InAuction())
asset := tradableInstrument.Instrument.Product.GetAsset()
riskEngine := risk.NewEngine(
log,
Expand Down Expand Up @@ -307,7 +300,6 @@ func NewMarket(
mkt: mkt,
closingAt: closingAt,
currentTime: now,
markPrice: tradableInstrument.Instrument.InitialMarkPrice,
matching: book,
tradableInstrument: tradableInstrument,
risk: riskEngine,
Expand Down
115 changes: 111 additions & 4 deletions execution/market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ func getMarket(closingAt time.Time, pMonitorSettings *types.PriceMonitoringSetti
"product:futures",
},
},
InitialMarkPrice: 99,
Product: &types.Instrument_Future{
Future: &types.Future{
Maturity: closingAt.Format(time.RFC3339),
Expand Down Expand Up @@ -556,7 +555,7 @@ func TestMarketGetMarginOnNewOrderEmptyBook(t *testing.T) {
}

func TestMarketGetMarginOnFailNoFund(t *testing.T) {
party1 := "party1"
party1, party2, party3 := "party1", "party2", "party3"
now := time.Unix(10, 0)
closingAt := time.Unix(10000000000, 0)
tm := getTestMarket(t, now, closingAt, nil, nil)
Expand All @@ -565,6 +564,42 @@ func TestMarketGetMarginOnFailNoFund(t *testing.T) {
// this will create 2 traders, credit their account
// and move some monies to the market
addAccountWithAmount(tm, party1, 0)
addAccountWithAmount(tm, party2, 1000000)
addAccountWithAmount(tm, party3, 1000000)

order1 := &types.Order{
Status: types.Order_STATUS_ACTIVE,
Type: types.Order_TYPE_LIMIT,
TimeInForce: types.Order_TIME_IN_FORCE_GTC,
Id: "someid12",
Side: types.Side_SIDE_BUY,
PartyId: party2,
MarketId: tm.market.GetID(),
Size: 100,
Price: 100,
Remaining: 100,
CreatedAt: now.UnixNano(),
Reference: "party2-buy-order",
}
order2 := &types.Order{
Status: types.Order_STATUS_ACTIVE,
Type: types.Order_TYPE_LIMIT,
TimeInForce: types.Order_TIME_IN_FORCE_GTC,
Id: "someid123",
Side: types.Side_SIDE_SELL,
PartyId: party3,
MarketId: tm.market.GetID(),
Size: 100,
Price: 100,
Remaining: 100,
CreatedAt: now.UnixNano(),
Reference: "party3-buy-order",
}
_, err := tm.market.SubmitOrder(context.TODO(), order1)
assert.NoError(t, err)
confirmation, err := tm.market.SubmitOrder(context.TODO(), order2)
assert.NoError(t, err)
assert.Equal(t, 1, len(confirmation.Trades))

// submit orders
// party1 buys
Expand All @@ -589,7 +624,7 @@ func TestMarketGetMarginOnFailNoFund(t *testing.T) {
tm.broker.EXPECT().Send(gomock.Any()).AnyTimes()
// tm.transferResponseStore.EXPECT().Add(gomock.Any()).AnyTimes()

_, err := tm.market.SubmitOrder(context.Background(), orderBuy)
_, err = tm.market.SubmitOrder(context.Background(), orderBuy)
assert.NotNil(t, err)
assert.EqualError(t, err, "margin check failed")
}
Expand Down Expand Up @@ -1590,14 +1625,86 @@ func TestHandleLPCommitmentChange(t *testing.T) {
ctx := context.Background()
party1 := "party1"
party2 := "party2"
party3 := "party3"
party4 := "party4"
now := time.Unix(10, 0)
closingAt := time.Unix(10000000000, 0)
tm := getTestMarket(t, now, closingAt, nil, nil)
var matchingPrice uint64 = 111

addAccount(tm, party1)
addAccount(tm, party2)
addAccount(tm, party3)
addAccount(tm, party4)
tm.broker.EXPECT().Send(gomock.Any()).AnyTimes()
price := uint64(99)

order1 := &types.Order{
Type: types.Order_TYPE_LIMIT,
TimeInForce: types.Order_TIME_IN_FORCE_GTC,
Status: types.Order_STATUS_ACTIVE,
Id: "someid3",
Side: types.Side_SIDE_SELL,
PartyId: party3,
MarketId: tm.market.GetID(),
Size: 1,
Price: price,
Remaining: 1,
CreatedAt: now.UnixNano(),
Reference: "party3-sell-order-1",
}
order2 := &types.Order{
Type: types.Order_TYPE_LIMIT,
TimeInForce: types.Order_TIME_IN_FORCE_GTC,
Status: types.Order_STATUS_ACTIVE,
Id: "someid4",
Side: types.Side_SIDE_BUY,
PartyId: party4,
MarketId: tm.market.GetID(),
Size: 1,
Price: price,
Remaining: 1,
CreatedAt: now.UnixNano(),
Reference: "party4-sell-order-1",
}
_, err := tm.market.SubmitOrder(context.TODO(), order1)
assert.NoError(t, err)
confirmationSell, err := tm.market.SubmitOrder(ctx, order2)
assert.NoError(t, err)
require.Equal(t, 1, len(confirmationSell.Trades))
order1 = &types.Order{
Type: types.Order_TYPE_LIMIT,
TimeInForce: types.Order_TIME_IN_FORCE_GTC,
Status: types.Order_STATUS_ACTIVE,
Id: "someid5",
Side: types.Side_SIDE_SELL,
PartyId: party4,
MarketId: tm.market.GetID(),
Size: 1,
Price: price,
Remaining: 1,
CreatedAt: now.UnixNano(),
Reference: "party5-sell-order-1",
}
order2 = &types.Order{
Type: types.Order_TYPE_LIMIT,
TimeInForce: types.Order_TIME_IN_FORCE_GTC,
Status: types.Order_STATUS_ACTIVE,
Id: "someid6",
Side: types.Side_SIDE_BUY,
PartyId: party3,
MarketId: tm.market.GetID(),
Size: 1,
Price: price,
Remaining: 1,
CreatedAt: now.UnixNano(),
Reference: "party6-sell-order-1",
}
_, err = tm.market.SubmitOrder(context.TODO(), order1)
assert.NoError(t, err)
confirmationSell, err = tm.market.SubmitOrder(ctx, order2)
assert.NoError(t, err)
require.Equal(t, 1, len(confirmationSell.Trades))

//TODO (WG 07/01/21): Currently limit orders need to be present on order book for liquidity provision submission to work, remove once fixed.
orderSell1 := &types.Order{
Expand All @@ -1615,7 +1722,7 @@ func TestHandleLPCommitmentChange(t *testing.T) {
ExpiresAt: closingAt.UnixNano(),
Reference: "party2-sell-order-1",
}
confirmationSell, err := tm.market.SubmitOrder(ctx, orderSell1)
confirmationSell, err = tm.market.SubmitOrder(ctx, orderSell1)
require.NotNil(t, confirmationSell)
require.NoError(t, err)

Expand Down
5 changes: 1 addition & 4 deletions governance/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,15 @@ func assignTradingMode(definition *types.NewMarketConfiguration, target *types.M
}

func createInstrument(
netp NetParams,
input *types.InstrumentConfiguration,
tags []string,
) (*types.Instrument, types.ProposalError, error) {
initialMarkPrice, _ := netp.GetInt(netparams.MarketInitialMarkPrice)
result := &types.Instrument{
Name: input.Name,
Code: input.Code,
Metadata: &types.InstrumentMetadata{
Tags: tags,
},
InitialMarkPrice: uint64(initialMarkPrice),
}

if perr, err := assignProduct(input, result); err != nil {
Expand Down Expand Up @@ -140,7 +137,7 @@ func createMarket(
if perr, err := validateNewMarket(currentTime, definition, assets, true, netp, openingAuctionDuration); err != nil {
return nil, perr, err
}
instrument, perr, err := createInstrument(netp, definition.Instrument, definition.Metadata)
instrument, perr, err := createInstrument(definition.Instrument, definition.Metadata)
if err != nil {
return nil, perr, err
}
Expand Down
10 changes: 5 additions & 5 deletions integration/features/1779-cannot-place-network-order.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ Feature: Cannot place an network order
Background:
Given the insurance pool initial balance for the markets is "0":
And the execution engine have these markets:
| name | quote name | asset | mark price | risk model | lamd/long | tau/short | mu/max move up | r/min move down | sigma | release factor | initial factor | search factor | settlement price | auction duration | maker fee | infrastructure fee | liquidity fee | p. m. update freq. | p. m. horizons | p. m. probs | p. m. durations | prob. of trading | oracle spec pub. keys | oracle spec property | oracle spec property type | oracle spec binding |
| ETH/DEC19 | ETH | ETH | 1000 | simple | 0.11 | 0.1 | 0 | 0 | 0 | 1.4 | 1.2 | 1.1 | 42 | 0 | 0 | 0 | 0 | 0 | | | | 0.1 | 0xDEADBEEF,0xCAFEDOOD | prices.ETH.value | TYPE_INTEGER | prices.ETH.value |
| name | quote name | asset | risk model | lamd/long | tau/short | mu/max move up | r/min move down | sigma | release factor | initial factor | search factor | settlement price | auction duration | maker fee | infrastructure fee | liquidity fee | p. m. update freq. | p. m. horizons | p. m. probs | p. m. durations | prob. of trading | oracle spec pub. keys | oracle spec property | oracle spec property type | oracle spec binding |
| ETH/DEC19 | ETH | ETH | simple | 0.11 | 0.1 | 0 | 0 | 0 | 1.4 | 1.2 | 1.1 | 42 | 0 | 0 | 0 | 0 | 0 | | | | 0.1 | 0xDEADBEEF,0xCAFEDOOD | prices.ETH.value | TYPE_INTEGER | prices.ETH.value |
And oracles broadcast data signed with "0xDEADBEEF":
| name | value |
| prices.ETH.value | 42 |

Scenario: an order is rejected if a trader try to place an order with type NETWORK
Given the following traders:
| name | amount |
| trader1 | 1 |
| trader1 | 1 |
Then I Expect the traders to have new general account:
| name | asset |
| trader1 | ETH |
And "trader1" general accounts balance is "1"
Then traders place following failing orders:
| trader | id | type | volume | price | error | type |
| trader1 | ETH/DEC19 | sell | 1 | 1000 | invalid order type | TYPE_NETWORK |
| trader | id | type | volume | price | error | type |
| trader1 | ETH/DEC19 | sell | 1 | 1000 | invalid order type | TYPE_NETWORK |
4 changes: 2 additions & 2 deletions integration/features/1847-closeout-long-with-fees.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Feature: Long close-out test (see ln 293 of system-tests/grpc/trading/tradesTest
Background:
Given the insurance pool initial balance for the markets is "0":
And the execution engine have these markets:
| name | quote name | asset | mark price | risk model | lamd/long | tau/short | mu/max move up | r/min move down | sigma | release factor | initial factor | search factor | settlement price | auction duration | maker fee | infrastructure fee | liquidity fee | p. m. update freq. | p. m. horizons | p. m. probs | p. m. durations | prob. of trading | oracle spec pub. keys | oracle spec property | oracle spec property type | oracle spec binding |
| ETH/DEC19 | BTC | BTC | 100 | simple | 0.1 | 0.1 | -1 | -1 | -1 | 1.4 | 1.2 | 1.1 | 100 | 0 | 0.00025 | 0.0005 | 0.001 | 0 | | | | 0.1 | 0xDEADBEEF,0xCAFEDOOD | prices.ETH.value | TYPE_INTEGER | prices.ETH.value |
| name | quote name | asset | risk model | lamd/long | tau/short | mu/max move up | r/min move down | sigma | release factor | initial factor | search factor | settlement price | auction duration | maker fee | infrastructure fee | liquidity fee | p. m. update freq. | p. m. horizons | p. m. probs | p. m. durations | prob. of trading | oracle spec pub. keys | oracle spec property | oracle spec property type | oracle spec binding |
| ETH/DEC19 | BTC | BTC | simple | 0.1 | 0.1 | -1 | -1 | -1 | 1.4 | 1.2 | 1.1 | 100 | 0 | 0.00025 | 0.0005 | 0.001 | 0 | | | | 0.1 | 0xDEADBEEF,0xCAFEDOOD | prices.ETH.value | TYPE_INTEGER | prices.ETH.value |
And oracles broadcast data signed with "0xDEADBEEF":
| name | value |
| prices.ETH.value | 100 |
Expand Down
4 changes: 2 additions & 2 deletions integration/features/1847-closeout-long.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Feature: Long close-out test (see ln 293 of system-tests/grpc/trading/tradesTest
Background:
Given the insurance pool initial balance for the markets is "0":
And the execution engine have these markets:
| name | quote name | asset | mark price | risk model | lamd/long | tau/short | mu/max move up | r/min move down | sigma | release factor | initial factor | search factor | settlement price | auction duration | maker fee | infrastructure fee | liquidity fee | p. m. update freq. | p. m. horizons | p. m. probs | p. m. durations | prob. of trading | oracle spec pub. keys | oracle spec property | oracle spec property type | oracle spec binding |
| ETH/DEC19 | BTC | BTC | 100 | simple | 0.1 | 0.1 | -1 | -1 | -1 | 1.4 | 1.2 | 1.1 | 100 | 0 | 0 | 0 | 0 | 0 | | | | 0.1 | 0xDEADBEEF,0xCAFEDOOD | prices.ETH.value | TYPE_INTEGER | prices.ETH.value |
| name | quote name | asset | risk model | lamd/long | tau/short | mu/max move up | r/min move down | sigma | release factor | initial factor | search factor | settlement price | auction duration | maker fee | infrastructure fee | liquidity fee | p. m. update freq. | p. m. horizons | p. m. probs | p. m. durations | prob. of trading | oracle spec pub. keys | oracle spec property | oracle spec property type | oracle spec binding |
| ETH/DEC19 | BTC | BTC | simple | 0.1 | 0.1 | -1 | -1 | -1 | 1.4 | 1.2 | 1.1 | 100 | 0 | 0 | 0 | 0 | 0 | | | | 0.1 | 0xDEADBEEF,0xCAFEDOOD | prices.ETH.value | TYPE_INTEGER | prices.ETH.value |
And oracles broadcast data signed with "0xDEADBEEF":
| name | value |
| prices.ETH.value | 100 |
Expand Down
Loading