# Quick Start

{% hint style="info" %}
Use the [Thallo SDK](https://github.com/thallo-io/thallo-exchange-npm-sdk/) NPM library to integrate at lightning speed ⚡
{% endhint %}

## Example Code

The full working code for this example can be found [here](https://github.com/thallo-io/thallo-api-example).

In this example we do the following:

1. Get the market data, this contains sell orders for specific projects and vintages, including quantity available and the price per tonne.
2. Get the rich project data for all projects that have credits for sale.
3. Find a project that has been implemented in Sierra Leone.
4. Ensure the price is within your defined boundaries.
5. Purchase 1 whole tonne and retire 20 grams of the credits in one atomic action.

> The purchase will only be made if you do not have 20 grams for this project and vintage available in your CaaS inventory

```ts
// get market data
const marketData = (await httpClient.get('/api/market')).data
// get project ids so we can get the project details
const projectIds = marketData.projects.map((project: { project_id: string }) => project.project_id)

// we should cache the project data as it doesn't change often
const projects = (await httpClient.get('/api/projects', {
    params: { project_ids: projectIds }
})).data.projects

// select project from Sierra Leone
const selectedProject = projects.filter((project: { location: string }) => project.location === 'SL')[0]

// get sell order for this project
const vintage = marketData.projects.filter((project: { project_id: string }) => project.project_id === selectedProject.project_id)[0]
    .vintages[0]
const sellOrder = vintage.sell_orders[0]

// ensure the price is less than the max we're comfortable paying e.g. $10.45
if (BigNumber.from(sellOrder.price_cents).gt(1045)) {
    throw new Error('Sell order price too high')
}

// request retirement
const retirementRequestId = (await httpClient.post('api/caas/request-retirement', {
    quantity_grams: '20',
    vintage_id: vintage.vintage_id,
    sell_order_id: sellOrder.sell_order_id,
    expected_price_cents: sellOrder.price_cents,
})).data.retirement_request_id

// get retirement details
const retirement = (await httpClient.post('api/retirement', {
    params: { id: retirementRequestId }
})).data
```


---

# 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.market.thallo.io/quickstart.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.
