A Python client for the Ooga Booga DEX aggregation and smart order routing REST API.
Project description
Ooga Booga Python Client
GitHub Repository
PyPI Package
The Ooga Booga Python Client is a wrapper for the Ooga Booga API V1, a powerful DEX aggregation and smart order routing REST API built to integrate Berachain's liquidity into your DApp or protocol. This client allows you to interact with Berachain's liquidity sources, including AMMs, bonding curves, and order books, to execute the best trades with minimal price impact.
For more details on the API and its capabilities, refer to the official Ooga Booga API Documentation.
Features
- Find the Best Rates: Get optimal real-time prices for your trades by leveraging Ooga Booga's liquidity aggregation.
- Simplified Integration: A single API integration grants access to all liquidity sources on Berachain, saving you development time.
- Optimal Trade Execution: Perform efficient trades with minimized price impact and maximum returns for your users.
- Enhanced Security: Execute trades securely via Ooga Booga's smart contract, which wraps each transaction.
- Asynchronous API calls using
aiohttpfor smooth, non-blocking operations.
Features
- Fetch token lists and prices
- Approve token allowances
- Query token allowances
- Perform token swaps
- Retrieve liquidity sources
- Comprehensive error handling
- Asynchronous API calls using
aiohttp
Table of Contents
Installation
Poetry (Recommended)
To install the Ooga-Booga-Python package using Poetry, run the following command in your terminal:
poetry add Ooga-Booga-Python
To upgrade the package to the latest version with Poetry:
poetry update Ooga-Booga-Python
If you prefer installing directly from the GitHub repository with Poetry:
poetry add git+https://github.com/1220moritz/Ooga_Booga_Python.git
Pip
Alternatively, you can install using pip:
pip install Ooga-Booga-Python
To upgrade the package to the latest version with pip:
pip install --upgrade Ooga-Booga-Python
If you prefer installing directly from the GitHub repository with pip:
pip install git+https://github.com/1220moritz/Ooga_Booga_Python.git
Setup
- Copy the
example_env.envfile to.env:
cp tests/example_env.env .env
- Add your API key and private key:
OOGA_BOOGA_API_KEY="your-api-key"
PRIVATE_KEY="your-private-key"
- Install dependencies:
With Poetry (Recommended):
poetry install --with dev
With Pip:
pip install -e ".[dev]"
Usage
Here's how to use the Ooga Booga Python Client, demonstrating various functionalities from a single client initialization:
from ooga_booga_python.client import OogaBoogaClient
from ooga_booga_python.models import SwapParams
import asyncio
from dotenv import load_dotenv
import os
# Load environment variables from the .env file
load_dotenv()
async def main():
# Initialize the client once for all operations
client = OogaBoogaClient(
api_key=os.getenv("OOGA_BOOGA_API_KEY"),
private_key=os.getenv("PRIVATE_KEY")
)
print("--- Initializing Client and Fetching Token List ---")
await fetch_token_list_example(client)
print("\n--- Performing a Token Swap ---")
await perform_swap_example(client)
print("\n--- Getting Token Prices ---")
await fetch_prices_example(client)
async def fetch_token_list_example(client):
"""
Fetches and prints the list of available tokens.
"""
try:
tokens = await client.get_token_list()
for token in tokens:
print(f"Name: {token.name}, Symbol: {token.symbol}")
except Exception as e:
print(f"Failed to fetch token list: {e}")
async def perform_swap_example(client):
"""
Demonstrates how to perform a token swap.
"""
swap_params = SwapParams(
tokenIn="0xTokenInAddress", # Replace with actual token address
amount=1000000000000000000, # 1 token in wei
tokenOut="0xTokenOutAddress", # Replace with actual token address
to="0xYourWalletAddress", # Replace with your wallet address
slippage=0.02,
)
try:
transaction_hash = await client.swap(swap_params)
print(f"Swap successful! Transaction Hash: {transaction_hash}")
except Exception as e:
print(f"Swap failed: {e}")
async def fetch_prices_example(client):
"""
Fetches and prints the prices of available tokens.
"""
try:
prices = await client.get_token_prices()
for price in prices:
print(f"Token: {price.address}, Price: {price.price}")
except Exception as e:
print(f"Failed to fetch token prices: {e}")
if __name__ == "__main__":
asyncio.run(main())
API Reference
OogaBoogaClient
Initialization
client = OogaBoogaClient(api_key: str, private_key: str, rpc_url: str = "https://rpc.berachain.com/")
api_key: Your API key for authentication.private_key: Your private key for signing transactions.rpc_url: (Optional) RPC URL for blockchain interaction.
Methods
-
get_token_list()
Fetches the list of available tokens. -
get_token_prices()
Fetches the current prices of tokens. -
get_liquidity_sources()
Fetches all available liquidity sources. -
swap(swap_params: SwapParams)
Performs a token swap using the provided parameters. -
approve_allowance(token: str, amount: str = MAX_INT)
Approves a token allowance for the router. -
get_token_allowance(from_address: str, token: str)
Fetches the allowance of a token for a specific address.
Testing
The package uses pytest for testing. To run the tests:
- Install test dependencies:
With Poetry (Recommended):
poetry install --with dev
With Pip:
pip install -e ".[dev]"
- Run the tests:
pytest tests/
Contributing
Contributions are welcome! Please fork the repository and submit a pull request.
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to your fork
- Open a pull request
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ooga_booga_python-0.0.6.tar.gz.
File metadata
- Download URL: ooga_booga_python-0.0.6.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.2 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87658299f7d876c7ca6c27491a4d9f9882c43b868370bb219dadd5238787f601
|
|
| MD5 |
69040862cefa00f51133a868b4edf226
|
|
| BLAKE2b-256 |
a233638b8ed29fe549e29ad578b819a31b12ec4d0ed2c1575ced4a226b6ba999
|
File details
Details for the file ooga_booga_python-0.0.6-py3-none-any.whl.
File metadata
- Download URL: ooga_booga_python-0.0.6-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.2 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41a6830e793695bce9a4d4bcd4ed67bfd5c9f37192001ee38392405dc38448bd
|
|
| MD5 |
e49adf8656c210006a01ca358ea66e28
|
|
| BLAKE2b-256 |
4239bd904eceb571e319bca244806e26690d6e82f8bc6d0a083a33d123986734
|