create_lighter_session
Documentation for eth_defi.lighter.session.create_lighter_session function.
- create_lighter_session(api_url='https://mainnet.zklighter.elliot.ai', retries=5, backoff_factor=0.5, requests_per_second=2.0, pool_maxsize=32, rate_limit_db_path=PosixPath('/home/runner/.tradingstrategy/lighter/rate-limit.sqlite'))
Create a
LighterSessionconfigured for Lighter API.The session is configured with:
The API URL stored in
LighterSession.api_urlRate limiting to respect Lighter API throttling (thread-safe via SQLite)
Retry logic for handling transient errors using exponential backoff
The rate limiter uses SQLite backend for thread-safe coordination across multiple threads (e.g., when using
joblib.Parallelwith threading backend).Example:
from eth_defi.lighter.session import create_lighter_session session = create_lighter_session()
- Parameters
api_url (str) – Lighter API base URL. Defaults to mainnet (
LIGHTER_API_URL).retries (int) – Maximum number of retry attempts for failed requests.
backoff_factor (float) – Backoff factor for exponential retry delays.
requests_per_second (float) – Maximum requests per second to avoid rate limiting.
pool_maxsize (int) – Maximum number of connections to keep in the connection pool. Should be at least as large as
max_workerswhen using parallel requests.rate_limit_db_path (pathlib.Path) – Path to SQLite database for storing rate limit state. Using SQLite ensures thread-safe rate limiting across multiple threads.
- Returns
Configured
LighterSessionwith rate limiting and retry logic.- Return type