ð 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 (āđāļāđāļ āļēāļĒāđāļāđāļāļĢāļ·āļāļāđāļēāļĒāļāļĩāđāļāļĨāļāļāļ āļąāļĒ)
ðĪ AI Code Deployment NEW
API āļŠāļģāļŦāļĢāļąāļāļŠāđāļāđāļāđāļāļāļēāļ AI Chat (āđāļāđāļ ChatGPT, Claude) āļĄāļēāļĢāļąāļāļāļāđāļāļīāļĢāđāļāđāļ§āļāļĢāđ
āļŠāđāļāđāļāđāļ 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
{
"code": "# My algorithm\nprint('Hello from AI!')\nresult = 42",
"name": "MyAlgorithm",
"auto_run": true,
"return_result": true
}
Example Response
{
"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
}
}
Execute Python code directly and return results
Request Body
{
"code": "import numpy as np\nprint(np.mean([1,2,3,4,5]))",
"name": "NumpyTest"
}
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 execution history
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| limit | integer | 50 | Number of records to return |
ð Backtest API NEW
API āļŠāļģāļŦāļĢāļąāļ Backtest āļāļĨāļĒāļļāļāļāđāļāļĩāđāļŠāļĢāđāļēāļāļāļēāļ AI - āļŠāđāļāđāļāđāļāļĄāļēāđāļĨāđāļ§āļĢāļ°āļāļāļāļ°āļāļķāļāļāđāļāļĄāļđāļĨāļĒāđāļāļāļŦāļĨāļąāļāđāļĨāļ°āļĢāļąāļ Backtest āđāļŦāđāļāļąāļāđāļāļĄāļąāļāļī
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
{
"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": 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"
}
}
Quick backtest with minimal configuration - uses defaults for most settings
Simplified Request
{
"code": "...strategy code...",
"symbol": "BTC/USDT:USDT",
"timeframe": "1h",
"exchange": "binance"
}
Validate strategy code without running backtest
Response
{
"success": true,
"validation": {
"valid": true,
"errors": [],
"warnings": []
}
}
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 example strategy code for reference
ðš Console Status API
API āļŠāļģāļŦāļĢāļąāļāļāļĢāļ§āļāļŠāļāļāļŠāļāļēāļāļ° Console āđāļĨāļ°āļāļĨāļĒāļļāļāļāđāļāļĩāđāļāļģāļĨāļąāļāļĢāļąāļ
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 quick summary of console status (lighter response)
Get only currently running strategies
âïļ Strategy Management
API āļŠāļģāļŦāļĢāļąāļāļāļąāļāļāļēāļĢāļāļĨāļĒāļļāļāļāđ - āđāļĢāļīāđāļĄ, āļŦāļĒāļļāļ, āļāļąāļāđāļāļāļāļēāļĢāļāļąāđāļāļāđāļē
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]
}
Stop running a strategy
Update strategy configuration
ð Webhook Integration
API āļŠāļģāļŦāļĢāļąāļāļŠāđāļ 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
}
Test webhook with sample payload
ð Strategy Code Template
Template āļŠāļģāļŦāļĢāļąāļāļŠāļĢāđāļēāļāļāļĨāļĒāļļāļāļāđāļāļĩāđāļŠāđāļāļĄāļēāļāļēāļ AI Chat
Required Methods
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