-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2141 from earlyvibz/feature/plugin-hyperliquid
feat: plugin-hyperliquid
- Loading branch information
Showing
14 changed files
with
832 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
* | ||
|
||
!dist/** | ||
!package.json | ||
!readme.md | ||
!tsup.config.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# Hyperliquid Plugin for Eliza | ||
|
||
This plugin enables interaction with the Hyperliquid DEX through Eliza, providing spot trading capabilities. | ||
|
||
## Features | ||
|
||
- 💱 Spot Trading | ||
- Market orders (immediate execution) | ||
- Limit orders (price-specific) | ||
- Smart price validation to prevent mistakes | ||
- 📊 Price Checking | ||
- Real-time price information | ||
- 24h price change | ||
- Volume statistics | ||
- 🔄 Order Management | ||
- Cancel all open orders | ||
- Clear feedback on execution | ||
|
||
## Installation | ||
|
||
Add the plugin to your Eliza configuration: | ||
|
||
```json | ||
{ | ||
"plugins": ["@elizaos/plugin-hyperliquid"] | ||
} | ||
``` | ||
|
||
## Configuration | ||
|
||
Set the following environment variables: | ||
|
||
```env | ||
HYPERLIQUID_PRIVATE_KEY=your_private_key # Required for trading and cancelling orders | ||
HYPERLIQUID_TESTNET=true_or_false # Optional, defaults to false | ||
``` | ||
|
||
## Available Actions | ||
|
||
### 1. SPOT_TRADE | ||
|
||
Place spot market or limit orders. | ||
|
||
Examples: | ||
|
||
``` | ||
# Market Orders | ||
"buy 1 PIP" -> Buys 1 PIP at market price | ||
"sell 2 HYPE" -> Sells 2 HYPE at market price | ||
"market buy 1 ETH" -> Buys 1 ETH at market price | ||
# Limit Orders | ||
"buy 1 PIP at 20 USDC" -> Places buy order for 1 PIP at 20 USDC | ||
"sell 0.5 HYPE at 21 USDC" -> Places sell order for 0.5 HYPE at 21 USDC | ||
``` | ||
|
||
### 2. PRICE_CHECK | ||
|
||
Get current price information for any token. | ||
|
||
Examples: | ||
|
||
``` | ||
"What's the price of PIP?" | ||
"Check HYPE price" | ||
"Get ETH price" | ||
``` | ||
|
||
Returns: Current price, 24h change, and volume. | ||
|
||
### 3. CANCEL_ORDERS | ||
|
||
Cancel all your open orders. | ||
|
||
Examples: | ||
|
||
``` | ||
"Cancel all orders" | ||
"Cancel my orders" | ||
``` | ||
|
||
## Price Validation | ||
|
||
The plugin includes smart price validation to prevent mistakes: | ||
|
||
- Market Orders: Validates price is within ±50% of market price | ||
- Limit Orders: | ||
- Buy orders must be below market price | ||
- Sell orders must be above market price | ||
- Warns if price is very different from market (±80%) | ||
|
||
## Error Handling | ||
|
||
The plugin provides clear error messages for common issues: | ||
|
||
- Invalid token symbols | ||
- Price validation failures | ||
- Network connection issues | ||
- Order execution failures | ||
|
||
## Security Notes | ||
|
||
- Store your private key securely using environment variables | ||
- Test with small amounts first | ||
- Use testnet for initial testing | ||
- Monitor your orders regularly | ||
- Double-check prices before confirming trades | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import eslintGlobalConfig from "../../eslint.config.mjs"; | ||
|
||
export default [...eslintGlobalConfig]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@elizaos/plugin-hyperliquid", | ||
"version": "0.1.7", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@elizaos/core": "workspace:*", | ||
"hyperliquid": "^1.5.6", | ||
"zod": "^3.23.8" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.0.0", | ||
"tsup": "8.3.5" | ||
}, | ||
"scripts": { | ||
"build": "tsup --format esm --dts", | ||
"dev": "tsup --format esm --dts --watch", | ||
"lint": "eslint --fix --cache ." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { | ||
Action, | ||
ActionExample, | ||
IAgentRuntime, | ||
Memory, | ||
State, | ||
HandlerCallback, | ||
elizaLogger, | ||
} from "@elizaos/core"; | ||
import { Hyperliquid } from "hyperliquid"; | ||
|
||
export const cancelOrders: Action = { | ||
name: "CANCEL_ORDERS", | ||
similes: ["CANCEL_ALL_ORDERS", "CANCEL", "CANCEL_ALL"], | ||
description: "Cancel all open orders on Hyperliquid", | ||
validate: async (runtime: IAgentRuntime) => { | ||
return !!runtime.getSetting("HYPERLIQUID_PRIVATE_KEY"); | ||
}, | ||
handler: async ( | ||
runtime: IAgentRuntime, | ||
message: Memory, | ||
state: State, | ||
options: Record<string, unknown>, | ||
callback?: HandlerCallback | ||
) => { | ||
try { | ||
// Initialize SDK | ||
const sdk = new Hyperliquid({ | ||
privateKey: runtime.getSetting("HYPERLIQUID_PRIVATE_KEY"), | ||
testnet: runtime.getSetting("HYPERLIQUID_TESTNET") === "true", | ||
enableWs: false, | ||
}); | ||
await sdk.connect(); | ||
|
||
elizaLogger.info("Cancelling all open orders..."); | ||
const result = await sdk.custom.cancelAllOrders(); | ||
elizaLogger.info("Cancel result:", result); | ||
|
||
if (callback) { | ||
const cancelledCount = | ||
result?.response?.data?.statuses?.length || 0; | ||
callback({ | ||
text: | ||
cancelledCount > 0 | ||
? `Successfully cancelled ${cancelledCount} open order${cancelledCount > 1 ? "s" : ""}` | ||
: "No open orders to cancel", | ||
content: result, | ||
}); | ||
} | ||
|
||
return true; | ||
} catch (error) { | ||
elizaLogger.error("Error cancelling orders:", error); | ||
if (callback) { | ||
callback({ | ||
text: `Error cancelling orders: ${error.message}`, | ||
content: { error: error.message }, | ||
}); | ||
} | ||
return false; | ||
} | ||
}, | ||
examples: [ | ||
[ | ||
{ | ||
user: "{{user1}}", | ||
content: { | ||
text: "Cancel all my orders", | ||
}, | ||
}, | ||
{ | ||
user: "{{agent}}", | ||
content: { | ||
text: "I'll cancel all your open orders.", | ||
action: "CANCEL_ORDERS", | ||
}, | ||
}, | ||
{ | ||
user: "{{agent}}", | ||
content: { | ||
text: "Successfully cancelled 2 open orders", | ||
}, | ||
}, | ||
], | ||
] as ActionExample[][], | ||
}; | ||
|
||
export default cancelOrders; |
Oops, something went wrong.