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

re-worked on #Add pylint workflow and fix all issues" #269

Merged
merged 28 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 19 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
48 changes: 48 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Pylint Check

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint

- name: Debug Information
run: |
echo "Current directory:"
pwd
echo "\nDirectory structure:"
ls -R
echo "\nGit root directory:"
git rev-parse --show-toplevel
echo "\nSearching for Python files:"
find . -name "*.py"
echo "\nGit ls-files output:"
git ls-files
echo "\nSpecific path search:"
git ls-files 'data_handler/*.py'
git ls-files './data_handler/*.py'
git ls-files 'apps/data_handler/*.py'
git ls-files './apps/data_handler/*.py'

- name: Run Pylint
run: |
PYTHON_FILES=$(find ./apps/data_handler -name "*.py")
if [ -n "$PYTHON_FILES" ]; then
echo "Files to lint: $PYTHON_FILES"
python -m pylint $PYTHON_FILES --disable=all --enable=C0114,C0115,C0116,C0301
else
echo "No Python files found in apps/data_handler/"
exit 1
fi
Empty file added .pylintrc
Empty file.
6 changes: 6 additions & 0 deletions .style.yapf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[style]
based_on_style = pep8
column_limit = 100
split_before_logical_operator = true
dedent_closing_brackets = true
split_before_first_argument = true
1 change: 1 addition & 0 deletions apps/data_handler/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
"""Module docstring placeholder."""

7 changes: 7 additions & 0 deletions apps/data_handler/celery_app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
This module initializes the Celery application for the data handler.

It sets up the necessary configurations and integrates with the broader
application to manage asynchronous tasks efficiently.
"""

27 changes: 23 additions & 4 deletions apps/data_handler/celery_app/celery_conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
"""
Celery configuration for scheduling periodic tasks.
"""

# run_loan_states_computation_for_hashtack_v0,;
# run_loan_states_computation_for_hashtack_v1,; run_loan_states_computation_for_nostra_alpha,;
# run_loan_states_computation_for_nostra_mainnet,; run_loan_states_computation_for_zklend,;
# run_liquidable_debt_computation_for_nostra_alpha,;
# run_liquidable_debt_computation_for_nostra_mainnet,;
# run_liquidable_debt_computation_for_hashstack_v0,;
# run_liquidable_debt_computation_for_hashstack_v1,; uniswap_v2_order_book,

from data_handler.celery_app.tasks import (
run_liquidable_debt_computation_for_zklend, )
from data_handler.celery_app.order_books_tasks import ekubo_order_book
import os

from celery import Celery
Expand All @@ -10,10 +25,8 @@
REDIS_HOST = os.environ.get("REDIS_HOST", "")
REDIS_PORT = os.environ.get("REDIS_PORT", 6379)


ORDER_BOOK_TIME_INTERVAL = int(os.environ.get("ORDER_BOOK_TIME_INTERVAL", 5))


app = Celery(
main="DataHandler",
broker=f"redis://{REDIS_HOST}:{REDIS_PORT}/0",
Expand Down Expand Up @@ -59,7 +72,13 @@

from data_handler.celery_app.order_books_tasks import ekubo_order_book
from data_handler.celery_app.tasks import (
run_liquidable_debt_computation_for_zklend,
) # run_loan_states_computation_for_hashtack_v0,; run_loan_states_computation_for_hashtack_v1,; run_loan_states_computation_for_nostra_alpha,; run_loan_states_computation_for_nostra_mainnet,; run_loan_states_computation_for_zklend,; run_liquidable_debt_computation_for_nostra_alpha,; run_liquidable_debt_computation_for_nostra_mainnet,; run_liquidable_debt_computation_for_hashstack_v0,; run_liquidable_debt_computation_for_hashstack_v1,; uniswap_v2_order_book,
run_liquidable_debt_computation_for_zklend, )

# run_loan_states_computation_for_hashtack_v0,; run_loan_states_computation_for_hashtack_v1,;
# run_loan_states_computation_for_nostra_alpha,; run_loan_states_computation_for_nostra_mainnet,;
# run_loan_states_computation_for_zklend,; run_liquidable_debt_computation_for_nostra_alpha,;
# run_liquidable_debt_computation_for_nostra_mainnet,;
# run_liquidable_debt_computation_for_hashstack_v0,;
# run_liquidable_debt_computation_for_hashstack_v1,; uniswap_v2_order_book,

app.autodiscover_tasks(["celery_app.tasks", "celery_app.order_books_tasks"])
18 changes: 7 additions & 11 deletions apps/data_handler/celery_app/order_books_tasks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Tasks for fetching and storing order book data from Ekubo and Haiko APIs.
"""

import logging

