Skip to content

Proposal: async client + async Signer interface (to enable remote signing) #73

@Whynot63

Description

@Whynot63

I'd like to add an AsyncClobClient alongside the existing sync ClobClient. HTTP is already on httpx, so httpx.Clienthttpx.AsyncClient is mechanical. Motivation: CLOB workflows are concurrent by nature (multi-market watching, batched cancels via asyncio.gather, mixing REST with the async-native WS feed), and most production Python stacks today are asyncio-based, so users currently wrap every call in asyncio.to_thread — a thread per call defeats the point. Sync client stays, no breaking change for existing users.

The non-obvious part is that Signer.sign(...) must also become async (async def sign(self, message_hash: bytes) -> str). Local eth_account signing is CPU-bound and fine sync, but the moment you want remote signing — KMS, Vault, Fireblocks, Web3Signer, MPC services — signing is a network round-trip, and a sync signer blocks the event loop on the hot path of every order. This propagates async/await through L1 auth header generation, EIP-712 signing, create_or_derive_api_key, and RFQ accept/approve — same surface area [#27](#27) already touched before it was closed. Happy to open a draft PR if direction is acceptable.

  1. Add AsyncClobClient mirroring ClobClient method-for-method, all async def.
  2. Add http_helpers/async_helpers.py using httpx.AsyncClient.
  3. Add AsyncSigner protocol; current Signer becomes LocalSigner implementing it.
  4. Split each "build-and-sign" function into build_unsigned_* + apply_signature so both clients reuse them.
  5. Async client body: build_unsigned_*await signer.sign(hash)apply_signatureawait apost(...).
  6. Tests on pytest-asyncio + equivalence test (sync and async produce identical signed payload).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions