diegobeyl/backtesting
2
1 2import requests3import json4import numpy as np5 6url = "http://127.0.0.1:8000/api/backtest/run"7payload = {8 "config": {9 "symbol": "BTCUSD",10 "timeframe": "H1",11 "donchian_period": 1,12 "risk_percent": 1.0,13 "initial_capital": 10000.0,14 "break_margin_d1": 0.4,15 "break_margin_w1": 2.0,16 "break_margin_mn": 3.0,17 "trade_direction": "BOTH",18 "lookbehind": 0,19 "stop_resets_support": True,20 "commission": 0.1,21 "slippage": 2,22 "trailing_mode": "FAST",23 "leverage": 30,24 "bars": 50025 }26}27 28print("Sending backtest request...")29try:30 response = requests.post(url, json=payload, timeout=30)31 if response.status_code == 200:32 data = response.json()33 print(f"Success: {data.get('success')}")34 35 metrics = data.get('metrics', {})36 print(f"Total Return: {metrics.get('total_return')}")37 38 chart_data = data.get('chart_data', {})39 structural = chart_data.get('structural', [])40 stop_loss = chart_data.get('stop_loss', [])41 42 res_count = len([s for s in structural if s.get('resistance') is not None])43 sup_count = len([s for s in structural if s.get('support') is not None])44 sl_count = len([s for s in stop_loss if s.get('sl') is not None])45 46 print(f"Bars in result: {len(structural)}")47 print(f"Resistance points: {res_count}")48 print(f"Support points: {sup_count}")49 print(f"Stop Loss points: {sl_count}")50 51 else:52 print(f"Error: {response.status_code}")53 print(response.text)54except Exception as e:55 print(f"Exception: {e}")56 