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

Feat/demo of client #14

Merged
merged 2 commits into from
Dec 26, 2023
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
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

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

```bash
pip install lyra-client
pip install lyra-v2-client
```

## Dev
Expand Down Expand Up @@ -35,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 @@ -50,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
38 changes: 37 additions & 1 deletion lyra/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def set_client(ctx):
else:
env = Environment.TEST
ctx.client = LyraClient(**auth, env=env)
print(f"Client created for environment `{ctx.client.env.value}`")

if ctx.logger.level == "DEBUG":
print(f"Client created for environment `{ctx.client.env.value}`")
return ctx.client


Expand Down Expand Up @@ -80,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 @@ -222,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.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.poetry]
name = "lyra-client"
name = "lyra-v2-client"
version = "0.1.2"
description = ""
authors = ["8baller <[email protected]>"]
Expand Down
84 changes: 84 additions & 0 deletions scripts/demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#! /bin/bash

set -e

SLEEP_TIME=3

cowsay The lyra V2 client offers both a library and a cli tool to manage positions on LyraV2.

sleep $SLEEP_TIME

clear

cowsay "The client can be installed from pip as so;"

echo "pip install lyra-v2-client"

sleep $SLEEP_TIME

clear

cowsay "Once the lyra client is installed, we can programatically interact with lyra"

lyra

sleep $SLEEP_TIME
clear

cowsay we can fetch markets by instrument type and currency

lyra instruments fetch --help

sleep $SLEEP_TIME
clear

echo \`lyra instruments fetch -i perp\`
lyra instruments fetch -i perp

sleep $SLEEP_TIME
clear

echo \`lyra instruments fetch -i perp -c btc\`
lyra instruments fetch -i perp -c btc
sleep $SLEEP_TIME
clear



cowsay we can manage orders
echo \`lyra orders\`
lyra orders
sleep $SLEEP_TIME
clear

cowsay we can create orders
echo \`lyra orders create -s sell -i ETH-PERP -a 1 -p 3000\`
lyra orders create -s sell -i ETH-PERP -a 1 -p 3000
sleep $SLEEP_TIME
clear

cowsay "we can then retrieve them"
echo \`lyra orders fetch -i ETH-PERP --status open\`
lyra orders fetch -i ETH-PERP --status open
sleep $SLEEP_TIME
clear


cowsay "we can then cancel them"
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)
Loading