Skip to content

Commit

Permalink
[feat] recorded demo video
Browse files Browse the repository at this point in the history
  • Loading branch information
8ball030 committed Dec 26, 2023
1 parent 1fa17c3 commit f9af345
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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
34 changes: 34 additions & 0 deletions lyra/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions lyra/lyra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Binary file added lyra_demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 16 additions & 3 deletions scripts/demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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

6 changes: 6 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit f9af345

Please sign in to comment.