🚀 Botmoon P2P API Documentation

āļ„āļđāđˆāļĄāļ·āļ­ API āļŠāļģāļŦāļĢāļąāļšāļĢāļ°āļšāļš Botmoon P2P - āļĢāļ­āļ‡āļĢāļąāļšāļāļēāļĢāļŠāđˆāļ‡āđ‚āļ„āđ‰āļ”āļˆāļēāļ AI Chat, Backtest āļ­āļąāļ•āđ‚āļ™āļĄāļąāļ•āļī, āđāļĨāļ°āļˆāļąāļ”āļāļēāļĢāļāļĨāļĒāļļāļ—āļ˜āđŒ

Base URL
http://localhost:37674
Features
  • AI Code Deployment - āļŠāđˆāļ‡āđ‚āļ„āđ‰āļ” Python āļˆāļēāļ AI Chat āļĄāļēāļĢāļąāļ™āļšāļ™āđ€āļ‹āļīāļĢāđŒāļŸāđ€āļ§āļ­āļĢāđŒ
  • Backtest API - Backtest āļāļĨāļĒāļļāļ—āļ˜āđŒāļ—āļĩāđˆāļŠāļĢāđ‰āļēāļ‡āļˆāļēāļ AI āļžāļĢāđ‰āļ­āļĄāļœāļĨāļĨāļąāļžāļ˜āđŒāđāļšāļšāļĨāļ°āđ€āļ­āļĩāļĒāļ”
  • Console Status - āļ•āļĢāļ§āļˆāļŠāļ­āļšāļŠāļ–āļēāļ™āļ°āļāļĨāļĒāļļāļ—āļ˜āđŒāļ—āļĩāđˆāļāļģāļĨāļąāļ‡āļĢāļąāļ™
  • Webhook Integration - āļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“āđ€āļ—āļĢāļ”āđ„āļ›āļĒāļąāļ‡āļĢāļ°āļšāļšāļ āļēāļĒāļ™āļ­āļ

🔐 Authentication

āļ›āļąāļˆāļˆāļļāļšāļąāļ™ API āđ„āļĄāđˆāļ•āđ‰āļ­āļ‡āļāļēāļĢ Authentication (āđƒāļŠāđ‰āļ āļēāļĒāđƒāļ™āđ€āļ„āļĢāļ·āļ­āļ‚āđˆāļēāļĒāļ—āļĩāđˆāļ›āļĨāļ­āļ”āļ āļąāļĒ)

⚠ïļ āļ„āļ§āļĢāđƒāļŠāđ‰ API āļ™āļĩāđ‰āđƒāļ™āđ€āļ„āļĢāļ·āļ­āļ‚āđˆāļēāļĒāļ—āļĩāđˆāļ›āļĨāļ­āļ”āļ āļąāļĒāđ€āļ—āđˆāļēāļ™āļąāđ‰āļ™ āļŦāļĢāļ·āļ­āđ€āļžāļīāđˆāļĄ Authentication āđ€āļĄāļ·āđˆāļ­āđƒāļŠāđ‰āļ‡āļēāļ™āļˆāļĢāļīāļ‡

ðŸĪ– AI Code Deployment NEW

API āļŠāļģāļŦāļĢāļąāļšāļŠāđˆāļ‡āđ‚āļ„āđ‰āļ”āļˆāļēāļ AI Chat (āđ€āļŠāđˆāļ™ ChatGPT, Claude) āļĄāļēāļĢāļąāļ™āļšāļ™āđ€āļ‹āļīāļĢāđŒāļŸāđ€āļ§āļ­āļĢāđŒ

POST /api/code/deploy

āļŠāđˆāļ‡āđ‚āļ„āđ‰āļ” Python āļˆāļēāļ AI Chat āļĄāļē deploy āļšāļ™āđ€āļ‹āļīāļĢāđŒāļŸāđ€āļ§āļ­āļĢāđŒ āļĢāļ°āļšāļšāļˆāļ° validate āđāļĨāļ° register code āļŠāļģāļŦāļĢāļąāļšāļĢāļąāļ™

