Skip to content

feat: prime order metadata caches through the public getters - #107

Merged
kartojal merged 3 commits into
mainfrom
feat/prime-order-metadata-caches
Sep 23, 2026
Merged

kartojal merged 3 commits into
mainfrom
feat/prime-order-metadata-caches

Conversation

@kartojal

@kartojal kartojal commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Alternative to #106 that adds no new public method. #106 stays open for comparison.

  • getVersion() adopts the fetched order version for later orders on the client and joins a version request that is already in flight. An error response adopts the default version 2 as before.
  • getClobMarketInfo() shares one in-flight request per condition. It already primes the tick size, neg-risk, and fee caches for both outcomes.
  • Concurrent orders share one in-flight version request. A refresh after an order version mismatch asks the server again.
  • createAndPostOrder and createAndPostMarketOrder retry once only when the CLOB rejected the order for a version mismatch, instead of when a version snapshot changed. This closes a double-post path and also retries under throwOnError before surfacing the ApiError.
  • Order creation rechecks the fee cache after resolving a token, so a market fetch that landed meanwhile is not repeated.
  • README documents the two-call recipe for warming these caches ahead of the first trade.

Release notes: calling getVersion() now also sets the version used to sign later orders on that client. Under throwOnError, a version mismatch is retried once before it throws.

No version bump. The release commit sets it.


Note

Medium Risk
Changes order-post retry semantics and version/market metadata caching on the trading path; incorrect retry logic could duplicate posts or leave orders on wrong exchange versions.

Overview
getVersion() and getClobMarketInfo() now prime per-client caches used when signing orders: version is stored on success (default 2 on soft failure), and market fetches refresh tick size, neg-risk, and fees for both outcomes. Concurrent callers share one in-flight /version or per-condition CLOB market request instead of duplicating GETs.

Create-and-post flows change how migration recovery works: createAndPostOrder / createAndPostMarketOrder retry once only when the CLOB returns an order version mismatch, including under throwOnError, instead of re-posting whenever a version snapshot changed between attempts (closing a double-post path). Forced refreshes after mismatch clear stale in-flight version requests. Token resolution skips a redundant market fetch if warm-up filled fee caches meanwhile.

The README documents a two-call warm-up (getVersion + getClobMarketInfo) before the first trade. New orderMetadataCache.test.ts covers cache priming, refresh, deduplication, failure modes, and mismatch retries.

Reviewed by Cursor Bugbot for commit a24bc4f. Bugbot is set up for automated code reviews on this repo. Configure here.

getVersion adopts the fetched order version for the orders that follow
and no longer caches error responses. getClobMarketInfo shares one
in-flight request per condition. Concurrent orders share a version
request, and a forced refresh after an order version mismatch supersedes
pending requests so every waiting caller receives the newer version.
Order creation rechecks the fee cache after resolving a token so a market
fetch that landed meanwhile is not repeated.
@kartojal
kartojal requested a review from a team as a code owner September 22, 2026 17:40

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a260eb1. Configure here.

Comment thread src/client.ts Outdated
Comment thread src/client.ts Outdated
Create-and-post retries only when the CLOB rejected the order for a
version mismatch, so a version change observed after a placed order no
longer posts it a second time. getVersion joins a pending version
request instead of superseding it, every version request adopts its
result when it settles, and an error response adopts the default
version 2 as before. Under throwOnError the mismatch retry now runs
once before the ApiError is surfaced.
@kartojal
kartojal force-pushed the feat/prime-order-metadata-caches branch from a24bc4f to cd4ae08 Compare September 23, 2026 11:43
@kartojal
kartojal merged commit 801696e into main Sep 23, 2026
7 checks passed
@kartojal
kartojal deleted the feat/prime-order-metadata-caches branch September 23, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants