> For the complete documentation index, see [llms.txt](https://docs.autonomynetwork.io/autonomy-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.autonomynetwork.io/autonomy-docs/autonomy-network/products/autoswap/how-it-works.md).

# How It Works

Having limit orders and stop losses execute on a DEX works the same as any other [`Request`](broken://spaces/P3QZIVWdqKkHhz0tX5KC) on Autonomy. Say the price of ETH is $1000 and the user wants to set a stop loss order to sell ETH when the price gets to $900:

1. The user makes a tx (the only tx that the user makes in the whole flow) which [creates a `Request`](https://github.com/Autonomy-Network/autonomy-contracts/blob/main/interfaces/IRegistry.sol#L76) on Autonomy that asks Autonomy to [call the limits/stops](https://github.com/Autonomy-Network/uniV2-limits-stops/blob/62def4a2a686fba8528ba3582278467e56b525c0/contracts/UniV2LimitsStops.sol#L110) contract. Initially this `Request` is impossible to execute, because the condition is [codified in a `require` statement](https://github.com/Autonomy-Network/uniV2-limits-stops/blob/62def4a2a686fba8528ba3582278467e56b525c0/contracts/UniV2LimitsStops.sol#L120) - any tx that tries to execute the `Request` will revert. This check is done on the actual input/output amounts of the trade, and is therefore a guarantee that the user will always get the trade they want, and doesn't need to rely on an oracle. The user still has their tokens in their wallet.
2. The price on the DEX drops to $900 as 3rd parties trade on it.
3. The Autonomy bots are constantly simulating whether executing a `Request` will succeed or revert. If they see it would succeed, that means that the condition for the trade is now true, and the `require` statement won't make the tx revert. This means the bot can know when a trade can be executed without knowing anything about tokens or prices or oracles. The bot now executes the `Request`, which atomically swaps the user's input token to the output token and it shows up in their wallet. At no point does the bot ever have control over the user's tokens.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.autonomynetwork.io/autonomy-docs/autonomy-network/products/autoswap/how-it-works.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
