This repository contains two main components; an API for visualizing the Coincidence of Wants (CoW) of settled batch auctions on the Ethereum protocol CowSwap, and an ETL pipeline for ingesting batch auctions data from a Subgraph and storing it in a MongoDB database.
The API is built using Flask and Flask-RESTx, providing a RESTful interface to visualize CoW values for settled batch auctions on CowSwap.
/cowiness/v1/
: Get the CoW value for a given transaction hash of a settled batch auction./cowiness/v1/extended
: Get the CoW value, total volume in USD, total volume out USD, and auction details of a given batch auction.
The ETL pipeline pulls data from the CowSwap Subgraph, processes it, and stores it in a MongoDB database. The pipeline is scheduled to run every 5 minutes, ensuring that the database is continually up-to-date.
- Clone the repository:
git clone https://github.com/0xaaiden/cowswap-cowiness.git
- Change to the repository directory:
cd cowswap-cowiness
- Install the required packages:
pip install -r requirements.txt
- Start the API:
python api/app.py
- Start the ETL pipeline:
python etl/main.py
- Access the API endpoints in your browser or using a tool like Postman:
http://localhost:5000/cowiness/v1/?batch_tx=<transaction_hash>
http://localhost:5000/cowiness/v1/extended?batch_tx=<transaction_hash>
Replace <transaction_hash>
with the desired transaction hash.
You can access the Swagger UI for the API at http://localhost:5000/docs
. This provides a convenient way to explore the API endpoints and test them interactively.
Create a .env
file and add the following environment variables:
#Only needed to run the ETL service
MONGODB_URI=<your_mongodb_uri>
MONGODB_DB_NAME=<your_mongodb_database_name>
MONGODB_COLLECTION_NAME=<your_mongodb_collection_name>
#Required to run the API
SUBGRAPH_ENDPOINT=<your_subgraph_endpoint>
ORDERBOOK_URL=https://api.cow.fi/mainnet
WEB3_URL=<eth_node_rpc_url>
Replace the placeholder values with the actual values for your MongoDB instance and Subgraph endpoint.
For example:
MONGODB_URI=mongodb+srv://username:[email protected]
MONGODB_DB_NAME=cow_batches
MONGODB_COLLECTION_NAME=last_batches
SUBGRAPH_ENDPOINT=https://api.thegraph.com/subgraphs/name/cowprotocol/cow
ORDERBOOK_URL=https://api.cow.fi/mainnet
WEB3_URL=https://eth.llamarpc.com
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
This project is licensed under the MIT License - see the MIT file for details.