Skip to content

Commit

Permalink
feat: Adding default mark price config (#590)
Browse files Browse the repository at this point in the history
* feat: Adding default mark price config
  • Loading branch information
TomMcL authored Jan 11, 2024
1 parent 014ea8f commit 78d7378
Show file tree
Hide file tree
Showing 16 changed files with 771 additions and 524 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VEGA_SIM_VEGA_TAG=097fd8aaa4fbf08eec5bbf038fac6d707aafc999
VEGA_SIM_VEGA_TAG=8c0829f925fc4b39f3e2f84fbe068f501df4d729
VEGA_SIM_CONSOLE_TAG=develop
VEGA_DEFAULT_KEY_NAME='Key 1'
VEGA_SIM_NETWORKS_INTERNAL_TAG=main
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pipeline {
disableConcurrentBuilds(abortPrevious: true)
}
parameters {
string( name: 'VEGA_VERSION', defaultValue: '097fd8aaa4fbf08eec5bbf038fac6d707aafc999',
string( name: 'VEGA_VERSION', defaultValue: '8c0829f925fc4b39f3e2f84fbe068f501df4d729',
description: 'Git branch, tag or hash of the vegaprotocol/vega repository')
string( name: 'VEGACAPSULE_VERSION', defaultValue: 'main',
description: 'Git branch, tag or hash of the vegaprotocol/vegacapsule repository')
Expand Down
7 changes: 4 additions & 3 deletions tests/vega_sim/api/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,7 @@ def ListStopOrders(self, request, context):
market_position_decimals_map={"market_id": 2},
)

expected_expiry = datetime.datetime.fromtimestamp(1672531200)
assert stop_orders == [
StopOrderEvent(
submission=OrderSubmission(
Expand All @@ -1387,12 +1388,12 @@ def ListStopOrders(self, request, context):
stop_order=StopOrder(
id="id",
oco_link_id="oco_link_id",
expires_at=datetime.datetime(2023, 1, 1, 0, 0),
expires_at=expected_expiry,
expiry_strategy=vega_protos.vega.StopOrder.EXPIRY_STRATEGY_CANCELS,
trigger_direction=vega_protos.vega.StopOrder.TRIGGER_DIRECTION_RISES_ABOVE,
status=vega_protos.vega.StopOrder.STATUS_PENDING,
created_at=datetime.datetime(2023, 1, 1, 0, 0),
updated_at=datetime.datetime(2023, 1, 1, 0, 0),
created_at=expected_expiry,
updated_at=expected_expiry,
order_id="order_id",
party_id="party_id",
market_id="market_id",
Expand Down
3 changes: 3 additions & 0 deletions vega_sim/api/governance.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ def __propose_market(
full_disposal_size=1000000000,
max_fraction_consumed="0.5",
),
mark_price_configuration=vega_protos.markets.CompositePriceConfiguration(
composite_price_type=vega_protos.markets.COMPOSITE_PRICE_TYPE_LAST_TRADE,
),
),
)
if parent_market_id is not None:
Expand Down
53 changes: 53 additions & 0 deletions vega_sim/api/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class MarketConfig(Config):
"successor": None,
"liquidity_sla_parameters": "default",
"liquidation_strategy": "default",
"mark_price_configuration": "default",
},
"perpetual": {
"decimal_places": 4,
Expand All @@ -142,6 +143,7 @@ class MarketConfig(Config):
"successor": None,
"liquidity_sla_parameters": "default",
"liquidation_strategy": "default",
"mark_price_configuration": "default",
},
}

Expand Down Expand Up @@ -174,6 +176,9 @@ def load(self, opt: Optional[str] = None):
self.liquidation_strategy = LiquidationStrategy(
opt=config["liquidation_strategy"]
)
self.mark_price_configuration = MarkPriceConfiguration(
opt=config["mark_price_configuration"]
)

def build(self):
new_market = vega_protos.governance.NewMarket(
Expand All @@ -189,6 +194,7 @@ def build(self):
linear_slippage_factor=self.linear_slippage_factor,
quadratic_slippage_factor=self.quadratic_slippage_factor,
liquidation_strategy=self.liquidation_strategy.build(),
mark_price_configuration=self.mark_price_configuration.build(),
)
)
if self.successor is not None:
Expand Down Expand Up @@ -390,6 +396,53 @@ def build(self):
)


class MarkPriceConfiguration(Config):
OPTS = {
"default": {
"decay_weight": None,
"composite_price_type": vega_protos.markets.COMPOSITE_PRICE_TYPE_LAST_TRADE,
"source_staleness_tolerance": None,
"decay_power": None,
"cash_amount": None,
"source_weights": None,
}
}

def load(self, opt: Optional[str] = None):
config = super().load(opt=opt)

self.decay_weight = (
str(config["decay_weight"]) if config["decay_weight"] is not None else None
)
self.composite_price_type = config["composite_price_type"]
self.source_staleness_tolerance = config["source_staleness_tolerance"]
self.decay_power = config["decay_power"]
self.cash_amount = (
str(config["cash_amount"]) if config["cash_amount"] is not None else None
)
self.source_weights = (
[str(w) for w in config["source_weights"]]
if config["source_weights"] is not None
else None
)

def build(self):
price_config = vega_protos.markets.CompositePriceConfiguration(
composite_price_type=self.composite_price_type,
)
if self.source_weights is not None:
price_config.source_weights = self.source_weights
if self.cash_amount is not None:
price_config.cash_amount = self.cash_amount
if self.decay_power is not None:
price_config.decay_power = self.decay_power
if self.source_staleness_tolerance is not None:
price_config.source_staleness_tolerance = self.source_staleness_tolerance
if self.decay_weight is not None:
price_config.decay_weight = self.decay_weight
return price_config


class LiquidationStrategy(Config):
OPTS = {
"default": {
Expand Down
52 changes: 27 additions & 25 deletions vega_sim/proto/vega/data_source_pb2.py

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

6 changes: 6 additions & 0 deletions vega_sim/proto/vega/data_source_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class DataSourceDefinition(_message.Message):
external: _Optional[_Union[DataSourceDefinitionExternal, _Mapping]] = ...,
) -> None: ...

class SpecBindingForCompositePrice(_message.Message):
__slots__ = ("price_source_property",)
PRICE_SOURCE_PROPERTY_FIELD_NUMBER: _ClassVar[int]
price_source_property: str
def __init__(self, price_source_property: _Optional[str] = ...) -> None: ...

class DataSourceSpecConfigurationTime(_message.Message):
__slots__ = ("conditions",)
CONDITIONS_FIELD_NUMBER: _ClassVar[int]
Expand Down
188 changes: 94 additions & 94 deletions vega_sim/proto/vega/governance_pb2.py

Large diffs are not rendered by default.

Loading

0 comments on commit 78d7378

Please sign in to comment.