@senpi-ai/runtime 3.0.3 → 3.0.4

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 (61) hide show
  1. package/dist/actions/decision-engine.js +1 -1
  2. package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
  3. package/dist/actions/open-position/open-position.action.js +21 -12
  4. package/dist/actions/open-position/open-position.action.js.map +1 -1
  5. package/dist/actions/open-position/resolve-margin.d.ts +18 -3
  6. package/dist/actions/open-position/resolve-margin.d.ts.map +1 -1
  7. package/dist/actions/open-position/resolve-margin.js +22 -9
  8. package/dist/actions/open-position/resolve-margin.js.map +1 -1
  9. package/dist/cli/guide-commands.d.ts.map +1 -1
  10. package/dist/cli/guide-commands.js +21 -3
  11. package/dist/cli/guide-commands.js.map +1 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +7 -3
  14. package/dist/index.js.map +1 -1
  15. package/dist/runtime-api/intake/intake-mount.d.ts.map +1 -1
  16. package/dist/runtime-api/intake/intake-mount.js +10 -1
  17. package/dist/runtime-api/intake/intake-mount.js.map +1 -1
  18. package/dist/runtime-api/intake/types.d.ts +5 -6
  19. package/dist/runtime-api/intake/types.d.ts.map +1 -1
  20. package/dist/runtime-api/routes/signals.d.ts.map +1 -1
  21. package/dist/runtime-api/routes/signals.js +3 -2
  22. package/dist/runtime-api/routes/signals.js.map +1 -1
  23. package/dist/runtime-api/routes/signals.schema.d.ts +1 -2
  24. package/dist/runtime-api/routes/signals.schema.d.ts.map +1 -1
  25. package/dist/runtime-api/routes/signals.schema.js +5 -3
  26. package/dist/runtime-api/routes/signals.schema.js.map +1 -1
  27. package/dist/scanners/external/scaffold/delivery.py +19 -0
  28. package/dist/scanners/external/scaffold/signal_envelope.py +57 -19
  29. package/dist/scanners/external-scanner-receiver.d.ts +9 -3
  30. package/dist/scanners/external-scanner-receiver.d.ts.map +1 -1
  31. package/dist/scanners/external-scanner-receiver.js +13 -5
  32. package/dist/scanners/external-scanner-receiver.js.map +1 -1
  33. package/dist/scanners/providers/factory.d.ts.map +1 -1
  34. package/dist/scanners/providers/factory.js +17 -19
  35. package/dist/scanners/providers/factory.js.map +1 -1
  36. package/dist/strategy/strategy-state.d.ts.map +1 -1
  37. package/dist/strategy/strategy-state.js +16 -19
  38. package/dist/strategy/strategy-state.js.map +1 -1
  39. package/dist/types/scanner.d.ts +12 -3
  40. package/dist/types/scanner.d.ts.map +1 -1
  41. package/dist/utils/clearing-house-aggregate.d.ts +32 -0
  42. package/dist/utils/clearing-house-aggregate.d.ts.map +1 -0
  43. package/dist/utils/clearing-house-aggregate.js +41 -0
  44. package/dist/utils/clearing-house-aggregate.js.map +1 -0
  45. package/examples/strategies/iguana/README.md +4 -4
  46. package/examples/strategies/iguana/recipe.yaml +1 -1
  47. package/examples/strategies/iguana/scanners/scan.py +4 -5
  48. package/examples/strategies/raptor/README.md +2 -2
  49. package/examples/strategies/raptor/recipe.yaml +1 -1
  50. package/examples/strategies/raptor/scanners/scan.py +5 -6
  51. package/examples/strategies/spider/README.md +3 -3
  52. package/examples/strategies/spider/scalp/recipe.yaml +1 -1
  53. package/examples/strategies/spider/scalp/scanners/scan.py +1 -1
  54. package/examples/strategies/spider/swing/recipe.yaml +1 -1
  55. package/examples/strategies/spider/swing/scanners/scan.py +3 -3
  56. package/examples/strategies/turbine/README.md +12 -9
  57. package/examples/strategies/turbine/recipe-runners.yaml +2 -2
  58. package/examples/strategies/turbine/recipe-volume.yaml +2 -2
  59. package/examples/strategies/turbine/scanners/scan.py +10 -6
  60. package/openclaw.plugin.json +1 -1
  61. package/package.json +1 -1
