create_lighter_session

Documentation for eth_defi.lighter.session.create_lighter_session function.

create_lighter_session(api_url=None, 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'), deployment=LighterAPIConfig(slug='ethereum', name='Lighter Ethereum', chain_id=9998, deployment_chain_id=1, api_url='https://mainnet.zklighter.elliot.ai', app_url='https://app.lighter.xyz', address_prefix='lighter-pool', denomination='USDC', lockup=datetime.timedelta(seconds=300), llp_account_index_override=None))

Create a LighterSession configured for Lighter API.

The session is configured with:

  • The API URL stored in LighterSession.api_url

  • Rate 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.Parallel with threading backend).

Example:

from eth_defi.lighter.session import create_lighter_session

session = create_lighter_session()
Parameters
  • api_url (Optional[str]) – Optional Lighter API base URL override. Defaults to the configured deployment 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_workers when 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.

  • deployment (eth_defi.lighter.constants.LighterAPIConfig) – Deployment whose pool namespace this session accesses. Defaults to the backwards-compatible Ethereum deployment.

Returns

Configured LighterSession with rate limiting and retry logic.

Return type

eth_defi.lighter.session.LighterSession