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"))
Additional Headers
You can pass additional HTTP headers that will be included in all API requests. This is useful for rate limiting bypass headers or other custom authentication:
# Initialize with additional headers (e.g., for rate limiting bypass)
additional_headers = {
"x-rate-limit-bypass": "your-secret-token",
"x-custom-header": "custom-value"
}
client = LimitlessClient(
private_key="your_private_key_here",
additional_headers=additional_headers
)
Note: Additional headers are included in all HTTP requests made by the SDK, including authentication, market data, and trading operations.
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 creationCreateOrderDto- Order creation requestCancelOrderDto- Order cancellation requestDeleteOrderBatchDto- Batch order cancellationMarketSlugValidator- Market slug validation
Enums
OrderSide.BUY/OrderSide.SELLOrderType.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:
- GitHub Issues: Create an issue
- Email: support@limitless.ai
Changelog
v0.2.0
- New Feature: Added
additional_headersparameter toLimitlessClient- Allows passing custom headers (e.g., rate limiting bypass tokens)
- Headers are included in all API requests automatically
- Maintains backward compatibility
- Fixed license configuration in pyproject.toml
- Enhanced test coverage for header functionality
v0.1.0
- Initial release
- Market data access
- Order management
- Portfolio tracking
- Automatic rate limit handling
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file limitless_sdk-0.2.0.tar.gz.
File metadata
- Download URL: limitless_sdk-0.2.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47b61fde4e6a89d517be34e547ff37622eabb03cc738d06114b5beaa3f55d9a0
|
|
| MD5 |
b94a6982f1551a1f94d3f8c5cf901c8d
|
|
| BLAKE2b-256 |
2bd0ed4479731d419cef9f0331f9be53be2a586321b0fc35907038943aa9f2a1
|
File details
Details for the file limitless_sdk-0.2.0-py3-none-any.whl.
File metadata
- Download URL: limitless_sdk-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c76423ca06f1e1c9fcd4a3849aad1909e98cb326f98db1e4c7b6eeefe282e852
|
|
| MD5 |
1fde2e7c995584ce2333ecf83587fc77
|
|
| BLAKE2b-256 |
1b3f1d8956b3d7311c83165f31e3e78196da3c581bff2f828cc8e1cf46b24922
|