> For the complete documentation index, see [llms.txt](https://earnbit.gitbook.io/earnbit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://earnbit.gitbook.io/earnbit/developers/exchange-api-documentation/public-endpoints-or-http/market-history.md).

# Market History

### Details

<mark style="color:blue;">`GET`</mark> `https://api.earnbit.com/api/v1/public/history`

#### Query Parameters

| Name                                     | Type    | Description                                                     | Example   |
| ---------------------------------------- | ------- | --------------------------------------------------------------- | --------- |
| market<mark style="color:red;">\*</mark> | STRING  | Any public pair                                                 | BTC\_USDT |
| lastId                                   | NUMERIC | How many last trades to skip (default  = 0)                     | 0         |
| limit                                    | NUMERIC | How many trades to display (default = 50, min  = 1, max = 1000) | 5         |

<details>

<summary>CURL Example</summary>

```javascript
curl -X GET "https://api.earnbit.com/api/v1/public/history?market=BTC_USDT&lastId=0&limit=5'" -H "accept: application/json"
```

</details>

{% tabs %}
{% tab title="200: OK Successful" %}
**Response parameters:**

|  Name  |   Type  | Description                              |
| :----: | :-----: | ---------------------------------------- |
|   id   | NUMERIC | Trade ID                                 |
|  time  | NUMERIC | Time of trade execution in seconds       |
|  price |  STRING | Trade price                              |
|  type  |  STRING | Trade type (buy / sell)                  |
| amount |  STRING | Trade amount (in 1st ticker of the pair) |
|  total |  STRING | Trade amount (in 2nd ticker of the pair) |

**Response example:**

```javascript
{
    "code": 200,
    "success": true,
    "message": "",
    "result": [
        {
            "id": 1255710662,
            "time": 1660804507.719000,
            "price": "23373.63607825",
            "type": "buy",
            "amount": "0.681245",
            "total": "15923.17271013"
        },
        ...
}
```

{% endtab %}

{% tab title="400: Bad Request " %}
**Response example 1:**

```javascript
<html>

<head>
	<title>400 Bad Request</title>
</head>

<body>
	<center>
		<h1>400 Bad Request</h1>
	</center>
	<hr>
	<center>nginx</center>
</body>

</html>
```

**This error occurs in the following cases:**

* One or more query parameters are invalid
* The request contains invalid headers

**Response example 2:**

```javascript
{
    "code": 400,
    "success": false,
    "message": "invalid input",
    "result": []
}
```

**This error occurs in the following cases:**

* The query parameter `market` was not provided in the request.
* One or more query parameters in the request contain invalid values.

**Response example 3:**

```javascript
{
    "code": 400,
    "success": false,
    "message": {
        "market": [
            "The market field is required."
        ]
    },
    "result": []
}
```

**This error occurs in the following cases:**

* The query parameter `market` was not provided in the request.
* The query parameter `market` was provided incorrectly.
  {% endtab %}

{% tab title="404: Not Found " %}
**Response example:**

```javascript
{
    "timestamp": 1660766043722,
    "status": 404,
    "error": "Not Found",
    "message": "",
    "path": "/api/v1/public/history-test"
}
```

**This error occurs in the following cases:**

* The requested URL was not found. Please check the endpoint and try again
  {% endtab %}
  {% endtabs %}

### With Authentication

This public endpoint can also be used as a `POST` request with [authentication](/earnbit/developers/exchange-api-documentation/private-endpoints-or-http/authentication-and-api-keys.md) (similar to [private endpoints](/earnbit/developers/exchange-api-documentation/private-endpoints-or-http.md)) to allow you to access more data.

<mark style="color:green;">`POST`</mark> `https://api.earnbit.com/api/v1/public/history`

#### Headers

| Name                                              | Type   | Description                                                                                                               |
| ------------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------- |
| X-TXC-APIKEY<mark style="color:red;">\*</mark>    | STRING | Public [API key](/earnbit/developers/exchange-api-documentation/private-endpoints-or-http/authentication-and-api-keys.md) |
| X-TXC-PAYLOAD<mark style="color:red;">\*</mark>   | STRING | Сonverted Base64 string containing body JSON                                                                              |
| X-TXC-SIGNATURE<mark style="color:red;">\*</mark> | STRING | Encrypted HmacSHA512 string containing body JSON with a API secret key                                                    |

#### Request Body

| Name                                      | Type    | Description                                                                                                                                                              | Example                |
| ----------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- |
| market<mark style="color:red;">\*</mark>  | STRING  | Any public pair                                                                                                                                                          | BTC\_USDT              |
| lastId                                    | NUMERIC | How many last trades to skip (default  = 0)                                                                                                                              | 1                      |
| limit                                     | NUMERIC | How many trades to display (default = 50, min  = 1, max = 1000)                                                                                                          | 10                     |
| request<mark style="color:red;">\*</mark> | STRING  | A request path without the domain name                                                                                                                                   | /api/v1/public/history |
| nonce<mark style="color:red;">\*</mark>   | NUMERIC | A 13-character number that must always be greater than the nonce of the previous completed request (we suggest generating a nonce as the UNIX timestamp in milliseconds) | 1704070810000          |

<details>

<summary>CURL Example</summary>

```javascript
curl --location --request POST 'https://api.earnbit.com/api/v1/public/history' \
--header 'Content-Type: application/json' \
--header 'X-TXC-APIKEY: 0000000000XXXXXXXXXXXXXXXXX' \
--header 'X-TXC-PAYLOAD: 0000000000XXXXXXXXXXXXXXXXX' \
--header 'X-TXC-SIGNATURE: 0000000000XXXXXXXXXXXXXXXXX' \
--data-raw '{"market":"BTC_USDT","lastId":1,"limit":10,"request":"/api/v1/public/history","nonce":1704070810000}'
```

</details>

{% tabs %}
{% tab title="200: OK Successful" %}
**Response example:**

```javascript
{
    "code": 200,
    "success": true,
    "message": "",
    "result": [
        {
            "id": 259861554,
            "time": 1722623930.579000,
            "price": "3",
            "type": "buy",
            "amount": "0.33333333",
            "total": "0.99999999"
        },
        ...
    ]
}
```

{% endtab %}

{% tab title="400: Authentication Failure " %}
**Response example:**

```javascript
{
    "code": 400,
    "success": false,
    "message": "authentication failure",
    "result": []
}
```

**This error occurs in the following cases:**

* The request was signed incorrectly.
* Some of the provided parameters are incorrect.
* Provided [nonce](/earnbit/developers/exchange-api-documentation/private-endpoints-or-http/authentication-and-api-keys.md) is incorrect or less than on previous completed request
* The base URL or path is incorrect.
* The API keys are not [activated](/earnbit/developers/exchange-api-documentation/private-endpoints-or-http/authentication-and-api-keys.md).
  {% endtab %}

{% tab title="404: Not Found " %}
**Response example:**

```javascript
{    
    "timestamp": 1727100904,
    "status": 404,
    "error": "Not Found",
    "message": "",
    "path": "/api/v1/public/public/test"
}
```

**This error occurs in the following cases:**

* The request was made with undefined data and the service cannot find the data for response.
  {% endtab %}
  {% endtabs %}
