#!/usr/bin/env python3 """ZEC vs BTC over fixed 12-hour windows, from the public MCP endpoint. Python standard library only; no API key under the current public-access experiment. Calls the `compare_relative_return` tool and prints: * how often ZEC finished ahead of BTC across all finished windows, * how the width of a window depends on the regime known at its open, * the window that is open right now, and * the latest finished windows with timestamped opens and closes. It reports what happened. It is not a prediction, a signed settlement oracle, or a low-latency SLA. python3 examples/beggy_zec_vs_btc.py python3 examples/beggy_zec_vs_btc.py --offset-bars 8 # 08:00 / 20:00 UTC rounds python3 examples/beggy_zec_vs_btc.py --window-open 2026-11-12T00:00:00Z python3 examples/beggy_zec_vs_btc.py --json # full payload """ import argparse import datetime as dt import json import urllib.request ENDPOINT = 'https://aipricepatterns.com/api/mcp' def rpc(endpoint, method, params, session=None, request_id=1): headers = { 'Content-Type': 'application/json', 'Accept': 'application/json, text/event-stream', 'User-Agent': 'beggy-example/1', } if session: headers['Mcp-Session-Id'] = session body = {'jsonrpc': '2.0', 'method': method, 'params': params} if request_id is not None: body['id'] = request_id request = urllib.request.Request(endpoint, json.dumps(body).encode(), headers) with urllib.request.urlopen(request, timeout=120) as response: session = response.headers.get('Mcp-Session-Id') or session raw = response.read().decode() if 'text/event-stream' in (response.headers.get('Content-Type') or ''): raw = [line[5:].strip() for line in raw.splitlines() if line.startswith('data:')][-1] return (json.loads(raw) if raw.strip() else {}), session def compare(endpoint, arguments): _, session = rpc(endpoint, 'initialize', { 'protocolVersion': '2025-03-26', 'capabilities': {}, 'clientInfo': {'name': 'beggy-example', 'version': '1'}, }) rpc(endpoint, 'notifications/initialized', {}, session, request_id=None) reply, _ = rpc(endpoint, 'tools/call', {'name': 'compare_relative_return', 'arguments': arguments}, session, 2) if 'error' in reply: raise SystemExit(f"MCP error: {reply['error']}") result = reply['result'] text = ''.join(part.get('text', '') for part in result.get('content', [])) if result.get('isError'): raise SystemExit(text) return result.get('structuredContent') or json.loads(text) def line(window): return (f"{window['openUtc'][:16]}Z → {window['closeUtc'][:16]}Z " f"ZEC {window['base']['open']:>9} → {window['base']['close']:<9} ({window['base']['returnPct']:+.2f}%) " f"BTC {window['versus']['open']:>9} → {window['versus']['close']:<9} ({window['versus']['returnPct']:+.2f}%) " f"relative {window['relativePct']:+.2f} {window['winner']:<6} [{window['status']}]") if __name__ == '__main__': parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('--endpoint', default=ENDPOINT) parser.add_argument('--base', default='ZECUSDT') parser.add_argument('--versus', default='BTCUSDT') parser.add_argument('--interval', default='1h', choices=['5m', '15m', '1h', '4h', '1d']) parser.add_argument('--horizon-bars', type=int, default=12, help='window length in bars (12 x 1h = 12 hours)') parser.add_argument('--offset-bars', type=int, default=0, help='shift the UTC window grid by this many bars') parser.add_argument('--threshold-pct', type=float, default=0.0, help='base must win by more than this many points') parser.add_argument('--recent', type=int, default=6, help='how many finished windows to list') parser.add_argument('--window-open', help='ISO time (UTC) of one window to settle, e.g. 2026-11-12T00:00:00Z') parser.add_argument('--json', action='store_true', help='print the full tool payload') args = parser.parse_args() arguments = { 'base': args.base, 'versus': args.versus, 'interval': args.interval, 'horizonBars': args.horizon_bars, 'offsetBars': args.offset_bars, 'thresholdPct': args.threshold_pct, 'recentWindows': args.recent, } if args.window_open: moment = dt.datetime.fromisoformat(args.window_open.replace('Z', '+00:00')) if moment.tzinfo is None: moment = moment.replace(tzinfo=dt.timezone.utc) arguments['windowOpenMs'] = int(moment.timestamp() * 1000) payload = compare(args.endpoint, arguments) if args.json: print(json.dumps(payload, indent=2)) raise SystemExit(0) print(payload['brief']) print() print('Rule:', payload['definition']['rule']) for note in payload['coverage']['notes']: print('Note:', note) regime = payload.get('regime') or {} if regime.get('byRegime'): state = regime.get('now') or {} print(f"\nRegime before the open ({regime['lookbackBars']} bars). Sets the width of a window, not its winner." f" Now: {state.get('regime', 'n/a')}") print(f" {'regime':<6} {'windows':>7} {'ZEC wins':>8} {'P10':>6} {'P90':>6} {'>1pt':>6} {'>2pts':>6} {'>3pts':>6}") for row in regime['byRegime']: ladder = {step['abovePct']: step['share'] for step in row['exceedance']} mark = ' <- now' if row['regime'] == state.get('regime') else '' print(f" {row['regime']:<6} {row['windows']:>7} {row['baseWins']['share']:>8.1%} " f"{row['relativeP10']:>+6.2f} {row['relativeP90']:>+6.2f} " f"{ladder[1]:>6.1%} {ladder[2]:>6.1%} {ladder[3]:>6.1%}{mark}") requested = payload.get('requestedWindow') if requested: print('\nRequested window') print(' ', line(requested) if requested['status'] != 'unavailable' else requested['reason']) current = payload.get('currentWindow') if current: print(f"\nOpen now ({current['barsElapsed']}/{current['barsTotal']} bars in, not final)") print(' ', line(current)) print('\nLatest finished windows') for window in payload['recentWindows']: print(' ', line(window))