> ## Documentation Index
> Fetch the complete documentation index at: https://docs.defiloops.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Binance safety

> What the enclave checks on every Binance order, what a breach on our side could and could not do, how you take control back, and what happens after a crash

**In short:** the key can trade and cannot withdraw. The enclave checks every order against your wallet's signatures before it signs. The fastest way to cut us off is to delete the API key on binance.com. **This describes the demo exchange today. Real-money trading is coming soon, with the same checks plus the ones demo cannot run.**

Read [trading venues](https://docs.defiloops.com/venues/overview.md) for the model all venues share. This page is the Binance detail.

## What the enclave checks on every order

The enclave judges each request alone. It keeps no memory between requests and reads its counts from Binance each time. It refuses if any check fails or any fact cannot be read.

| check | what is refused |
| - | - |
| **the key** | a key that can withdraw or transfer, a Portfolio Margin account, a key with no IP restriction (real money only) |
| **the lock** | a market that is off in your lock, or leverage over the lock's ceiling |
| **your grant** | a missing or expired grant, a bad signature, an order type, side or market the grant does not list, leverage over the grant's |
| **the run** | a run number out of order, or an order Binance already holds |
| **the trigger** | a price or schedule trigger that is not true yet |
| **freshness** | a run due more than 10 minutes ago |
| **the price** | a market order is sent as a limit order bounded by your price tolerance. A market with no tolerance is refused |
| **the account** | cross margin, hedge mode, writing options |
| **the history** | a grant whose start Binance's order history does not reach: it fails closed |

Exits pass with no grant, no lock and no price check: a cancel, a reduce-only futures order, and a sale of options you hold. The enclave writes its decision to a log before it signs, a refusal included. If the log cannot be written, it signs nothing.

## What a breach on our side could and could not do

Our servers hold the queue of orders and decide, for a grant with no condition, when a run is offered. They hold no key.

**A breach of our servers could:**

* offer runs of a grant you armed at times it chooses, inside the grant's limits
* cancel any open order on the account, including ones you placed yourself
* place reduce-only futures orders in any futures market, at any price. These can close your futures positions, including ones you opened by hand
* sell options you hold, at any price
* keep using a grant you revoked in the app, until it expires, because revoking in the app stops our relay and does not cancel your signature
* stop placing or cancelling orders

**It could not:**

* withdraw or transfer money: the API key has no such permission, and Binance enforces that
* open or add to a position in a market that is off in your lock
* raise leverage past your lock or grant
* go past the grant's per-run and total limits, or its run count
* place an entry order without a grant you signed
* use a grant after it expires

## If the enclave's build were bad

If our operators approved a bad build, it could trade your whole Binance balance badly, in any market and at any leverage the API key's permissions allow. Your lock is enforced only by the enclave's own code, so a bad build need not respect it. A bad build still could not withdraw, because your key cannot. The same enclave holds the agent's own signing key, so [trading venues](https://docs.defiloops.com/venues/overview.md#what-a-breach-on-our-side-could-and-could-not-do) covers the wider case.

## How you take control back

From fastest and hardest to slowest:

1. **Delete the API key on binance.com.** It works at once and needs nothing from us.
2. **Tighten the markets in your lock.** This needs your wallet signature. It stops new orders in those markets.
3. **Stop the card** on the card page, in close mode or cancel-all mode. See [cards on Binance](https://docs.defiloops.com/venues/binance/cards.md#stop-a-card).
4. **Cancel an order or close a position** from the card page. These need no grant.
5. **Revoke the grant** in the app. This stops our relay only.

Deleting a connection in the app removes our record. It does not delete the key on Binance.

## Crashes and retries

* **A run is never sent twice.** The order id comes from the grant and the run number. A repeat of a run Binance already holds is refused, not doubled.
* **A run is never placed late.** A network fault is retried for at most 10 minutes. After that the run is dropped, and the enclave refuses a run that old.
* **A restart does not skip or double a card's run.** Each run is named for the closed bar it fired on.
* **A stop in cancel-all mode or a halt never sends a leg.** If our service crashed while a take-profit or stop-loss leg was being placed, and the card is then stopped in cancel-all mode or halted by our kill switch, recovery cancels that leg's order by its id and never sends it again. Keeping the leg pending and retrying the cancel when Binance does not confirm it comes in a later update.

**Setting take-profit and stop-loss is paused.** Every new set is refused until the sync of your fills is switched on. That ships with a coming update, together with fixes for how a refused set is undone. Legs you set earlier stay on Binance, and you can still cancel them. A set that failed part way could mark a leg cancelled while its order still rested on Binance, so check your legs on Binance. See [trading](https://docs.defiloops.com/venues/binance/trading.md#take-profit-and-stop-loss-on-futures).

## What this does not protect you from

* **Binance itself.** If Binance fails or freezes your account, we cannot help.
* **Bad fills inside your limits.** The lock has no cap on total size and no liquidation buffer. The grant's totals are the only bound on size.
* **A market that moves.** A market order can fill anywhere inside your price tolerance.
* **A stale picture.** The app does not show open futures positions or fills after placement. Check Binance.
* **A key with no IP restriction.** Demo cannot restrict a key to addresses. On real money the enclave refuses such a key.

## Under the hood

*For readers who want the mechanism.*

* The enclave derives each trading key from one sealed secret for Binance, so no key is stored. Only an enclave build our operators approve can open the secret.
* Requests to Binance leave the enclave through a fixed allow-list of hosts. The secure connection ends inside it.
* The lock is read from MegaETH on every order that opens or adds risk. Exits do not read it. If that read fails or is stale, the enclave refuses.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.