hl-trade-flow 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. hl_trade_flow-0.2.0/LICENSE +21 -0
  2. hl_trade_flow-0.2.0/PKG-INFO +290 -0
  3. hl_trade_flow-0.2.0/README.md +272 -0
  4. hl_trade_flow-0.2.0/pyproject.toml +30 -0
  5. hl_trade_flow-0.2.0/setup.cfg +4 -0
  6. hl_trade_flow-0.2.0/src/hl_trade_flow.egg-info/PKG-INFO +290 -0
  7. hl_trade_flow-0.2.0/src/hl_trade_flow.egg-info/SOURCES.txt +26 -0
  8. hl_trade_flow-0.2.0/src/hl_trade_flow.egg-info/dependency_links.txt +1 -0
  9. hl_trade_flow-0.2.0/src/hl_trade_flow.egg-info/requires.txt +6 -0
  10. hl_trade_flow-0.2.0/src/hl_trade_flow.egg-info/top_level.txt +1 -0
  11. hl_trade_flow-0.2.0/src/hyperliquid_autopilot/__init__.py +3 -0
  12. hl_trade_flow-0.2.0/src/hyperliquid_autopilot/audit.py +194 -0
  13. hl_trade_flow-0.2.0/src/hyperliquid_autopilot/common.py +154 -0
  14. hl_trade_flow-0.2.0/src/hyperliquid_autopilot/flow.py +140 -0
  15. hl_trade_flow-0.2.0/src/hyperliquid_autopilot/market_snapshot.py +177 -0
  16. hl_trade_flow-0.2.0/src/hyperliquid_autopilot/metrics.py +174 -0
  17. hl_trade_flow-0.2.0/src/hyperliquid_autopilot/order.py +648 -0
  18. hl_trade_flow-0.2.0/src/hyperliquid_autopilot/policy.py +385 -0
  19. hl_trade_flow-0.2.0/src/hyperliquid_autopilot/py.typed +0 -0
  20. hl_trade_flow-0.2.0/src/hyperliquid_autopilot/quote.py +158 -0
  21. hl_trade_flow-0.2.0/src/hyperliquid_autopilot/state_machine.py +315 -0
  22. hl_trade_flow-0.2.0/tests/test_audit.py +70 -0
  23. hl_trade_flow-0.2.0/tests/test_imports.py +41 -0
  24. hl_trade_flow-0.2.0/tests/test_logic.py +266 -0
  25. hl_trade_flow-0.2.0/tests/test_market_snapshot.py +96 -0
  26. hl_trade_flow-0.2.0/tests/test_metrics.py +99 -0
  27. hl_trade_flow-0.2.0/tests/test_policy.py +164 -0
  28. hl_trade_flow-0.2.0/tests/test_state_machine.py +252 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 counterfactual5
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,290 @@
1
+ Metadata-Version: 2.4
2
+ Name: hl-trade-flow
3
+ Version: 0.2.0
4
+ Summary: Hyperliquid perpetual futures trading toolkit โ€” quotes, orders, and trade flows
5
+ Author: counterfactual5
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/counterfactual5/hyperliquid-autopilot
8
+ Project-URL: Issues, https://github.com/counterfactual5/hyperliquid-autopilot/issues
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: hyperliquid-python-sdk>=0.1.0
13
+ Provides-Extra: dev
14
+ Requires-Dist: pytest>=7.0; extra == "dev"
15
+ Requires-Dist: pytest-cov; extra == "dev"
16
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
17
+ Dynamic: license-file
18
+
19
+ <div align="center">
20
+
21
+ # ๐Ÿ“ˆ Hyperliquid Autopilot
22
+
23
+ ### Perpetual futures trading, in Python.
24
+
25
+ **Quotes. Orders. Leverage. Positions.** Everything you need to trade on Hyperliquid.
26
+
27
+ Built on the Official SDK ยท Testnet + Mainnet ยท Market & Limit Orders ยท Position Management
28
+
29
+ [![Test](https://github.com/counterfactual5/hyperliquid-autopilot/actions/workflows/test.yml/badge.svg)](https://github.com/counterfactual5/hyperliquid-autopilot/actions)
30
+ [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
31
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
32
+
33
+ [Installation](#installation) ยท [Quotes](#-get-quotes--market-data) ยท [Trading](#-place--manage-orders) ยท [Trade Flow](#-end-to-end-trade-flow)
34
+
35
+ </div>
36
+
37
+ ---
38
+
39
+ > [!IMPORTANT]
40
+ > **Trading safety.** Order paths run through a shared risk-control policy
41
+ > (amount caps, leverage limit, coin allow-list, slippage limits) evaluated
42
+ > between the `PREFLIGHT` and `SIGNED` states. Read **[RISK_POLICY.md](RISK_POLICY.md)**
43
+ > and copy `policy.yaml` to `~/.stageforge/policy.yaml` before going live.
44
+
45
+ ## What Is This?
46
+
47
+ [Hyperliquid](https://hyperliquid.xyz) is a high-performance perpetual futures DEX. Their official Python SDK handles the low-level protocol โ€” but it's bare-bones. No quotes, no slippage estimation, no end-to-end trade flows.
48
+
49
+ **hyperliquid-autopilot wraps the SDK with a practical trading layer:**
50
+
51
+ ```
52
+ Official SDK: "Here's how to send a raw order to the API"
53
+ hyperliquid-autopilot: "Quote ETH โ†’ check slippage โ†’ place order โ†’ done"
54
+ ```
55
+
56
+ ---
57
+
58
+ ## Features
59
+
60
+ - **Market Data** โ€” mid price, L2 orderbook, slippage estimation, available assets
61
+ - **Market Orders** โ€” instant execution with size in USD
62
+ - **Limit Orders** โ€” place at specific price, with time-in-force options
63
+ - **Position Management** โ€” view positions, close positions, set leverage
64
+ - **Order Management** โ€” cancel single or all orders, view open orders
65
+ - **Trade Flow** โ€” end-to-end: quote โ†’ confirm โ†’ execute in one call
66
+ - **Testnet & Mainnet** โ€” switch with one env var
67
+
68
+ ---
69
+
70
+ ## Installation
71
+
72
+ ```bash
73
+ pip install hyperliquid-autopilot
74
+ ```
75
+
76
+ This installs the [official Hyperliquid Python SDK](https://github.com/hyperliquid-dex/hyperliquid-python-sdk) as a dependency.
77
+
78
+ ---
79
+
80
+ ## Quick Start
81
+
82
+ ### Configuration
83
+
84
+ ```bash
85
+ # Required for trading
86
+ export HYPERLIQUID_WALLET_ADDRESS="0x..."
87
+ export HYPERLIQUID_PRIVATE_KEY="0x..." # env var only, never on disk
88
+
89
+ # Switch to testnet (default is mainnet)
90
+ export HYPERLIQUID_TESTNET=1
91
+ ```
92
+
93
+ ### ๐Ÿ“Š Get Quotes & Market Data
94
+
95
+ ```python
96
+ from hyperliquid_autopilot.quote import get_mid_price, prepare_quote, get_l2_snapshot
97
+
98
+ # Current ETH price
99
+ mid = get_mid_price("ETH")
100
+ print(f" ETH mid price: ${mid:,.2f}")
101
+
102
+ # Quote for buying $100 of ETH
103
+ quote = prepare_quote(coin="ETH", size_usd=100, is_buy=True)
104
+ print(f" Entry price: ${quote['estimated_fill_price']}")
105
+ print(f" Slippage: {quote['slippage_bps']} bps")
106
+
107
+ # L2 orderbook depth
108
+ book = get_l2_snapshot("ETH")
109
+ for level in book["bids"][:3]:
110
+ print(f" Bid: ${level['px']} Size: {level['sz']}")
111
+ ```
112
+
113
+ ```
114
+ ETH mid price: $3,245.50
115
+ Entry price: $3,246.80
116
+ Slippage: 4.0 bps
117
+ Bid: $3,245.00 Size: 12.5
118
+ Bid: $3,244.50 Size: 8.3
119
+ Bid: $3,244.00 Size: 15.1
120
+ ```
121
+
122
+ ### โšก Place & Manage Orders
123
+
124
+ ```python
125
+ from hyperliquid_autopilot.order import (
126
+ place_market_order, place_limit_order,
127
+ get_positions, get_open_orders,
128
+ set_leverage, close_position, cancel_order, cancel_all_orders,
129
+ )
130
+ ```
131
+
132
+ **Open a position:**
133
+
134
+ ```python
135
+ # Market buy ETH
136
+ result = place_market_order(coin="ETH", is_buy=True, size=0.05)
137
+ print(f" Status: {result['status']}")
138
+ print(f" Filled: {result.get('filled_size')} @ ${result.get('avg_price')}")
139
+
140
+ # Limit order at specific price
141
+ result = place_limit_order(coin="ETH", is_buy=True, price=3000, size=0.1)
142
+ print(f" Order ID: {result['order_id']}")
143
+ ```
144
+
145
+ **Manage positions:**
146
+
147
+ ```python
148
+ # Set leverage
149
+ set_leverage(coin="ETH", leverage=5)
150
+
151
+ # View positions
152
+ positions = get_positions()
153
+ for pos in positions:
154
+ print(f" {pos['coin']}: {pos['side']} {pos['size']} @ entry ${pos['entry_px']}")
155
+ print(f" PnL: ${pos['unrealized_pnl']}")
156
+ print(f" Leverage: {pos['leverage']}x")
157
+
158
+ # Close a position
159
+ close_position(coin="ETH")
160
+ ```
161
+
162
+ **Manage orders:**
163
+
164
+ ```python
165
+ # View open orders
166
+ orders = get_open_orders(coin="ETH")
167
+ for o in orders:
168
+ print(f" {o['coin']}: {o['side']} {o['sz']} @ ${o['limit_px']}")
169
+
170
+ # Cancel specific order
171
+ cancel_order(coin="ETH", order_id=12345)
172
+
173
+ # Cancel all orders for a coin
174
+ cancel_all_orders(coin="ETH")
175
+ ```
176
+
177
+ ### ๐Ÿ”„ End-to-End Trade Flow
178
+
179
+ ```python
180
+ from hyperliquid_autopilot.flow import run_trade_flow
181
+
182
+ # Full flow: quote โ†’ confirm โ†’ execute
183
+ result = run_trade_flow(
184
+ coin="ETH",
185
+ side="buy",
186
+ size_usd=100,
187
+ dry_run=True, # paper trade mode
188
+ )
189
+ print(result["summary"])
190
+ ```
191
+
192
+ ---
193
+
194
+ ## API Reference
195
+
196
+ ### Market Data (quote.py)
197
+
198
+ | Function | Description |
199
+ |---|---|
200
+ | `get_mid_price(coin)` | Current mid price |
201
+ | `get_l2_snapshot(coin)` | L2 order book (bids + asks) |
202
+ | `get_meta()` | All tradeable assets and metadata |
203
+ | `prepare_quote(coin, size_usd, is_buy)` | Full quote with slippage estimation |
204
+
205
+ ### Order Execution (order.py)
206
+
207
+ | Function | Description |
208
+ |---|---|
209
+ | `place_market_order(coin, is_buy, size)` | Market order by size |
210
+ | `place_limit_order(coin, is_buy, price, size)` | Limit order at specific price |
211
+ | `cancel_order(coin, order_id)` | Cancel a specific order |
212
+ | `cancel_all_orders(coin)` | Cancel all orders for a coin |
213
+ | `get_open_orders(coin)` | List open orders |
214
+ | `get_positions()` | List all positions with PnL |
215
+ | `get_account_value()` | Account equity and margin |
216
+ | `set_leverage(coin, leverage)` | Set leverage for a coin |
217
+ | `close_position(coin)` | Close entire position |
218
+
219
+ ### Trade Flow (flow.py)
220
+
221
+ | Function | Description |
222
+ |---|---|
223
+ | `run_trade_flow(coin, is_buy, size, ...)` | End-to-end: quote โ†’ confirm โ†’ execute |
224
+
225
+ ### Configuration (common.py)
226
+
227
+ | Function | Description |
228
+ |---|---|
229
+ | `get_base_url()` | API URL (testnet or mainnet) |
230
+ | `is_testnet()` | Check testnet mode |
231
+ | `make_info_client()` | Create SDK Info client |
232
+ | `make_exchange_client()` | Create SDK Exchange client |
233
+
234
+ ---
235
+
236
+ ## Architecture
237
+
238
+ ```
239
+ hyperliquid_autopilot/
240
+ โ”œโ”€โ”€ quote.py Market data โ€” prices, orderbook, slippage
241
+ โ”œโ”€โ”€ order.py Order execution โ€” market, limit, cancel, positions
242
+ โ”œโ”€โ”€ common.py Shared utilities โ€” env config, SDK client creation
243
+ โ””โ”€โ”€ flow.py End-to-end trade orchestration
244
+
245
+ Data Flow:
246
+
247
+ User Code
248
+ โ”‚
249
+ โ”œโ”€โ”€ quote.prepare_quote("ETH", 100, "buy")
250
+ โ”‚ โ”‚
251
+ โ”‚ โ””โ”€โ”€ Hyperliquid Info API โ†’ mid price + L2 book โ†’ slippage calc
252
+ โ”‚
253
+ โ””โ”€โ”€ order.place_market_order("ETH", "buy", 200)
254
+ โ”‚
255
+ โ””โ”€โ”€ SDK Exchange Client โ†’ sign + submit โ†’ โœ… filled
256
+ ```
257
+
258
+ ## Supported Markets
259
+
260
+ All Hyperliquid perpetual futures โ€” ETH, BTC, SOL, and 100+ other pairs. Use `get_meta()` to list all available assets.
261
+
262
+ ## Development
263
+
264
+ ```bash
265
+ pip install -e ".[dev]"
266
+ pytest -v # 12 tests
267
+ ```
268
+
269
+ ## Roadmap
270
+
271
+ - [ ] Stop-loss / take-profit automation
272
+ - [ ] Async support (async/await)
273
+ - [ ] WebSocket real-time price feeds
274
+ - [ ] Strategy backtesting framework
275
+
276
+ ## Security
277
+
278
+ | Concern | How we handle it |
279
+ |---|---|
280
+ | Private keys | Environment variable `HYPERLIQUID_PRIVATE_KEY` โ€” never on disk |
281
+ | Network | Default to mainnet; set `HYPERLIQUID_TESTNET=1` for testnet |
282
+ | Test first | All functions support testnet mode for safe experimentation |
283
+
284
+ ## License
285
+
286
+ [MIT](LICENSE) โ€” use it however you want.
287
+
288
+ ---
289
+
290
+ If this project helped you, please โญ star this repo โ€” it helps others find it!
@@ -0,0 +1,272 @@
1
+ <div align="center">
2
+
3
+ # ๐Ÿ“ˆ Hyperliquid Autopilot
4
+
5
+ ### Perpetual futures trading, in Python.
6
+
7
+ **Quotes. Orders. Leverage. Positions.** Everything you need to trade on Hyperliquid.
8
+
9
+ Built on the Official SDK ยท Testnet + Mainnet ยท Market & Limit Orders ยท Position Management
10
+
11
+ [![Test](https://github.com/counterfactual5/hyperliquid-autopilot/actions/workflows/test.yml/badge.svg)](https://github.com/counterfactual5/hyperliquid-autopilot/actions)
12
+ [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
13
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
14
+
15
+ [Installation](#installation) ยท [Quotes](#-get-quotes--market-data) ยท [Trading](#-place--manage-orders) ยท [Trade Flow](#-end-to-end-trade-flow)
16
+
17
+ </div>
18
+
19
+ ---
20
+
21
+ > [!IMPORTANT]
22
+ > **Trading safety.** Order paths run through a shared risk-control policy
23
+ > (amount caps, leverage limit, coin allow-list, slippage limits) evaluated
24
+ > between the `PREFLIGHT` and `SIGNED` states. Read **[RISK_POLICY.md](RISK_POLICY.md)**
25
+ > and copy `policy.yaml` to `~/.stageforge/policy.yaml` before going live.
26
+
27
+ ## What Is This?
28
+
29
+ [Hyperliquid](https://hyperliquid.xyz) is a high-performance perpetual futures DEX. Their official Python SDK handles the low-level protocol โ€” but it's bare-bones. No quotes, no slippage estimation, no end-to-end trade flows.
30
+
31
+ **hyperliquid-autopilot wraps the SDK with a practical trading layer:**
32
+
33
+ ```
34
+ Official SDK: "Here's how to send a raw order to the API"
35
+ hyperliquid-autopilot: "Quote ETH โ†’ check slippage โ†’ place order โ†’ done"
36
+ ```
37
+
38
+ ---
39
+
40
+ ## Features
41
+
42
+ - **Market Data** โ€” mid price, L2 orderbook, slippage estimation, available assets
43
+ - **Market Orders** โ€” instant execution with size in USD
44
+ - **Limit Orders** โ€” place at specific price, with time-in-force options
45
+ - **Position Management** โ€” view positions, close positions, set leverage
46
+ - **Order Management** โ€” cancel single or all orders, view open orders
47
+ - **Trade Flow** โ€” end-to-end: quote โ†’ confirm โ†’ execute in one call
48
+ - **Testnet & Mainnet** โ€” switch with one env var
49
+
50
+ ---
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ pip install hyperliquid-autopilot
56
+ ```
57
+
58
+ This installs the [official Hyperliquid Python SDK](https://github.com/hyperliquid-dex/hyperliquid-python-sdk) as a dependency.
59
+
60
+ ---
61
+
62
+ ## Quick Start
63
+
64
+ ### Configuration
65
+
66
+ ```bash
67
+ # Required for trading
68
+ export HYPERLIQUID_WALLET_ADDRESS="0x..."
69
+ export HYPERLIQUID_PRIVATE_KEY="0x..." # env var only, never on disk
70
+
71
+ # Switch to testnet (default is mainnet)
72
+ export HYPERLIQUID_TESTNET=1
73
+ ```
74
+
75
+ ### ๐Ÿ“Š Get Quotes & Market Data
76
+
77
+ ```python
78
+ from hyperliquid_autopilot.quote import get_mid_price, prepare_quote, get_l2_snapshot
79
+
80
+ # Current ETH price
81
+ mid = get_mid_price("ETH")
82
+ print(f" ETH mid price: ${mid:,.2f}")
83
+
84
+ # Quote for buying $100 of ETH
85
+ quote = prepare_quote(coin="ETH", size_usd=100, is_buy=True)
86
+ print(f" Entry price: ${quote['estimated_fill_price']}")
87
+ print(f" Slippage: {quote['slippage_bps']} bps")
88
+
89
+ # L2 orderbook depth
90
+ book = get_l2_snapshot("ETH")
91
+ for level in book["bids"][:3]:
92
+ print(f" Bid: ${level['px']} Size: {level['sz']}")
93
+ ```
94
+
95
+ ```
96
+ ETH mid price: $3,245.50
97
+ Entry price: $3,246.80
98
+ Slippage: 4.0 bps
99
+ Bid: $3,245.00 Size: 12.5
100
+ Bid: $3,244.50 Size: 8.3
101
+ Bid: $3,244.00 Size: 15.1
102
+ ```
103
+
104
+ ### โšก Place & Manage Orders
105
+
106
+ ```python
107
+ from hyperliquid_autopilot.order import (
108
+ place_market_order, place_limit_order,
109
+ get_positions, get_open_orders,
110
+ set_leverage, close_position, cancel_order, cancel_all_orders,
111
+ )
112
+ ```
113
+
114
+ **Open a position:**
115
+
116
+ ```python
117
+ # Market buy ETH
118
+ result = place_market_order(coin="ETH", is_buy=True, size=0.05)
119
+ print(f" Status: {result['status']}")
120
+ print(f" Filled: {result.get('filled_size')} @ ${result.get('avg_price')}")
121
+
122
+ # Limit order at specific price
123
+ result = place_limit_order(coin="ETH", is_buy=True, price=3000, size=0.1)
124
+ print(f" Order ID: {result['order_id']}")
125
+ ```
126
+
127
+ **Manage positions:**
128
+
129
+ ```python
130
+ # Set leverage
131
+ set_leverage(coin="ETH", leverage=5)
132
+
133
+ # View positions
134
+ positions = get_positions()
135
+ for pos in positions:
136
+ print(f" {pos['coin']}: {pos['side']} {pos['size']} @ entry ${pos['entry_px']}")
137
+ print(f" PnL: ${pos['unrealized_pnl']}")
138
+ print(f" Leverage: {pos['leverage']}x")
139
+
140
+ # Close a position
141
+ close_position(coin="ETH")
142
+ ```
143
+
144
+ **Manage orders:**
145
+
146
+ ```python
147
+ # View open orders
148
+ orders = get_open_orders(coin="ETH")
149
+ for o in orders:
150
+ print(f" {o['coin']}: {o['side']} {o['sz']} @ ${o['limit_px']}")
151
+
152
+ # Cancel specific order
153
+ cancel_order(coin="ETH", order_id=12345)
154
+
155
+ # Cancel all orders for a coin
156
+ cancel_all_orders(coin="ETH")
157
+ ```
158
+
159
+ ### ๐Ÿ”„ End-to-End Trade Flow
160
+
161
+ ```python
162
+ from hyperliquid_autopilot.flow import run_trade_flow
163
+
164
+ # Full flow: quote โ†’ confirm โ†’ execute
165
+ result = run_trade_flow(
166
+ coin="ETH",
167
+ side="buy",
168
+ size_usd=100,
169
+ dry_run=True, # paper trade mode
170
+ )
171
+ print(result["summary"])
172
+ ```
173
+
174
+ ---
175
+
176
+ ## API Reference
177
+
178
+ ### Market Data (quote.py)
179
+
180
+ | Function | Description |
181
+ |---|---|
182
+ | `get_mid_price(coin)` | Current mid price |
183
+ | `get_l2_snapshot(coin)` | L2 order book (bids + asks) |
184
+ | `get_meta()` | All tradeable assets and metadata |
185
+ | `prepare_quote(coin, size_usd, is_buy)` | Full quote with slippage estimation |
186
+
187
+ ### Order Execution (order.py)
188
+
189
+ | Function | Description |
190
+ |---|---|
191
+ | `place_market_order(coin, is_buy, size)` | Market order by size |
192
+ | `place_limit_order(coin, is_buy, price, size)` | Limit order at specific price |
193
+ | `cancel_order(coin, order_id)` | Cancel a specific order |
194
+ | `cancel_all_orders(coin)` | Cancel all orders for a coin |
195
+ | `get_open_orders(coin)` | List open orders |
196
+ | `get_positions()` | List all positions with PnL |
197
+ | `get_account_value()` | Account equity and margin |
198
+ | `set_leverage(coin, leverage)` | Set leverage for a coin |
199
+ | `close_position(coin)` | Close entire position |
200
+
201
+ ### Trade Flow (flow.py)
202
+
203
+ | Function | Description |
204
+ |---|---|
205
+ | `run_trade_flow(coin, is_buy, size, ...)` | End-to-end: quote โ†’ confirm โ†’ execute |
206
+
207
+ ### Configuration (common.py)
208
+
209
+ | Function | Description |
210
+ |---|---|
211
+ | `get_base_url()` | API URL (testnet or mainnet) |
212
+ | `is_testnet()` | Check testnet mode |
213
+ | `make_info_client()` | Create SDK Info client |
214
+ | `make_exchange_client()` | Create SDK Exchange client |
215
+
216
+ ---
217
+
218
+ ## Architecture
219
+
220
+ ```
221
+ hyperliquid_autopilot/
222
+ โ”œโ”€โ”€ quote.py Market data โ€” prices, orderbook, slippage
223
+ โ”œโ”€โ”€ order.py Order execution โ€” market, limit, cancel, positions
224
+ โ”œโ”€โ”€ common.py Shared utilities โ€” env config, SDK client creation
225
+ โ””โ”€โ”€ flow.py End-to-end trade orchestration
226
+
227
+ Data Flow:
228
+
229
+ User Code
230
+ โ”‚
231
+ โ”œโ”€โ”€ quote.prepare_quote("ETH", 100, "buy")
232
+ โ”‚ โ”‚
233
+ โ”‚ โ””โ”€โ”€ Hyperliquid Info API โ†’ mid price + L2 book โ†’ slippage calc
234
+ โ”‚
235
+ โ””โ”€โ”€ order.place_market_order("ETH", "buy", 200)
236
+ โ”‚
237
+ โ””โ”€โ”€ SDK Exchange Client โ†’ sign + submit โ†’ โœ… filled
238
+ ```
239
+
240
+ ## Supported Markets
241
+
242
+ All Hyperliquid perpetual futures โ€” ETH, BTC, SOL, and 100+ other pairs. Use `get_meta()` to list all available assets.
243
+
244
+ ## Development
245
+
246
+ ```bash
247
+ pip install -e ".[dev]"
248
+ pytest -v # 12 tests
249
+ ```
250
+
251
+ ## Roadmap
252
+
253
+ - [ ] Stop-loss / take-profit automation
254
+ - [ ] Async support (async/await)
255
+ - [ ] WebSocket real-time price feeds
256
+ - [ ] Strategy backtesting framework
257
+
258
+ ## Security
259
+
260
+ | Concern | How we handle it |
261
+ |---|---|
262
+ | Private keys | Environment variable `HYPERLIQUID_PRIVATE_KEY` โ€” never on disk |
263
+ | Network | Default to mainnet; set `HYPERLIQUID_TESTNET=1` for testnet |
264
+ | Test first | All functions support testnet mode for safe experimentation |
265
+
266
+ ## License
267
+
268
+ [MIT](LICENSE) โ€” use it however you want.
269
+
270
+ ---
271
+
272
+ If this project helped you, please โญ star this repo โ€” it helps others find it!
@@ -0,0 +1,30 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "hl-trade-flow"
7
+ version = "0.2.0"
8
+ description = "Hyperliquid perpetual futures trading toolkit โ€” quotes, orders, and trade flows"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.10"
12
+ authors = [
13
+ { name = "counterfactual5" },
14
+ ]
15
+ dependencies = [
16
+ "hyperliquid-python-sdk>=0.1.0",
17
+ ]
18
+
19
+ [project.optional-dependencies]
20
+ dev = ["pytest>=7.0", "pytest-cov", "ruff>=0.1.0"]
21
+
22
+ [project.urls]
23
+ Repository = "https://github.com/counterfactual5/hyperliquid-autopilot"
24
+ Issues = "https://github.com/counterfactual5/hyperliquid-autopilot/issues"
25
+
26
+ [tool.setuptools.packages.find]
27
+ where = ["src"]
28
+
29
+ [tool.pytest.ini_options]
30
+ pythonpath = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+