Skip to content

Commit

Permalink
feat: all tests fixed and refacto minor stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
EvolveArt committed Jul 5, 2024
1 parent 8ea98ae commit 3b4c159
Show file tree
Hide file tree
Showing 40 changed files with 205 additions and 293 deletions.
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
KAIKO_API_KEY=
NETWORK_FORK=mainnet
TESTNET_ACCOUNT_ADDRESS=
TESTNET_PRIVATE_KEY=
8 changes: 1 addition & 7 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,10 @@ jobs:
run: poetry run poe circular_imports_check
- name: Run tests
env:
KAIKO_API_KEY: ${{ secrets.KAIKO_API_KEY }}
NETWORK_FORK: mainnet
TESTNET_ACCOUNT_ADDRESS: ${{ secrets.TESTNET_ACCOUNT_ADDRESS }}
TESTNET_PRIVATE_KEY: ${{ secrets.TESTNET_PRIVATE_KEY }}
run: |
poetry run poe test_ci_update_client
poetry run poe test_ci_client
poetry run poe test_ci_publisher
poetry run poe test_ci_vrf
poetry run poe test_ci_api_client
poetry run poe test_all
- name: Generate coverage in XML
run: poetry run coverage xml
- name: Upload coverage to Codecov
Expand Down
7 changes: 4 additions & 3 deletions pragma-sdk/pragma_sdk/common/fetchers/fetchers/binance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import logging
import time
from typing import List, Optional, Any

Expand All @@ -13,7 +12,9 @@
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.fetchers.handlers.hop_handler import HopHandler

logger = logging.getLogger(__name__)
from pragma_utils.logger import get_stream_logger

logger = get_stream_logger()

