D
D
DIA Documentation
Search…
Write your own Defi Lending Rate Scraper

Getting Started

To add a Defi Lending Rate Scraper you first have to create an entry for the defi protocol your rate is being scraped from, with this function call
1
SetDefiProtocol(protocol dia.DefiProtocol)
Copied!
With dia.DefiProtocol being defined in pkg/dia/Messages.go:
1
type DefiProtocol struct {
2
Name string
3
Address string
4
UnderlyingBlockchain string
5
}
Copied!
Once you added the metadata about the Protocol (or made sure it already exists by querying it in the database) you can proceed with scraping actual interest values.

Scraping the lending rate value

For that, you need to get all data that is defined in this structure at pkg/dia/Messages.go
1
type DefiLendingRate type {
2
Timestamp time.Time
3
LendingRate float64
4
BorrowingRate float64
5
Asset string
6
Protocol DefiProtocol
7
}
Copied!
The timestamp should be the timestamp of observation (i.e., now), the LendingRate is the actual rate, the asset is the asset that is lent and the Protocol is the protocol object created above.
You can add the scraped value using this function in pkg/model/db.go:
1
SetDefiRateInflux(rate *dia.DefiLendingRate) error
Copied!
After that, you are done. To test your addition, retrieve your value using this function:
1
GetDefiRateInflux(starttime time.Time, endtime time.Time, asset string, protocol string) ([]dia.DefiLendingRate, error)
Copied!
It will return a slice of scraped values between starttime and endtime for the asset on the selected protocol.

Scraping additional protocol quantities

If possible, scrape data for the following structure as well (structure at pkg/dia/Messages.go ).
1
type DefiProtocolState {
2
TotalUSD float64
3
TotalETH float64
4
TotalPerDay map[string]float64
5
MostLockedAsset string
6
}
Copied!
Here, TotalUSD and TotalETH are the total amounts locked in the protocol. TotalPerDay is the total value locked in 24H in USD, Ether and Bitcoin.
Last modified 1yr ago