# Market

## Create

#### Description:

This function creates a new market.

#### Previous Steps:

1. [Create an account](broken://pages/PkADXmgJ4GV5VuHSeUDi#create)
2. [Fund an account](broken://pages/PkADXmgJ4GV5VuHSeUDi#fund)

#### Steps:

1. Call the market/create\_market endpoint with the following request body:

* seed: the seed of the account that will pay for the transaction.&#x20;
* market\_id: the market identifier.

#### Example Input:

```
{
    "seed": "//Alice",
    "market_id": 1
}
```

#### Expected Output:

```
{
    "market_id": 1,
    "who": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
}
```

* who: the account address associated with the market.&#x20;
* market\_id: the market identifier.

## Create Market Rate

#### Description:

This function creates a new market rate.

#### Previous Steps:

1. [Create an account](broken://pages/PkADXmgJ4GV5VuHSeUDi#create)
2. [Fund an account](broken://pages/PkADXmgJ4GV5VuHSeUDi#fund)
3. [Create a class](broken://pages/U0RjrSPg2emUTyyTlAs1#create-class)
4. [Create an asset](broken://pages/U0RjrSPg2emUTyyTlAs1#create)
5. [Mint an asset](broken://pages/U0RjrSPg2emUTyyTlAs1#mint)
6. [Create a market](#create)

#### Steps:

1. Call the market/create\_market\_rate endpoint with the following request body:

* seed: the seed of the account that will pay for the transaction.&#x20;
* market\_id: the market identifier&#x20;
* market\_rate\_id: the market rate identifier
* rates:&#x20;
  * rates: an array of the requirements that the transaction needs to fullfilled.&#x20;
  * metadata: additional information about the rates.

#### Example Input:

```
{
    "seed": "//Alice",
    "market_id": 1,
    "market_rate_id": 1,
    "rates": {
        "rates": [
            {
                "class_id": 2000,
                "asset_id": 1,
                "action": {
                    "Transfer": 1
                },
                "from": "Market",
                "to": "Buyer"
            },
            {
                "class_id": 2000,
                "asset_id": 2,
                "action": {
                    "Mint": 1
                },
                "from": "Market",
                "to": "Buyer"
            },
            {
                "class_id": 3000,
                "asset_id": 1,
                "action": {
                    "Has": [
                        "GreaterEqualThan",
                        5000
                    ]
                },
                "from": "Buyer",
                "to": "Market"
            },
            {
                "class_id": 3000,
                "asset_id": 2,
                "action": {
                    "Transfer": 5
                },
                "from": "Buyer",
                "to": "Market"
            },
            {
                "class_id": 3000,
                "asset_id": 3,
                "action": {
                    "Burn": 50
                },
                "from": "Buyer",
                "to": "Market"
            },
            {
                "class_id": 4000,
                "asset_id": 1,
                "action": {
                    "Transfer": 2
                },
                "from": "Market",
                "to": {
                    "Account": "//Alice"
                }
            },
            {
                "class_id": 4000,
                "asset_id": 2,
                "action": {
                    "Transfer": 1
                },
                "from": "Buyer",
                "to": {
                    "Account": "//Alice"
                }
            }
        ],
        "metadata": []
    }
}
```

#### Expected Output:

```
{
    "market_id": 1,
    "market_rate_id": 1,
    "who": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
}
```

* who: the account address associated with the market.&#x20;
* market\_id: the market identifier.
* market\_rate\_id: the market rate identifier.

## Deposit Assets

#### Description:

This function deposits a given amount of assets in the market.

#### Previous Steps:

1. [Create an account](broken://pages/PkADXmgJ4GV5VuHSeUDi#create)
2. [Fund an account](broken://pages/PkADXmgJ4GV5VuHSeUDi#fund)
3. [Create a class](broken://pages/U0RjrSPg2emUTyyTlAs1#create-class)
4. [Create an asset](broken://pages/U0RjrSPg2emUTyyTlAs1#create)
5. [Mint an asset](broken://pages/U0RjrSPg2emUTyyTlAs1#mint)
6. [Create a market](#create)
7. [Create a market rate](#create-market-rate)

#### Steps:

1. Call the market/deposit\_assets endpoint with the following request body:

* seed: the seed of the account that will pay for the transaction.&#x20;
* market\_id: the market identifier&#x20;
* market\_rate\_id: the market rate identifier
* amount: the specific amount of assets to be deposited.

#### Example Input:

```
{
    "seed": "//Alice",
    "market_id": 1,
    "market_rate_id": 1,
    "amount": 1000
}
```

#### Expected Output:

```
{
    "who": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
    "market_id": 1,
    "market_rate_id": 1,
    "amount": 1000,
    "balances": [],
    "success": true
}
```

* who: the account address associated with the market.&#x20;
* market\_id: the market identifier.
* market\_rate\_id: the market rate identifier.
* amount: the specific amount of assets deposited.&#x20;
* balances: an array of the results of each operation after the deposit
* success: an indicator to see if the deposited was successful

## Exchange Assets

#### Description:

This function deposits a given amount of assets in the market.

#### Previous Steps:

1. [Create an account](broken://pages/PkADXmgJ4GV5VuHSeUDi#create)
2. [Fund an account](broken://pages/PkADXmgJ4GV5VuHSeUDi#fund)
3. [Create a class](broken://pages/U0RjrSPg2emUTyyTlAs1#create-class)
4. [Create an asset](broken://pages/U0RjrSPg2emUTyyTlAs1#create)
5. [Mint an asset](broken://pages/U0RjrSPg2emUTyyTlAs1#mint)
6. [Create a market](#create)
7. [Create a market rate](#create-market-rate)
8. [Deposit assets](#deposit-assets)

#### Steps:

1. Call the market/exchange\_assets endpoint with the following request body:

* seed: the seed of the account that will pay for the transaction.&#x20;
* market\_id: the market identifier&#x20;
* market\_rate\_id: the market rate identifier
* amount: the specific amount of assets to be deposited.

#### Example Input:

```
{
    "seed": "//Bob",
    "market_id": 1,
    "market_rate_id": 1,
    "amount": 1000
}
```

#### Expected Output:

```
{
    "buyer": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
    "market_id": 1,
    "market_rate_id": 1,
    "amount": 1000,
    "balances": [
        {
            "rate": {
                "class_id": 1,
                "asset_id": 1,
                "action": "Mint",
                "amount": 1000,
                "from": "Market",
                "to": "Buyer"
            },
            "balance": 1000000
        }
    ],
    "success": true
}
```

* buyer: the account address associated with the market.&#x20;
* market\_id: the market identifier.
* market\_rate\_id: the market rate identifier.
* amount: the specific amount of assets deposited.&#x20;
* balances: an array of the results of each operation after the deposit
* success: an indicator to see if the deposited was successful


---

# Agent Instructions: 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:

```
GET https://envida-protocol.gitbook.io/envida/api-recipes/market.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
