UniswapGraphQLClient is a Python library designed to interact with the Uniswap V2 and V3 subgraphs via GraphQL. This project provides an API client to fetch information about tokens, pairs, and swap transactions from Uniswap. It also includes utility functions for data conversions and metrics calculation.
- Fetch token details by contract address for V2 and V3
- Retrieve pairs involving a particular token for V2 and V3
- Get swap transactions for a specific pair for V2 and V3
- Utility functions for data conversion and error handling
- Paginated data fetching
- Real-time data updater service
- Support for Uniswap V3 queries and metrics
Clone the repository:
git clone https://github.com/your_username/UniswapGraphQLClient.git
cd UniswapGraphQLClient
Install the required packages:
pip install -r requirements.txt
Alternatively, run the setup file to install the package:
python setup.py install
Here is an example code snippet on how to use the V2 library:
from api.client import UniswapClient
client = UniswapClient()
# Fetch token information
token_data = client.fetch_token('0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984')
print(f"Token Data: {token_data}")
# Fetch pairs for a specific token
pairs = client.fetch_pairs_for_token('0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984')
print(f"Pairs: {pairs}")
Here is an example code snippet on how to use the V3 library:
from api.client_v3 import UniswapV3Client
client = UniswapV3Client()
# Fetch token information
token_data = client.fetch_token('0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984')
print(f"Token Data: {token_data}")
# Fetch pairs for a specific token
pairs = client.fetch_pairs_for_token('0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984')
print(f"Pairs: {pairs}")
For more examples, please refer to the main.py
and mainv3.py
files.
To run the tests, navigate to the project directory and run:
python -m unittest discover tests
- Fork the repository
- Create a new branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -m 'Add some feature'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request
MIT
For more details on each part of the code, please refer to the comments and documentation in the respective files. Feel free to contribute and make any improvements.