Skip to content

Commit

Permalink
💱 Example resolving limit OB
Browse files Browse the repository at this point in the history
  • Loading branch information
JFWooten4 committed Dec 8, 2024
1 parent c7865bb commit 1f31ba4
Showing 1 changed file with 30 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,51 +312,7 @@ The trading behavior of an account trading asset A for B depends on the status o
| Trustline for A is not authorized or doesn’t exist | New offer operation fails, existing offers cancelled at time of deathorization |
| Trustline for B is not authorized or doesn’t exist | New offer operation fails, existing offers cancelled at time of deathorization |

<CodeExample title="listing depth">

```python
Query Horizon and print the order book for AstroDollar/AstroPeso
```

```js
// at 311
```

```java

```

```go

```

</CodeExample>

## Liquidity

### Market Depth

The more orders available to transact against, the more currency you can convert at any time without moving the market. Stellar stores these open orders as `offer` [objects](https://developers.stellar.org/docs/data/horizon/api-reference/resources/offers/object) directly on chain. This transparency allows anyone to analyze the order book and understand the trading activity for any asset pair.

### Fill Prices

The network and by extension its [validators](https://stellarbeat.io) match orders based on the protocol rules of [Stellar Core](https://github.com/stellar/stellar-core/blob/fbb53d8ad42dcc12a046c9be949d654821a24d38/src/transactions/OfferExchange.cpp#L227-L550). Orders are filled at the same price or better than specified, ensuring fair execution. This means you receive the best possible price available in the market at that moment.

## Submitting Trades

Let's pretend you just got paid in Mexican Pesos, but you'd prefer to hold your savings in U.S. Dollars. After querying the [exchange rate](#reading-prices), we can send a new offer to the network, swapping Pesos for Dollars at our desired rate. By submitting a sell offer that matches the current market price, we can ensure our pesos are converted to dollars promptly.

<CodeExample>

```python
should be implemented already ###
```

</CodeExample>

## Source of Truth

Now that we know how to submit an order to the SDEX, let's walk through reading the current order book. This entails collecting all the buyers for a specific currency pair and comparing this demand to all the sellers of that pair. We'll stick with our pesos-dollars example and ignore potential [passive offers](#passive-order) for the time being.
We will see these in action in the later example preamvle (TODO: move above), for now let's uncover the listing depth of our peso-dollar order book.

<CodeExample>

Expand Down Expand Up @@ -392,7 +348,7 @@ orderBook.asks.forEach((ask) => {
```java
import java.util.List;

public static void main(String[] args) throws Exception {
public static void main(String[] args) {
OrderBookResponse orderBook = server.orderBook(astroPeso, astroDollar).execute();

System.out.println("Bids:");
Expand Down Expand Up @@ -431,6 +387,34 @@ func main() {

</CodeExample>

## Liquidity

### Market Depth

The more orders available to transact against, the more currency you can convert at any time without moving the market. Stellar stores these open orders as `offer` [objects](https://developers.stellar.org/docs/data/horizon/api-reference/resources/offers/object) directly on chain. This transparency allows anyone to analyze the order book and understand the trading activity for any asset pair.

### Fill Prices

The network and by extension its [validators](https://stellarbeat.io) match orders based on the protocol rules of [Stellar Core](https://github.com/stellar/stellar-core/blob/fbb53d8ad42dcc12a046c9be949d654821a24d38/src/transactions/OfferExchange.cpp#L227-L550). Orders are filled at the same price or better than specified, ensuring fair execution. This means you receive the best possible price available in the market at that moment.

## Submitting Trades

Let's pretend you just got paid in Mexican Pesos, but you'd prefer to hold your savings in U.S. Dollars. After querying the [exchange rate](#reading-prices), we can send a new offer to the network, swapping Pesos for Dollars at our desired rate. By submitting a sell offer that matches the current market price, we can ensure our pesos are converted to dollars promptly.

<CodeExample>

```python
should be implemented already ###
```

</CodeExample>

## Source of Truth

Now that we know how to submit an order to the SDEX, let's walk through reading the current order book. This entails collecting all the buyers for a specific currency pair and comparing this demand to all the sellers of that pair. We'll stick with our pesos-dollars example and crossing/implementing potential [passive offers](#passive-order)

OlD xeAmPleE

When performing this analysis on live [mainnet](https://developers.stellar.org/docs/run-api/horizon/tutorials/quickstart#using-the-public-network) data, you will likely see a combination of trading taking place on top of the SDEX. The first, most basic option, is when a new order crosses the price set by an outstanding order. The two instantly cross once the new order gets accepted, and the transaction generates a taker `contraID` rather than an `offerID` for the "buyer" of the existing liquidity.

The other two options are exchanges made using [path payments](https://developers.stellar.org/docs/encyclopedia/path-payments) or [liquidity pools](https://developers.stellar.org/docs/encyclopedia/liquidity-on-stellar). Both path payments and liquidity pools are constantly interacting with the SDEX. Indeed, every new path payment and liquidity pool operation can only happen because of existing order book offers or new user [swap requests](https://developers.stellar.org/docs/start/list-of-operations/#manage-sell-offer).
Expand Down

0 comments on commit 1f31ba4

Please sign in to comment.