diff --git a/README.md b/README.md index 5ca5bbb..8613104 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ This repo provides a unified interface for the Lyra V2 Exchange. Please checkout the [examples](./examples) directory for usage. +Here is a quick demonstration of the cli functionality. + +![alt text](lyra_demo.gif "Demo of cli tools.") ## Install @@ -37,7 +40,6 @@ For convience, all commands can be run with; make all ``` -### Releases ### Releasing We can use `tbump` to automatically bump our versions in preparation of a release. @@ -52,3 +54,6 @@ tbump new_version The release workflow will then detect that a branch with a `v` prefix exists and create a release from it. Additionally, the package will be published to PyPI. + + +[def]: ./lyra_demo.gif \ No newline at end of file diff --git a/lyra/cli.py b/lyra/cli.py index 713776d..3b8f753 100644 --- a/lyra/cli.py +++ b/lyra/cli.py @@ -82,6 +82,36 @@ def orders(): """Interact with orders.""" +@cli.group("collateral") +def collateral(): + """Interact with collateral.""" + + +@cli.group("positions") +def positions(): + """Interact with positions.""" + + +@positions.command("fetch") +@click.pass_context +def fetch_positions(ctx): + """Fetch positions.""" + print("Fetching positions") + client = ctx.obj["client"] + positions = client.get_positions() + print(positions) + + +@collateral.command("fetch") +@click.pass_context +def fetch_collateral(ctx): + """Fetch collateral.""" + print("Fetching collateral") + client = ctx.obj["client"] + collateral = client.get_collaterals() + print(collateral) + + @instruments.command("fetch") @click.pass_context @click.option( @@ -224,21 +254,25 @@ def cancel_all_orders(ctx): "--instrument-name", "-i", type=str, + required=True, ) @click.option( "--side", "-s", type=click.Choice(i.value for i in OrderSide), + required=True, ) @click.option( "--price", "-p", type=float, + required=True, ) @click.option( "--amount", "-a", type=float, + required=True, ) @click.option( "--order-type", diff --git a/lyra/lyra.py b/lyra/lyra.py index dc93a8a..bac7d1d 100644 --- a/lyra/lyra.py +++ b/lyra/lyra.py @@ -345,3 +345,14 @@ def get_positions(self): response = requests.post(url, json=payload, headers=headers) results = response.json()["result"]['positions'] return results + + def get_collaterals(self): + """ + Get collaterals + """ + url = f"{self.contracts['BASE_URL']}/private/get_collaterals" + payload = {"subaccount_id": self.subaccount_id} + headers = self._create_signature_headers() + response = requests.post(url, json=payload, headers=headers) + results = response.json()["result"]['collaterals'] + return results.pop() diff --git a/lyra_demo.gif b/lyra_demo.gif new file mode 100644 index 0000000..c78c1c4 Binary files /dev/null and b/lyra_demo.gif differ diff --git a/scripts/demo.sh b/scripts/demo.sh index ee50a6d..ce66cfe 100644 --- a/scripts/demo.sh +++ b/scripts/demo.sh @@ -2,7 +2,7 @@ set -e -SLEEP_TIME=1 +SLEEP_TIME=3 cowsay The lyra V2 client offers both a library and a cli tool to manage positions on LyraV2. @@ -38,7 +38,7 @@ lyra instruments fetch -i perp sleep $SLEEP_TIME clear -echo \`lyra instruments fetch -i perp -c btc +echo \`lyra instruments fetch -i perp -c btc\` lyra instruments fetch -i perp -c btc sleep $SLEEP_TIME clear @@ -65,7 +65,20 @@ clear cowsay "we can then cancel them" -echo \`lyra orders fetch -i ETH-PERP --status open\` +echo \`lyra orders cancel_all\` lyra orders cancel_all +sleep $SLEEP_TIME +clear + +cowsay "we can also check our balances" +echo \`lyra collateral fetch\` +lyra collateral fetch +sleep $SLEEP_TIME +clear +cowsay "we can also check our positions" +echo \`lyra positions fetch\` +lyra positions fetch +sleep $SLEEP_TIME +clear diff --git a/tests/test_main.py b/tests/test_main.py index 4b6f5be..2fdde0e 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -163,3 +163,9 @@ def test_get_positions(lyra_client): """Test get positions.""" positions = lyra_client.get_positions() assert isinstance(positions, list) + + +def test_get_collaterals(lyra_client): + """Test get collaterals.""" + collaterals = lyra_client.get_collaterals() + assert isinstance(collaterals, dict)