Name | async-hyperliquid JSON |
Version |
0.2.3
JSON |
| download |
home_page | https://github.com/oneforalone/async-hyperliquid |
Summary | Async Hyperliquid client using aiohttp |
upload_time | 2025-08-07 11:49:52 |
maintainer | None |
docs_url | None |
author | Yuki |
requires_python | <4,>=3.10 |
license | MIT License
Copyright (c) 2024 async-hyperliquid
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
|
keywords |
dex
hyperliquid
async
aiohttp
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Async Hyperliquid
An asynchronous Python client for interacting with the Hyperliquid API using `aiohttp`.
## Overview
This library provides an easy-to-use asynchronous interface for the Hyperliquid cryptocurrency exchange, supporting both mainnet and testnet environments. It handles API interactions, request signing, and data processing for both perpetual futures and spot trading.
## Features
- Asynchronous API communication using `aiohttp`
- Support for both mainnet and testnet environments
- Message signing for authenticated endpoints
- Trading operations for both perpetual futures and spot markets
- Comprehensive type hints for better IDE integration
## Installation
```bash
# Using pip
pip install async-hyperliquid
# Using Poetry
poetry add async-hyperliquid
# Using uv
uv add async-hyperliquid
```
## Quick Start
```python
import asyncio
import os
from async_hyperliquid.async_hyper import AsyncHyper
async def main():
# Initialize the client
address = os.getenv("HYPER_ADDRESS")
api_key = os.getenv("HYPER_API_KEY")
# Test on testnet
client = AsyncHyper(address, api_key, is_mainnet=False)
# Place a market order
response = await client.place_order(
coin="BTC",
is_buy=True,
sz=0.001,
px=0, # For market orders, price is ignored
is_market=True
)
print(response)
# Clean up
await client.close()
if __name__ == "__main__":
asyncio.run(main())
```
Or if you perfer context way:
```python
import asyncio
import os
from async_hyperliquid.async_hyper import AsyncHyper
async def main():
# Initialize the client
address = os.getenv("HYPER_ADDRESS")
api_key = os.getenv("HYPER_API_KEY")
# Test on testnet
async with AsyncHyper(address, api_key, is_mannet=False) as client:
# place an market order open a BTC Long position
resp = await client.place_order(coin="BTC", is_buy=True, sz=0.0001, px=0, is_market=True)
print(resp)
if __name__ == "__main__":
asyncio.run(main())
```
### Place TP/SL orders
```python
coin = "BTC"
is_buy = True
sz = 0.001
px = 105_000
tp_px = px + 5_000
sl_px = px - 5_000
o1 = {
"coin": coin,
"is_buy": is_buy,
"sz": sz,
"px": px,
"ro": False,
"order_type": LimitOrder.ALO.value,
}
# Take profit
tp_order_type = {
"trigger": {"isMarket": False, "triggerPx": tp_px, "tpsl": "tp"}
}
o2 = {
"coin": coin,
"is_buy": not is_buy,
"sz": sz,
"px": px,
"ro": True,
"order_type": tp_order_type,
}
# Stop loss
sl_order_type = {
"trigger": {"isMarket": False, "triggerPx": sl_px, "tpsl": "sl"}
}
o3 = {
"coin": coin,
"is_buy": not is_buy,
"sz": sz,
"px": px,
"ro": True,
"order_type": sl_order_type,
}
# Place a market order to open position
resp = await client.batch_place_orders([o1], is_market=True)
print("\nBatch place market orders response: ", resp)
assert resp["status"] == "ok"
# Position TP/SL orders: position must be opened, otherwise it would failed
orders = [o2, o3]
resp = await client.batch_place_orders(orders, grouping="positionTpsl")
print("Batch place orders with 'positionTpsl' response: ", resp)
assert resp["status"] == "ok"
# Close all positions
resp = await client.close_all_positions()
print("Close all positions response: ", resp)
assert resp["status"] == "ok"
# Normal TP/SL orders: main order and tp/sl must exists, each coin's normal
# TP/SL orders can not batch with other coins', i.e. one coin one request.
orders = [o1, o2, o3]
resp = await client.batch_place_orders(orders, grouping="normalTpsl")
print("Batch place orders with 'normalTpsl' response: ", resp)
# Retrieve user opened orders
orders = await client.get_user_open_orders(is_frontend=True)
cancels = []
for o in orders:
coin = o["coin"]
oid = o["oid"]
cancels.append((coin, oid))
resp = await client.batch_cancel_orders(cancels)
print("Batch cancel orders response: ", resp)
```
For detailed usage, please check the test cases under `test/` directory.
## Environment Variables
Create a `.env.local` file with the following variables:
```
HYPER_ADDRESS=your_ethereum_address
HYPER_API_KEY=your_ethereum_private_key or api key generate hyperliquid website
```
## Testing
Tests use pytest and pytest-asyncio. To run tests:
```bash
uv pip install -e .
# Run all tests
pytest
# Run with coverage
pytest --cov=async_hyperliquid
```
## License
MIT
## Acknowledgements
This library is a community-developed project and is not officially affiliated with Hyperliquid.
Raw data
{
"_id": null,
"home_page": "https://github.com/oneforalone/async-hyperliquid",
"name": "async-hyperliquid",
"maintainer": null,
"docs_url": null,
"requires_python": "<4,>=3.10",
"maintainer_email": null,
"keywords": "DEX, hyperliquid, async, aiohttp",
"author": "Yuki",
"author_email": "oneforalone@proton.me",
"download_url": "https://files.pythonhosted.org/packages/56/81/9f13b5455ba33e8f9c12f71ab3169b529dee0c70fa7f303c5de118069480/async_hyperliquid-0.2.3.tar.gz",
"platform": null,
"description": "# Async Hyperliquid\n\nAn asynchronous Python client for interacting with the Hyperliquid API using `aiohttp`.\n\n## Overview\n\nThis library provides an easy-to-use asynchronous interface for the Hyperliquid cryptocurrency exchange, supporting both mainnet and testnet environments. It handles API interactions, request signing, and data processing for both perpetual futures and spot trading.\n\n## Features\n\n- Asynchronous API communication using `aiohttp`\n- Support for both mainnet and testnet environments\n- Message signing for authenticated endpoints\n- Trading operations for both perpetual futures and spot markets\n- Comprehensive type hints for better IDE integration\n\n## Installation\n\n```bash\n# Using pip\npip install async-hyperliquid\n\n# Using Poetry\npoetry add async-hyperliquid\n\n# Using uv\nuv add async-hyperliquid\n```\n\n## Quick Start\n\n```python\nimport asyncio\nimport os\nfrom async_hyperliquid.async_hyper import AsyncHyper\n\nasync def main():\n # Initialize the client\n address = os.getenv(\"HYPER_ADDRESS\")\n api_key = os.getenv(\"HYPER_API_KEY\")\n # Test on testnet\n client = AsyncHyper(address, api_key, is_mainnet=False)\n\n # Place a market order\n response = await client.place_order(\n coin=\"BTC\",\n is_buy=True,\n sz=0.001,\n px=0, # For market orders, price is ignored\n is_market=True\n )\n\n print(response)\n\n # Clean up\n await client.close()\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\nOr if you perfer context way:\n\n```python\nimport asyncio\nimport os\nfrom async_hyperliquid.async_hyper import AsyncHyper\n\nasync def main():\n # Initialize the client\n address = os.getenv(\"HYPER_ADDRESS\")\n api_key = os.getenv(\"HYPER_API_KEY\")\n # Test on testnet\n async with AsyncHyper(address, api_key, is_mannet=False) as client:\n # place an market order open a BTC Long position\n resp = await client.place_order(coin=\"BTC\", is_buy=True, sz=0.0001, px=0, is_market=True)\n print(resp)\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n\n```\n\n### Place TP/SL orders\n\n```python\n coin = \"BTC\"\n is_buy = True\n sz = 0.001\n px = 105_000\n tp_px = px + 5_000\n sl_px = px - 5_000\n o1 = {\n \"coin\": coin,\n \"is_buy\": is_buy,\n \"sz\": sz,\n \"px\": px,\n \"ro\": False,\n \"order_type\": LimitOrder.ALO.value,\n }\n # Take profit\n tp_order_type = {\n \"trigger\": {\"isMarket\": False, \"triggerPx\": tp_px, \"tpsl\": \"tp\"}\n }\n o2 = {\n \"coin\": coin,\n \"is_buy\": not is_buy,\n \"sz\": sz,\n \"px\": px,\n \"ro\": True,\n \"order_type\": tp_order_type,\n }\n # Stop loss\n sl_order_type = {\n \"trigger\": {\"isMarket\": False, \"triggerPx\": sl_px, \"tpsl\": \"sl\"}\n }\n o3 = {\n \"coin\": coin,\n \"is_buy\": not is_buy,\n \"sz\": sz,\n \"px\": px,\n \"ro\": True,\n \"order_type\": sl_order_type,\n }\n\n # Place a market order to open position\n resp = await client.batch_place_orders([o1], is_market=True)\n print(\"\\nBatch place market orders response: \", resp)\n assert resp[\"status\"] == \"ok\"\n\n # Position TP/SL orders: position must be opened, otherwise it would failed\n orders = [o2, o3]\n resp = await client.batch_place_orders(orders, grouping=\"positionTpsl\")\n print(\"Batch place orders with 'positionTpsl' response: \", resp)\n assert resp[\"status\"] == \"ok\"\n\n # Close all positions\n resp = await client.close_all_positions()\n print(\"Close all positions response: \", resp)\n assert resp[\"status\"] == \"ok\"\n\n # Normal TP/SL orders: main order and tp/sl must exists, each coin's normal\n # TP/SL orders can not batch with other coins', i.e. one coin one request.\n orders = [o1, o2, o3]\n resp = await client.batch_place_orders(orders, grouping=\"normalTpsl\")\n print(\"Batch place orders with 'normalTpsl' response: \", resp)\n\n # Retrieve user opened orders\n orders = await client.get_user_open_orders(is_frontend=True)\n cancels = []\n for o in orders:\n coin = o[\"coin\"]\n oid = o[\"oid\"]\n cancels.append((coin, oid))\n resp = await client.batch_cancel_orders(cancels)\n print(\"Batch cancel orders response: \", resp)\n```\n\nFor detailed usage, please check the test cases under `test/` directory.\n\n## Environment Variables\n\nCreate a `.env.local` file with the following variables:\n\n```\nHYPER_ADDRESS=your_ethereum_address\nHYPER_API_KEY=your_ethereum_private_key or api key generate hyperliquid website\n```\n\n## Testing\n\nTests use pytest and pytest-asyncio. To run tests:\n\n```bash\nuv pip install -e .\n\n# Run all tests\npytest\n\n# Run with coverage\npytest --cov=async_hyperliquid\n```\n\n## License\n\nMIT\n\n## Acknowledgements\n\nThis library is a community-developed project and is not officially affiliated with Hyperliquid.\n",
"bugtrack_url": null,
"license": "MIT License\n\nCopyright (c) 2024 async-hyperliquid\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
"summary": "Async Hyperliquid client using aiohttp",
"version": "0.2.3",
"project_urls": {
"Changelog": "https://github.com/oneforalone/async-hyperliquid/blob/master/CHANGELOG.md",
"Documentation": "https://github.com/oneforalone/async-hyperliquid",
"Homepage": "https://github.com/oneforalone/async-hyperliquid",
"Issues": "https://github.com/oneforalone/async-hyperliquid/issues",
"Repository": "https://github.com/oneforalone/async-hyperliquid"
},
"split_keywords": [
"dex",
" hyperliquid",
" async",
" aiohttp"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e196f5f6d185a113a1904565993feb89aee1fc1ef1cad0e2cb0cd4924c66404c",
"md5": "c1520e823e864bfc01ae87c2038c84ea",
"sha256": "d080bb14cf43ead42abe1705794c6a5a4b4ac83eb1f0f85753d8981f6161ca63"
},
"downloads": -1,
"filename": "async_hyperliquid-0.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c1520e823e864bfc01ae87c2038c84ea",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4,>=3.10",
"size": 18182,
"upload_time": "2025-08-07T11:49:50",
"upload_time_iso_8601": "2025-08-07T11:49:50.934458Z",
"url": "https://files.pythonhosted.org/packages/e1/96/f5f6d185a113a1904565993feb89aee1fc1ef1cad0e2cb0cd4924c66404c/async_hyperliquid-0.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "56819f13b5455ba33e8f9c12f71ab3169b529dee0c70fa7f303c5de118069480",
"md5": "a8c2120e9f38a0b9fe648ecfb90fdd71",
"sha256": "12e18ec6246d11ead55be35108a166d5c44036f1ced72d08d592dfea6ef4c499"
},
"downloads": -1,
"filename": "async_hyperliquid-0.2.3.tar.gz",
"has_sig": false,
"md5_digest": "a8c2120e9f38a0b9fe648ecfb90fdd71",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4,>=3.10",
"size": 16342,
"upload_time": "2025-08-07T11:49:52",
"upload_time_iso_8601": "2025-08-07T11:49:52.512968Z",
"url": "https://files.pythonhosted.org/packages/56/81/9f13b5455ba33e8f9c12f71ab3169b529dee0c70fa7f303c5de118069480/async_hyperliquid-0.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-07 11:49:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "oneforalone",
"github_project": "async-hyperliquid",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "async-hyperliquid"
}