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:
        receipt = await client.swap(swap_params)
        if receipt.success:
            print(f"Swap successful! Hash: {receipt.transactionHash}")
        else:
            print(f"Swap failed on-chain! Hash: {receipt.transactionHash}")
    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, returns TransactionReceipt.
approve_allowance(token, amount) Approves token allowance, returns TransactionReceipt.
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 --extra dev && uv run pytest

Running Linter:

uv sync --extra dev && uv run lint

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.9.tar.gz (19.0 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.9-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ooga_booga_python-0.0.9.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.20

File hashes

Hashes for ooga_booga_python-0.0.9.tar.gz
Algorithm Hash digest
SHA256 f3f3bc7bf57950bd2808a07addf230dbeba05ba608ea37f6b59eebad8b24db9e
MD5 c298c190827b658a0e90fbc6fe43d114
BLAKE2b-256 e2e1c70d0364f29bf380fc21ad5448f3422ef0a75eff75e993ee6429fdafed38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ooga_booga_python-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 6d25cdd1ad1dfd50e18ea3d47e9354c44508d1a040b78fbad11b8bd00ea80511
MD5 3b1218fbdda3318b75d3c6c781d7af7b
BLAKE2b-256 00d52a21096d10e1bc0703a1c349c2436d047e5fe70f49fe061416f924d1e234

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