Request Body
Parameter Type Required Description
code string Yes Python code to deploy
name string No Algorithm name (default: "AI_Deployed")
auto_run boolean No Auto-execute on console (default: true)
return_result boolean No Return execution result (default: false)
Example Request
JSON
{
  "code": "# My algorithm\nprint('Hello from AI!')\nresult = 42",
  "name": "MyAlgorithm",
  "auto_run": true,
  "return_result": true
}
Example Response
Response 200
{
  "success": true,
  "execution_id": "exec_abc123",
  "name": "MyAlgorithm",
  "status": "completed",
  "auto_deploy": true,
  "execution": {
    "status": "completed",
    "output": "Hello from AI!\n",
    "result": 42,
    "execution_time_ms": 15
  }
}
POST /api/code/execute

Execute Python code directly and return results

Request Body
{
  "code": "import numpy as np\nprint(np.mean([1,2,3,4,5]))",
  "name": "NumpyTest"
}
POST /api/code/validate

Validate Python code without executing it

Security Checks
  • ðŸšŦ Blocks: os, sys, subprocess, socket
  • ðŸšŦ Blocks: eval(), exec(), open(), compile()
  • ✅ Allows: numpy, pandas, standard math functions
GET /api/code/history

Get execution history

Query Parameters
Parameter Type Default Description
limit integer 50 Number of records to return

📊 Backtest API NEW

API āļŠāļģāļŦāļĢāļąāļš Backtest āļāļĨāļĒāļļāļ—āļ˜āđŒāļ—āļĩāđˆāļŠāļĢāđ‰āļēāļ‡āļˆāļēāļ AI - āļŠāđˆāļ‡āđ‚āļ„āđ‰āļ”āļĄāļēāđāļĨāđ‰āļ§āļĢāļ°āļšāļšāļˆāļ°āļ”āļķāļ‡āļ‚āđ‰āļ­āļĄāļđāļĨāļĒāđ‰āļ­āļ™āļŦāļĨāļąāļ‡āđāļĨāļ°āļĢāļąāļ™ Backtest āđƒāļŦāđ‰āļ­āļąāļ•āđ‚āļ™āļĄāļąāļ•āļī

POST /api/backtest/code

Run backtest with custom strategy code from AI chat

Request Body
Parameter Type Required Description
code string Yes Python strategy code
backtest_config object No Backtest configuration
strategy_params object No Strategy parameters
Backtest Config Options
{
  "exchange": "binance",           // binance, okx
  "symbol": "BTC/USDT:USDT",       // Trading symbol
  "timeframe": "1h",               // 1m, 5m, 15m, 1h, 4h, 1d
  "symbol_type": "CRYPTO_FUTURE",  // CRYPTO_FUTURE, CRYPTO_SPOT
  "initial_capital": 10000,        // Starting capital
  "commission_rate": 0.0005,       // Trading fee (0.05%)
  "limit": 500,                    // Number of candles
  "enabled_directions": ["long", "short"]
}
Example Request
Full Example
{
  "code": "class EMAStrategy:\n    def __init__(self, params):\n        self.ema_short = params.get('ema_short', 9)\n        self.ema_long = params.get('ema_long', 21)\n    \n    def generate_signals(self, data):\n        # ... strategy logic\n        return {'signals': signals}\n    \n    def calculate_tp_sl_levels(self, entry_price, side):\n        # ... TP/SL logic\n        return tp_price, sl_price\n    \n    def calculate_position_size(self, capital, entry_price, sl_price, side):\n        # ... position sizing\n        return size",
  "backtest_config": {
    "exchange": "binance",
    "symbol": "BTC/USDT:USDT",
    "timeframe": "1h",
    "initial_capital": 10000
  },
  "strategy_params": {
    "ema_short": 9,
    "ema_long": 21,
    "tp_pct": 2.0,
    "sl_pct": 1.0
  }
}
Example Response
Success Response
{
  "success": true,
  "metrics": {
    "total_return": 4523.50,
    "total_return_pct": 45.24,
    "cagr": 32.15,
    "max_drawdown": 12.50,
    "win_rate": 58.33,
    "profit_factor": 1.85,
    "sharpe_ratio": 1.42,
    "total_trades": 24,
    "winning_trades": 14,
    "losing_trades": 10,
    "avg_trade": 188.48,
    "avg_win": 450.25,
    "avg_loss": -235.15
  },
  "trades": [...],
  "equity_curve": [...],
  "config": {
    "exchange": "binance",
    "symbol": "BTC/USDT:USDT",
    "timeframe": "1h",
    "data_points": 500,
    "data_start": "2025-01-01 00:00:00",
    "data_end": "2025-02-17 00:00:00"
  }
}
POST /api/backtest/quick

