hypertrader 0.1.8__tar.gz → 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 (45) hide show
  1. {hypertrader-0.1.8 → hypertrader-0.2.0}/PKG-INFO +55 -7
  2. {hypertrader-0.1.8 → hypertrader-0.2.0}/README.md +54 -6
  3. {hypertrader-0.1.8 → hypertrader-0.2.0}/hypertrader.egg-info/PKG-INFO +55 -7
  4. {hypertrader-0.1.8 → hypertrader-0.2.0}/hypertrader.egg-info/SOURCES.txt +8 -0
  5. {hypertrader-0.1.8 → hypertrader-0.2.0}/hypertrader.py +95 -19
  6. {hypertrader-0.1.8 → hypertrader-0.2.0}/modes/auto_trader.py +245 -66
  7. {hypertrader-0.1.8 → hypertrader-0.2.0}/modes/position_management.py +27 -1
  8. {hypertrader-0.1.8 → hypertrader-0.2.0}/setup.py +1 -1
  9. hypertrader-0.2.0/strategies/fib_reversal.py +444 -0
  10. {hypertrader-0.1.8 → hypertrader-0.2.0}/strategies/registry.py +4 -0
  11. {hypertrader-0.1.8 → hypertrader-0.2.0}/strategies/reversal.py +1 -1
  12. hypertrader-0.2.0/tests/test_api_retry.py +127 -0
  13. hypertrader-0.2.0/tests/test_auto_dry_run.py +83 -0
  14. {hypertrader-0.1.8 → hypertrader-0.2.0}/tests/test_auto_strategy_registry.py +31 -3
  15. hypertrader-0.2.0/tests/test_cli_shutdown.py +86 -0
  16. hypertrader-0.2.0/tests/test_fib_reversal_strategy.py +319 -0
  17. hypertrader-0.2.0/tests/test_simulated_logging.py +170 -0
  18. {hypertrader-0.1.8 → hypertrader-0.2.0}/utils/constants.py +1 -0
  19. {hypertrader-0.1.8 → hypertrader-0.2.0}/utils/helpers.py +18 -6
  20. hypertrader-0.2.0/utils/retry.py +41 -0
  21. hypertrader-0.2.0/utils/simulated_logging.py +26 -0
  22. {hypertrader-0.1.8 → hypertrader-0.2.0}/hypertrader.egg-info/dependency_links.txt +0 -0
  23. {hypertrader-0.1.8 → hypertrader-0.2.0}/hypertrader.egg-info/entry_points.txt +0 -0
  24. {hypertrader-0.1.8 → hypertrader-0.2.0}/hypertrader.egg-info/requires.txt +0 -0
  25. {hypertrader-0.1.8 → hypertrader-0.2.0}/hypertrader.egg-info/top_level.txt +0 -0
  26. {hypertrader-0.1.8 → hypertrader-0.2.0}/modes/market_maker.py +0 -0
  27. {hypertrader-0.1.8 → hypertrader-0.2.0}/modes/position_watcher.py +0 -0
  28. {hypertrader-0.1.8 → hypertrader-0.2.0}/modes/trailing_stop.py +0 -0
  29. {hypertrader-0.1.8 → hypertrader-0.2.0}/setup.cfg +0 -0
  30. {hypertrader-0.1.8 → hypertrader-0.2.0}/strategies/__init__.py +0 -0
  31. {hypertrader-0.1.8 → hypertrader-0.2.0}/strategies/base.py +0 -0
  32. {hypertrader-0.1.8 → hypertrader-0.2.0}/strategies/default.py +0 -0
  33. {hypertrader-0.1.8 → hypertrader-0.2.0}/strategies/orderflow_metrics.py +0 -0
  34. {hypertrader-0.1.8 → hypertrader-0.2.0}/strategies/orderflow_models.py +0 -0
  35. {hypertrader-0.1.8 → hypertrader-0.2.0}/strategies/orderflow_pullback.py +0 -0
  36. {hypertrader-0.1.8 → hypertrader-0.2.0}/tests/test_async_hyperliquid.py +0 -0
  37. {hypertrader-0.1.8 → hypertrader-0.2.0}/tests/test_auto_trader_logging.py +0 -0
  38. {hypertrader-0.1.8 → hypertrader-0.2.0}/tests/test_market_ids.py +0 -0
  39. {hypertrader-0.1.8 → hypertrader-0.2.0}/tests/test_orderflow_metrics.py +0 -0
  40. {hypertrader-0.1.8 → hypertrader-0.2.0}/tests/test_orderflow_pullback_lifecycle.py +0 -0
  41. {hypertrader-0.1.8 → hypertrader-0.2.0}/tests/test_reversal_strategy.py +0 -0
  42. {hypertrader-0.1.8 → hypertrader-0.2.0}/tests/test_trailing_stop.py +0 -0
  43. {hypertrader-0.1.8 → hypertrader-0.2.0}/utils/style.py +0 -0
  44. {hypertrader-0.1.8 → hypertrader-0.2.0}/utils/timer.py +0 -0
  45. {hypertrader-0.1.8 → hypertrader-0.2.0}/utils/worker.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hypertrader
