Skip to main content
@totalistrading/hip4-client 0.14.0 wraps every route, both flows, every signed message and the WebSocket. It never stores a key: every signature goes to the signer you pass in.

Install

The SDK is private. Email founders@totalis.trade with the GitHub account that should read it, then:
.npmrc
ESM, Node 22 or later, and browsers. viem or ethers only turns a private key into a signer.

Clients

environment is "production" or "staging"; baseUrl overrides it. Money is atomic USDC as a bigint or decimal string. createTotalis and createMaker expose client and stream; call close() when done.

Open a position

openPosition subscribes, creates the RFQ, picks a quote, signs, accepts with any funding, and recovers a lost accept. It returns rfqId, acceptanceId, quoteId, positionId, entry, status and operationId. status can also be NOT_ADMITTED: every response was lost, and the SDK cancelled the RFQ. watchQuotes(rfqId, listener) reports live quotes, and [] while the stream is down.

Cash out and withdraw

After a restart, waitForWithdrawal(withdrawalId) follows a started withdrawal. To store the signed request first, signWithdrawal returns { idempotencyKey, account, body } and sendWithdrawal(signed) sends it.

Make markets

  • onRfq runs once per open RFQ, from events and the snapshot, and pages a truncated snapshot.
  • quote builds entry terms with the deployment’s fees and a 20 second life (lifetimeSeconds). bid builds sell_back or transfer terms with a 45 second life.
  • onAcceptance checks the terms, signs them once, and resends a lost answer byte for byte. It never signs terms this maker did not create.
  • published stores the quote_ids this maker created (record, forget, expiry). Back it with durable storage so a restarted process can confirm them.
  • Pass stream: { cursor } to resume, and save maker.stream.cursor after each event.
Vault call builders: approveUsdc, deposit, requestWithdraw, executeWithdraw, cancelWithdraw, setQuoteSigner, resetDiscount.

Signing

hashTypedData gives a digest, canonicalSignature the form the API accepts, depositNonce and payoutNonce the USDC nonces.

WebSocket and pagination

It applies the snapshot or replay, drops duplicates, and reconnects from the last applied cursor. status is live only while caught up.

Retries and errors

Each command is built once with its Idempotency-Key and resent byte for byte after a network failure or a BACKOFF error, up to five sends (retry: { attempts }, or retry: false). unwrap throws ApiError with code, retry, status, requestId, fieldViolations and retryAfterMs.
NetworkError means the outcome is unknown. Call resend(), never a new command.

Changes in 0.14.0

Breaking; needs contract 118. Signed messages and digests are unchanged. The full list ships as CHANGELOG.md.