Spaces:
Running
Running
File size: 7,533 Bytes
da0ce7b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | #!/usr/bin/env python3
"""
Lightweight CLI to inspect EnhancementLayer modifiers + a quick fused probability proxy
for a given symbol/exchange using public tickers (Binance/Kraken).
Usage examples:
python scripts/enhancement_cli.py --symbol BTCUSDT --exchange binance
python scripts/enhancement_cli.py --symbol XBTUSD --exchange kraken
Outputs:
- Price, 24h change %, volume
- Enhancement modifier + emotional state/phase/band/chakra
- Simple fused probability + action bucket (proxy, not production router)
This avoids needing full aureon_unified_ecosystem; uses public REST.
"""
from aureon_baton_link import link_system as _baton_link; _baton_link(__name__)
import argparse
import sys
import math
from typing import Optional, Tuple, List
import requests
# Ensure local imports work when run from repository root
sys.path.append('.')
try:
from aureon_enhancements import EnhancementLayer, get_emotional_color
except Exception as exc: # pragma: no cover - optional deps
print(f"β οΈ EnhancementLayer not available: {exc}")
EnhancementLayer = None # type: ignore
get_emotional_color = lambda x: '' # type: ignore
def clamp(val: float, lo: float, hi: float) -> float:
return max(lo, min(hi, val))
def synth_waveform(freq: float, samples: int = 32, sample_rate: int = 8000) -> List[float]:
"""Generate a short sine waveform preview for readability (not for audio)."""
if freq <= 0 or samples <= 0:
return []
out: List[float] = []
for n in range(samples):
t = n / sample_rate
out.append(math.sin(2 * math.pi * freq * t))
return out
def sparkline(values: List[float]) -> str:
"""Render a tiny sparkline for quick visual read."""
if not values:
return ""
blocks = "βββββ
βββ"
lo, hi = min(values), max(values)
span = hi - lo if hi != lo else 1.0
scaled = [int((v - lo) / span * (len(blocks) - 1)) for v in values]
return ''.join(blocks[i] for i in scaled)
def fetch_binance(symbol: str) -> Tuple[Optional[float], Optional[float], Optional[float]]:
url = 'https://api.binance.com/api/v3/ticker/24hr'
try:
resp = requests.get(url, params={'symbol': symbol}, timeout=5)
data = resp.json()
if 'lastPrice' not in data:
return None, None, None
price = float(data.get('lastPrice', 0))
change_pct = float(data.get('priceChangePercent', 0))
volume = float(data.get('quoteVolume', 0))
return price, change_pct, volume
except Exception:
return None, None, None
def fetch_kraken(symbol: str) -> Tuple[Optional[float], Optional[float], Optional[float]]:
# Kraken expects pairs like XBTUSD, ETHUSD, SOLUSD
pair = symbol.upper()
url = 'https://api.kraken.com/0/public/Ticker'
try:
resp = requests.get(url, params={'pair': pair}, timeout=5)
data = resp.json()
if data.get('error'):
return None, None, None
result = data.get('result') or {}
if not result:
return None, None, None
first = next(iter(result.values()))
last = float(first.get('c', [0])[0])
open_price = float(first.get('o', last)) or last
change_pct = ((last - open_price) / open_price * 100) if open_price else 0.0
volume = float(first.get('v', [0, 0])[1])
return last, change_pct, volume
except Exception:
return None, None, None
def action_bucket(p: float) -> str:
if p >= 0.70:
return 'STRONG_BUY'
if p >= 0.60:
return 'BUY'
if p >= 0.55:
return 'SLIGHT_BUY'
if p >= 0.45:
return 'HOLD'
if p >= 0.40:
return 'SLIGHT_SELL'
if p >= 0.30:
return 'SELL'
return 'STRONG_SELL'
def main():
parser = argparse.ArgumentParser(description="Enhancement modifier + fused-prob proxy")
parser.add_argument('--symbol', default='BTCUSDT', help='Symbol (e.g., BTCUSDT or XBTUSD)')
parser.add_argument('--exchange', default='binance', choices=['binance', 'kraken'], help='Exchange to query')
parser.add_argument('--waveform', action='store_true', help='Show a short waveform preview at the emotional frequency')
parser.add_argument('--samples', type=int, default=32, help='Number of samples for waveform preview (default 32)')
args = parser.parse_args()
exchange = args.exchange.lower()
symbol = args.symbol.upper()
if exchange == 'binance':
price, change_pct, volume = fetch_binance(symbol)
else:
price, change_pct, volume = fetch_kraken(symbol)
if price is None:
print(f"π« Could not fetch ticker for {symbol} on {exchange}")
sys.exit(1)
change_pct = change_pct or 0.0
volume = volume or 0.0
# Proxy lambda and coherence from price action
lambda_value = clamp(change_pct / 100.0, -1.0, 1.0)
coherence = clamp(abs(change_pct) / 10.0, 0.0, 1.0) # heuristic: larger move β higher coherence
volatility = abs(change_pct) / 100.0
enh_modifier = 1.0
enh_state = 'Neutral'
enh_phase = 'LOVE'
enh_band = None
enh_chakra = None
enh_freq = None
color = ''
if EnhancementLayer:
try:
layer = EnhancementLayer()
result = layer.get_unified_modifier(
lambda_value=lambda_value,
coherence=coherence,
price=price,
volume=volume,
volatility=volatility,
exchange=exchange.upper(),
)
enh_modifier = result.trading_modifier
enh_state = result.emotional_state
enh_phase = result.cycle_phase
enh_band = result.emotion_band
enh_chakra = result.chakra_alignment
enh_freq = result.emotional_frequency
color = get_emotional_color(result.emotional_state)
except Exception as exc: # pragma: no cover
print(f"β οΈ Enhancement calc failed: {exc}")
# Simple fused probability proxy
base_prob = 0.5 + (change_pct / 100.0) * 0.5 # map -100..+100% to 0..1 with center 0.5
base_prob = clamp(base_prob, 0.0, 1.0)
fused_prob = clamp(base_prob * enh_modifier, 0.0, 1.0)
action = action_bucket(fused_prob)
print(f"\nπ {exchange.upper()} {symbol}")
print(f" Price: {price:.6f} | 24h Ξ: {change_pct:+.2f}% | Vol: {volume:.2f}")
print(f" Ξ»: {lambda_value:+.3f} | Coherence: {coherence:.3f} | Volatility: {volatility:.3f}")
print(f"\n⨠Enhancement Layer")
print(f" Modifier: {enh_modifier:.3f}x | State: {enh_state} | Phase: {enh_phase} {color}")
if enh_band:
print(f" Emotion band: {enh_band}")
if enh_chakra:
print(f" Chakra alignment: {enh_chakra}")
if args.waveform and enh_freq:
wf = synth_waveform(enh_freq, samples=args.samples)
print(f" Waveform @ {enh_freq:.1f}Hz (first {len(wf)} samples):")
print(f" {sparkline(wf)}")
if wf:
# Show numeric preview for clarity
preview = ', '.join(f"{v:+.2f}" for v in wf[:8])
print(f" samples: {preview} ...")
print(f"\nπ§ Fused Prob (proxy)")
print(f" Base: {base_prob:.3f} | Fused: {fused_prob:.3f} | Action: {action}")
print()
if __name__ == '__main__':
main()
|