3
- Version: 0.1.8
3
+ Version: 0.2.0
4
4
  Summary: Async Hyperliquid trading helper built on the async SDK.
5
5
  Author: darkerego
6
6
  License: MIT
@@ -66,10 +66,11 @@ The canonical bot file in this repo is [`hypertrader.py`](/media/anon/developmen
66
66
  - Network access to Hyperliquid APIs
67
67
  - Account created with referral code [DARKEREGO](https://app.hyperliquid.xyz/join/DARKEREGO) (see account creation [*])
68
68
 
69
- Install from pip:
69
+ Install from pip: https://pypi.org/project/hypertrader
70
70
 
71
71
  <pre>
72
- pip install hypertrader[auto]
72
+ pip install --upgrade pip setuptools wheel
73
+ pip install hypertrader[auto] --upgrade
73
74
  </pre>
74
75
 
75
76
  Base dependencies:
@@ -282,6 +283,7 @@ Key options:
282
283
 
283
284
  - `default`: the existing MACD/SAR/ADX/Bollinger auto trader and the implicit default when `--strategy` is omitted
284
285
  - `orderflow_pullback`: order-flow-confirmed trend pullback scalp strategy, also available as `of_pullback` and `orderflow`
286
+ - `fib_reversal`: Fibonacci pullbacks in the original impulse direction; aliases `fib` and `fibonacci`
285
287
  - `reversal`: a closed-candle trend-exhaustion, structure-break, and retest strategy
286
288
 
287
289
  The strategy selection changes the signal engine only. Shared sizing, risk controls, modify-order entry, market-fallback cleanup, hidden-order behavior, and bracket management still run through the same common auto execution path.
@@ -301,8 +303,7 @@ python3 hypertrader.py auto [COIN] (--size SIZE | --size-pct SIZE_PCT) [options]
301
303
 
302
304
  Key options:
303
305
 
304
- - `--strategy {default,reversal}`
305
- - `--strategy {default,orderflow_pullback,reversal}` with aliases `of_pullback` and `orderflow`
306
+ - `--strategy {default,fib_reversal,orderflow_pullback,reversal}` with aliases `fib`, `fibonacci`, `of_pullback`, and `orderflow`
306
307
  - `--size` or `--size-pct`
307
308
  - `--top-markets`
308
309
  - `--intervals`
@@ -341,7 +342,7 @@ Key options:
341
342
  - `--no-market-fallback`
342
343
  - `--market-slippage`
343
344
  - `--keep-existing-tpsl`
344
- - `--dry-run`
345
+ - `--dry-run`: assume 10,000 cUSDC for account balance and percentage sizing; simulate positions without placing exchange orders. Percentage sizing uses public market prices and maximum leverage from market metadata, without querying account collateral or configured leverage.
345
346
  - `--max-trades`
346
347
  - `--cooldown-after-trade`
347
348
  - `--loop-after-trade`
@@ -363,6 +364,51 @@ Key options:
363
364
 
364
365
  `auto` derives TP from Bollinger Bands unless `--take-profit-pct` overrides it. If TP is set and SL is omitted, SL defaults to half TP. Executions route through the same bracket-entry path used by `enter`.
365
366
 
367
+ Fibonacci pullback strategy:
368
+
369
+ ```bash
370
+ python3 hypertrader.py auto BTC --size-pct 10 --strategy fib_reversal
371
+ ```
372
+
373
+ `fib_reversal` detects an ATR-qualified impulse on the trend timeframe,
374
+ waits for a 38.2%/50%/61.8% Fibonacci retracement, then scores MACD
375
+ reversal, DMI/ADX trend strength, optional ROC, price rejection, and
376
+ higher-timeframe EMA alignment. It trades a pullback reversal in the original
377
+ impulse direction. Anchors use confirmed symmetric pivots (default width 2),
378
+ with at least 5 bars and a 2 ATR move inside the last 120 trend candles.
379
+
380
+ ```bash
381
+ python3 hypertrader.py auto \
382
+ --size-pct 10 \
383
+ --top-markets 20 \
384
+ --strategy fib_reversal \
385
+ --trend-interval 1h \
386
+ --entry-interval 15m \
387
+ --fib-entry-levels "0.382,0.5,0.618" \
388
+ --fib-min-impulse-atr 2.0 \
389
+ --fib-min-score 5 \
390
+ --fib-min-rr 1.5
391
+ ```
392
+
393
+ - Zone contact is required. Rejection, MACD histogram rotation/crossover, DMI,
394
+ rising ADX, ROC, and HTF EMA alignment contribute a weighted score (default
395
+ threshold 5/10). `--no-fib-roc` removes ROC and lowers the maximum to 9.
396
+ - `--fib-zone-atr 0.15` sets zone tolerance. Confirmation expires after
397
+ `--fib-confirm-timeout 4` entry intervals and cannot trigger farther than
398
+ `--fib-max-entry-distance-atr 0.50` from the touched level.
399
+ - Stops use the 0.786 retracement plus `--fib-stop-atr-buffer 0.25` ATR.
400
+ Closes beyond 0.786 plus `--fib-invalidation-atr 0.10` invalidate structure.
401
+ Explicitly including 0.786 moves invalidation to the impulse start; a 0.786
402
+ entry also places its stop beyond that start.
403
+ - TP1 is the impulse extreme; TP2/TP3 are 1.272/1.618 extensions with
404
+ 40%/35%/25% allocations. `--fib-min-rr 1.5` gates RR to **TP2**.
405
+ - Each impulse can emit once per session. Entry references use completed candle
406
+ closes by default; actual fills remain owned by smart entry. Trend pivots
407
+ always require closed right-side candles. Timeouts use elapsed entry intervals.
408
+ - Indicator defaults: ATR 14, MACD 12/26/9, ADX/DMI 14 with strength thresholds
409
+ 18/25, ROC 9, trend EMAs 20/50. See `auto --help` for all `--fib-*` options.
410
+ TA-Lib period parameters requiring at least 2 are validated before launch.
411
+
366
412
  Reversal strategy notes:
367
413
 
368
414
  - All confirmations use closed candles only.
@@ -521,7 +567,9 @@ The websocket cache is used as the fast path for market data such as mids, best
521
567
 
522
568
  ## Logging
523
569
 
524
- Runtime logs are written to [`logs/hypertrader.log`](/media/anon/development/anon/PycharmProjects/hypertrader/logs/hypertrader.log).
570
+ Dry-run console output, runtime messages, risk events, and simulated trades are written to `logs/simulated.log`. Simulation fills at observed market mid prices. Plans with explicit take-profit allocations, including `fib_reversal`, close the allocated portion of the original size at each reached target (40% at TP1, 35% at TP2, and 25% at TP3 for Fibonacci). Each fill logs a `simulated_take_profit_filled` event with its size and PnL. Position records track remaining size, cumulative realized PnL, and unrealized PnL on the remaining position; a stop closes only that remainder. Completed-trade PnL includes all partial exits. Plans without explicit allocations exit the full position at the stop or final target. Fees, funding, slippage, and dynamic stop adjustments are not modeled. Open positions at shutdown are logged with realized partial profits and their remaining unrealized PnL.
571
+
572
+ Runtime logs for live runs are written to [`logs/hypertrader.log`](/media/anon/development/anon/PycharmProjects/hypertrader/logs/hypertrader.log).
525
573
  Completed auto-trades are appended to [`logs/auto_trades.log`](/media/anon/development/anon/PycharmProjects/hypertrader/logs/auto_trades.log).
526
574
 
527
575
  ## Validation
@@ -35,10 +35,11 @@ The canonical bot file in this repo is [`hypertrader.py`](/media/anon/developmen
35
35
  - Network access to Hyperliquid APIs
36
36
  - Account created with referral code [DARKEREGO](https://app.hyperliquid.xyz/join/DARKEREGO) (see account creation [*])
37
37
 
38
- Install from pip:
38
+ Install from pip: https://pypi.org/project/hypertrader
39
39
 
40
40
  <pre>
41
- pip install hypertrader[auto]
41
+ pip install --upgrade pip setuptools wheel
42
+ pip install hypertrader[auto] --upgrade
42
43
  </pre>
43
44
 
44
45
  Base dependencies:
@@ -251,6 +252,7 @@ Key options:
251
252
 
252
253
  - `default`: the existing MACD/SAR/ADX/Bollinger auto trader and the implicit default when `--strategy` is omitted
253
254
  - `orderflow_pullback`: order-flow-confirmed trend pullback scalp strategy, also available as `of_pullback` and `orderflow`
255
+ - `fib_reversal`: Fibonacci pullbacks in the original impulse direction; aliases `fib` and `fibonacci`
254
256
  - `reversal`: a closed-candle trend-exhaustion, structure-break, and retest strategy
255
257
 
256
258
  The strategy selection changes the signal engine only. Shared sizing, risk controls, modify-order entry, market-fallback cleanup, hidden-order behavior, and bracket management still run through the same common auto execution path.
@@ -270,8 +272,7 @@ python3 hypertrader.py auto [COIN] (--size SIZE | --size-pct SIZE_PCT) [options]
270
272
 
271
273
  Key options:
272
274
 
273
- - `--strategy {default,reversal}`
274
- - `--strategy {default,orderflow_pullback,reversal}` with aliases `of_pullback` and `orderflow`
275
+ - `--strategy {default,fib_reversal,orderflow_pullback,reversal}` with aliases `fib`, `fibonacci`, `of_pullback`, and `orderflow`
275
276
  - `--size` or `--size-pct`
276
277
  - `--top-markets`
277
278
  - `--intervals`
@@ -310,7 +311,7 @@ Key options:
310
311
  - `--no-market-fallback`
311
312
  - `--market-slippage`
312
313
  - `--keep-existing-tpsl`
313
- - `--dry-run`
314
+ - `--dry-run`: assume 10,000 cUSDC for account balance and percentage sizing; simulate positions without placing exchange orders. Percentage sizing uses public market prices and maximum leverage from market metadata, without querying account collateral or configured leverage.
314
315
  - `--max-trades`
315
316
  - `--cooldown-after-trade`
316
317
  - `--loop-after-trade`
@@ -332,6 +333,51 @@ Key options:
332
333
 
333
334
  `auto` derives TP from Bollinger Bands unless `--take-profit-pct` overrides it. If TP is set and SL is omitted, SL defaults to half TP. Executions route through the same bracket-entry path used by `enter`.
334
335
 
336
+ Fibonacci pullback strategy:
337
+
338
+ ```bash
339
+ python3 hypertrader.py auto BTC --size-pct 10 --strategy fib_reversal
340
+ ```
341
+
342
+ `fib_reversal` detects an ATR-qualified impulse on the trend timeframe,
343
+ waits for a 38.2%/50%/61.8% Fibonacci retracement, then scores MACD
344
+ reversal, DMI/ADX trend strength, optional ROC, price rejection, and
345
+ higher-timeframe EMA alignment. It trades a pullback reversal in the original
346
+ impulse direction. Anchors use confirmed symmetric pivots (default width 2),
347
+ with at least 5 bars and a 2 ATR move inside the last 120 trend candles.
348
+
349
+ ```bash
350
+ python3 hypertrader.py auto \
351
+ --size-pct 10 \
352
+ --top-markets 20 \
353
+ --strategy fib_reversal \
354
+ --trend-interval 1h \
355
+ --entry-interval 15m \
356
+ --fib-entry-levels "0.382,0.5,0.618" \
357
+ --fib-min-impulse-atr 2.0 \
358
+ --fib-min-score 5 \
359
+ --fib-min-rr 1.5
360
+ ```
361
+
362
+ - Zone contact is required. Rejection, MACD histogram rotation/crossover, DMI,
363
+ rising ADX, ROC, and HTF EMA alignment contribute a weighted score (default
364
+ threshold 5/10). `--no-fib-roc` removes ROC and lowers the maximum to 9.
365
+ - `--fib-zone-atr 0.15` sets zone tolerance. Confirmation expires after
366
+ `--fib-confirm-timeout 4` entry intervals and cannot trigger farther than
367
+ `--fib-max-entry-distance-atr 0.50` from the touched level.
368
+ - Stops use the 0.786 retracement plus `--fib-stop-atr-buffer 0.25` ATR.
369
+ Closes beyond 0.786 plus `--fib-invalidation-atr 0.10` invalidate structure.
370
+ Explicitly including 0.786 moves invalidation to the impulse start; a 0.786
371
+ entry also places its stop beyond that start.
372
+ - TP1 is the impulse extreme; TP2/TP3 are 1.272/1.618 extensions with
373
+ 40%/35%/25% allocations. `--fib-min-rr 1.5` gates RR to **TP2**.
374
+ - Each impulse can emit once per session. Entry references use completed candle
375
+ closes by default; actual fills remain owned by smart entry. Trend pivots
376
+ always require closed right-side candles. Timeouts use elapsed entry intervals.
377
+ - Indicator defaults: ATR 14, MACD 12/26/9, ADX/DMI 14 with strength thresholds
378
+ 18/25, ROC 9, trend EMAs 20/50. See `auto --help` for all `--fib-*` options.
379
+ TA-Lib period parameters requiring at least 2 are validated before launch.
380
+
335
381
  Reversal strategy notes:
336
382
 
337
383
  - All confirmations use closed candles only.
@@ -490,7 +536,9 @@ The websocket cache is used as the fast path for market data such as mids, best
490
536
 
491
537
  ## Logging
492
538
 
493
- Runtime logs are written to [`logs/hypertrader.log`](/media/anon/development/anon/PycharmProjects/hypertrader/logs/hypertrader.log).
539
+ Dry-run console output, runtime messages, risk events, and simulated trades are written to `logs/simulated.log`. Simulation fills at observed market mid prices. Plans with explicit take-profit allocations, including `fib_reversal`, close the allocated portion of the original size at each reached target (40% at TP1, 35% at TP2, and 25% at TP3 for Fibonacci). Each fill logs a `simulated_take_profit_filled` event with its size and PnL. Position records track remaining size, cumulative realized PnL, and unrealized PnL on the remaining position; a stop closes only that remainder. Completed-trade PnL includes all partial exits. Plans without explicit allocations exit the full position at the stop or final target. Fees, funding, slippage, and dynamic stop adjustments are not modeled. Open positions at shutdown are logged with realized partial profits and their remaining unrealized PnL.
540
+
541
+ Runtime logs for live runs are written to [`logs/hypertrader.log`](/media/anon/development/anon/PycharmProjects/hypertrader/logs/hypertrader.log).
494
542
  Completed auto-trades are appended to [`logs/auto_trades.log`](/media/anon/development/anon/PycharmProjects/hypertrader/logs/auto_trades.log).
495
543
 
496
544
  ## Validation
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hypertrader
3
- Version: 0.1.8
3
+ Version: 0.2.0
4
4
  Summary: Async Hyperliquid trading helper built on the async SDK.
5
5
  Author: darkerego
6
6
  License: MIT
@@ -66,10 +66,11 @@ The canonical bot file in this repo is [`hypertrader.py`](/media/anon/developmen
66
66
  - Network access to Hyperliquid APIs
67
67
  - Account created with referral code [DARKEREGO](https://app.hyperliquid.xyz/join/DARKEREGO) (see account creation [*])
68
68
 
69
- Install from pip:
69
+ Install from pip: https://pypi.org/project/hypertrader
70
70
 
71
71
  <pre>
72
- pip install hypertrader[auto]
72
+ pip install --upgrade pip setuptools wheel
73
+ pip install hypertrader[auto] --upgrade
73
74
  </pre>
74
75
 
75
76
  Base dependencies:
@@ -282,6 +283,7 @@ Key options:
282
283
 
283
284
  - `default`: the existing MACD/SAR/ADX/Bollinger auto trader and the implicit default when `--strategy` is omitted
284
285
  - `orderflow_pullback`: order-flow-confirmed trend pullback scalp strategy, also available as `of_pullback` and `orderflow`
286
+ - `fib_reversal`: Fibonacci pullbacks in the original impulse direction; aliases `fib` and `fibonacci`
285
287
  - `reversal`: a closed-candle trend-exhaustion, structure-break, and retest strategy
286
288
 
287
289
  The strategy selection changes the signal engine only. Shared sizing, risk controls, modify-order entry, market-fallback cleanup, hidden-order behavior, and bracket management still run through the same common auto execution path.
@@ -301,8 +303,7 @@ python3 hypertrader.py auto [COIN] (--size SIZE | --size-pct SIZE_PCT) [options]
301
303
 
302
304
  Key options:
303
305
 
304
- - `--strategy {default,reversal}`
305
- - `--strategy {default,orderflow_pullback,reversal}` with aliases `of_pullback` and `orderflow`
306
+ - `--strategy {default,fib_reversal,orderflow_pullback,reversal}` with aliases `fib`, `fibonacci`, `of_pullback`, and `orderflow`
306
307
  - `--size` or `--size-pct`
307
308
  - `--top-markets`
308
309
  - `--intervals`
@@ -341,7 +342,7 @@ Key options:
341
342
  - `--no-market-fallback`
342
343
  - `--market-slippage`
343
344
  - `--keep-existing-tpsl`
344
- - `--dry-run`
345
+ - `--dry-run`: assume 10,000 cUSDC for account balance and percentage sizing; simulate positions without placing exchange orders. Percentage sizing uses public market prices and maximum leverage from market metadata, without querying account collateral or configured leverage.
345
346
  - `--max-trades`
346
347
  - `--cooldown-after-trade`
347
348
  - `--loop-after-trade`
@@ -363,6 +364,51 @@ Key options:
363
364
 
364
365
  `auto` derives TP from Bollinger Bands unless `--take-profit-pct` overrides it. If TP is set and SL is omitted, SL defaults to half TP. Executions route through the same bracket-entry path used by `enter`.
365
366
 
367
+ Fibonacci pullback strategy:
368
+
369
+ ```bash
370
+ python3 hypertrader.py auto BTC --size-pct 10 --strategy fib_reversal
371
+ ```
372
+
373
+ `fib_reversal` detects an ATR-qualified impulse on the trend timeframe,
374
+ waits for a 38.2%/50%/61.8% Fibonacci retracement, then scores MACD
375
+ reversal, DMI/ADX trend strength, optional ROC, price rejection, and
376
+ higher-timeframe EMA alignment. It trades a pullback reversal in the original
377
+ impulse direction. Anchors use confirmed symmetric pivots (default width 2),
378
+ with at least 5 bars and a 2 ATR move inside the last 120 trend candles.
379
+
380
+ ```bash
381
+ python3 hypertrader.py auto \
382
+ --size-pct 10 \
383
+ --top-markets 20 \
384
+ --strategy fib_reversal \
385
+ --trend-interval 1h \
386
+ --entry-interval 15m \
387
+ --fib-entry-levels "0.382,0.5,0.618" \
388
+ --fib-min-impulse-atr 2.0 \
389
+ --fib-min-score 5 \
390
+ --fib-min-rr 1.5
391
+ ```
392
+
393
+ - Zone contact is required. Rejection, MACD histogram rotation/crossover, DMI,
394
+ rising ADX, ROC, and HTF EMA alignment contribute a weighted score (default
395
+ threshold 5/10). `--no-fib-roc` removes ROC and lowers the maximum to 9.
396
+ - `--fib-zone-atr 0.15` sets zone tolerance. Confirmation expires after
397
+ `--fib-confirm-timeout 4` entry intervals and cannot trigger farther than
398
+ `--fib-max-entry-distance-atr 0.50` from the touched level.
399
+ - Stops use the 0.786 retracement plus `--fib-stop-atr-buffer 0.25` ATR.
400
+ Closes beyond 0.786 plus `--fib-invalidation-atr 0.10` invalidate structure.
401
+ Explicitly including 0.786 moves invalidation to the impulse start; a 0.786
402
+ entry also places its stop beyond that start.
403
+ - TP1 is the impulse extreme; TP2/TP3 are 1.272/1.618 extensions with
404
+ 40%/35%/25% allocations. `--fib-min-rr 1.5` gates RR to **TP2**.
405
+ - Each impulse can emit once per session. Entry references use completed candle
406
+ closes by default; actual fills remain owned by smart entry. Trend pivots
407
+ always require closed right-side candles. Timeouts use elapsed entry intervals.
408
+ - Indicator defaults: ATR 14, MACD 12/26/9, ADX/DMI 14 with strength thresholds
409
+ 18/25, ROC 9, trend EMAs 20/50. See `auto --help` for all `--fib-*` options.
410
+ TA-Lib period parameters requiring at least 2 are validated before launch.
411
+
366
412
  Reversal strategy notes:
367
413
 
368
414
  - All confirmations use closed candles only.
@@ -521,7 +567,9 @@ The websocket cache is used as the fast path for market data such as mids, best
521
567
 
522
568
  ## Logging
523
569
 
524
- Runtime logs are written to [`logs/hypertrader.log`](/media/anon/development/anon/PycharmProjects/hypertrader/logs/hypertrader.log).
570
+ Dry-run console output, runtime messages, risk events, and simulated trades are written to `logs/simulated.log`. Simulation fills at observed market mid prices. Plans with explicit take-profit allocations, including `fib_reversal`, close the allocated portion of the original size at each reached target (40% at TP1, 35% at TP2, and 25% at TP3 for Fibonacci). Each fill logs a `simulated_take_profit_filled` event with its size and PnL. Position records track remaining size, cumulative realized PnL, and unrealized PnL on the remaining position; a stop closes only that remainder. Completed-trade PnL includes all partial exits. Plans without explicit allocations exit the full position at the stop or final target. Fees, funding, slippage, and dynamic stop adjustments are not modeled. Open positions at shutdown are logged with realized partial profits and their remaining unrealized PnL.
571
+
572
+ Runtime logs for live runs are written to [`logs/hypertrader.log`](/media/anon/development/anon/PycharmProjects/hypertrader/logs/hypertrader.log).
525
573
  Completed auto-trades are appended to [`logs/auto_trades.log`](/media/anon/development/anon/PycharmProjects/hypertrader/logs/auto_trades.log).
526
574
 
527
575
  ## Validation
@@ -15,21 +15,29 @@ modes/trailing_stop.py
15
15
  strategies/__init__.py
16
16
  strategies/base.py
17
17
  strategies/default.py
18
+ strategies/fib_reversal.py
18
19
  strategies/orderflow_metrics.py
19
20
  strategies/orderflow_models.py
20
21
  strategies/orderflow_pullback.py
21
22
  strategies/registry.py
22
23
  strategies/reversal.py
24
+ tests/test_api_retry.py
23
25
  tests/test_async_hyperliquid.py
26
+ tests/test_auto_dry_run.py
24
27
  tests/test_auto_strategy_registry.py
25
28
  tests/test_auto_trader_logging.py
29
+ tests/test_cli_shutdown.py
30
+ tests/test_fib_reversal_strategy.py
26
31
  tests/test_market_ids.py
27
32
  tests/test_orderflow_metrics.py
28
33
  tests/test_orderflow_pullback_lifecycle.py
29
34
  tests/test_reversal_strategy.py
35
+ tests/test_simulated_logging.py
30
36
  tests/test_trailing_stop.py
31
37
  utils/constants.py
32
38
  utils/helpers.py
39
+ utils/retry.py
40
+ utils/simulated_logging.py
33
41
  utils/style.py
34
42
  utils/timer.py
35
43
  utils/worker.py
@@ -23,6 +23,7 @@ import os
23
23
  import sys
24
24
  from typing import Any, Dict, List, Optional
25
25
 
26
+ from strategies.fib_reversal import validate_fib_config
26
27
  from strategies.registry import available_strategy_names, available_strategies, normalize_strategy_name
27
28
 
28
29
  from hyperliquid.info import Info
@@ -31,7 +32,7 @@ from modes.market_maker import run_market_maker
31
32
  from modes.position_management import run_bracket_entry
32
33
  from modes.position_watcher import run_position_watcher
33
34
  from modes.trailing_stop import trailing_stop_for_all_positions
34
- from utils.constants import DEFAULT_LOG_FILE, INTERVAL_TO_MS
35
+ from utils.constants import DEFAULT_LOG_FILE, SIMULATED_LOG_FILE, INTERVAL_TO_MS
35
36
  from utils.helpers import parse_fractional_pct, normalize_hyperliquid_market_id, split_hyperliquid_market_id
36
37
  from utils.style import install_pretty_stdout
37
38
 
@@ -335,7 +336,7 @@ def build_arg_parser() -> argparse.ArgumentParser:
335
336
  help="Slippage fraction for market-style entry/exit. Default: 0.05.")
336
337
  auto_parser.add_argument("--keep-existing-tpsl", action="store_true",
337
338
  help="Do not cancel existing reduce-only TP/SL orders before entry.")
338
- auto_parser.add_argument("--dry-run", action="store_true", help="Print auto signals but do not enter trades.")
339
+ auto_parser.add_argument("--dry-run", action="store_true", help="Simulate positions using 10,000 cUSDC assumed collateral and log to logs/simulated.log.")
339
340
  auto_parser.add_argument("--max-trades", type=int, default=0,
340
341
  help="Maximum completed auto trades before exit. 0 means unlimited. Default: 0.")
341
342
  auto_parser.add_argument("--cooldown-after-trade", type=float, default=60.0,
@@ -372,6 +373,31 @@ def build_arg_parser() -> argparse.ArgumentParser:
372
373
  help="Disable ws for kline data (not recommended): ")
373
374
  auto_parser.add_argument("--hide-orders", "-ho", action="store_true",
374
375
  help="Keep auto-mode TP/SL targets private; no exchange-side bracket orders are placed until targets trigger.")
376
+ fib_group = auto_parser.add_argument_group("Fibonacci reversal strategy")
377
+ fib_group.add_argument("--fib-entry-levels", type=str, default='0.382,0.5,0.618')
378
+ fib_group.add_argument("--fib-pivot-width", type=int, default=2)
379
+ fib_group.add_argument("--fib-impulse-lookback", type=int, default=120)
380
+ fib_group.add_argument("--fib-min-impulse-atr", type=float, default=2.0)
381
+ fib_group.add_argument("--fib-min-impulse-bars", type=int, default=5)
382
+ fib_group.add_argument("--fib-zone-atr", type=float, default=0.15)
383
+ fib_group.add_argument("--fib-invalidation-atr", type=float, default=0.1)
384
+ fib_group.add_argument("--fib-stop-atr-buffer", type=float, default=0.25)
385
+ fib_group.add_argument("--fib-max-entry-distance-atr", type=float, default=0.5)
386
+ fib_group.add_argument("--fib-atr-period", type=int, default=14)
387
+ fib_group.add_argument("--fib-macd-fast", type=int, default=12)
388
+ fib_group.add_argument("--fib-macd-slow", type=int, default=26)
389
+ fib_group.add_argument("--fib-macd-signal", type=int, default=9)
390
+ fib_group.add_argument("--fib-adx-period", type=int, default=14)
391
+ fib_group.add_argument("--fib-min-adx", type=float, default=18.0)
392
+ fib_group.add_argument("--fib-strong-adx", type=float, default=25.0)
393
+ fib_group.add_argument("--fib-roc-period", type=int, default=9)
394
+ fib_group.add_argument("--no-fib-roc", dest="fib_roc", action="store_false", default=True)
395
+ fib_group.add_argument("--fib-trend-ema-fast", type=int, default=20)
396
+ fib_group.add_argument("--fib-trend-ema-slow", type=int, default=50)
397
+ fib_group.add_argument("--fib-confirm-timeout", type=int, default=4)
398
+ fib_group.add_argument("--fib-min-score", type=int, default=5)
399
+ fib_group.add_argument("--fib-min-rr", type=float, default=1.5)
400
+
375
401
  reversal_group = auto_parser.add_argument_group("Reversal strategy")
376
402
  reversal_group.add_argument("--trend-interval", type=str, default="1h",
377
403
  help="Higher timeframe used for reversal trend classification. Default: 1h.")
@@ -716,6 +742,18 @@ async def async_main(argv: Optional[List[str]] = None) -> None:
716
742
  if args.ws_candles and args.no_websocket:
717
743
  print("[ERROR] --ws-candles requires websocket market data; remove --no-websocket.")
718
744
  sys.exit(1)
745
+ try:
746
+ validate_fib_config(args)
747
+ except ValueError as exc:
748
+ print(f"[ERROR] {exc}")
749
+ sys.exit(1)
750
+ if args.strategy == "fib_reversal":
751
+ if args.trend_interval not in INTERVAL_TO_MS or args.entry_interval not in INTERVAL_TO_MS:
752
+ print("[ERROR] Unsupported Fibonacci trend/entry interval.")
753
+ sys.exit(1)
754
+ if INTERVAL_TO_MS[args.entry_interval] >= INTERVAL_TO_MS[args.trend_interval]:
755
+ print("[ERROR] --entry-interval must be shorter than --trend-interval for fib_reversal.")
756
+ sys.exit(1)
719
757
  if args.strategy == "reversal":
720
758
  if args.trend_interval not in INTERVAL_TO_MS:
721
759
  print(f"[ERROR] Unsupported --trend-interval {args.trend_interval!r}.")
@@ -858,6 +896,29 @@ async def async_main(argv: Optional[List[str]] = None) -> None:
858
896
  risk_session_log=args.risk_session_log,
859
897
  trend_interval=args.trend_interval,
860
898
  entry_interval=args.entry_interval,
899
+ fib_entry_levels=args.fib_entry_levels,
900
+ fib_pivot_width=args.fib_pivot_width,
901
+ fib_impulse_lookback=args.fib_impulse_lookback,
902
+ fib_min_impulse_atr=args.fib_min_impulse_atr,
903
+ fib_min_impulse_bars=args.fib_min_impulse_bars,
904
+ fib_zone_atr=args.fib_zone_atr,
905
+ fib_invalidation_atr=args.fib_invalidation_atr,
906
+ fib_stop_atr_buffer=args.fib_stop_atr_buffer,
907
+ fib_max_entry_distance_atr=args.fib_max_entry_distance_atr,
908
+ fib_atr_period=args.fib_atr_period,
909
+ fib_macd_fast=args.fib_macd_fast,
910
+ fib_macd_slow=args.fib_macd_slow,
911
+ fib_macd_signal=args.fib_macd_signal,
912
+ fib_adx_period=args.fib_adx_period,
913
+ fib_min_adx=args.fib_min_adx,
914
+ fib_strong_adx=args.fib_strong_adx,
915
+ fib_roc_period=args.fib_roc_period,
916
+ fib_roc=args.fib_roc,
917
+ fib_trend_ema_fast=args.fib_trend_ema_fast,
918
+ fib_trend_ema_slow=args.fib_trend_ema_slow,
919
+ fib_confirm_timeout=args.fib_confirm_timeout,
920
+ fib_min_score=args.fib_min_score,
921
+ fib_min_rr=args.fib_min_rr,
861
922
  reversal_ema_fast=args.reversal_ema_fast,
862
923
  reversal_ema_confirm=args.reversal_ema_confirm,
863
924
  reversal_ema_trend_fast=args.reversal_ema_trend_fast,
@@ -971,26 +1032,41 @@ async def async_main(argv: Optional[List[str]] = None) -> None:
971
1032
 
972
1033
 
973
1034
  def main(argv: Optional[List[str]] = None) -> None:
974
- log_path = configure_runtime_logging()
975
- try:
976
- loop = asyncio.new_event_loop()
977
- asyncio.set_event_loop(loop)
978
- install_asyncio_exception_logging(loop)
1035
+ from utils.simulated_logging import LoggedConsole
1036
+
1037
+ async def start() -> None:
1038
+ install_asyncio_exception_logging(asyncio.get_running_loop())
979
1039
  print(f"[LOG] Writing runtime logs to {log_path}")
980
1040
  print(f"[START] argv={argv if argv is not None else sys.argv[1:]}")
981
- loop.run_until_complete(async_main(argv))
982
- except KeyboardInterrupt:
983
- print("\n[!] Interrupted.")
984
- except Exception:
985
- logging.getLogger("hypertrader").exception("[FATAL] Unhandled main() exception.")
986
- sys.exit(1)
1041
+ await async_main(argv)
1042
+
1043
+ args = argv if argv is not None else sys.argv[1:]
1044
+ dry_run = "--dry-run" in args
1045
+ log_path = configure_runtime_logging(SIMULATED_LOG_FILE if dry_run else None)
1046
+ original_stdout, original_stderr = sys.stdout, sys.stderr
1047
+ if dry_run:
1048
+ sys.stdout = LoggedConsole(original_stdout)
1049
+ # sys.stderr = LoggedConsole(original_stderr)
1050
+ try:
1051
+ # Give both the initial run and the single retry a complete lifecycle:
1052
+ # cancellation, awaited cleanup, then event-loop shutdown.
1053
+ for attempt in range(2):
1054
+ try:
1055
+ asyncio.run(start())
1056
+ break
1057
+ except KeyboardInterrupt:
1058
+ print("\n[!] Interrupted.")
1059
+ break
1060
+ except Exception as err:
1061
+ logging.getLogger("hypertrader").exception("[FATAL] Unhandled main() exception: %s", err)
1062
+ if attempt == 1:
1063
+ raise
1064
+ print('[!] Restarting ... ')
987
1065
  finally:
988
- try:
989
- loop = asyncio.get_event_loop()
990
- except RuntimeError:
991
- loop = None
992
- if loop is not None and not loop.is_closed():
993
- loop.close()
1066
+ if dry_run:
1067
+ sys.stdout.flush()
1068
+ sys.stderr.flush()
1069
+ sys.stdout, sys.stderr = original_stdout, original_stderr
994
1070
 
995
1071
 
996
1072
  if __name__ == "__main__":