Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arielhorwitz/kersd
Kyberswap Exchange Rate Scraper Daemon
https://github.com/arielhorwitz/kersd
Last synced: 18 days ago
JSON representation
Kyberswap Exchange Rate Scraper Daemon
- Host: GitHub
- URL: https://github.com/arielhorwitz/kersd
- Owner: ArielHorwitz
- Created: 2023-07-24T16:34:04.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-07-25T15:45:41.000Z (over 1 year ago)
- Last Synced: 2024-11-06T10:17:23.643Z (2 months ago)
- Language: Rust
- Homepage:
- Size: 67.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Kyberswap Exchange Rate Scraper Daemon
Scrape [Kyberswap](https://kyberswap.com) Classic pools' exchange rates and save as JSON to disk. Requires [Docker](https://www.docker.com) and an [Infura](https://infura.io) API key.
## Getting Started
Download source and build the image (this may take a while):
```bash
git clone https://github.com/ArielHorwitz/kersd.git
cd kersd
docker build -t kersd .
```To configure our API key we make a copy of the template file and edit it:
```bash
cp ./dockerenv.template ~/.kersd-dockerenv
$EDITOR ~/.kersd-dockerenv
```Run the container and pass our dockerenv file as an argument:
```bash
docker run --env-file ~/.kersd-dockerenv kersd
```The daemon should be running in your terminal and printing log messages. We can stop the container in another terminal and copy data from the container to our local machine:
```bash
docker kill $(docker ps -ql)
rm -rf ~/.kersdb/
docker cp $(docker ps -qla):/app/db/ ~/.kersdb/
```We saved the exchange rates JSON files in `~/.kersdb/`, where each subdirectory is a block number containing a file for each pool's exchange rate (in both directions). Token amounts are encoded in hex. Let's take a look at one of these as an example:
```bash
cat $(find ~/.kersdb/* | grep 0x | head -1) ; echo
```The above command produces the contents of a random file in `~/.kersdb/`:
```json
{
"block_number": 17770883,
"pool": "0x6a4d5f8385ff6e7fc4ebf6f726e12a958daa1cba",
"token0": "0xb9eefc4b0d472a44be93970254df4f4016569d27",
"token1": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"sell0_buy1": {
"sell_amount": "0x45f5",
"buy_amount": "0x1",
"exchange_rate": 0.00005583784689262382
},
"sell1_buy0": {
"sell_amount": "0x5",
"buy_amount": "0x186a0",
"exchange_rate": 20000.0
}
}
```## Potential Improvements
- Real database
- Tests