# TODO: add exception list
EXCEPTION_LIST: List[Pair] = []
Expand Down Expand Up @@ -116,7 +117,7 @@ def _construct(
timestamp = int(time.time())
price_int = int(price * (10 ** pair.decimals()))

logger.info("Fetched price %d for %s from Binance", price, pair.id)
logger.info("Fetched price %d for %s from Binance", price, pair)

return SpotEntry(
pair_id=pair.id,
Expand Down
6 changes: 3 additions & 3 deletions pragma-sdk/pragma_sdk/common/fetchers/fetchers/bitstamp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import logging
from typing import Any, List

from aiohttp import ClientSession
Expand All @@ -8,8 +7,9 @@
from pragma_sdk.common.types.pair import Pair
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_utils.logger import get_stream_logger

logger = logging.getLogger(__name__)
logger = get_stream_logger()


class BitstampFetcher(FetcherInterfaceT):
Expand Down Expand Up @@ -43,7 +43,7 @@ def _construct(self, pair: Pair, result: Any) -> SpotEntry:
price = float(result["last"])
price_int = int(price * (10 ** pair.decimals()))

logger.info("Fetched price %d for %s from Bitstamp", price, pair.id)
logger.info("Fetched price %d for %s from Bitstamp", price, pair)

return SpotEntry(
pair_id=pair.id,
Expand Down
6 changes: 3 additions & 3 deletions pragma-sdk/pragma_sdk/common/fetchers/fetchers/bybit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import logging
import time
from typing import List, Optional, Any

Expand All @@ -12,8 +11,9 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.fetchers.handlers.hop_handler import HopHandler
from pragma_utils.logger import get_stream_logger

logger = logging.getLogger(__name__)
logger = get_stream_logger()


class BybitFetcher(FetcherInterfaceT):
Expand Down Expand Up @@ -113,7 +113,7 @@ def _construct(
if hop_result is None
else 0
)
logger.info("Fetched price %d for %s from Bybit", price, pair.id)
logger.info("Fetched price %d for %s from Bybit", price, pair)

return SpotEntry(
pair_id=pair.id,
Expand Down
7 changes: 4 additions & 3 deletions pragma-sdk/pragma_sdk/common/fetchers/fetchers/coinbase.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import logging
import time
from typing import Any, List

Expand All @@ -10,7 +9,9 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT

logger = logging.getLogger(__name__)
from pragma_utils.logger import get_stream_logger

logger = get_stream_logger()


class CoinbaseFetcher(FetcherInterfaceT):
Expand Down Expand Up @@ -46,7 +47,7 @@ def _construct(self, pair: Pair, result: Any) -> SpotEntry | PublisherFetchError
price_int = int(price * (10 ** pair.decimals()))
timestamp = int(time.time())

logger.info("Fetched price %d for %s from Coinbase", price, pair.id)
logger.info("Fetched price %d for %s from Coinbase", price, pair)

return SpotEntry(
pair_id=pair.id,
Expand Down
8 changes: 4 additions & 4 deletions pragma-sdk/pragma_sdk/common/fetchers/fetchers/defillama.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import logging
from typing import Any, List, Optional

from aiohttp import ClientSession
Expand All @@ -9,8 +8,9 @@
from pragma_sdk.common.types.pair import Pair
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_utils.logger import get_stream_logger

logger = logging.getLogger(__name__)
logger = get_stream_logger()


class DefillamaFetcher(FetcherInterfaceT):
Expand Down Expand Up @@ -89,18 +89,18 @@ def _construct(
self, pair: Pair, result: Any, hop_result: Optional[Any] = None
) -> SpotEntry:
base_id = AssetConfig.get_coingecko_id_from_ticker(pair.base_currency.id)
quote_id = AssetConfig.get_coingecko_id_from_ticker(pair.quote_currency.id)
timestamp = int(result["coins"][f"coingecko:{base_id}"]["timestamp"])
decimals = pair.decimals()
if hop_result is not None:
quote_id = AssetConfig.get_coingecko_id_from_ticker(pair.quote_currency.id)
price = result["coins"][f"coingecko:{base_id}"]["price"]
hop_price = hop_result["coins"][f"coingecko:{quote_id}"]["price"]
price_int = int((price / hop_price) * (10**decimals))
else:
price = result["coins"][f"coingecko:{base_id}"]["price"]
price_int = int(price * (10**decimals))

logger.info("Fetched price %d for %s from Coingecko", price, pair.id)
logger.info("Fetched price %d for %s from Coingecko", price, pair)

entry = SpotEntry(
pair_id=pair.id,
Expand Down
6 changes: 3 additions & 3 deletions pragma-sdk/pragma_sdk/common/fetchers/fetchers/gateio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import logging
import time
from typing import List, Optional, Any

Expand All @@ -12,8 +11,9 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.fetchers.handlers.hop_handler import HopHandler
from pragma_utils.logger import get_stream_logger

logger = logging.getLogger(__name__)
logger = get_stream_logger()


class GateioFetcher(FetcherInterfaceT):
Expand Down Expand Up @@ -110,7 +110,7 @@ def _construct(
volume = int(float(result[0]["quote_volume"])) if hop_result is None else 0
price_int = int(price * (10 ** pair.decimals()))

logger.info("Fetched price %d for %s from Gate.io", price, pair.id)
logger.info("Fetched price %d for %s from Gate.io", price, pair)

return SpotEntry(
pair_id=pair.id,
Expand Down
7 changes: 4 additions & 3 deletions pragma-sdk/pragma_sdk/common/fetchers/fetchers/gecko.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import logging
import time
from typing import Any, Dict, List, Optional

Expand All @@ -12,7 +11,9 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT

logger = logging.getLogger(__name__)
from pragma_utils.logger import get_stream_logger

logger = get_stream_logger()


ASSET_MAPPING: Dict[str, Any] = {
Expand Down Expand Up @@ -178,7 +179,7 @@ def _construct(

timestamp = int(time.time())

logger.info("Fetched price %d for %s from GeckoTerminal", price, pair.id)
logger.info("Fetched price %d for %s from GeckoTerminal", price, pair)

return SpotEntry(
pair_id=pair.id,
Expand Down
6 changes: 3 additions & 3 deletions pragma-sdk/pragma_sdk/common/fetchers/fetchers/huobi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import logging
from typing import List, Optional, Any

from aiohttp import ClientSession
Expand All @@ -11,8 +10,9 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.fetchers.handlers.hop_handler import HopHandler
from pragma_utils.logger import get_stream_logger

logger = logging.getLogger(__name__)
logger = get_stream_logger()


class HuobiFetcher(FetcherInterfaceT):
Expand Down Expand Up @@ -107,7 +107,7 @@ def _construct(
timestamp = int(result["ts"] / 1000)
price_int = int(price * (10 ** pair.decimals()))
volume = float(result["tick"]["vol"]) if hop_result is None else 0
logger.info("Fetched price %d for %s from Bybit", price, pair.id)
logger.info("Fetched price %d for %s from Bybit", price, pair)

return SpotEntry(
pair_id=pair.id,
Expand Down
6 changes: 3 additions & 3 deletions pragma-sdk/pragma_sdk/common/fetchers/fetchers/indexcoop.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import json
import logging
import time
from typing import Any, List

Expand All @@ -14,8 +13,9 @@
from pragma_sdk.common.fetchers.handlers.index_aggregator_handler import AssetQuantities
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_utils.logger import get_stream_logger

logger = logging.getLogger(__name__)
logger = get_stream_logger()

SUPPORTED_INDEXES = {
"DPI": "0x1494CA1F11D487c2bBe4543E90080AeBa4BA3C2b",
Expand Down Expand Up @@ -86,7 +86,7 @@ def _construct(self, pair: Pair, result: Any) -> SpotEntry:
price_int = int(price * (10**decimals))
volume = int(float(result["volume24h"]) * (10**decimals))

logger.info("Fetched price %d for %s from IndexCoop", price, pair.id)
logger.info("Fetched price %d for %s from IndexCoop", price, pair)

return SpotEntry(
pair_id=pair.id,
Expand Down
6 changes: 3 additions & 3 deletions pragma-sdk/pragma_sdk/common/fetchers/fetchers/kucoin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import logging
from typing import List, Optional, Any

from aiohttp import ClientSession
Expand All @@ -11,8 +10,9 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.fetchers.handlers.hop_handler import HopHandler
from pragma_utils.logger import get_stream_logger

logger = logging.getLogger(__name__)
logger = get_stream_logger()


class KucoinFetcher(FetcherInterfaceT):
Expand Down Expand Up @@ -100,7 +100,7 @@ def _construct(
price = hop_price / price
timestamp = int(result["data"]["time"] / 1000)
price_int = int(price * (10 ** pair.decimals()))
logger.info("Fetched price %d for %s from Kucoin", price, pair.id)
logger.info("Fetched price %d for %s from Kucoin", price, pair)

return SpotEntry(
pair_id=pair.id,
Expand Down
6 changes: 3 additions & 3 deletions pragma-sdk/pragma_sdk/common/fetchers/fetchers/mexc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import logging
import time
from typing import List, Optional, Any

Expand All @@ -12,8 +11,9 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.fetchers.handlers.hop_handler import HopHandler
from pragma_utils.logger import get_stream_logger

logger = logging.getLogger(__name__)
logger = get_stream_logger()


class MEXCFetcher(FetcherInterfaceT):
Expand Down Expand Up @@ -110,7 +110,7 @@ def _construct(
price_int = int(price * (10 ** pair.decimals()))
volume = int(float(result["quoteVolume"])) if hop_result is None else 0

logger.info("Fetched price %d for %s from MEXC", price, pair.id)
logger.info("Fetched price %d for %s from MEXC", price, pair)

return SpotEntry(
pair_id=pair.id,
Expand Down
6 changes: 3 additions & 3 deletions pragma-sdk/pragma_sdk/common/fetchers/fetchers/okx.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import json
import logging
from typing import Any, List

from aiohttp import ClientSession
Expand All @@ -10,8 +9,9 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.fetchers.handlers.hop_handler import HopHandler
from pragma_utils.logger import get_stream_logger

logger = logging.getLogger(__name__)
logger = get_stream_logger()


class OkxFetcher(FetcherInterfaceT):
Expand Down Expand Up @@ -72,7 +72,7 @@ def _construct(self, pair: Pair, result: Any, usdt_price: float = 1) -> SpotEntr
price_int = int(price * (10 ** pair.decimals()))
volume = float(data["volCcy24h"])

logger.info("Fetched price %d for %s from OKX", price, pair.id)
logger.info("Fetched price %d for %s from OKX", price, pair)

return SpotEntry(
pair_id=pair.id,
Expand Down
6 changes: 3 additions & 3 deletions pragma-sdk/pragma_sdk/common/fetchers/fetchers/propeller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import json
import logging
import time
from typing import Any, Dict, List, Optional

Expand All @@ -11,8 +10,9 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.types.currency import Currency
from pragma_utils.logger import get_stream_logger

logger = logging.getLogger(__name__)
logger = get_stream_logger()

SELL_AMOUNTS = [1, 10, 100, 1000]

Expand Down Expand Up @@ -133,7 +133,7 @@ def _construct(

timestamp = int(time.time())

logger.info("Fetched price %d for %s from Propeller", price, pair.id)
logger.info("Fetched price %d for %s from Propeller", price, pair)

return SpotEntry(
pair_id=pair.id,
Expand Down
Loading

0 comments on commit 3b4c159

Please sign in to comment.