Quick backtest with minimal configuration - uses defaults for most settings

Simplified Request
{
  "code": "...strategy code...",
  "symbol": "BTC/USDT:USDT",
  "timeframe": "1h",
  "exchange": "binance"
}
POST /api/backtest/validate

Validate strategy code without running backtest

Response
{
  "success": true,
  "validation": {
    "valid": true,
    "errors": [],
    "warnings": []
  }
}
GET /api/backtest/symbols

Get list of available symbols for backtesting

Response
{
  "success": true,
  "symbols": [
    {"symbol": "BTC/USDT:USDT", "name": "Bitcoin", "type": "CRYPTO_FUTURE"},
    {"symbol": "ETH/USDT:USDT", "name": "Ethereum", "type": "CRYPTO_FUTURE"},
    {"symbol": "SOL/USDT:USDT", "name": "Solana", "type": "CRYPTO_FUTURE"}
  ],
  "exchanges": ["binance", "okx"],
  "timeframes": ["1m", "5m", "15m", "30m", "1h", "2h", "4h", "1d"]
}
GET /api/backtest/example-code

Get example strategy code for reference

📚 Console Status API

API āļŠāļģāļŦāļĢāļąāļšāļ•āļĢāļ§āļˆāļŠāļ­āļšāļŠāļ–āļēāļ™āļ° Console āđāļĨāļ°āļāļĨāļĒāļļāļ—āļ˜āđŒāļ—āļĩāđˆāļāļģāļĨāļąāļ‡āļĢāļąāļ™

GET /api/console/status

Get detailed console status including strategies, AI executions, streams, and saved algorithms

Response
{
  "success": true,
  "timestamp": "2026-02-17T12:00:00",
  "summary": {
    "total_strategies": 3,
    "running_strategies": 1,
    "enabled_strategies": 2,
    "total_symbols": 38,
    "enabled_symbols": 38,
    "active_streams": 38,
    "ai_executions_count": 5,
    "saved_algorithms_count": 2
  },
  "strategies": [...],
  "ai_executions": [...],
  "streams": [...],
  "saved_algorithms": [...]
}
GET /api/console/summary

Get quick summary of console status (lighter response)

GET /api/console/running

Get only currently running strategies

⚙ïļ Strategy Management

API āļŠāļģāļŦāļĢāļąāļšāļˆāļąāļ”āļāļēāļĢāļāļĨāļĒāļļāļ—āļ˜āđŒ - āđ€āļĢāļīāđˆāļĄ, āļŦāļĒāļļāļ”, āļ­āļąāļ›āđ€āļ”āļ•āļāļēāļĢāļ•āļąāđ‰āļ‡āļ„āđˆāļē

POST /api/strategy/start/{strategy_name}

Start running a strategy

Request Body (optional)
{
  "symbols": ["BTCUSDT_BINANCE", "ETHUSDT_BINANCE"],
  "price_source": "ccxt",
  "timeframe": "15m",
  "interval_seconds": 60,
  "webhook_endpoint_ids": [1, 2]
}
POST /api/strategy/stop/{strategy_name}

Stop running a strategy

POST /api/strategy/update

Update strategy configuration

🔗 Webhook Integration

