Skip to main content

A simple package to simplify interfacing with tron energy lending RESTful API

Project description

Tron-Energy

Tron-Energy is a Python package designed to simplify interaction with the Tron energy lending RESTful API. It provides a clean and easy-to-use interface for placing energy orders, estimating costs, and managing your API usage on the Tron network. The package ensures secure communication with the API by handling signature creation and request authentication.

Features

  • Retrieve public data from the TronEnergy API.
  • Place energy orders with customizable parameters.
  • Estimate the cost of energy orders before placing them.
  • Manage and monitor API usage effectively.
  • Secure API requests with HMAC-based signature verification.

Installation

To install the Tron-Energy package, run the command:

pip install tronenergy

Ensure you have Python 3.6 or higher installed.

Usage

To use the Tron-Energy package, start by importing the necessary classes and creating an instance of the TronEnergy class:

from tronenergy import TronEnergy

# Create an instance of TronEnergy
tron_energy = TronEnergy(api_key='your-api-key', api_secret='your-api-secret')

# Retrieve public data
public_data = tron_energy.get_public_data()
print(public_data)

# Place an energy order
order_response = tron_energy.place_order(
    receive_address="TR7NHnXw5423f8j766h899234567890",
    energy_amount=100_000
)
print(order_response)

Example

Here’s an example of how you might use Tron-Energy to estimate the cost of an energy order and then place the order:

from tronenergy import TronEnergy

# Initialize the TronEnergy client
tron_energy = TronEnergy(api_key='your-api-key', api_secret='your-api-secret')

# Estimate the cost of an energy order
estimate = tron_energy.estimate_order(
    energy_amount=100_000,
    period='1H'
)
print(estimate)

# Place the energy order
order_response = tron_energy.place_order(
    receive_address="TR7NHnXw5423f8j766h899234567890",
    energy_amount=100_000,
    period='1H'
)
print(order_response)

API Reference

TronEnergy

  • __init__(self, api_key: str, api_secret: str)

    • Initializes the TronEnergy object with the given API key and secret.
  • get_public_data(self) -> dict

    • Retrieves public data from the TronEnergy API.
  • place_order(self, receive_address: TronAddress, energy_amount: int, period: str = '1H', out_trade_no: str = None, callback_url: str = None) -> dict

    • Places an energy order on the TronEnergy API.
  • make_request(self, method: str, url: str, data: dict = None) -> dict

    • Makes a request to the TronEnergy API.
  • verify_signature(self, signature: str, timestamp: str, data: dict) -> bool

    • Verifies the authenticity of a signature.

Testing

The package includes unit tests to ensure that all functionalities work as expected. You can run the tests using the following command:

  1. Clone the repository:

    git clone https://github.com/Ephraim-Akolo/Tron-Energy
    
  2. Navigate to the project directory:

    cd TRON-ENERGY
    
  3. Install the required dependencies:

    pip install -r requirements.txt
    
  4. Run the following command to test

    python -m unittest
    

The tests cover various functionalities, including placing orders, estimating orders, and recycling orders. Mocking is used to simulate API responses.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Acknowledgements

This package was inspired by and partially based on the examples and guidelines in the Tron Energy API Documentation. We appreciate the comprehensive resources provided by the Tron Energy team.

Contributing

Contributions are welcome! If you have suggestions for improvements or new features, please open an issue or submit a pull request.


Feel free to reach out with any questions or feedback!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tron_energy-0.1.2.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

Tron_Energy-0.1.2-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file tron_energy-0.1.2.tar.gz.

File metadata

  • Download URL: tron_energy-0.1.2.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for tron_energy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b2e2162f63c33f8488c01f687b9d9f1574ad6dfe3fd9b5417ec15860211f53ec
MD5 d741dc6df6ecbfc4b1a1ca19ef14f30e
BLAKE2b-256 c8e6b510ab79ae41eeac41c6176d58bf638378af5327068cdfaa68e35c4597dc

See more details on using hashes here.

File details

Details for the file Tron_Energy-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: Tron_Energy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for Tron_Energy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 211c8c861c546d3f3722dd94826f950ee91d2438f749ac83933ab7420aa1577a
MD5 3b5cee055d4b530776e5b0805149b95c
BLAKE2b-256 ea118e57dc6b871f13ea2aab7889959383dd744f4f56bb5d1cefcb9ee59fc0d8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page