docs(fiqh): long-only is bay' ma la yamlik, and it is not closed at the venue boundary - #669
Merged
Merged
Conversation
…he venue boundary `docs/fiqh-basis.md` had no section on long-only at all. The rails table covered the prudential rails, rails 18/19 covered the spot-only charter, and the one ruling that is neither -- keel never sells what it does not hold -- was left implicit in four places that enforce it and named in none. It is a fiqh-derivation, not a charter, and it descends from Ayub Ch 5.4.2 (§65.11) and Ch 6.5.1 (§65.4): *bay' ma la yamlik*. That anchor is more direct than riba for this class of failure, and the difference is load-bearing -- a sale of what the seller does not hold is impermissible with no interest anywhere in the transaction, so a riba-framed defence does not reach it at all. The section carries a qualification, because §65.4 is invoked here for nearly the opposite of what it was read for. §65.4's own point is that possession is CONSTRUCTIVE -- "what is meant by possession here is the inability to deliver the goods" -- which is exactly how exchange-held balances qualify as valid `qabd`. That lenient reading does not weaken the claim, it sharpens it: in every failure mode recorded here the asset is not there at all, so selling it fails the prohibition on the lenient reading and not merely the strict one. The hadith of Hakim ibn Hizam (Sunan an-Nasa'i 4613 / Abu Dawud 3503) is recorded as the operator's citation and explicitly marked as NOT extracted in this repo's knowledge base -- it carries no §N.x row and is not disguised as one. A test pins the disclaimer AND its truth: if a source file ever extracts the hadith, the disclaimer has become false and the test says so. And a new open question, because the ruling is sound where keel DECIDES and open where it SETTLES. A SELL is never clamped to the account's available base, so fee dust, an unrecorded partial fill (`filled_quantity` is NULL on every filled live order), or an out-of-band transfer can send an order for more than is held (#667). A resting stop leg can outlive the position that justified it, because no sweep cancels a SELL whose position is gone (#668). On a cash account each is a rejection; on a margin-enabled account the venue fills the difference as a short, and there is no cash-account posture check on Coinbase -- `verify_cash_account` exists only on the Alpaca adapter (#666). Named here rather than left to be found. Four pins, all two-sided and all mutation-verified (12 mutants, 12 killed). The base.py pin matches the FIELD LINE by regex rather than the file, because the `__post_init__` docstring quotes the annotation too and a prose mention is not a contract; it also pins the runtime check, since the annotation is a promise to mypy and a foreign rule never runs mypy. The venue-boundary pin is anchored to `_sell_base_size`'s own stated contract, so when #667 lands the test fails -- the doc gets updated with the code rather than after it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NzuKAe2RVrPt9acVAWjRyL
This was referenced Sep 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
docs/fiqh-basis.mdhad no section on long-only at all. The rails table covered the prudential rails, rails 18/19 covered the spot-only charter, and the one ruling that is neither — keel never sells what it does not hold — was left implicit in four places that enforce it and named in none.What the section says
Long-only is a fiqh-derivation, not a charter, and it descends from Ayub Ch 5.4.2 (§65.11) and Ch 6.5.1 (§65.4): bay' ma la yamlik. That anchor is more direct than riba for this class of failure, and the difference is load-bearing — a sale of what the seller does not hold is impermissible with no interest anywhere in the transaction, so a riba-framed defence does not reach it.
The four enforcement points are named with the source text that carries them:
direction: Literal["long"]plus its__post_init__runtime check (#447),side=Side.BUYunconditional in the engine, rail 10, rails 18/19.One qualification, stated because §65.4 is invoked here for nearly the opposite of what it was read for. §65.4's own point is that possession is CONSTRUCTIVE — "what is meant by possession here is the inability to deliver the goods" — which is exactly how exchange-held balances qualify as valid
qabd. That lenient reading does not weaken the long-only claim; it sharpens it. In every failure mode below the asset is not there at all, so selling it fails the prohibition on the lenient reading, not merely the strict one.The hadith is recorded honestly. Hakim ibn Hizam — "Do not sell what is not with you", Sunan an-Nasa'i 4613 / Abu Dawud 3503 — is marked as not extracted in this repository's knowledge base. It carries no
§N.xrow and is not disguised as one. A test pins the disclaimer and its truth: if a source file ever extracts the hadith, the disclaimer has become false and the test says so.The new open question
The ruling is sound where keel decides and open where it settles:
filled_quantityis NULL on every filled live order), or an out-of-band transfer can send an order for more than is held (A SELL is never clamped to the venue's available base — fee dust, partial fills and out-of-band drift all oversell #667).verify_cash_accountexists only on the Alpaca adapter (Coinbase has no cash-account posture check — a margin-enabled account can turn a spot SELL into a short #666).Named in the doc rather than left for a reader to discover.
Pins
Four tests, all two-sided, 12 mutants and 12 killed.
The
base.pypin matches the field line by regex rather than the file, because__post_init__'s docstring quotes the annotation too and a prose mention is not a contract — an earlier version of this pin passed againstdirection: str. It also pins the runtime check separately, since the annotation is a promise to mypy and a foreign rule never runs mypy.The venue-boundary pin is anchored to
_sell_base_size's own stated contract, so when #667 lands this test fails — the doc gets updated with the code, not after it.Full suite: 5059 passed, 3 skipped. ruff and mypy clean; no new
ruff formatdeltas.Closes nothing — it records what #666/#667/#668 are for.