> 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-methods-or-websoket/deals-methods.md).

# Deals methods

Used to get information about the last trade for a specific pair.

### List of Deals methods:

* [Deals Query ](#deals-query-method)- used for one-time data get requests.
* [Deals Subscribe ](#deals-subscribe-method)- used to subscribe to receive real-time updates.
* [Deals Unsubscribe ](#deals-unsubscribe-method)- used to unsubscribe from the [Deals Subscribe](#deals-subscribe-method) method.

### Deals Query method

Used for one-time data get requests.

#### Method

```javascript
deals.query
```

#### Request "params" parameters

|                   Name                   |   Type  |       Description       | Example  |
| :--------------------------------------: | :-----: | :---------------------: | -------- |
| market<mark style="color:red;">\*</mark> |  STRING |     Any public pair     | ETH\_BTC |
|  limit<mark style="color:red;">\*</mark> | NUMERIC | How many trades to show | 2        |
| lastId<mark style="color:red;">\*</mark> | NUMERIC | How many trades to skip | 0        |

#### Request example

```javascript
{
  "method":"deals.query",
  "params":
    [
      "ETH_BTC",
      2,
      0
    ],
  "id":1
}
```

#### Response "params" and "result" parameters

|  Name  |   Type  | Description                          |
| :----: | :-----: | ------------------------------------ |
| market |  STRING | Pair name                            |
|  type  |  STRING | Trade type (buy or sell)             |
|  time  | NUMERIC | Time in TimeStamp format             |
|   id   | NUMERIC | ID                                   |
| amount |  STRING | Trade amount (in 1st ticker of pair) |
|  price |  STRING | Trade price (in 1st ticker of pair)  |

#### Response example

```javascript
{
    "id": 1,
    "params": [
        "BTC_USDT",                        // market
        2,                                 // limit
        0                                  // lastId
    ],
    "result": [
        {
            "id": 19201768267,             // ID
            "type": "buy",                 // type
            "time": 1.727276247759E9,      // time
            "price": "63865.07",           // price
            "amount": "0.00448678"         // amount
        },
        {
            "id": 19201768100,
            "type": "sell",
            "time": 1.727276246117E9,
            "price": "63860.3281504",
            "amount": "0.00155184"
        }
    ],
    "error": null
}
```

### Deals Subscribe method

Used to subscribe to receive real-time updates.

#### Method

```javascript
deals.subscribe
```

#### Request "params" parameters

|                   Name                   |  Type  |       Type      | Example   |
| :--------------------------------------: | :----: | :-------------: | --------- |
| market<mark style="color:red;">\*</mark> | STRING | Any public pair | BTC\_USDT |

#### Request example

```javascript
{
  "method":"deals.subscribe",
  "params":
    [
      "BTC_USDT"
    ],
  "id":1
}
```

#### Response example (successfully subscribed)

```javascript
{
    "id": 1,
    "params": [],
    "result": {
        "status": "success"
    },
    "error": null
}
```

#### Response "params" parameters ("deals.update")

|  Name  |   Type  | Description                          |
| :----: | :-----: | ------------------------------------ |
| market |  STRING | Pair name                            |
|   id   | NUMERIC | ID                                   |
|  type  |  STRING | Trade type (buy or sell)             |
|  time  | NUMERIC | Time in TimeStamp format             |
|  price |  STRING | Trade price (in 1st ticker of pair)  |
| amount |  STRING | Trade amount (in 1st ticker of pair) |

#### **Response example  ("**&#x64;eals.updat&#x65;**")**

```javascript
{
    "id": null,
    "method": "deals.update",
    "params": [
        "BTC_USDT",                           // market
        [
            {
                "id": 19201677141,            // ID
                "type": "sell",               // type
                "time": 1.727275412302E9,     // time
                "price": "63859.83136",       // price
                "amount": "0.0020744"         // amount
            },
            ...
            ]
    ]
}
```

### Deals Unsubscribe method

Used to unsubscribe from the [Deals Subscribe](#deals-subscribe-method) method.

#### Method

```javascript
deals.unsubscribe
```

#### Request example

```javascript
{
  "method":"deals.unsubscribe",
  "params":[],
  "id":2
}
```

#### Response example (successfully unsubscribed)

```javascript
{
    "id": 2,
    "params": [],
    "result": {
        "status": "success"
    },
    "error": null
}
```
