Python Guide for Calling Mefree.NET API

This guide demonstrates how to use Python to interact with the Mefree.NET API, including signature generation, HTTP request construction, and example API calls.


1. Overview of the Signature Rules

1.1 Signature String Rules

Mefree.NET API requires requests to be signed for authentication. Follow these rules to generate the signature:

  1. Construct the String to Sign:

    sign = timestamp + method + requestPath
    • timestamp: UTC time in ISO 8601 format, e.g., 2024-11-26T12:34:56.789Z.

    • method: HTTP method, e.g., GET or POST.

    • requestPath: API request path (including query parameters), such as:

      • /api/config

      • /api/order?quantity=65000&target_address=TRON_ADDRESS&period=1

  2. Generate the Signature:

    • Use the HMAC-SHA256 algorithm with the Secret Key to hash the string.

    • Encode the resulting hash with Base64 to generate the final signature.


1.2 Required HTTP Headers

Each request must include the following headers:

  • Content-Type: application/json

  • MF-ACCESS-KEY: Your API Key.

  • MF-ACCESS-SIGN: The generated signature.

  • MF-ACCESS-TIMESTAMP: Current UTC timestamp.


2. Environment Setup

Ensure you have Python 3.6+ installed. Install the required libraries using:


3. Signature Generation Function

Below is the Python implementation for generating the signature:


4. Sending HTTP Requests

You can use the requests library to send HTTP requests with the required headers.


5. Example API Calls

5.1 Get Account Information

API Endpoint: /api/config HTTP Method: GET

Code Example:


5.2 Create an Order

API Endpoint: /api/order?quantity=65000&target_address=TRON_ADDRESS&period=1 HTTP Method: POST

Code Example:


5.3 Query Order Status

API Endpoint: /api/order/{pay_hash} HTTP Method: GET

Code Example:


6. Common Issues

6.1 Invalid Signature (401 Unauthorized)

  • Ensure the MF-ACCESS-KEY matches your API Key.

  • Verify the signature generation logic:

    • Concatenate the string in the correct order: timestamp + method + requestPath.

    • Use the correct SECRET_KEY.

  • Ensure the timestamp is in UTC format and not older than 5 seconds.

6.2 Bad Request (400)

  • Verify the request path and query parameters are correct.

  • Ensure Content-Type is set to application/json.

6.3 Too Many Requests (429)

  • Respect the API rate limits. Implement request throttling if necessary.


7. Summary

This guide covers Python implementation for calling Mefree.NET API. It includes signature generation, HTTP request construction, and example usage. By following this guide, you can easily integrate Mefree.NET API into your Python applications. For further support, contact Mefree technical support or consult the official API documentation.

Last updated