from data_handler.celery_app.celery_conf import app
Expand All @@ -19,27 +22,20 @@ def ekubo_order_book():
"""
pool_states = EkuboAPIConnector().get_pools()
filtered_pool_states = [
pool_state
for pool_state in pool_states
if isinstance(pool_state, dict)
and pool_state["token0"] in TOKEN_MAPPING
and pool_state["token1"] in TOKEN_MAPPING
pool_state for pool_state in pool_states if isinstance(pool_state, dict)
and pool_state["token0"] in TOKEN_MAPPING and pool_state["token1"] in TOKEN_MAPPING
]
for pool_state in filtered_pool_states:
token_a = pool_state["token0"]
token_b = pool_state["token1"]
logging.getLogger().info(
f"Fetching data for token pair: {token_a} and {token_b}"
)
logging.getLogger().info(f"Fetching data for token pair: {token_a} and {token_b}")
try:
order_book = EkuboOrderBook(token_a, token_b)
order_book.fetch_price_and_liquidity()
serialized_data = order_book.serialize()
connector.write_to_db(OrderBookModel(**serialized_data.model_dump()))
except Exception as exc:
logger.info(
f"With token pair: {token_a} and {token_b} something happened: {exc}"
)
logger.info(f"With token pair: {token_a} and {token_b} something happened: {exc}")
continue


Expand Down
16 changes: 12 additions & 4 deletions apps/data_handler/celery_app/tasks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Celery tasks for running loan state and liquidable debt computations,
and fetching Uniswap V2 order book data."""

import logging
from time import monotonic

Expand All @@ -13,7 +16,9 @@
# from data_handler.handlers.loan_states.hashtack_v0.run import HashtackV0StateComputation
# from data_handler.handlers.loan_states.hashtack_v1.run import HashtackV1StateComputation
# from data_handler.handlers.loan_states.zklend.run import ZkLendLoanStateComputation
from data_handler.handlers.loan_states.nostra_alpha.run import NostraAlphaStateComputation
from data_handler.handlers.loan_states.nostra_alpha.run import (
NostraAlphaStateComputation,
)
from data_handler.handlers.order_books.constants import TOKEN_MAPPING
from data_handler.handlers.order_books.ekubo.api_connector import EkuboAPIConnector
from data_handler.handlers.order_books.uniswap_v2.main import UniswapV2OrderBook
Expand All @@ -25,7 +30,6 @@

connector = DBConnector()


# @app.task(name="run_loan_states_computation_for_hashtack_v0")
# def run_loan_states_computation_for_hashtack_v0():
# start = monotonic()
Expand All @@ -40,7 +44,6 @@
# monotonic() - start,
# )


# @app.task(name="run_loan_states_computation_for_hashtack_v1")
# def run_loan_states_computation_for_hashtack_v1():
# start = monotonic()
Expand All @@ -55,7 +58,6 @@
# monotonic() - start,
# )


# @app.task(name="run_loan_states_computation_for_zklend")
# def run_loan_states_computation_for_zklend():
# start = monotonic()
Expand All @@ -73,6 +75,7 @@

@app.task(name="run_loan_states_computation_for_nostra_alpha")
def run_loan_states_computation_for_nostra_alpha():
"""fn docstring"""
start = monotonic()
logging.basicConfig(level=logging.INFO)

Expand Down Expand Up @@ -124,34 +127,39 @@ def uniswap_v2_order_book():

@app.task(name="run_liquidable_debt_computation_for_zklend")
def run_liquidable_debt_computation_for_zklend():
"""fn docstring"""
logging.info("Starting zkLend liquidable debt computation")
zklend.run()
logging.info("zkLend liquidable debt computation finished")


@app.task(name="run_liquidable_debt_computation_for_nostra_alpha")
def run_liquidable_debt_computation_for_nostra_alpha():
"""fn docstring"""
logging.info("Starting nostra alpha liquidable debt computation")
nostra_alpha.run()
logging.info("Nostra alpha liquidable debt computation finished")


@app.task(name="run_liquidable_debt_computation_for_hashstack_v0")
def run_liquidable_debt_computation_for_hashstack_v0():
"""fn docstring"""
logging.info("Starting hashstack v0 liquidable debt computation")
hashstack_v0.run()
logging.info("Hashstack v0 liquidable debt computation finished")


@app.task(name="run_liquidable_debt_computation_for_nostra_mainnet")
def run_liquidable_debt_computation_for_nostra_mainnet():
"""fn docstring"""
logging.info("Starting nostra mainnet liquidable debt computation")
nostra_mainnet.run()
logging.info("Nostra mainnet liquidable debt computation finished")


@app.task(name="run_liquidable_debt_computation_for_hashstack_v1")
def run_liquidable_debt_computation_for_hashstack_v1():
"""fn docstring"""
logging.info("Starting hashstack v1 liquidable debt computation")
hashstack_v1.run()
logging.info("Hashstack v1 liquidable debt computation finished")
8 changes: 8 additions & 0 deletions apps/data_handler/db/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
"""
This module initializes the database connection and imports necessary components.
It imports:
- `SQLALCHEMY_DATABASE_URL`: The URL for the SQLAlchemy database connection.
- `Base`: The declarative base class for SQLAlchemy models.
"""

from data_handler.db.database import SQLALCHEMY_DATABASE_URL, Base
Loading