A sophisticated autonomous trading agent implementing Pythagorean geometric risk distribution for perpetual futures trading with real-time WebSocket capabilities.
- Pythagorean Risk Model: Geometric distribution of risk across positions
- Oracle Integrations: Katya, Pyth, and custom oracle support
- Automated Position Sizing: Intelligent position management based on risk metrics
- Smart Contract Execution: Direct interaction with DeFi protocols
- Adaptive Strategy Switching: Dynamic strategy selection based on market conditions
- Real-time Monitoring: Live dashboard and performance metrics via WebSocket
- Advanced Risk Management: VaR analysis, drawdown protection, correlation limits
- WebSocket Integration: Real-time updates for trading activities, market data, and alerts
- Node.js >= 14.0.0
- npm or yarn
git clone https://github.com/REChain-Network-Solutions/Autonomous-Agent-for-Pythagorean-perpetual-futures-pyth-.git
cd Autonomous-Agent-for-Pythagorean-perpetual-futures-pyth-
npm installCopy the environment template and configure your settings:
cp .env.example .envEdit the .env file with your specific configuration.
npm startThe agent will start on http://localhost:3000 (default port).
See .env.example for comprehensive configuration options. Key environment variables include:
API_KEY: Secret API key for authenticationPORT: Server port (default: 3000)INITIAL_CASH: Initial trading capitalMAX_POSITION_SIZE: Maximum position size per tradeMAX_DRAWDOWN: Maximum allowed drawdown percentageSTOP_LOSS_PERCENT: Stop-loss percentageTAKE_PROFIT_PERCENT: Take-profit percentageLEVERAGE: Trading leverage
All API endpoints require authentication via API key in the x-api-key header.
- Health Check:
GET /healthz - Readiness Check:
GET /readyz - Metrics Status:
GET /metrics/status - Positions:
GET /metrics/positions - Performance:
GET /metrics/performance
- Manual Refresh:
POST /admin/refresh-metrics - Webhook Management:
POST/DELETE/GET /admin/hooks - Event Emission:
POST /admin/emit - Configuration View:
GET /admin/config - Session Management:
GET/DELETE /admin/sessions
- Nonce Generation:
GET /web3/nonce - Signature Verification:
POST /web3/verify
- SSE Metrics Stream:
GET /metrics/stream(Server-Sent Events) - WebSocket Connection:
ws://localhost:3000(Real-time updates)
The WebSocket server provides real-time updates for:
- Trading Activities: Position opens, closes, and modifications
- Market Data: Price updates and market data changes
- Alerts: System alerts and notifications
- Analytics: Dashboard updates and performance metrics
- Risk Management: Risk assessment updates and limit breaches
For detailed API specification, see openapi.yaml or visit /docs when the server is running.
docker build -t pyth-aa .docker run -p 3000:3000 --env-file .env pyth-aadocker-compose up --buildnpm testnpm test -- test/alertSystem.test.js
npm test -- test/api.test.js
npm test -- test/tradingEngine.test.jsnpm run lintMIT License - see LICENSE for details.
We welcome contributions! Please see our Contributing Guidelines for details.
We accept donations through KatyaAI and forward a portion to other open-source projects that made Pyth possible.