@@ -36,9 +36,9 @@ emission ceiling on purpose.
36
36
 
37
37
  Sizing — carried on each signal's data{} so the OPEN_POSITION rule action sizes
38
38
  identically to the source:
39
- - marginUsd = round(account_value * margin_pct), margin_pct 0.25 (0.35 if
40
- score >= 10). Dual-DEX equity is collapsed via max() (NOT sum()) — one
41
- cross-margined wallet, two sub-DEX views; summing double-counts free balance.
39
+ - marginPct = percent of withdrawable (0–100), 25.0 (35.0 if score >= 10).
40
+ Dual-DEX equity is collapsed via max() (NOT sum()) — one cross-margined
41
+ wallet, two sub-DEX views; summing double-counts free balance.
42
42
  - leverage = conviction tier (>=10 -> 10x, >=8 -> 8x, >=6 -> 7x), clamped to
43
43
  the per-asset Hyperliquid venue max via strategy_get_asset_trading_limits.
44
44
 
@@ -297,9 +297,8 @@ def scan(inputs, ctx):
297
297
  candidates.sort(key=lambda c: c["score"], reverse=True)
298
298
  best = candidates[0]
299
299
  if best["score"] >= min_score:
300
- # Conviction-tier sizing.
300
+ # Conviction-tier sizing: emit percent of withdrawable (0–100).
301
301
  margin_pct = margin_pct_high if best["score"] >= 10 else margin_pct_base
302
- margin_usd = round(account_value * margin_pct, 2)
303
302
  requested = scoring.get_leverage_for_score(
304
303
  best["score"], scoring.LEVERAGE_TIERS, default_leverage)
305
304
  leverage = _get_safe_leverage(ctx, best["asset"], requested)
