create_grvt_session
Documentation for eth_defi.grvt.session.create_grvt_session function.
- create_grvt_session(api_url=None, api_key=None, private_key=None, trading_account_id=None, retries=5, backoff_factor=0.5, requests_per_second=None, pool_maxsize=32, rate_limit_db_path=PosixPath('/home/runner/.tradingstrategy/grvt/rate-limit.sqlite'), timeout=30.0, authenticate=False)
Create a requests Session configured for the GRVT API.
By default, creates an unauthenticated session suitable for public endpoints (
market-data.grvt.io). Setauthenticate=Trueand provide credentials for private endpoints (edge.grvt.io).The session is configured with:
Rate limiting to respect GRVT API throttling (thread-safe via SQLite)
Retry logic for handling transient errors using exponential backoff
Optional cookie-based authentication via
/auth/api_key/login
Example:
from eth_defi.grvt.session import create_grvt_session # Public session (no auth needed) session = create_grvt_session() # Authenticated session session = create_grvt_session(authenticate=True)
- Parameters
api_url (Optional[str]) – GRVT API base URL. Falls back to
GRVT_API_URL.api_key (Optional[str]) – GRVT API key. Falls back to
GRVT_API_KEYenv var.private_key (Optional[str]) – GRVT private key. Falls back to
GRVT_PRIVATE_KEYenv var.trading_account_id (Optional[str]) – GRVT trading account ID. Falls back to
GRVT_TRADING_ACCOUNT_IDenv var.retries (int) – Maximum number of retry attempts for failed requests.
backoff_factor (float) – Backoff factor for exponential retry delays.
requests_per_second (Optional[float]) – Maximum requests per second to avoid rate limiting. Falls back to
GRVT_DEFAULT_REQUESTS_PER_SECOND.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.
timeout (float) – HTTP request timeout in seconds.
authenticate (bool) – If True, authenticate with the GRVT API using credentials. Required for private endpoints like
vault_investor_summary.
- Returns
Configured requests Session.
- Raises
AssertionError – If
authenticate=Trueand required credentials are not provided.- Return type
requests.sessions.Session