Skip to main content

A Python client for the Ooga Booga DEX aggregation and smart order routing REST API.

Project description

Ooga Booga Python Client

PyPI Downloads Tests

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

  • Optimal Trade Execution: Get real-time prices and execute trades with minimized price impact by leveraging liquidity aggregation.
  • Simplified Integration: Single API access to all liquidity sources on Berachain.
  • Token Management: Fetch token lists, prices, and query or approve allowances.
  • Enhanced Security: Trades are executed via Ooga Booga's smart contract.
  • Async Support: Built with aiohttp for high-performance asynchronous calls.
  • Custom Error Decoding: Decode custom errors from smart contracts for better error handling.

Table of Contents


Installation

You can install the package using your preferred package manager.

Package Manager

Manager Install Command Upgrade Command
Poetry poetry add Ooga-Booga-Python poetry update Ooga-Booga-Python
uv uv add Ooga-Booga-Python uv add Ooga-Booga-Python
pip pip install Ooga-Booga-Python pip install --upgrade Ooga-Booga-Python

From Source

To install directly from the repository:

# Poetry
poetry add git+https://github.com/1220moritz/Ooga_Booga_Python.git

# uv
uv add git+https://github.com/1220moritz/Ooga_Booga_Python.git

# pip
pip install git+https://github.com/1220moritz/Ooga_Booga_Python.git

Setup

  1. Environment Configuration
    Copy the example environment file:

    cp tests/example_env.env .env
    
  2. Credentials
    Add your keys to .env:

    OOGA_BOOGA_API_KEY="your-api-key"
    PRIVATE_KEY="your-private-key"
    
  3. Dev Dependencies (Optional for contributors)

    # Poetry
    poetry install --with dev
    
    # uv
    uv sync --extra dev
    
    # pip
    pip install -e ".[dev]"
    

Usage

Here is a complete example initializing the client and performing standard operations.

import asyncio
import os
from dotenv import load_dotenv
from ooga_booga_python.client import OogaBoogaClient
from ooga_booga_python.models import SwapParams

# Load environment variables
load_dotenv()

async def main():
    # Initialize the client
    client = OogaBoogaClient(
        api_key=os.getenv("OOGA_BOOGA_API_KEY"),
        private_key=os.getenv("PRIVATE_KEY")
    )

    print("--- Fetching Token List ---")
    await fetch_token_list_example(client)

    print("\n--- Getting Token Prices ---")
    await fetch_prices_example(client)

    print("\n--- Performing a Token Swap ---")
    await perform_swap_example(client)

async def fetch_token_list_example(client):
    try:
        tokens = await client.get_token_list()
        for token in tokens[:5]: # Print first 5 for brevity
            print(f"Name: {token.name}, Symbol: {token.symbol}")
    except Exception as e:
        print(f"Error: {e}")

async def fetch_prices_example(client):
    try:
        prices = await client.get_token_prices()
        for price in prices[:5]:
            print(f"Token: {price.address}, Price: {price.price}")
    except Exception as e:
        print(f"Error: {e}")

async def perform_swap_example(client):
    swap_params = SwapParams(
        tokenIn="0xTokenInAddress",    # Replace with actual address
        amount=1000000000000000000,    # 1 token in wei
        tokenOut="0xTokenOutAddress",  # Replace with actual address
        to="0xYourWalletAddress",      # Your wallet
        slippage=0.02,
    )
    try:
        tx_hash = await client.swap(swap_params)
        print(f"Swap successful! Hash: {tx_hash}")
    except Exception as e:
        print(f"Swap failed: {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/"
)

Core Methods

Method Description
get_token_list() Returns list of available tokens.
get_token_prices() Returns current token prices.
get_liquidity_sources() Returns all available liquidity sources.
swap(swap_params) Executes a token swap given SwapParams.
approve_allowance(token, amount) Approves token allowance for the router (default: MAX_INT).
get_token_allowance(address, token) Checks allowance for a specific address/token.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to your fork
  5. Open a pull request

Running Tests:

# Poetry
poetry install --with dev && poetry run pytest

# uv
uv sync && uv run pytest

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ooga_booga_python-0.0.7.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ooga_booga_python-0.0.7-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file ooga_booga_python-0.0.7.tar.gz.

File metadata

  • Download URL: ooga_booga_python-0.0.7.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for ooga_booga_python-0.0.7.tar.gz
Algorithm Hash digest
SHA256 a67fe051604ffc56c03ec7b2e82fbc60b0ad2ab10fe0984e9aeac5551b44860b
MD5 995f8a40ee695c29204ae25cbee008e4
BLAKE2b-256 f2236b1c472ecf06dea8725a30fef2ecabee12846169c83531496ac6230ae02b

See more details on using hashes here.

File details

Details for the file ooga_booga_python-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for ooga_booga_python-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 935000820b8311a8f0a4374d5a753d26a3f1e1e3ce556eab9b62b92b50ad1d15
MD5 cab0ec43b9e97d50638253b848bc4503
BLAKE2b-256 5e1c4d108a037e4427b490b1031bd54827bbff06a53698c5f3dfc104c15e0fca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page