# API Overview

### 1. Introduction

CatFee.IO offers a secure and standardized API for efficient access to its resources. With this API, users can perform various operations such as creating orders, querying accounts, and more. All requests must be signed to ensure their authenticity and security.

📢 **Subscribe to the CatFee Telegram Channel for updates**\
<https://t.me/CatFeeOfficial>

***

### 2. Apply for API <a href="#apply-api-info" id="apply-api-info"></a>

After registering and logging in to CatFee, go to the **User Center**, click on the **"API"** menu on the right, and select **"API Settings"**. On this page, you can:

* View your **API Key** and **API Secret**
* Set an **IP Whitelist** to restrict access to your API, enhancing security and preventing potential losses due to API key leakage

Please keep your API credentials secure and enable IP whitelisting to protect your account and assets.

***

### 3. Base URL Description

CatFee provides both a **production environment** and a **Nile test environment**, allowing developers to choose according to their specific needs.

⚠️ **Note:** The account systems and API Keys for these two environments are completely separate and not interchangeable. You must register and obtain them independently.

#### Environment Details

| Item              | Production Environment                                                   | Test Environment (Nile)                                            |
| ----------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------ |
| Website           | <https://catfee.io>                                                      | <https://nile.catfee.io>                                           |
| API Base URL      | <https://api.catfee.io>                                                  | <https://nile.catfee.io>                                           |
| API Key / Secret  | Obtain from **User Center → API** after registering a production account | Obtain from **User Center → API** after registering a test account |
| TRON Explorer     | <https://tronscan.org>                                                   | <https://nile.tronscan.org>                                        |
| Test Token Faucet | Not required                                                             | <https://nileex.io/join/getJoinPage> (up to 2000 TRX daily)        |

***

#### Usage Guidelines

**1. Environment Selection**

* For **production deployment or mainnet usage**, use:\
  `https://api.catfee.io`
* For **local development or testing**, use:\
  `https://nile.catfee.io`

**2. Account & API Key Registration**

* Production and test environments require **separate account registrations**
* Their **data and API keys are not shared**
* After registration, retrieve your **API Key and Secret** from the corresponding environment’s User Center

**3. Test Token (TRX) Acquisition**

* Visit the Nile faucet to obtain test TRX
* You can receive up to **2000 TRX per day**
* After receiving tokens, verify balances and transactions via the Nile TRON explorer

***

### 4. Signature Mechanism

To ensure secure API access, CatFee.IO uses **HMAC-SHA256** signatures for authentication. Each request must include a valid signature to confirm it has not been tampered with and is authorized.

***

### 5. How to Generate a Signature

**5.1 Signature String Concatenation**

The signature string is constructed by concatenating the following:

```
sign = timestamp + method + requestPath
```

* **timestamp**: The current ISO 8601 UTC time, e.g., `2023-08-26T12:34:56.789Z`
* **method**: The HTTP method, such as `GET`, `POST`, `PUT`, or `DELETE`
* **requestPath**: The API endpoint path, **including query parameters** if present.\
  Example:\
  `/v1/order?quantity=65000&receiver=TRON_ADDRESS&duration=1h`

> ⚠️ *Note: Query parameters must be included in the `requestPath`.*

**5.2 Signature Generation Steps**

1. Concatenate `timestamp + method + requestPath`
2. Use HMAC-SHA256 to encrypt the string with your API Secret as the key
3. Encode the result using **Base64** to produce the final signature

**5.3 Example**

Given:

```
timestamp = 2023-08-26T12:34:56.789Z
method = POST
requestPath = /v1/order?quantity=65000&receiver=TRON_ADDRESS&duration=1h
```

The string to sign is:

```
2023-08-26T12:34:56.789ZPOST/v1/order?quantity=65000&receiver=TRON_ADDRESS&duration=1h
```

Apply HMAC-SHA256 using your API Secret, then Base64 encode the result to generate the signature.

***

### 6. Required HTTP Headers

Each request must include the following headers:

```
Content-Type: application/json
CF-ACCESS-KEY: your_api_key
CF-ACCESS-SIGN: generated_signature
CF-ACCESS-TIMESTAMP: timestamp_in_ISO_8601
```

***

### 7. Request Examples

**7.1 POST Request Example**

Let’s say you want to **buy energy** by creating an order using the following parameters:

```
quantity = 65000
receiver = TRON_ADDRESS
duration = 1h
```

The request URL would be:

```
https://api.catfee.io/v1/order?quantity=65000&receiver=TRON_ADDRESS&duration=1h
```

Headers:

```
Content-Type: application/json
CF-ACCESS-KEY: your_api_key
CF-ACCESS-SIGN: generated_signature
CF-ACCESS-TIMESTAMP: 2023-08-26T12:34:56.789Z
```

***

**7.2 GET Request Example**

If you want to query configuration information (no parameters), the request URL is:

```
https://api.catfee.io/v1/account
```

Headers:

```
Content-Type: application/json
CF-ACCESS-KEY: your_api_key
CF-ACCESS-SIGN: generated_signature
CF-ACCESS-TIMESTAMP: 2023-08-26T12:34:56.789Z
```

***

### 8. Response Format

All responses follow a standard structure:

```json
{
  "code": "0",
  "msg": "",
  "data": {
    "key": "value"
  }
}
```

* **code**: `"0"` means the request was successful
* **msg**: Message or error description
* **data**: Actual result payload (typically a JSON object with key-value pairs)

<table data-column-title-hidden data-view="cards" data-full-width="true"><thead><tr><th></th><th data-hidden></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Java API Example</strong></td><td><strong>Java调用示例</strong></td><td></td><td></td><td><a href="/pages/Z5vtRHg20W3TdmY7YcPv">/pages/Z5vtRHg20W3TdmY7YcPv</a></td></tr><tr><td><strong>Python Example</strong></td><td><strong>Python调用示例</strong></td><td></td><td></td><td><a href="/pages/B1L9YeRGdOSu0KCct3fP">/pages/B1L9YeRGdOSu0KCct3fP</a></td></tr><tr><td><strong>PHP Example</strong></td><td><strong>PHP调用示例</strong></td><td></td><td></td><td><a href="/pages/p2S9v6TZfr92IrBiypZQ">/pages/p2S9v6TZfr92IrBiypZQ</a></td></tr><tr><td><strong>Node.js Example</strong></td><td>Node.js调用示例</td><td></td><td></td><td><a href="/pages/Aou1f9rB1IjJpeLEacVT">/pages/Aou1f9rB1IjJpeLEacVT</a></td></tr><tr><td><strong>Go Example</strong></td><td>Go 调用示例</td><td></td><td></td><td><a href="/pages/DHLS7Qz9gR79dJKTwhGb">/pages/DHLS7Qz9gR79dJKTwhGb</a></td></tr></tbody></table>


---

# 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.catfee.io/en/getting-started/buy-energy-via-api-on-catfee/api-overview.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.
