Skip to content

Commit

Permalink
[feat] mmp config settings
Browse files Browse the repository at this point in the history
  • Loading branch information
8baller committed Feb 2, 2024
1 parent 263860d commit ba74bc5
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
89 changes: 89 additions & 0 deletions lyra/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,95 @@ def positions():
"""Interact with positions."""


@cli.group("mmp")
def mmp():
"""Interact with market making parameters."""


@mmp.command("fetch")
@click.option(
"--underlying-currency",
"-u",
type=click.Choice([f.value for f in UnderlyingCurrency]),
default=UnderlyingCurrency.ETH.value,
)
@click.option(
"--subaccount-id",
"-s",
type=int,
required=True,
)
@click.pass_context
def fetch_mmp(ctx, underlying_currency, subaccount_id):
"""Fetch market making parameters."""
client = ctx.obj["client"]
mmp = client.get_mmp_config(subaccount_id=subaccount_id, currency=UnderlyingCurrency(underlying_currency))
print(mmp)


@mmp.command("set")
@click.option(
"--underlying-currency",
"-u",
type=click.Choice([f.value for f in UnderlyingCurrency]),
default=UnderlyingCurrency.ETH.value,
)
@click.option(
"--subaccount-id",
"-s",
type=int,
required=True,
)
@click.option(
"--frozen-time",
"-f",
type=int,
required=True,
help="Time interval in ms setting how long the subaccount is frozen after an mmp trigger, "
+ "if 0 then a manual reset would be required via private/reset_mmp",
default=10000,
)
@click.option(
"--interval",
"-i",
type=int,
required=True,
help="Time interval in ms over which the limits are monotored, if 0 then mmp is disabled",
default=10000,
)
@click.option(
"--amount-limit",
"-a",
type=float,
help="Maximum total order amount that can be traded within the mmp_interval across all "
+ "instruments of the provided currency. The amounts are not netted, so a filled bid "
+ "of 1 and a filled ask of 2 would count as 3.",
default=5,
)
@click.option(
"--delta-limit",
"-d",
type=float,
help="Maximum total delta that can be traded within the mmp_interval across all instruments "
+ "of the provided currency. This quantity is netted, so a filled order with +1 delta and "
+ "a filled order with -2 delta would count as 3",
default=2,
)
@click.pass_context
def set_mmp(ctx, underlying_currency, subaccount_id, frozen_time, interval, amount_limit, delta_limit):
"""Set market making parameters."""
client = ctx.obj["client"]
mmp = client.set_mmp_config(
subaccount_id=subaccount_id,
currency=UnderlyingCurrency(underlying_currency),
mmp_frozen_time=frozen_time,
mmp_interval=interval,
mmp_amount_limit=amount_limit,
mmp_delta_limit=delta_limit,
)
print(mmp)


@positions.command("fetch")
@click.pass_context
def fetch_positions(ctx):
Expand Down
35 changes: 35 additions & 0 deletions lyra/lyra.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,38 @@ def _generate_signed_action(self, action_hash: bytes, nonce: int, expiration: in
"signature_expiry_sec": expiration,
"signer": self.signer.address,
}

def get_mmp_config(self, subaccount_id: int, currency: UnderlyingCurrency = None):
"""Get the mmp config."""
url = f"{self.contracts['BASE_URL']}/private/get_mmp_config"
payload = {"subaccount_id": self.subaccount_id}
if currency:
payload['currency'] = currency.name
headers = self._create_signature_headers()
response = requests.post(url, json=payload, headers=headers)
results = response.json()["result"]
return results

def set_mmp_config(
self,
subaccount_id,
currency: UnderlyingCurrency,
mmp_frozen_time: int,
mmp_interval: int,
mmp_amount_limit: str,
mmp_delta_limit: str,
):
"""Set the mmp config."""
url = f"{self.contracts['BASE_URL']}/private/set_mmp_config"
payload = {
"subaccount_id": subaccount_id,
"currency": currency.name,
"mmp_frozen_time": mmp_frozen_time,
"mmp_interval": mmp_interval,
"mmp_amount_limit": mmp_amount_limit,
"mmp_delta_limit": mmp_delta_limit,
}
headers = self._create_signature_headers()
response = requests.post(url, json=payload, headers=headers)
results = response.json()["result"]
return results
25 changes: 25 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,28 @@ def test_analyser(underlying_currency, lyra_client):
assert len(analyser.get_open_positions(underlying_currency))
assert analyser.get_subaccount_value()
assert len(analyser.get_total_greeks(underlying_currency))


def test_get_mmp_config(lyra_client):
"""Test get mmp config."""
config = lyra_client.get_mmp_config(lyra_client.subaccount_id)
assert isinstance(config, list)


def test_set_mmp_config(lyra_client):
"""Test set mmp config."""
config = {
"subaccount_id": lyra_client.subaccount_id,
"currency": UnderlyingCurrency.ETH,
"mmp_frozen_time": 0,
"mmp_interval": 10_000,
"mmp_amount_limit": 10,
"mmp_delta_limit": 0.1,
}
lyra_client.set_mmp_config(**config)
set_config = lyra_client.get_mmp_config(lyra_client.subaccount_id, UnderlyingCurrency.ETH)[0]
for k, v in config.items():
if k == "currency":
assert set_config[k] == v.name
else:
assert float(set_config[k]) == v

0 comments on commit ba74bc5

Please sign in to comment.