lighter.api
Documentation for eth_defi.lighter.api Python module.
Lighter API helpers for manual trading workflows.
This module follows the same api.py / session.py split as other
exchange-style integrations in eth_defi. It wraps the optional
lighter-python SDK for scripts and manual integration tests. It covers
account polling, API-key registration, small trade sizing and simple
market-order round trips.
Authoritative documentation:
Lighter API keys: https://apidocs.lighter.xyz/docs/api-keys
Deposits and withdrawals: https://apidocs.lighter.xyz/docs/deposits-transfers-and-withdrawals
Functions
|
Round a decimal up to the next step. |
|
Fetch a Lighter account by index. |
|
Read a signed ETH position size from a Lighter account response. |
|
Read the available USDC balance from a Lighter account response. |
|
Read the total USDC collateral from a Lighter account response. |
Import the optional Lighter SDK with an actionable error. |
|
|
Generate and register a Lighter API key through a Safe. |
|
Resolve Lighter ETH market minimums and choose manual-test sizes. |
|
Convert a Lighter SDK public-key string to on-chain bytes. |
|
Open and close an ETH long on Lighter. |
|
Unwrap a Lighter account API response. |
|
Wait until the ETH position matches a predicate. |
|
Wait until Lighter API exposes an account for an L1 owner. |
|
Wait until the Lighter account shows deposited collateral. |
|
Request a secure USDC withdrawal from Lighter. |
Classes
USDC and ETH sizes used by a Lighter manual trade. |
- class LighterTradeAmounts
Bases:
objectUSDC and ETH sizes used by a Lighter manual trade.
- Parameters
deposit_usdc – Suggested USDC deposit amount.
position_usdc – Effective ETH long notional in USDC.
base_amount – Lighter integer base amount for the ETH market order.
max_buy_price – Worst acceptable buy price in Lighter integer price units.
min_quote_amount – ETH market minimum quote amount, as reported by Lighter.
min_base_amount – ETH market minimum base amount, as reported by Lighter.
- __init__(deposit_usdc, position_usdc, base_amount, max_buy_price, min_quote_amount, min_base_amount)
- Parameters
deposit_usdc (decimal.Decimal) –
position_usdc (decimal.Decimal) –
base_amount (int) –
max_buy_price (int) –
min_quote_amount (decimal.Decimal) –
min_base_amount (decimal.Decimal) –
- Return type
None
- ceil_decimal(value, step)
Round a decimal up to the next step.
- Parameters
value (decimal.Decimal) – Value to round.
step (decimal.Decimal) – Rounding step.
- Returns
Rounded value.
- Return type
- async fetch_lighter_account(lighter, account_index)
Fetch a Lighter account by index.
- get_eth_position(account, market_index=0)
Read a signed ETH position size from a Lighter account response.
- Parameters
- Returns
Signed ETH position amount.
- Return type
- get_lighter_available_balance(account)
Read the available USDC balance from a Lighter account response.
- Parameters
account (Any) – Lighter account response.
- Returns
Available USDC collateral.
- Return type
- get_lighter_collateral(account)
Read the total USDC collateral from a Lighter account response.
- Parameters
account (Any) – Lighter account response.
- Returns
Total USDC collateral.
- Return type
- import_lighter()
Import the optional Lighter SDK with an actionable error.
- Returns
Imported
lightermodule.- Return type
- async register_lighter_api_key(lighter, web3, safe, hot_wallet, account_index, api_key_index)
Generate and register a Lighter API key through a Safe.
- Parameters
lighter (Any) – Imported Lighter SDK module.
web3 (web3.main.Web3) – Web3 connection.
safe (safe_eth.safe.safe.Safe) – Safe that owns the Lighter account.
hot_wallet (eth_defi.hotwallet.HotWallet) – 1-of-1 Safe owner.
account_index (int) – Lighter account index.
api_key_index (int) – Lighter API-key slot.
- Returns
SDK API private key.
- Return type
- async resolve_eth_trade_amounts(lighter, deposit_usdc=None, position_usdc=None)
Resolve Lighter ETH market minimums and choose manual-test sizes.
- Parameters
lighter (Any) – Imported Lighter SDK module.
deposit_usdc (Optional[decimal.Decimal]) – Optional explicit deposit amount.
position_usdc (Optional[decimal.Decimal]) – Optional explicit position notional.
- Returns
Trade amount configuration.
- Return type
- sdk_pubkey_to_bytes(public_key)
Convert a Lighter SDK public-key string to on-chain bytes.
- async trade_eth_roundtrip(lighter, account_index, api_private_key, api_key_index, amounts)
Open and close an ETH long on Lighter.
- Parameters
lighter (Any) – Imported Lighter SDK module.
account_index (int) – Lighter account index.
api_private_key (str) – SDK API private key.
api_key_index (int) – Lighter API-key slot.
amounts (eth_defi.lighter.api.LighterTradeAmounts) – Trade sizing information.
- Return type
None
- unwrap_lighter_account(account)
Unwrap a Lighter account API response.
- async wait_for_eth_position(lighter, account_index, predicate, description, timeout=300)
Wait until the ETH position matches a predicate.
- Parameters
- Returns
Matching position.
- Return type
- async wait_for_lighter_account(lighter, safe_address, timeout=900)
Wait until Lighter API exposes an account for an L1 owner.
- async wait_for_lighter_collateral(lighter, account_index, expected_usdc, timeout=900)
Wait until the Lighter account shows deposited collateral.
L1 deposits are asynchronous. The Ethereum transaction can be mined before Lighter’s API reflects the credited USDC balance, so callers must wait before registering a trading key and opening a position.
- Parameters
lighter (Any) – Imported Lighter SDK module.
account_index (int) – Lighter account index.
expected_usdc (decimal.Decimal) – Expected deposited USDC amount.
timeout (int) – Maximum wait in seconds.
- Returns
Observed collateral.
- Return type
- async withdraw_from_lighter(lighter, account_index, api_private_key, api_key_index, withdraw_usdc)
Request a secure USDC withdrawal from Lighter.
- Parameters
lighter (Any) – Imported Lighter SDK module.
account_index (int) – Lighter account index.
api_private_key (str) – SDK API private key.
api_key_index (int) – Lighter API-key slot.
withdraw_usdc (decimal.Decimal) – Human-readable USDC withdrawal amount.
- Return type
None