# Tutorial : Placing Orders

You can think of [AlgodexApi#placeOrder](https://docs-sdk.algodex.com/AlgodexApi.html#placeOrder) as a toolbox: it's got everything you need to tackle order execution.

### Steps

1. Create a `new` instance of the [AlgodexApi](https://docs-sdk.algodex.com/AlgodexApi.html).
2. Set a default [Wallet](https://docs-sdk.algodex.com/Wallet.html) using [AlgodexApi#setWallet](https://docs-sdk.algodex.com/AlgodexApi.html#setWallet).
3. Generate an [Order](https://docs-sdk.algodex.com/Order.html) compatible object.
4. Pass in the [Order](https://docs-sdk.algodex.com/Order.html) object to [AlgodexApi#placeOrder](https://docs-sdk.algodex.com/AlgodexApi.html#placeOrder).

## Order Executions

{% hint style="info" %}
If you are unsure of which execution type to choose input `execution:'both'` and we'll handle the rest!
{% endhint %}

#### Details:

The [Order](https://docs-sdk.algodex.com/Order.html) object has an `execution` key that determines how the SDK will handle the [Order](https://docs-sdk.algodex.com/Order.html). Each `execution` will interact with the [Order book](https://docs.algodex.com/developer-tools/algodex-sdk-v2/tutorial-order-book) in different ways. Algodex supports the following executions: [Maker](#maker), [Taker](#taker), [Both](#both).

## Maker Order <a href="#maker" id="maker"></a>

A Maker Order will always be placed into the [Order book](https://docs.algodex.com/developer-tools/algodex-sdk-v2/tutorial-order-book). They can be either Buy or Sell order types.

### What is a Maker Order?

A Maker Order is an order that **does not** execute instantly. A maker order has no active takers, therefore it "makes" its own order to be fulfilled at a later date.

### Condition

When a user places an order, if no one immediately agrees to the terms of the order, the order is considered a Maker Order.

### Walkthrough

1. There are no existing orders in the [Algodex Order book](https://docs.algodex.com/developer-tools/algodex-sdk-v2/tutorial-order-book) that fulfill the user's criteria so they decide to "make" their own order.
2. The users submitted order is added to the [Algodex Order book](https://docs.algodex.com/developer-tools/algodex-sdk-v2/tutorial-order-book).
3. The order is now visible to other users of Algodex and will be fulfilled when another user agrees to "take" the order.

#### Buy Order \[<mark style="color:red;">JavaScript</mark>]

```javascript
//Buy Example:
const res = await api.placeOrder({
'asset': {
  'id': 15322902,
  'decimals': 6,
},
'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI',
'price': 3.22, // Limit price for the asset
'amount': 1, // Amount willing to purchase (The total amount sent will be price * amount)
'execution': 'maker',
'type': 'buy',
});
```

#### Sell Order \[<mark style="color:red;">JavaScript</mark>]

```javascript
// Sell Example:
const res = await api.placeOrder({
  'asset': {
    'id': 15322902,
    'decimals': 6,
  },
  'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI',
  'price': 80000, // Limit price for the asset to sell
  'amount': 1, // Amount of the asset for sale
  'execution': 'maker',
  'type': 'sell',
});
```

## Taker Order <a href="#taker" id="taker"></a>

A Taker Order will always execute existing orders in the [Order book](https://docs.algodex.com/developer-tools/algodex-sdk-v2/tutorial-order-book). They can be either Buy or Sell order types.

### What is a Taker Order?

A Taker Order is an order that executes instantly. A taker order closes or modifies an existing order in the [Algodex Order book](https://docs.algodex.com/developer-tools/algodex-sdk-v2/tutorial-order-book).

### Condition

There must be at least one existing order in the order book that fulfills the user's criteria. Therefore, the user "takes" from an existing order.

### Walkthrough

The user submitted order changes the state of the Order book in 1 of 3 ways:

1. The user does not "take" the entire order. The remainder of the order remains open.
2. The user takes the entire order removing it from the order book.
3. The user takes multiple orders, removing them from the order book.

#### Buy Order \[<mark style="color:red;">JavaScript</mark>]

```javascript
// Buy Example
const res = await api.placeOrder({
  'asset': {
    'id': 15322902,
    'decimals': 6,
  },
  'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI',
  'price': 3.22,
  'amount': 1,
  'execution': 'taker',
  'type': 'buy',
});
```

#### Sell Order \[<mark style="color:red;">JavaScript</mark>]

```javascript
// Sell Example
const res = await api.placeOrder({
  'asset': {
    'id': 15322902,
    'decimals': 6,
  },
  'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI',
  'price': 80000,
  'amount': 1,
  'execution': 'taker',
  'type': 'sell',
});
```

## Maker/Taker Order <a href="#both" id="both"></a>

Maker/Taker will first check the [Order book](https://docs.algodex.com/developer-tools/algodex-sdk-v2/tutorial-order-book) for existing orders that match the current order.

#### Buy Order \[<mark style="color:red;">JavaScript</mark>]

```javascript
  const res = await api.placeOrder({
    'asset': {
      'id': 15322902,
      'decimals': 6,
    },
    'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI',
    'price': 3.22,
    'amount': 1,
    'execution': 'both',
    'type': 'buy',
  });
```

#### Sell Order \[<mark style="color:red;">JavaScript</mark>]

```javascript
  const res = await api.placeOrder({
    'asset': {
      'id': 15322902,
      'decimals': 6,
    },
    'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI',
    'price': 80000,
    'amount': 1,
    'execution': 'both',
    'type': 'sell',
  });
```

## Advanced

#### There are multiple ways to place an order using our SDK.

If you are curious about the internal processes of placing an order and how they relate to the different execution types, the [Structure Module](https://docs-sdk.algodex.com/module-order_structure.html) is a great place to start.

Some users find it clunky to lug around a toolbox if they only need one or two tools.

If that sounds like you, we recommend checking out the [Buy](https://docs-sdk.algodex.com/module-txns_buy.html) & [Sell](https://docs-sdk.algodex.com/module-txns_sell.html) modules to get a better sense of what methods fit your use case.


---

# 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://docs.algodex.com/developer-tools/algodex-sdk-v2/tutorial-placing-orders.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.
