> For the complete documentation index, see [llms.txt](https://contango-2.gitbook.io/exchange/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://contango-2.gitbook.io/exchange/protocol/how-it-works.md).

# How it works

Contango protocol synthesises expirable positions by using spot exchanges and borrowing and lending at a fixed rate, i.e. cash flows of expirable positions are replicated through [fixed interest rate markets](/exchange/resources/glossary.md#fixed-rate-market). The different steps are realized atomically, i.e. in one transaction each time a trader buys or sells an expirable. If for any reason the transaction fails then no position will be taken neither by the trader nor by the protocol.

## Position opening

Below are presented the steps to open an expirable position.

![Steps to open a position on ETHDAI.](/files/pebce7tdS9JgvOxPbn3Q)

| Short                                                                                                                                                                                                                                                                               | Long                                                                                                                                                                                                                                                                            |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <ol><li>Trader sells a expirable</li><li>Protocol borrows the base currency</li><li>Protocol sells the borrowed amount for an equivalent amount of the quote currency on the spot market to synthesize a short position.</li><li>The amount of the quote currency is lent</li></ol> | <ol><li>Trader buys a expirable</li><li>Protocol borrows the quote currency</li><li>Protocol sells the borrowed amount for an equivalent amount of the base currency on the spot market to synthesize a long position</li><li>The amount of the base currency is lent</li></ol> |

## Position closing

Below are presented the steps to close an expirable position.

![Steps to close a position on ETHDAI.](/files/wX9PvYyAjyfYxeOsB61s)

| Short                                                                                                                                                                                                                                                                                                  | Long                                                                                                                                                                                                                                                                                             |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <ol><li>Trader closes a short position</li><li>Protocol gets the principal and the interest from lending the quote currency</li><li>Protocol swaps the quote currency for the base currency on the spot market</li><li>Protocol gives back the borrowed funds including the accrued interest</li></ol> | <ol><li>Trader closes a long position</li><li>Protocol gets the principal and interest from lending the base currency</li><li>Protocol swaps the base currency for the quote currency on the spot market</li><li>Protocol gives back the borrowed funds including the accrued interest</li></ol> |

{% hint style="info" %}
In order to quote a price to a trader, Contango simulates what would happen in a real execution and enriches the answer with min/max values, also simulating how the position status would look like after execution. To achieve that Contango uses the "preview" functions provided by the underlying protocols.
{% endhint %}


---

# 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://contango-2.gitbook.io/exchange/protocol/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.