@@ -310,7 +309,7 @@ def scan(inputs, ctx):
310
309
  out.append({
311
310
  "asset": best["asset"],
312
311
  "direction": best["direction"],
313
- "marginUsd": float(margin_usd),
312
+ "marginPct": round(margin_pct * 100, 2),
314
313
  "leverage": float(leverage),
315
314
  "data": {
316
315
  "score": best["score"],
@@ -78,9 +78,9 @@ emitted at most `min(open_slots, affordable)` signals per tick, where
78
78
  `affordable` was derived from free margin. In v2 the runtime owns slot count and
79
79
  affordability (`strategy.slots` + the `risk.guard_rails`), so `scan()` emits
80
80
  **every** candidate that clears `minScore` (after filtering held + recently
81
- signaled assets) and carries the computed `marginUsd` + venue-clamped `leverage`
82
- on each signal's `data{}`. The signal-gating thresholds are unchanged; only the
83
- per-tick emission cap moved to the runtime.
81
+ signaled assets) and carries `marginPct` (percent of withdrawable, 0–100) +
82
+ venue-clamped `leverage` on each signal's top level. The signal-gating
83
+ thresholds are unchanged; only the per-tick emission cap moved to the runtime.
84
84
 
85
85
  ## Action gate
86
86
 
@@ -19,7 +19,7 @@ description: >
19
19
  strategy:
20
20
  wallet: "${SPIDER_SCALP_WALLET}"
21
21
  slots: 4 # source maxSlots 4
22
- margin_pct: 15 # source marginPct 0.15 → margin_usd = account_value * 0.15
22
+ margin_pct: 15 # source marginPct 0.15 → scan.py emits marginPct 15.0 (% of withdrawable)
23
23
  default_leverage: 5 # source scalpMaxLeverage cap (clamped per-asset to HL venue max in scan.py)
24
24
  trading_risk: moderate
25
25
  enabled: true
@@ -187,7 +187,7 @@ def scan(inputs, ctx):
187
187
  out.append({
188
188
  "asset": th["coin"],
189
189
  "direction": th["direction"],
190
- "marginUsd": margin_usd,
190
+ "marginPct": round(margin_pct * 100, 2),
191
191
  "leverage": leverage,
192
192
  "data": {
193
193
  "score": th["score"],
@@ -19,7 +19,7 @@ description: >
19
19
  strategy:
20
20
  wallet: "${SPIDER_SWING_WALLET}"
21
21
  slots: 3 # source maxSlots 3
22
- margin_pct: 28 # source marginPct 0.28 → margin_usd = account_value * 0.28
22
+ margin_pct: 28 # source marginPct 0.28 → scan.py emits marginPct 28.0 (% of withdrawable)
23
23
  default_leverage: 10 # source swingMaxLeverage cap (clamped per-asset to HL venue max in scan.py)
24
24
  trading_risk: moderate
25
25
  enabled: true
@@ -24,8 +24,8 @@ What was simplified vs the source (FLAGGED):
24
24
  qualifying candidates above minScore (held + recently-signaled filtered).
25
25
  The signal-GATING thresholds (minScore, held-set, recent-dedup, venue min
26
26
  notional) are preserved exactly; only the per-tick emission CAP moves to the
27
- runtime. marginUsd is still computed (account_value * marginPct) and carried
28
- on data{} so the action sizes identically to the source.
27
+ runtime. marginPct (percent of withdrawable, 0–100) is carried on each signal
28
+ so the action sizes identically to the source.
29
29
  """
30
30
 
31
31
  import sys
@@ -301,7 +301,7 @@ def scan(inputs, ctx):
301
301
  out.append({
302
302
  "asset": th["coin"],
303
303
  "direction": th["direction"],
304
- "marginUsd": margin_usd,
304
+ "marginPct": round(margin_pct * 100, 2),
305
305
  "leverage": leverage,
306
306
  "data": {
307
307
  "score": th["score"],
@@ -13,8 +13,8 @@ recipe's `interval_seconds`.
13
13
 
14
14
  | Leg | Thesis (identical signal) | Slots | Margin/slot | Lev | DSL exit |
15
15
  |-----------|---------------------------|-------|-------------|-----|----------|
16
- | `volume` | Funding-fade rotation | 7 | $700 | 5x | force-close: 10-min hard timeout, phase1 max_loss 50 / retrace 30, **no phase2**, maker exit |
17
- | `runners` | Funding-fade rotation | 2 | $1300 | 5x | patient: 4h hard timeout, weak_peak 90m@3 + dead_weight 120m, phase1 max_loss 30 / retrace 8, 5-tier phase2 (5/0·10/35·20/55·35/75·50/85), taker exit |
16
+ | `volume` | Funding-fade rotation | 7 | 20% withdrawable | 5x | force-close: 10-min hard timeout, phase1 max_loss 50 / retrace 30, **no phase2**, maker exit |
17
+ | `runners` | Funding-fade rotation | 2 | 20% withdrawable | 5x | patient: 4h hard timeout, weak_peak 90m@3 + dead_weight 120m, phase1 max_loss 30 / retrace 8, 5-tier phase2 (5/0·10/35·20/55·35/75·50/85), taker exit |
18
18
 
19
19
  Both legs run the **identical** rotation alpha (same universe, same direction
20
20
  logic, same gates). The wallet boundary selects DSL behavior: `volume` prints
@@ -59,7 +59,7 @@ turbine/
59
59
  └── scoring.py # pure rotation/direction/spread functions (unit-tested)
60
60
  ```
61
61
 
62
- The per-leg sizing (`marginUsd`, `leverage`, `maxSlots`) rides on each recipe's
62
+ The per-leg sizing (`marginPct`, `leverage`, `maxSlots`) rides on each recipe's
63
63
  `inputs:` block, so the one `scan.py` emits correctly-sized signals for whichever
64
64
  leg supervises it.
65
65
 
@@ -127,9 +127,10 @@ The source computed `effective_slots = min(maxSlots, account_value /
127
127
  margin_per_slot)` and emitted at most that many signals per tick. In v2 the
128
128
  runtime owns slot count (`strategy.slots`) and affordability (`risk.guard_rails`),
129
129
  so `scan()` emits all candidates clearing the gates (held + cooldown + spread),
130
- carrying `marginUsd` + `leverage` on each signal's `data{}`. It still caps a tick
131
- at `maxSlots` candidates (the rotation only advances that many times) so the
132
- scanner doesn't flood the queue; the runtime makes the final open/skip decision.
130
+ carrying `marginPct` (percent of withdrawable) + `leverage` on each signal's top
131
+ level. It still caps a tick at `maxSlots` candidates (the rotation only advances
132
+ that many times) so the scanner doesn't flood the queue; the runtime makes the
133
+ final open/skip decision.
133
134
 
134
135
  ### Kept: non-deterministic `random` picks
135
136
 
@@ -161,6 +162,8 @@ v2 recipes use `decision_mode: rule` directly.
161
162
  ### Sizing source of truth
162
163
 
163
164
  The source had margin/slot drift across files (700/1300 in config v3.3 vs
164
- 500/950 producer defaults vs YAML). This port uses **config v3.3**: volume 7
165
- slots @ $700, runners 2 slots @ $1300, both 5x, `xyzWeight 0.80`, spread
166
- main 3 bps / xyz 10 bps.
165
+ 500/950 producer defaults vs YAML). This port uses **config v3.3** proportions:
166
+ volume 7 slots, runners 2 slots, both 5x, `xyzWeight 0.80`, spread main 3 bps /
167
+ xyz 10 bps. Sizing is now `marginPct` (percent of withdrawable) set in each
168
+ recipe's `inputs:` block (default 20); the old fixed-USD amounts can't be
169
+ preserved as a percent without knowing account size.
@@ -23,7 +23,7 @@ description: >
23
23
  strategy:
24
24
  wallet: "${TURBINE_RUNNERS_WALLET}"
25
25
  slots: 2 # source slots.runners 2
26
- margin_per_slot: 100 # FALLBACK sizing — used only if a signal omits marginUsd. scan.py emits per-signal marginUsd (from inputs below), which WINS. TEST 100; prod source margin.runners 1300 (config v3.3)
26
+ margin_per_slot: 100 # FALLBACK sizing — used only if a signal omits marginPct. scan.py emits per-signal marginPct (% of withdrawable, from inputs below), which WINS. TEST 100; prod source margin.runners 1300 (config v3.3)
27
27
  default_leverage: 5 # source leverage.runners 5 (clamped per-asset in scan.py)
28
28
  trading_risk: moderate # source trading_risk balanced → nearest v2 tier moderate
29
29
  enabled: true
@@ -48,7 +48,7 @@ scanners:
48
48
  spreadXyzBps: 10 # source spread.xyzBps 10
49
49
  # ── per-leg sizing (runners) ──
50
50
  leverage: 5 # source leverage.runners 5
51
- marginUsd: 100 # per-signal USD margin; scan.py emits it TOP-LEVEL → runtime honors it as the EFFECTIVE sizing (overrides margin_per_slot). TEST 100; prod source 1300
51
+ marginPct: 20 # per-signal % of withdrawable; scan.py emits it TOP-LEVEL → runtime honors it as the EFFECTIVE sizing (overrides margin_per_slot). 20 is an example default; prod source 1300 USD intent must be sized as a percent
52
52
  maxSlots: 2 # source slots.runners 2 (per-tick emission ceiling)
53
53
  signal_data_schema:
54
54
  thesis: { type: string }
@@ -19,7 +19,7 @@ description: >
19
19
  strategy:
20
20
  wallet: "${TURBINE_VOLUME_WALLET}"
21
21
  slots: 7 # source slots.volume 7
22
- margin_per_slot: 100 # FALLBACK sizing — used only if a signal omits marginUsd. scan.py emits per-signal marginUsd (from inputs below), which WINS. TEST 100; prod source margin.volume 700 (config v3.3)
22
+ margin_per_slot: 100 # FALLBACK sizing — used only if a signal omits marginPct. scan.py emits per-signal marginPct (% of withdrawable, from inputs below), which WINS. TEST 100; prod source margin.volume 700 (config v3.3)
23
23
  default_leverage: 5 # source leverage.volume 5 (clamped per-asset in scan.py)
24
24
  trading_risk: aggressive # source trading_risk aggressive
25
25
  enabled: true
@@ -44,7 +44,7 @@ scanners:
44
44
  spreadXyzBps: 10 # source spread.xyzBps 10
45
45
  # ── per-leg sizing (volume) ──
46
46
  leverage: 5 # source leverage.volume 5
47
- marginUsd: 100 # per-signal USD margin; scan.py emits it TOP-LEVEL → runtime honors it as the EFFECTIVE sizing (overrides margin_per_slot). TEST 100; prod source 700
47
+ marginPct: 20 # per-signal % of withdrawable; scan.py emits it TOP-LEVEL → runtime honors it as the EFFECTIVE sizing (overrides margin_per_slot). 20 is an example default; prod source 700 USD intent must be sized as a percent
48
48
  maxSlots: 7 # source slots.volume 7 (per-tick emission ceiling)
49
49
  signal_data_schema:
50
50
  thesis: { type: string }
@@ -7,7 +7,7 @@ ONE scanner, TWO recipes. Turbine's two legs (volume + runners) ran the IDENTICA
7
7
  rotation alpha on the source; only the DSL exit preset and the per-slot sizing differed, and
8
8
  those live entirely in the recipe YAMLs. So both recipe-volume.yaml and recipe-runners.yaml
9
9
  point `path: ./scanners` + `entrypoint: scan.py` at THIS one module. The `inputs` block carries
10
- the per-leg sizing (marginUsd, leverage, slots) so the same code emits correctly-sized signals
10
+ the per-leg sizing (marginPct, leverage, slots) so the same code emits correctly-sized signals
11
11
  for whichever leg supervises it.
12
12
 
13
13
  What stayed faithful to the source (see scoring.py — ported verbatim):
@@ -39,9 +39,10 @@ FLAGS — behaviors that changed under the v2 contract (do NOT read as silent dr
39
39
  computed effective_slots = min(maxSlots, account_value / margin_per_slot) and emitted at
40
40
  most that many signals per tick. In v2 the runtime owns slot count (strategy.slots) and
41
41
  affordability (risk gates), so scan() emits ALL candidates clearing the gates (held +
42
- cooldown + spread), carrying marginUsd + leverage at each signal's TOP LEVEL. We still emit
43
- at most `maxSlots` candidates per tick (the rotation only advances that many times) so the
44
- scanner doesn't flood the queue, but the runtime makes the final open/skip decision.
42
+ cooldown + spread), carrying marginPct (percent of withdrawable) + leverage at each signal's
43
+ TOP LEVEL. We still emit at most `maxSlots` candidates per tick (the rotation only advances
44
+ that many times) so the scanner doesn't flood the queue, but the runtime makes the final
45
+ open/skip decision.
45
46
 
46
47
  3. random pool/direction picks are non-deterministic — kept verbatim (this is the source's
47
48
  design: rotation desync + neutral-regime coin flip). Tests assert STRUCTURE (valid gated
@@ -186,7 +187,10 @@ def scan(inputs, ctx):
186
187
  spread_main_bps = float(inputs.get("spreadMainBps", 3))
187
188
  spread_xyz_bps = float(inputs.get("spreadXyzBps", 10))
188
189
  leg_leverage = float(inputs.get("leverage", 5))
189
- margin_usd = float(inputs.get("marginUsd", 700))
190
+ # marginPct: percent of withdrawable to size each slot (0–100). Default 20 is
191
+ # an example; the old fixed-USD intent can't be preserved as a percent without
192
+ # knowing account size. Set this in the recipe inputs: block.
193
+ margin_pct = float(inputs.get("marginPct", 20))
190
194
  max_slots = int(inputs.get("maxSlots", 7))
191
195
 
192
196
  held_set, _account_value = _get_held(ctx)
@@ -246,7 +250,7 @@ def scan(inputs, ctx):
246
250
  out.append({
247
251
  "asset": asset,
248
252
  "direction": direction,
249
- "marginUsd": float(margin_usd),
253
+ "marginPct": float(margin_pct),
250
254
  "leverage": float(leverage),
251
255
  "data": {
252
256
  "thesis": thesis,
@@ -2,7 +2,7 @@
2
2
  "id": "runtime",
3
3
  "name": "Senpi Runtime",
4
4
  "description": "Senpi runtime plugin for OpenClaw. Orchestrates scanners, LLM-based trade decisions, and a DSL trailing stop-loss exit engine.",
5
- "version": "3.0.3",
5
+ "version": "3.0.4",
6
6
  "commandAliases": [
7
7
  {
8
8
  "name": "senpi"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@senpi-ai/runtime",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "description": "Senpi runtime plugin for OpenClaw",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",