Golang Guide for calling Mefree.NET API
This guide provides detailed instructions on how to use Go (Golang) to interact with the Mefree.NET API, including generating signatures, building requests, and handling API responses.
1. Signature Rules Overview
Mefree.NET API uses a signature-based authentication mechanism. The signature is generated as follows:
1.1 Signature String Rules
The signature string is constructed in the following format:
timestamp: UTC time in ISO 8601 format (e.g.,
2024-11-26T12:34:56.789Z
).method: HTTP method, such as
GET
orPOST
.requestPath: API request path (including query parameters), for example:
/api/config
/api/order?quantity=65000&target_address=TRON_ADDRESS&period=1
1.2 Signature Generation Process
Concatenate
timestamp
,method
, andrequestPath
into a string.Use the HMAC-SHA256 algorithm to hash the concatenated string with your API Secret Key.
Encode the resulting hash using Base64 to generate the signature.
1.3 Required HTTP Headers
Each API 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. Implementing Signature in Go
2.1 Signature Generation Function
Here’s how to generate the signature in Go:
3. Constructing API Requests
3.1 Configuration
Define your API configuration:
3.2 General HTTP Request Function
Here’s a reusable function to make API requests:
4. API Call Examples
4.1 Fetch Account Information
Endpoint: /api/config
HTTP Method: GET
Code Example:
4.2 Create an Order
Endpoint: /api/order?quantity=65000&target_address=TRON_ADDRESS&period=1
HTTP Method: POST
Code Example:
4.3 Check Order Status
Endpoint: /api/order/{pay_hash}
HTTP Method: GET
Code Example:
5. Common Issues
5.1 Invalid Signature (401 Unauthorized)
Verify that
MF-ACCESS-KEY
matches your API Key.Ensure the signature string follows the format:
timestamp + method + requestPath
.Use the correct Secret Key to generate the signature.
Ensure the timestamp is in UTC and formatted correctly (e.g.,
2024-11-26T12:34:56.789Z
).
5.2 Invalid Parameters (400 Bad Request)
Double-check the request path and query parameters.
Ensure the
Content-Type
header is set toapplication/json
.
5.3 Rate Limit Exceeded (429 Too Many Requests)
Mefree API enforces rate limits. Avoid sending excessive requests within a short period.
Add delays or throttle requests (e.g., no more than 2 requests per second).
6. Conclusion
This guide demonstrates how to interact with the Mefree.NET API using Go, including generating signatures, sending requests, and handling responses. For critical operations, such as placing orders, it is recommended to implement retry mechanisms for better reliability. If you encounter any issues, contact Mefree's official support team for assistance.
Last updated