> For the complete documentation index, see [llms.txt](https://coat.gitbook.io/paal-ai-apis/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coat.gitbook.io/paal-ai-apis/paal-ai-api-docs/stats-api.md).

# Stats API

### PAAL AI Stats API Documentation

#### Introduction

This API documentation outlines the endpoints available for managing and retrieving statistical data in the PAAL AI application. These endpoints allow for the modification and retrieval of various statistics such as active users, total users, members, and prompts.

#### Base URL

The base URL for all endpoints is: <https://paal-ecosystem-backend.onrender.com>

#### Authentication

Some endpoints require authentication using a bearer token in the request header.

***

#### Save Stats Data

Save or modify statistical data.

* **URL:** `/stats/save`
* **Method:** `POST`
* **Authentication:** Required (Bearer Token)
* **Request Body:**
  * `active` (integer, optional): Number of active users.
  * `users` (integer, optional): Total number of registered users.
  * `members` (integer, optional): Total number of members.
  * `prompt` (integer, optional): Total number of prompts.

**Example Request:**

```http
POST /stats/save
Authorization: Bearer <TOKEN>
Content-Type: application/json

{
    "active": 100,
    "users": 500,
    "members": 200,
    "prompt": 300
}
```

**Example Response (Success):**

```json
{
    "status": true,
    "data": {
        "active": 100,
        "users": 500,
        "members": 200,
        "prompt": 300
    }
}
```

**Example Response (Error):**

```json
{
    msg: "Request missing some parametres",
    status: 'error',
    error: '1052'
}
```

***

#### Retrieve Stats Data

Retrieve statistical data.

* **URL:** `/stats`
* **Method:** `GET`
* **Authentication:** Not Required

**Example Request:**

```http
GET /stats
```

**Example Response (Success):**

```json
{
    "status": true,
    "data": {
        "active": 100,
        "users": 500,
        "members": 200,
        "prompt": 300
    }
}
```

**Example Response (Empty):**

```json
{
    "status": true,
    "data": {
        "active": 0,
        "users": 0,
        "members": 0,
        "prompt": 0
    }
}
```

#### Error Responses

In case of errors, the API returns JSON responses with appropriate error messages.

**Example Error Response:**

```json
{
     msg: "Internal server error",
    status: 'error',
    error: '2000'
}
```

***

#### **Get Token Market Chart Data**

**Endpoint:** `GET /stats/:chain/:address/chart`

**Authorization:** Requires **Bearer Token**

**Description**

This endpoint retrieves historical market data, including price, trading volume, and market capitalization, for a given token contract on a specific blockchain.

**Path Parameters**

| Parameter | Type     | Description                                 |
| --------- | -------- | ------------------------------------------- |
| `chain`   | `number` | The blockchain network ID (800 for solana). |
| `address` | `string` | The token contract address.                 |

**Query Parameters**

| Parameter  | Type                 | Default    | Description                                                                                                                     |
| ---------- | -------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `duration` | `string`             | `7d`       | The time range for the data. Accepted values: `1yr`, `6mon`, `3mon`, `1mon`, `30d`, `7d`, `24h`, `6h`, `1h`, `30m`, `5m`, `1m`. |
| `filter`   | `string`             | `d`        | Data granularity. Accepted values: `d` (daily), `mon` (monthly), `w` (weekly), `h` (hourly), `m` (minute).                      |
| `start`    | `number (timestamp)` | *optional* | Custom start time (Unix timestamp in seconds).                                                                                  |
| `end`      | `number (timestamp)` | *optional* | Custom end time (Unix timestamp in seconds).                                                                                    |

**Response**

A JSON object with three main arrays: `prices`, `volume`, and `marketCap`. Each contains date-value pairs.

```json
{
  "prices": [
    { "date": "2024-02-12T00:00:00.000Z", "value": 250.5 },
    { "date": "2024-02-13T00:00:00.000Z", "value": 255.2 }
  ],
  "volume": [
    { "date": "2024-02-12T00:00:00.000Z", "value": 1050000 },
    { "date": "2024-02-13T00:00:00.000Z", "value": 980000 }
  ],
  "marketCap": [
    { "date": "2024-02-12T00:00:00.000Z", "value": 500000000 },
    { "date": "2024-02-13T00:00:00.000Z", "value": 510000000 }
  ]
}
```

**Error Responses**

| Status Code | Message                                                 |
| ----------- | ------------------------------------------------------- |
| `403`       | `{ "status": "error", "msg": "Missing parameters" }`    |
| `403`       | `{ "status": "error", "msg": "Something went wrong" }`  |
| `500`       | `{ "status": "error", "msg": "Internal server error" }` |

***

This documentation provides details on how to manage and retrieve statistical data using the PAAL AI Stats API. For any further assistance or clarification, please refer to the API documentation or contact support.
