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 && 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.8.tar.gz (18.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.8-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ooga_booga_python-0.0.8.tar.gz
  • Upload date:
  • Size: 18.0 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.8.tar.gz
Algorithm Hash digest
SHA256 bc3b460c26ceb1b819fb4fd67f6a49d1771efe71bbd76991d18c36f453367c0f
MD5 288421f08eec8d2e88acd7bdeffb05df
BLAKE2b-256 6fc987d5b1b041cc10ab9f8dca9f8127c7c253e09804842df5d92fabe1391452

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ooga_booga_python-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 d42cbae25f0b539a222501fba37b22707080d75dcce878ae0b0c3eff338c625d
MD5 586b3403e4e6d3d65a3cdd7ad381d41a
BLAKE2b-256 439cc24f0cf30c7c9421c92866fc8220e178ae2d43eb0da7af5f5675a3e62c88

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