Molecule and AsyncMolecule classes are the entry points to the SDK. Both expose the same sub-API namespaces — Molecule makes synchronous HTTP calls, while AsyncMolecule exposes an async request() coroutine suitable for use with asyncio. Ed25519 request signing happens inside the process; your private key is never transmitted.
Molecule (Synchronous)
Constructor
string
required
API base URL. Falls back to the
MOLECULE_BASE_URL environment variable. The SDK raises ValueError at construction time if neither is set.string
Trading key ID used to identify the signing key. Use together with
private_key to enable Ed25519 request signing for trading routes. Falls back to MOLECULE_KEY_ID.string | bytes
Ed25519 private key. Provide the base64-encoded 32-byte seed (the canonical format). Also accepts a hex string or raw bytes. The key never leaves the process. Falls back to
MOLECULE_PRIVATE_KEY.string
JWT token for management routes. Mutually exclusive with
key_id/private_key for authentication — use one or the other.float
default:"30.0"
HTTP request timeout in seconds applied to all REST calls.
httpx.BaseTransport
Custom
httpx transport, useful for testing with a mock transport or configuring proxies.Context Manager
UseMolecule as a context manager to ensure the client is properly closed after use:
AsyncMolecule (Asynchronous)
AsyncMolecule accepts the same constructor parameters as Molecule. Its request() method is a coroutine — await it inside an async context. The sub-API namespaces (markets, orders, portfolio, etc.) are available as attributes and work the same way as on the synchronous client.
httpx.AsyncBaseTransport
Custom async
httpx transport for AsyncMolecule, useful for testing or proxy configuration.Sub-API Namespaces
Each namespace groups a set of related endpoints. Access them as attributes on the client instance.Convenience Methods
TheMolecule client exposes shortcut methods for the most common operations. Each one delegates to the corresponding sub-API method.
client.search_markets(**params)
Shortcut for client.markets.search(). Pass any supported search parameters as keyword arguments.
client.create_order(**payload)
Shortcut for client.orders.create(). Pass the full order payload as keyword arguments.
client.create_complex_order(**payload)
Shortcut for client.complex_orders.create(). Pass the full complex order payload as keyword arguments.
client.positions(subaccount_id)
Shortcut for client.portfolio.positions(). Returns all open positions for the specified subaccount.
client.iter_ws(path, params)
Yields parsed JSON messages from a signed WebSocket connection. The method handles URL signing, connection management, and JSON decoding. Iterate over it with a for loop.