API āļŠāļģāļŦāļĢāļąāļšāļŠāđˆāļ‡ Webhook āđ„āļ›āļĒāļąāļ‡āļĢāļ°āļšāļšāļ āļēāļĒāļ™āļ­āļ

POST /api/send_webhook

Send webhook payload to external system

Request Body
{
  "webhook_url": "https://your-webhook-url.com/webhook",
  "market_type": "CRYPTO_FUTURES",
  "symbol": "BTCUSDT",
  "side": "BUY_MARKET",
  "signal_type": "EMA_CROSS",
  "risk_level": "BALANCED",
  "timeframe": "15",
  "price": 50000.00,
  "tp_pct": 2.0,
  "sl_pct": 1.0
}
POST /api/test_webhook

Test webhook with sample payload

📝 Strategy Code Template

Template āļŠāļģāļŦāļĢāļąāļšāļŠāļĢāđ‰āļēāļ‡āļāļĨāļĒāļļāļ—āļ˜āđŒāļ—āļĩāđˆāļŠāđˆāļ‡āļĄāļēāļˆāļēāļ AI Chat

Required Methods
Python Strategy Class
class MyStrategy:
    """Your strategy description"""
    
    def __init__(self, params):
        """Initialize strategy with parameters"""
        self.tp_pct = params.get('tp_pct', 2.0)
        self.sl_pct = params.get('sl_pct', 1.0)
        # Add your parameters here
    
    def generate_signals(self, data):
        """
        Generate trading signals.
        
        Args:
            data: DataFrame with columns [open, high, low, close, volume]
        
        Returns:
            Dict with 'signals' list containing signal objects:
            [
                {
                    'time': timestamp,
                    'type': 'long' or 'short',
                    'price': entry_price
                },
                ...
            ]
        """
        import numpy as np
        import pandas as pd
        
        signals = []
        
        # Your signal logic here
        # Example: EMA crossover
        df = data.copy()
        df['ema_fast'] = df['close'].ewm(span=9).mean()
        df['ema_slow'] = df['close'].ewm(span=21).mean()
        
        for i in range(1, len(df)):
            # Long signal
            if df['ema_fast'].iloc[i-1] <= df['ema_slow'].iloc[i-1] and \
               df['ema_fast'].iloc[i] > df['ema_slow'].iloc[i]:
                signals.append({
                    'time': df.index[i],
                    'type': 'long',
                    'price': df['close'].iloc[i]
                })
            
            # Short signal
            elif df['ema_fast'].iloc[i-1] >= df['ema_slow'].iloc[i-1] and \
                 df['ema_fast'].iloc[i] < df['ema_slow'].iloc[i]:
                signals.append({
                    'time': df.index[i],
                    'type': 'short',
                    'price': df['close'].iloc[i]
                })
        
        return {'signals': signals}
    
    def calculate_tp_sl_levels(self, entry_price, side):
        """
        Calculate take profit and stop loss levels.
        
        Args:
            entry_price: Entry price
            side: 'long' or 'short'
        
        Returns:
            Tuple (tp_price, sl_price)
        """
        if side == 'long':
            tp = entry_price * (1 + self.tp_pct / 100)
            sl = entry_price * (1 - self.sl_pct / 100)
        else:
            tp = entry_price * (1 - self.tp_pct / 100)
            sl = entry_price * (1 + self.sl_pct / 100)
        return tp, sl
    
    def calculate_position_size(self, capital, entry_price, sl_price, side):
        """
        Calculate position size.
        
        Args:
            capital: Available capital
            entry_price: Entry price
            sl_price: Stop loss price
            side: 'long' or 'short'
        
        Returns:
            Position size (quantity)
        """
        risk_pct = 2.0  # Risk 2% per trade
        risk_amount = capital * (risk_pct / 100)
        
        if sl_price is None:
            return risk_amount / entry_price
        
        risk_per_unit = abs(entry_price - sl_price)
        if risk_per_unit == 0:
            return risk_amount / entry_price
        
        return risk_amount / risk_per_unit