Beispiel #1
0
 async def _run_once(self):
     for action in self.actions:
         data = self.store.create_input(action)
         action_name = action.__class__.__name__
         with get_prometheus().summary(
             f"{action_name.lower()}_time",
             f"Time taken to process action {action_name}",
         ).time():
             await action.on_next(data)
Beispiel #2
0
"""Event filter is a helpter class for filtering events with asyncio."""
import logging

from prometheus_async.aio import time

from Arbie.async_helpers import async_map, run_async
from Arbie.prometheus import get_prometheus

GET_ENTRIES = get_prometheus().summary(
    "event_filter_get_entries", "Time for getting entries"
)


class EventTransform(object):
    def __init__(self, event_filter, event_transform):
        self.event_filter = event_filter
        self.event_transform = event_transform

    def run(self):
        events = self.event_filter.get_all_entries()
        return self.event_transform(events)


class EventFilter(object):
    def __init__(self, event, event_transform, from_block, to_block, steps):
        self.from_block = from_block
        self.to_block = to_block
        self.steps = steps
        self.event = event
        self.event_transform = event_transform
Beispiel #3
0
 def add(self, key, item):
     if hasattr(item, "__len__"):  # noqa: WPS421
         get_prometheus().gauge(f"{key.lower()}_number",
                                f"Number of {key}").set(  # noqa: WPS221
                                    len(item))  # noqa: WPS221
     self.state[key] = item
Beispiel #4
0
"""Base class for actions."""

from typing import Dict

import yaml

from Arbie import StateError
from Arbie.prometheus import get_prometheus

ADD_TIME = get_prometheus().summary("store_add_time",
                                    "Time spent adding items from store")
GET_TIME = get_prometheus().summary("store_get_time",
                                    "Time spent getting items from store")


class Argument(object):
    def __init__(self, default_value):
        self.name = None
        self.value = None
        if default_value == "None":
            return
        if isinstance(default_value, str):
            self.name = default_value
        else:
            self.value = default_value

    def __eq__(self, other):
        return self.name == other.name and self.value == other.value


def parse_settings(settings: Dict):
Beispiel #5
0
from typing import List, Tuple

from prometheus_async.aio import time

from Arbie import DeployContractError, IERC20TokenError
from Arbie.async_helpers import async_map, run_async
from Arbie.Contracts.contract import Contract, ContractFactory
from Arbie.Contracts.pool_contract import PoolContract
from Arbie.Contracts.tokens import GenericToken
from Arbie.prometheus import get_prometheus
from Arbie.Variables import BigNumber, PoolType

logger = logging.getLogger()

CREATE_PAIR = get_prometheus().summary(
    "uniswap_factory_create_pair_index", "Time for creating a pair"
)


async def create_reserve(result: Tuple[float, GenericToken]):
    (value, token) = result
    try:
        exp = await token.decimals()
    except Exception:
        raise IERC20TokenError("Token doesn't contain decimals.")
    return BigNumber.from_value(value, exp)


class UniswapPair(PoolContract):
    name = "UniswapV2Pair"
    protocol = "uniswap"
Beispiel #6
0
"""ActionTree is a set of Actions."""

import asyncio
import inspect
import logging
import sys
from typing import Dict, List, Tuple

from Arbie.Actions.action import Action, Store
from Arbie.prometheus import get_prometheus

RUN_TIME = get_prometheus().summary("arbie_run", "Time spent running actions")


def is_class_action(member):
    return inspect.isclass(member) and Action in member.__bases__  # noqa: WPS609


def get_all_actions(extra_actions=None) -> List[Tuple[str, type(Action)]]:
    actions = inspect.getmembers(sys.modules["Arbie.Actions"], is_class_action)
    if extra_actions is not None:
        return actions + extra_actions
    return actions


def create_action(name, config, extra_actions):
    for name_cls, action_cls in get_all_actions(extra_actions):
        if name_cls == name:
            return action_cls(config)
    raise ValueError(f"Action: {name} not found.")
Beispiel #7
0
from typing import List, Set, Tuple

from prometheus_async.aio import time

from Arbie import IERC20TokenError, PoolValueError
from Arbie.Actions.action import Action
from Arbie.async_helpers import async_map
from Arbie.Contracts import BalancerFactory, GenericToken, UniswapFactory, UniswapPair
from Arbie.Contracts.pool_contract import PoolContract
from Arbie.prometheus import get_prometheus
from Arbie.Variables import Pools, Token, Tokens

logger = logging.getLogger()

CREATE_TOKEN_TIME = get_prometheus().summary(
    "pool_finder_create_and_check_token",
    "Time for creating and checking a token")


def check_and_get_price(balances) -> Tuple[bool, float]:
    for balance in balances:
        if isclose(balance.value, 0, abs_tol=1e-3):  # noqa: WPS432
            return True, 0
    return False, balances[0] / balances[1]


class TokenFinder(object):
    def __init__(self, uoa, whitelist: Set[str]):
        self.uoa = uoa
        self.whitelist = whitelist