Skip to main content

A Python wrapper for the Ooga Booga API, providing seamless integration with Berachain liquidity for DApps and protocols.

Project description

Ooga Booga Python Client

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 aiohttp for 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

To install the package, clone this repository and use the setup.py file:

git clone <repository-url>
cd ooga_booga_python
pip install .

Or add it to your project by adding it to your requirements.txt file.


Setup

  1. Copy the example_env.env file to .env:
cp tests/example_env.env .env
  1. Add your API key and private key:
OOGA_BOOGA_API_KEY="your-api-key"
PRIVATE_KEY="your-private-key"
  1. Install dependencies:
pip install -r requirements.txt

Usage

Here’s how to use the Ooga Booga Python Client in your project:

Initialize the Client

from ooga_booga_python.client import OogaBoogaClient
import asyncio

async def main():
    client = OogaBoogaClient(
        api_key="your-api-key",
        private_key="your-private-key"
    )
    # Example: Fetch token list
    tokens = await client.get_token_list()
    for token in tokens:
        print(f"Name: {token.name}, Symbol: {token.symbol}")

asyncio.run(main())

Perform a Token Swap

from ooga_booga_python.models import SwapParams

async def perform_swap(client):
    swap_params = SwapParams(
        tokenIn="0xTokenInAddress",
        amount=1000000000000000000,  # 1 token in wei
        tokenOut="0xTokenOutAddress",
        to="0xYourWalletAddress",
        slippage=0.02,
    )
    await client.swap(swap_params)

asyncio.run(perform_swap(client))

Get Token Prices

async def fetch_prices(client):
    prices = await client.get_token_prices()
    for price in prices:
        print(f"Token: {price.address}, Price: {price.price}")

asyncio.run(fetch_prices(client))

API Reference

OogaBoogaClient

Initialization

client = OogaBoogaClient(api_key: str, private_key: str, rpc_url: str = "https://bartio.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

  1. get_token_list()
    Fetches the list of available tokens.

  2. get_token_prices()
    Fetches the current prices of tokens.

  3. get_liquidity_sources()
    Fetches all available liquidity sources.

  4. swap(swap_params: SwapParams)
    Performs a token swap using the provided parameters.

  5. approve_allowance(token: str, amount: str = MAX_INT)
    Approves a token allowance for the router.

  6. 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:

  1. Install test dependencies:
pip install -r requirements.txt
  1. Run the tests:
pytest tests/

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

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.1.tar.gz (10.3 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.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ooga_booga_python-0.0.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.2

File hashes

Hashes for ooga_booga_python-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4ce1007fed722e865bf02227f838bfced9ff3fc2715c02cf1059c8fd2b1371bc
MD5 20c3b09b17fbbcf8cb1d81961f21f418
BLAKE2b-256 1682bd111d4155dbf16fb1b0865f1ee253871ed626ab3865fbcf0252668b3e6e

See more details on using hashes here.

File details

Details for the file Ooga_Booga_Python-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for Ooga_Booga_Python-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1de95b0c838e7478835b08773a7cd7a2e667ffc4f8b70db85f657b61d0ba235f
MD5 fd1c926691700df964658347183446ca
BLAKE2b-256 3ad4a1b1893f8ea3b41feecbf99cfbee404d1ed6dd90bf9b707e7637b9fd6421

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