Check the Chain (ctc)
latest

The Basics

  • Introduction
  • Installation
  • Dependencies
  • Configuration
  • Changelog
  • FAQ

Data & Ops

  • Obtaining Data
  • Storing Data
  • Performance
  • Monitoring

Command Line Interface

  • Basic Usage
  • Subcommands
  • Useful Aliases
  • Similar CLI tools

Python Interface

  • Basic Usage
  • RPC Client
  • Asynchronous Code
  • Datatypes
  • Specific Protocols
    • 4byte
    • Aave V2
    • Balancer
    • Chainlink
    • Compound
    • Gnosis Safe
    • Curve
    • Gnosis Safe
    • ENS
    • Fei
    • Gnosis Safe
    • Defi Llama
    • Multicall
    • Rari
    • Uniswap V2
    • Uniswap V3
    • Yearn
  • Similar Python Tools
Check the Chain (ctc)
  • »
  • Specific Protocols »
  • Chainlink
  • Edit on GitHub

Chainlink

Examples

Note

These examples are crafted as a Jupyter notebook. You can download the original notebook file here.

Also note that inside Jupyter notebooks, await can be used freely outside of asyncio.run().

chainlink
In [1]:
from ctc.protocols import chainlink_utils
In [2]:
feed = 'ETH_USD'

Get feed address¶

In [3]:
await chainlink_utils.async_resolve_feed_address(feed)
Out[3]:
'0x5f4ec3df9cbd43714fe2740f5e3616155c5b8419'

Get current value of feed¶

In [4]:
await chainlink_utils.async_get_feed_datum(feed)
Out[4]:
1295.91

Get historical values of a feed¶

In [5]:
feed_data = await chainlink_utils.async_get_feed_data(feed)

feed_data
Out[5]:
block_number
10606572         399.33
10606572         399.37
10606572         399.33
10606573         399.37
10606573         399.33
               ...     
15613216        1287.27
15613248    1273.925028
15613287    1280.742804
15613305    1288.935935
15613347        1295.91
Name: answer, Length: 237563, dtype: object

Get interpolated historical values of a feed¶

In [6]:
feed_data = await chainlink_utils.async_get_feed_data(feed, interpolate=True)

feed_data
Out[6]:
block_number
10606572     399.330
10606573     399.320
10606574     399.325
10606575     399.320
10606576     399.320
              ...   
15613492    1295.910
15613493    1295.910
15613494    1295.910
15613495    1295.910
15613496    1295.910
Name: answer, Length: 5006925, dtype: float64

Get feed aggregator history¶

In [7]:
await chainlink_utils.async_get_feed_previous_aggregators(feed)
Out[7]:
['0xf79d6afbb6da890132f9d7c355e3015f15f3406f',
 '0xb103ede8acd6f0c106b7a5772e9d24e34f5ebc2c',
 '0x00c7a37b03690fb9f41b5c5af8131735c7275446',
 '0xd3fcd40153e56110e6eeae13e12530e26c9cb4fd',
 '0x37bc7498f4ff12c19678ee8fe19d713b87f6a9e6']
In [8]:
# blocks where aggregators updated

await chainlink_utils.async_get_feed_aggregator_history(feed)
Out[8]:
{'0xf79d6afbb6da890132f9d7c355e3015f15f3406f': 10606501,
 '0xb103ede8acd6f0c106b7a5772e9d24e34f5ebc2c': 10607120,
 '0x00c7a37b03690fb9f41b5c5af8131735c7275446': 11008985,
 '0xd3fcd40153e56110e6eeae13e12530e26c9cb4fd': 12187957,
 '0x37bc7498f4ff12c19678ee8fe19d713b87f6a9e6': 12453813}

Reference

async ctc.protocols.chainlink_utils.async_print_feed_summary(feed, *, start_block=None, n_recent=None, verbose=False)
Previous Next

Revision dae7e64e.