Skip to main content

Tron-Energy

Tron-Energy is a Python package that simplifies 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.

Installation

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

pip install tron_energy

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.

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 tron_energy import TronEnergy

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

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

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

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

Asynchronous Usage

In addition to the synchronous interface, Tron-Energy provides an asynchronous version for applications requiring non-blocking I/O operations. The asynchronous class, AsyncTronEnergy, allows you to make API requests without blocking your event loop.

Here’s an example of how to use the asynchronous AsyncTronEnergy class:

import asyncio
from tron_energy import AsyncTronEnergy

async def main():
    # Initialize the AsyncTronEnergy client
    client = AsyncTronEnergy(api_key='your-api-key', api_secret='your-api-secret')

    try:
        # Retrieve public data
        public_data = await client.get_public_data()
        print(public_data)

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

        # Place the energy order
        order_response = await client.place_order(
            receive_address="TR7NHnXw5423f8j766h899234567890",
            energy_amount=100_000,
            period='1H'
        )
        print(order_response)
    finally:
        # Close the session to clean up resources
        await client.close()

# Run the asynchronous main function
asyncio.run(main())

Or use the Python context manager:

import asyncio
from tron_energy import AsyncTronEnergy

async def main():
    # Initialize the AsyncTronEnergy client
    async with AsyncTronEnergy(api_key='your-api-key', api_secret='your-api-secret') as client:
        # Retrieve public data
        public_data = await client.get_public_data()
        print(public_data)

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

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

# Run the asynchronous main function
asyncio.run(main())

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!

Metadata

Release files for Tron-Energy 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Tron-Energy 0.2.1
File Size Uploaded
tron_energy-0.2.1.tar.gz 12.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Tron-Energy 0.2.1
File Interpreter ABI Platform
Tron_Energy-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.5 kB

Release files / tron_energy-0.2.1.tar.gz

Download URL tron_energy-0.2.1.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3d4848364d50ba56552429ad31e94b30f4c10c3d4e4f4a237ad89f75e50c82b4
BLAKE2b-256 checksum
How to use checksums
36dc7a673e0a56d10c23ce9cbab4e031202f9f9341501ebf95fe4fa4f62d9e22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / Tron_Energy-0.2.1-py3-none-any.whl

Download URL Tron_Energy-0.2.1-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04240646c9f7066612389b9786b55d2ecd506ef2f41eabf1dfd757ab28fc78f1
BLAKE2b-256 checksum
How to use checksums
f720e48a66f309a515554d920cd7eee8dd0336a6df058e3d06d5f44e03f7eda0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.5

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page