# Tron-Energy
Tron-Energy is a Python package that simplifies interaction with the [Tron energy](https://itrx.io/) 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:
```bash
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:
```python
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:
```python
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:
```python
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:
```bash
git clone https://github.com/Ephraim-Akolo/Tron-Energy
```
2. Navigate to the project directory:
```bash
cd TRON-ENERGY
```
3. Install the required dependencies:
```bash
pip install -r requirements.txt
```
4. Run the following command to test
```bash
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](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](https://develop.itrx.io/100-before.html). 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!
Raw data
{
"_id": null,
"home_page": null,
"name": "Tron-Energy",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.7",
"maintainer_email": null,
"keywords": "TRON-ENERGY, tronenergy",
"author": null,
"author_email": "Ephraim <ephraimakolo2017@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/36/dc/7a673e0a56d10c23ce9cbab4e031202f9f9341501ebf95fe4fa4f62d9e22/tron_energy-0.2.1.tar.gz",
"platform": null,
"description": "\n# Tron-Energy\n\nTron-Energy is a Python package that simplifies interaction with the [Tron energy](https://itrx.io/) 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.\n\n## Installation\n\nTo install the Tron-Energy package, run the command:\n\n```bash\npip install tron_energy\n```\n\n\nEnsure you have Python 3.6 or higher installed.\n\n## Usage\n\nTo use the Tron-Energy package, start by importing the necessary classes and creating an instance of the `TronEnergy` class.\n\nHere\u2019s an example of how you might use Tron-Energy to estimate the cost of an energy order and then place the order:\n\n```python\nfrom tron_energy import TronEnergy\n\n# Initialize the TronEnergy client\nclient = TronEnergy(api_key='your-api-key', api_secret='your-api-secret')\n\n# Retrieve public data\npublic_data = client.get_public_data()\nprint(public_data)\n\n# Estimate the cost of an energy order\nestimate = client.estimate_order(\n energy_amount=100_000,\n period='1H'\n)\nprint(estimate)\n\n# Place the energy order\norder_response = client.place_order(\n receive_address=\"TR7NHnXw5423f8j766h899234567890\",\n energy_amount=100_000,\n period='1H'\n)\nprint(order_response)\n```\n\n## Asynchronous Usage\n\nIn 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.\n\nHere\u2019s an example of how to use the asynchronous AsyncTronEnergy class:\n\n```python\nimport asyncio\nfrom tron_energy import AsyncTronEnergy\n\nasync def main():\n # Initialize the AsyncTronEnergy client\n client = AsyncTronEnergy(api_key='your-api-key', api_secret='your-api-secret')\n\n try:\n # Retrieve public data\n public_data = await client.get_public_data()\n print(public_data)\n\n # Estimate the cost of an energy order\n estimate = await client.estimate_order(\n energy_amount=100_000,\n period='1H'\n )\n print(estimate)\n\n # Place the energy order\n order_response = await client.place_order(\n receive_address=\"TR7NHnXw5423f8j766h899234567890\",\n energy_amount=100_000,\n period='1H'\n )\n print(order_response)\n finally:\n # Close the session to clean up resources\n await client.close()\n\n# Run the asynchronous main function\nasyncio.run(main())\n\n```\n\nOr use the Python context manager:\n\n```python\nimport asyncio\nfrom tron_energy import AsyncTronEnergy\n\nasync def main():\n # Initialize the AsyncTronEnergy client\n async with AsyncTronEnergy(api_key='your-api-key', api_secret='your-api-secret') as client:\n # Retrieve public data\n public_data = await client.get_public_data()\n print(public_data)\n\n # Estimate the cost of an energy order\n estimate = await client.estimate_order(\n energy_amount=100_000,\n period='1H'\n )\n print(estimate)\n\n # Place the energy order\n order_response = await client.place_order(\n receive_address=\"TR7NHnXw5423f8j766h899234567890\",\n energy_amount=100_000,\n period='1H'\n )\n print(order_response)\n\n# Run the asynchronous main function\nasyncio.run(main())\n\n```\n\n## Testing\n\nThe package includes unit tests to ensure that all functionalities work as expected. You can run the tests using the following command:\n\n1. Clone the repository:\n\n ```bash\n git clone https://github.com/Ephraim-Akolo/Tron-Energy\n ```\n\n2. Navigate to the project directory:\n\n ```bash\n cd TRON-ENERGY\n ```\n\n3. Install the required dependencies:\n\n ```bash\n pip install -r requirements.txt\n ```\n\n4. Run the following command to test\n ```bash\n python -m unittest\n ```\n\nThe tests cover various functionalities, including placing orders, estimating orders, and recycling orders. Mocking is used to simulate API responses.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.\n\n## Acknowledgements\n\nThis package was inspired by and partially based on the examples and guidelines in the [Tron Energy API Documentation](https://develop.itrx.io/100-before.html). We appreciate the comprehensive resources provided by the Tron Energy team.\n\n## Contributing\n\nContributions are welcome! If you have suggestions for improvements or new features, please open an issue or submit a pull request.\n\n---\n\nFeel free to reach out with any questions or feedback!\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A simple package to simplify interfacing with tron energy lending RESTful API",
"version": "0.2.1",
"project_urls": {
"homepage": "https://itrx.io/",
"repository": "https://github.com/Ephraim-Akolo/Tron-Energy"
},
"split_keywords": [
"tron-energy",
" tronenergy"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f720e48a66f309a515554d920cd7eee8dd0336a6df058e3d06d5f44e03f7eda0",
"md5": "dae005cfadbccbd0ea77a431d29a36ad",
"sha256": "04240646c9f7066612389b9786b55d2ecd506ef2f41eabf1dfd757ab28fc78f1"
},
"downloads": -1,
"filename": "Tron_Energy-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "dae005cfadbccbd0ea77a431d29a36ad",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.7",
"size": 9014,
"upload_time": "2024-09-09T18:17:21",
"upload_time_iso_8601": "2024-09-09T18:17:21.532284Z",
"url": "https://files.pythonhosted.org/packages/f7/20/e48a66f309a515554d920cd7eee8dd0336a6df058e3d06d5f44e03f7eda0/Tron_Energy-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "36dc7a673e0a56d10c23ce9cbab4e031202f9f9341501ebf95fe4fa4f62d9e22",
"md5": "8d432ffe05f263bac8caef19cbc6fd98",
"sha256": "3d4848364d50ba56552429ad31e94b30f4c10c3d4e4f4a237ad89f75e50c82b4"
},
"downloads": -1,
"filename": "tron_energy-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "8d432ffe05f263bac8caef19cbc6fd98",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.7",
"size": 12448,
"upload_time": "2024-09-09T18:17:22",
"upload_time_iso_8601": "2024-09-09T18:17:22.915598Z",
"url": "https://files.pythonhosted.org/packages/36/dc/7a673e0a56d10c23ce9cbab4e031202f9f9341501ebf95fe4fa4f62d9e22/tron_energy-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-09 18:17:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Ephraim-Akolo",
"github_project": "Tron-Energy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "aiohappyeyeballs",
"specs": [
[
"==",
"2.4.0"
]
]
},
{
"name": "aiohttp",
"specs": [
[
"==",
"3.10.5"
]
]
},
{
"name": "aiosignal",
"specs": [
[
"==",
"1.3.1"
]
]
},
{
"name": "async-timeout",
"specs": [
[
"==",
"4.0.3"
]
]
},
{
"name": "attrs",
"specs": [
[
"==",
"24.2.0"
]
]
},
{
"name": "backports.tarfile",
"specs": [
[
"==",
"1.2.0"
]
]
},
{
"name": "build",
"specs": [
[
"==",
"1.2.1"
]
]
},
{
"name": "certifi",
"specs": [
[
"==",
"2024.8.30"
]
]
},
{
"name": "cffi",
"specs": [
[
"==",
"1.17.0"
]
]
},
{
"name": "charset-normalizer",
"specs": [
[
"==",
"3.3.2"
]
]
},
{
"name": "cryptography",
"specs": [
[
"==",
"43.0.1"
]
]
},
{
"name": "docutils",
"specs": [
[
"==",
"0.21.2"
]
]
},
{
"name": "frozenlist",
"specs": [
[
"==",
"1.4.1"
]
]
},
{
"name": "idna",
"specs": [
[
"==",
"3.8"
]
]
},
{
"name": "importlib_metadata",
"specs": [
[
"==",
"8.4.0"
]
]
},
{
"name": "jaraco.classes",
"specs": [
[
"==",
"3.4.0"
]
]
},
{
"name": "jaraco.context",
"specs": [
[
"==",
"6.0.1"
]
]
},
{
"name": "jaraco.functools",
"specs": [
[
"==",
"4.0.2"
]
]
},
{
"name": "jeepney",
"specs": [
[
"==",
"0.8.0"
]
]
},
{
"name": "keyring",
"specs": [
[
"==",
"25.3.0"
]
]
},
{
"name": "markdown-it-py",
"specs": [
[
"==",
"3.0.0"
]
]
},
{
"name": "mdurl",
"specs": [
[
"==",
"0.1.2"
]
]
},
{
"name": "more-itertools",
"specs": [
[
"==",
"10.4.0"
]
]
},
{
"name": "multidict",
"specs": [
[
"==",
"6.0.5"
]
]
},
{
"name": "nh3",
"specs": [
[
"==",
"0.2.18"
]
]
},
{
"name": "packaging",
"specs": [
[
"==",
"24.1"
]
]
},
{
"name": "pkginfo",
"specs": [
[
"==",
"1.10.0"
]
]
},
{
"name": "pycparser",
"specs": [
[
"==",
"2.22"
]
]
},
{
"name": "Pygments",
"specs": [
[
"==",
"2.18.0"
]
]
},
{
"name": "pyproject_hooks",
"specs": [
[
"==",
"1.1.0"
]
]
},
{
"name": "readme_renderer",
"specs": [
[
"==",
"44.0"
]
]
},
{
"name": "requests",
"specs": [
[
"==",
"2.32.3"
]
]
},
{
"name": "requests-toolbelt",
"specs": [
[
"==",
"1.0.0"
]
]
},
{
"name": "rfc3986",
"specs": [
[
"==",
"2.0.0"
]
]
},
{
"name": "rich",
"specs": [
[
"==",
"13.8.0"
]
]
},
{
"name": "SecretStorage",
"specs": [
[
"==",
"3.3.3"
]
]
},
{
"name": "tomli",
"specs": [
[
"==",
"2.0.1"
]
]
},
{
"name": "twine",
"specs": [
[
"==",
"5.1.1"
]
]
},
{
"name": "urllib3",
"specs": [
[
"==",
"2.2.2"
]
]
},
{
"name": "yarl",
"specs": [
[
"==",
"1.9.6"
]
]
},
{
"name": "zipp",
"specs": [
[
"==",
"3.20.1"
]
]
}
],
"lcname": "tron-energy"
}