Skip to main content

Python SDK for Limitless Exchange

Project description

Limitless Exchange Python SDK

A clean, async Python SDK for interacting with the Limitless Exchange API.

Features

  • 🔐 Ethereum wallet authentication - Sign in with your private key
  • 📈 Market data access - Get markets, prices, and historical data
  • 📋 Order management - Place, cancel, and manage orders
  • 💼 Portfolio tracking - View positions and trading history
  • 🔄 Automatic retries - Built-in retry logic for rate limits
  • 🛡️ Type safety - Full Pydantic models for request/response validation
  • Async/await support - Modern async Python with aiohttp

Installation

pip install limitless-sdk

Or install from source:

git clone https://github.com/your-org/limitless-sdk.git
cd limitless-sdk
pip install -e .

Quick Start

import asyncio
from limitless_sdk import LimitlessClient

async def main():
    # Initialize client with your private key
    async with LimitlessClient(private_key="your_private_key_here") as client:
        # Login
        await client.login()
        
        # Get active markets
        markets = await client.get_active_markets()
        print(f"Found {len(markets)} markets")
        
        # Get market details
        market = await client.get_market("market-slug")
        
        # Get orderbook
        orderbook = await client.get_orderbook("market-slug")
        
        # Get your positions
        positions = await client.get_positions()

if __name__ == "__main__":
    asyncio.run(main())

Authentication

The SDK requires an Ethereum private key for authentication. Pass it directly to the client constructor:

from limitless_sdk import LimitlessClient

# Initialize with your private key
client = LimitlessClient(private_key="0x1234567890abcdef...")

# For applications, you might load from environment variables
import os
client = LimitlessClient(private_key=os.getenv("PRIVATE_KEY"))

Market Data

Get Markets

# Get all markets with pagination
markets = await client.get_active_markets(page=1, limit=10)

# Get all active markets (handles pagination automatically)
all_markets = await client.get_all_active_markets()

# Get specific market
market = await client.get_market("market-slug-or-address")

Get Historical Data

# Get historical prices
data, interval = await client.get_historical_prices("market-slug")
print(f"Data interval: {interval}")
print(f"Price points: {len(data['prices'])}")

Get Orderbook

orderbook = await client.get_orderbook("market-slug")
print(f"Orders: {len(orderbook['orders'])}")

Order Management

Place Orders

from limitless_sdk import Order, CreateOrderDto, OrderType, OrderSide
import time

# Create order
order = Order(
    salt=int(time.time()),
    maker="0x...",  # Your wallet address
    signer="0x...",  # Your wallet address
    token_id="token123",
    maker_amount="1000000",  # Amount in wei
    taker_amount="1000000",  # Amount in wei
    price="0.5",
    fee_rate_bps=30,  # 0.3% fee
    side=OrderSide.BUY,
    signature="0x...",  # Order signature
)

create_order_dto = CreateOrderDto(
    order=order,
    order_type=OrderType.LIMIT,
    market_slug="market-slug"
)

# Place the order
result = await client.place_order(create_order_dto)

Cancel Orders

from limitless_sdk import CancelOrderDto, DeleteOrderBatchDto, MarketSlugValidator

# Cancel single order
cancel_dto = CancelOrderDto(order_id="order-id")
await client.cancel_order(cancel_dto)

# Cancel multiple orders
batch_dto = DeleteOrderBatchDto(order_ids=["order1", "order2"])
await client.cancel_order_batch(batch_dto)

# Cancel all orders for a market
market_validator = MarketSlugValidator(slug="market-slug")
await client.cancel_all_orders(market_validator)

Get User Orders

# Get your orders for a specific market
orders = await client.get_user_orders("market-slug")

Portfolio

Get Positions

positions = await client.get_positions()
for position in positions:
    print(f"Market: {position['market']['title']}")
    print(f"Size: {position['size']}")

Get Trading History

# Get paginated history
history = await client.get_user_history(page=1, limit=50)
print(f"Total entries: {history['totalCount']}")

for entry in history['data']:
    print(f"Type: {entry['type']}")
    print(f"Amount: {entry['amount']}")

Error Handling

The SDK includes custom exceptions for different error types:

from limitless_sdk import LimitlessAPIError, RateLimitError, AuthenticationError

try:
    await client.get_markets()
except RateLimitError as e:
    print(f"Rate limited: {e}")
    # SDK automatically retries rate limits
except AuthenticationError as e:
    print(f"Auth failed: {e}")
except LimitlessAPIError as e:
    print(f"API error {e.status_code}: {e}")

Rate Limiting

The SDK automatically handles rate limits with exponential backoff:

  • Automatic retries for 429 (Too Many Requests) responses
  • Configurable retry delays (default: 5s, 10s)
  • Max retry attempts (default: 2)

Logging

Enable debug logging to see API requests:

import logging
logging.basicConfig(level=logging.DEBUG)

Models

The SDK uses Pydantic models for type safety:

Order Models

  • Order - Order details for creation
  • CreateOrderDto - Order creation request
  • CancelOrderDto - Order cancellation request
  • DeleteOrderBatchDto - Batch order cancellation
  • MarketSlugValidator - Market slug validation

Enums

  • OrderSide.BUY / OrderSide.SELL
  • OrderType.LIMIT / OrderType.MARKET

Development

Setup

git clone https://github.com/your-org/limitless-sdk.git
cd limitless-sdk
pip install -e ".[dev]"

Testing

pytest

Linting

ruff check .
mypy limitless_sdk/

License

MIT License - see LICENSE file for details.

Support

For questions or issues:

Changelog

v0.1.0

  • Initial release
  • Market data access
  • Order management
  • Portfolio tracking
  • Automatic rate limit handling

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

limitless_sdk-0.1.0.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

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

limitless_sdk-0.1.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file limitless_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: limitless_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for limitless_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a12a6110a3015a74de8a37e8fc902b97c39b4ba58c3571ca8fff5a8c1b9d9ebe
MD5 dc49503fa1ae434740a77860b237af80
BLAKE2b-256 b210ad4ca77d95102abf632556a357781c316b3cf3ebc6e338c4a756287f7626

See more details on using hashes here.

File details

Details for the file limitless_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: limitless_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for limitless_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a705b46edf74cedc4ab7c5ac77b8c56429fb806897b894b45a76289b3fe06b98
MD5 400f2ceb31cadc2cfeb7190fc3452154
BLAKE2b-256 b9cd0cc650320f3e4903759697c22f7dbf476532c3e9fc3ef409ee3d8f65da26

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