Spaces:
Sleeping
Sleeping
File size: 5,803 Bytes
3eb720d aaa6bb4 3eb720d 740fcec 712f4ea 740fcec 712f4ea 740fcec 712f4ea 740fcec 712f4ea 740fcec 712f4ea 740fcec 712f4ea 740fcec 712f4ea 740fcec 712f4ea 740fcec 712f4ea 740fcec 712f4ea 740fcec 712f4ea 740fcec 712f4ea 2ee81a5 7ce0cc9 2ee81a5 740fcec | 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 | ---
title: Perps Institutional Quant Terminal
emoji: ⚡
colorFrom: purple
colorTo: blue
sdk: gradio
sdk_version: 4.44.1
app_file: app.py
pinned: false
---
# ⚡ PerpsAI — Institutional Multi-Exchange Signal Intelligence, Execution & AI Co-Pilot
Engine analisis posisi Perpetual Futures (Long/Short) berbasis **konfluensi multi-sinyal real-time** dari **5 Bursa (Binance, Bybit, OKX, Bitget, dan Hyperliquid DEX)**, dilengkapi **Causal Historical Backtester**, eksekusi bracket order **Bybit V5 (Demo / Testnet / Real)** secara **stateless & fail-closed**, penyimpanan **Neon PostgreSQL** (dengan **in-memory fallback otomatis** saat `DATABASE_URL` kosong), serta **Tanya AI** (Vikey, Gemini, OpenAI).
---
## 🚀 Fitur Utama
1. **Anti-ISP Block Bawaan & TLS Verified:**
- Modul **DNS-over-HTTPS (DoH)** internal untuk mem-bypass DNS filtering tanpa menonaktifkan verifikasi sertifikat TLS (`verify=True`).
- Endpoint redundan lintas **Binance, Bybit (`api.bybit.biz`), OKX, Bitget, dan Hyperliquid on-chain DEX**.
2. **5-Way Quantitative Confluence Triangulation (Threshold `±4`):**
- Triangulasi OI-weighted lintas 5 venue (`funding_rate`, `oi_divergence`, `basis`, `ls_ratio` contrarian) dengan klaster Order Flow (`cvd`, `spot_futures_cvd`, `whale_order_flow`) yang dibatasi di `[-3, +3]` dan deduplikasi DEX-vs-CEX spread pada Hyperliquid.
- Circuit Breakers & `FakeDetector` (1m OHLCV + wick/spoof/divergence) men-veto arah secara ketat menjadi `NEUTRAL` dengan `trade_levels = None`.
3. **Bybit V5 Execution (Stateless & Fail-Closed Security):**
- Route sensitif (`/api/execution/*`, `/api/pairs*`, `/api/journal*`, `/api/cron/refresh`) wajib Bearer token `PERPS_API_TOKEN` (`503` jika belum dikonfigurasi, `401` jika token salah/kosong).
- Kredensial Bybit tidak disimpan global di memori server, melainkan dikirim per-request (`body` / header `X-Bybit-*` dari `sessionStorage` browser) atau `.env` server.
- Limit order dengan split TP1/TP2 otomatis meluncurkan background post-fill reconciliation pada server stateful, atau melaporkan status jujur `STATELESS_MANUAL_TP2` di serverless.
4. **Causal Historical Replay Backtester:**
- Mensimulasikan `SignalEngine` bar-by-bar tanpa *lookahead bias* (`backend/engine/backtester.py`), dilengkapi eksekusi *next-bar-open*, resolusi *SL-first* intra-bar, biaya taker, slippage, dan funding 8-jam (`backend/scripts/run_backtest.py`).
5. **Cloud PostgreSQL + Zero-Config In-Memory Fallback:**
- Menggunakan Neon PostgreSQL (`DATABASE_URL`) untuk persistensi penuh, atau otomatis fallback ke `InMemoryDatabaseStore` saat dijalankan lokal/CI tanpa database eksternal.
6. **🤖 Tanya AI & Modern Real-Time UI:**
- React 18 + Vite + TypeScript + Tailwind CSS + Capacitor Android support, terhubung melalui WebSocket streaming dan pengaturan `PERPS_API_TOKEN` di *Server Settings*.
---
## 📁 Struktur Direktori
```
perps/
├── app.py # Entrypoint Hugging Face Spaces (Gradio proxy)
├── start_all.bat # 1-Click launcher Windows (Backend + Frontend)
├── start_all.ps1 # PowerShell launcher
├── backend/ # FastAPI + Quantitative Engines
│ ├── config.py # Konfigurasi & env loader (PERPS_API_TOKEN, DATABASE_URL)
│ ├── security.py # Fail-closed Bearer token & Cron secret verification
│ ├── main.py # Entrypoint FastAPI + WebSocket + Background loop
│ ├── database/ # Neon PostgreSQL pool + InMemoryDatabaseStore fallback
│ ├── engine/ # SignalEngine, MTFAnalyzer, FakeDetector, Confluence, Predictive, CausalBacktester
│ ├── exchanges/ # Async httpx adapters: Binance, Bybit, OKX, Bitget, Hyperliquid
│ ├── routers/ # Endpoint pairs, signals, market, ai, journal, execution, websocket
│ └── scripts/ # run_backtest.py (CLI causal historical replay)
└── frontend/ # React + Vite + Capacitor Dashboard
└── src/
```
---
## ⚡ Cara Menjalankan
### Backend + Frontend Lokal
1. Salin env dan isi `PERPS_API_TOKEN` (wajib untuk aksi eksekusi/pairs/jurnal):
```bash
cp backend/.env.example backend/.env
```
2. Jalankan Backend:
```bash
cd backend
pip install -r requirements.txt
python -m uvicorn main:app --host 0.0.0.0 --port 8000 --reload
```
3. Jalankan Frontend:
```bash
cd frontend
npm install
npm run dev
```
### Causal Historical Backtester CLI
```bash
# Offline JSON fixture replay
python backend/scripts/run_backtest.py --fixture path/to/history.json --json
# Live Binance 1H OHLCV + Funding History replay
python backend/scripts/run_backtest.py --symbol BTCUSDT --days 14
```
### Menjalankan Test Suite
```bash
python -m pytest -q
```
---
## 🔑 Konfigurasi Environment (`.env`)
Salin `backend/.env.example` menjadi `backend/.env`:
```env
PERPS_API_TOKEN=ganti-dengan-token-rahasia-panjang
CRON_SECRET=opsional-secret-cron-vercel
DATABASE_URL= # Kosongkan untuk In-Memory fallback, atau isi URL Neon PostgreSQL
UPDATE_INTERVAL=60
```
---
## ☁️ Panduan Deploy ke Vercel (Multi-Service Project)
Projek ini dikonfigurasi untuk **Vercel Multi-Services** via [`vercel.json`](file:///c:/Users/ASUS/OneDrive/Desktop/perps/vercel.json) dengan layanan `frontend` (Vite SPA) dan `backend` (FastAPI Python).
### Environment Variables Wajib di Vercel:
- `PERPS_API_TOKEN`: Token Bearer rahasia untuk mengamankan endpoint `/api/execution/*`, `/api/pairs*`, `/api/journal*`, dan `/api/cron/refresh` (lalu masukkan token ini via modal **Server Settings** di browser).
- `DATABASE_URL`: URL koneksi Neon PostgreSQL Anda.
- `CRON_SECRET` *(opsional)*: Secret untuk Vercel Cron Jobs pada `/api/cron/refresh`.
|