Skip to content

Commit

Permalink
Merge pull request #4 from 8ball030/feat/python_conversion
Browse files Browse the repository at this point in the history
Feat/python conversion
  • Loading branch information
8ball030 authored Nov 9, 2023
2 parents e90a17e + 5623ecc commit b5261b8
Show file tree
Hide file tree
Showing 21 changed files with 1,836 additions and 1,005 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/common_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This is a basic workflow to help you get started with Actions

name: Code Quality
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
check:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
poetry-version: ["1.3.2"]
os: [ubuntu-20.04,]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: ${{ matrix.poetry-version }}
virtualenvs-create: true
virtualenvs-in-project: false
virtualenvs-path: ~/my-custom-path
installer-parallel: true

- name: Install Packages
run: |
poetry install -v
- name: Install Host Dependencies
run: |
poetry run python script/install.py
- name: Lint
run: |
poetry run make lint
- name: Tests
run: |
poetry run make tests
- name: Doc Tests
run: |
make test-docs
52 changes: 52 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This is a basic workflow to help you get started with Actions

name: Dependency Workflows
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
pull_request_target:
types:
- opened
branches:
- 'main'
- 'master'
paths:
- 'pyproject.toml'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
check_deps:
strategy:
matrix:
python-versions:
- 3.8
- 3.9
os:
- ubuntu-20.04
runs-on: ubuntu-20.04
env:
PYTHONPATH: .
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-versions }}

- name: Install ci dependencies
run: |
make are_deps_dirty && exit 0
python -m pip install --upgrade pip
pip install poetry tox-gh-actions tox-poetry
- name: Install application deps
run: |
make are_deps_dirty && exit 0
poetry install
- name: Lock application deps
run: |
make are_deps_dirty || poetry lock
echo "No change in dependencies not locking."
67 changes: 67 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Publish package on main branch if it's tagged with 'v*'

name: release & publish workflow

# Controls when the action will run.
on:
# Triggers the workflow on push events but only for the master branch
push:
tags:
- 'v*'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "release"
release:
name: Create Release
runs-on: ubuntu-20.04

strategy:
matrix:
python-versions: [3.8]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Get version from tag
id: tag_name
run: |
echo ::set-output name=current_version::${GITHUB_REF#refs/tags/v}
shell: bash

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-versions }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Build wheels and source tarball
run: >-
poetry build
- name: create github release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
body: ${{ steps.changelog_reader.outputs.changes }}
files: dist/*.whl
draft: false
prerelease: false

- name: publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,5 @@ site/
.history

trader

node_modules
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: tests
tests:
pytest tests -vv
poetry run pytest tests -vv

fmt:
poetry run black tests lyra
Expand All @@ -9,4 +9,7 @@ fmt:
lint:
poetry run flake8 tests lyra

all: fmt lint tests
all: fmt lint tests

test-docs:
echo making docs
64 changes: 64 additions & 0 deletions install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
Installations for the necessary packages.
"""

import os
from dataclasses import dataclass

from rich.progress import track

from rysk_client.src.utils import get_logger

logger = get_logger()


@dataclass
class HostDependency:
"""
represents a host dependency
"""

name: str
install_cmd: str

def is_present(self) -> bool:
"""
silently check if the dependency is present on the host
"""
return os.popen(f"which {self.name}").read() != ""

def install(self) -> None:
"""
install the dependency
"""
os.system(self.install_cmd)


def install_dependencies() -> None:
"""
install the dependencies
"""
dependencies = [
(
"rustc",
"curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh",
),
(
"anvil",
"git clone https://github.com/foundry-rs/foundry && "
+ "cd foundry && "
+ "cargo install --path ./anvil --bins --locked --force && "
+ "rm -rf ../foundry",
),
]
logger.info(f"Installing {len(dependencies)} dependencies")
for dependency in track(dependencies):
dep = HostDependency(*dependency)
if not dep.is_present():
logger.info(f"Installing {dep.name}")
# dep.install()
logger.info("Done!")


if __name__ == "__main__":
install_dependencies()
75 changes: 75 additions & 0 deletions lyra/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""
Cli module in order to allow interaction.
"""
import os

import rich_click as click
from dotenv import load_dotenv

from lyra.enums import Environment
from lyra.lyra import LyraClient
from lyra.utils import get_logger

click.rich_click.USE_RICH_MARKUP = True


def set_logger(ctx, level):
"""Set the logger."""
if not hasattr(ctx, "logger"):
ctx.logger = get_logger()
ctx.logger.setLevel(level)
return ctx.logger


def set_client(ctx):
"""Set the client."""
# we use dotenv to load the env vars from DIRECTORY where the cli tool is executed
_path = os.getcwd()
env_path = os.path.join(_path, ".env")
load_dotenv(dotenv_path=env_path)
if not hasattr(ctx, "client"):
auth = {
"private_key": os.environ.get("ETH_PRIVATE_KEY"),
"logger": ctx.logger,
"verbose": ctx.logger.level == "DEBUG",
}
chain = os.environ.get("ENVIROMENT")
if chain == Environment.PROD.value:
env = Environment.PROD
else:
env = Environment.TEST
ctx.client = LyraClient(**auth, env=env)
breakpoint()
if not ctx.client.web3_client.isConnected():
raise ConnectionError("Web3 client not connected.")
return ctx.client


@click.group("Lyra Client")
@click.option(
"--log-level",
"-l",
default="INFO",
type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]),
help="Logging level.",
)
@click.pass_context
def cli(ctx, log_level):
"""Lyra v2 client command line interface."""
ctx.ensure_object(dict)
ctx.obj["logger"] = set_logger(ctx, log_level)
ctx.obj["client"] = set_client(ctx)


@cli.group("markets")
def markets():
"""Interact with markets."""


@markets.command("fetch")
@click.pass_context
def fetch_markets(ctx):
"""Fetch markets."""
client = ctx.obj["client"]
markets = client.fetch_markets()
click.echo(markets)
49 changes: 49 additions & 0 deletions lyra/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
Necessary enumarations for the Lyra project.
"""

from enum import Enum


class InstrumentType(Enum):
"""Instrument types."""

ERC20 = "erc20"
OPTION = "option"
PERP = "perp"


class UnderlyingCurrency(Enum):
"""Underlying currencies."""

ETH = "eth"
BTC = "btc"


class OrderSide(Enum):
"""Order sides."""

BUY = "buy"
SELL = "sell"


class OrderType(Enum):
"""Order types."""

LIMIT = "limit"
MARKET = "market"


class TimeInForce(Enum):
"""Time in force."""

GTC = "gtc"
IOC = "ioc"
FOK = "fok"


class Environment(Enum):
"""Environment."""

PROD = "prod"
TEST = "test"
Loading

0 comments on commit b5261b8

Please sign in to comment.