Skip to content

fix(client): sign market BUY amounts at exactly the order price - #393

Draft
samsondav wants to merge 3 commits into
mainfrom
fix/market-buy-exact-price
Draft

samsondav wants to merge 3 commits into
mainfrom
fix/market-buy-exact-price

Conversation

@samsondav

Copy link
Copy Markdown
Contributor

A market BUY now signs the largest whole-cent spend within amount whose share count gives the order price exactly. Part of amount can stay unspent: $10 at 0.65 signs $9.88 for 15.2 shares. If no spend reaches the $1 marketable minimum, the SDK raises UserInputError before it signs.

samsondav and others added 3 commits October 26, 2026 11:44
A market BUY signed the requested spend and floored the share count, so
spend / shares was a hair above the order price and almost never an exact
price. Market BUYs now sign the largest whole-cent spend within the
requested amount whose share count, at the market's share precision,
encodes the order price exactly. The amounts move in fixed steps from the
gcd of the price and the two precisions. When no step fits, or the steps
fall below the 1 USDC marketable BUY minimum, the SDK raises
UserInputError with the smallest amount that works.

Protected BUYs now sign exactly max_price, so the guard against crossing
a higher ask after a tick refinement is no longer needed. Market SELLs and
limit orders are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KngHU7sipb4T9BmJb35tV8
… for market BUYs

The exchange now accepts a market BUY's cash at the same precision as a
limit BUY's cash (4 decimals at tick 0.01, 5 at 0.001, 6 at 0.0001), not
whole cents, and lowers the marketable BUY minimum to 0.99 USDC. Market
BUYs now sign the largest spend at that precision whose share count
encodes the order price exactly. The steps are much finer: 10 USDC at
0.65 now signs 9.9996 USDC for 15.384 shares, not 9.88 USDC for 15.2.

A 1 USDC market BUY at any on-tick price now lands at or above 0.99 USDC.
The SDK still raises UserInputError when no step fits, or when the steps
fall below the minimum, and names the smallest amount that works.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UeLKj8qqMa5RMRnhNFFWZX
….99 USDC minimum

A requested amount below the minimum used to sign and leave the rejection
to the exchange. Now that cash uses the finer limit BUY precision, such an
amount often has a non-zero exact spend, so the SDK raises UserInputError
for any exact spend below the minimum, as the TypeScript SDK does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UeLKj8qqMa5RMRnhNFFWZX
@samsondav

Copy link
Copy Markdown
Contributor Author

Fixes DEFIQA-2233.

This branch has not been deployed

No deployments
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.

1 participant