Skip to content

Query Types

SpotPrice dataclass

Bases: AbiQuery

Returns the spot price of a cryptocurrency asset in the given currency.

Attributes:

Name Type Description
asset str

Asset ID (see data specifications for a full list of supported assets)

currency str

Currency (default = usd)

Source code in telliot_feeds/queries/price/spot_price.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
@dataclass
class SpotPrice(AbiQuery):
    """Returns the spot price of a cryptocurrency asset in the given currency.

    Attributes:
        asset:
            Asset ID (see data specifications for a full list of supported assets)
        currency:
            Currency (default = `usd`)

    """

    asset: str
    currency: str

    #: ABI used for encoding/decoding parameters
    abi = [{"name": "asset", "type": "string"}, {"name": "currency", "type": "string"}]

    @property
    def value_type(self) -> ValueType:
        """Data type returned for a SpotPrice query.

        - `ufixed256x18`: 256-bit unsigned integer with 18 decimals of precision
        - `packed`: false
        """
        return UnsignedFloatType(abi_type="ufixed256x18", packed=False)

    def __post_init__(self) -> None:
        """Validate parameters."""
        self.asset = self.asset.lower()
        self.currency = self.currency.lower()

        if self.currency not in CURRENCIES:
            raise ValueError(f"currency {self.currency} not supported")

        if (self.asset, self.currency) not in format_spot_price_pairs():
            raise ValueError(f"{self.asset}/{self.currency} is not a supported pair")

value_type: ValueType property

Data type returned for a SpotPrice query.

  • ufixed256x18: 256-bit unsigned integer with 18 decimals of precision
  • packed: false

__post_init__()

Validate parameters.

Source code in telliot_feeds/queries/price/spot_price.py
78
79
80
81
82
83
84
85
86
87
def __post_init__(self) -> None:
    """Validate parameters."""
    self.asset = self.asset.lower()
    self.currency = self.currency.lower()

    if self.currency not in CURRENCIES:
        raise ValueError(f"currency {self.currency} not supported")

    if (self.asset, self.currency) not in format_spot_price_pairs():
        raise ValueError(f"{self.asset}/{self.currency} is not a supported pair")

StringQuery dataclass

Bases: JsonQuery

Static Oracle Query

A text query supports a question in the form of an arbitrary text.

Source code in telliot_feeds/queries/string_query.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
@dataclass
class StringQuery(JsonQuery):
    """Static Oracle Query

    A text query supports a question in the form of an arbitrary
    text.
    """

    #: Static query text
    text: Optional[str]

    @property
    def value_type(self) -> ValueType:
        """Returns a default text response type."""
        return ValueType(abi_type="string", packed=False)

value_type: ValueType property

Returns a default text response type.