Skip to main content

Backtest Run

DSL (Domain Specific Language) Backtest is an advanced trading feature provided by Deepcoin, allowing users to backtest complex market-triggered strategies via JSON against historical data.


1. API Information​

  • Endpoint Name: DSL Backtest Run (Backtest Run)
  • Request Method: POST
  • Request URL: /deepcoin/trade/backtest-run
  • Content-Type: application/json

2. Overall Request Architecture​

The request body consists of two core objects: strategy logic definition (dsl) and historical data configuration (data_source):

{
"dsl": { ... }, // Defines: Strategy logic, indicators, execution actions, risk control
"data_source": { ... } // Defines: Which trading pair? What time period for backtesting?
}

3. Detailed Parameter Definitions​

3.1 Strategy Logic Layer (dsl)​

ParameterRequiredTypeDescription
versionNoStringDSL version, e.g., "1.0"
indicatorsYesArrayArray of technical indicators and their trigger conditions (see 3.1.1)
thenYesObjectExecution actions after conditions are met: open/close position (see 3.1.2)
riskNoObjectOrder's built-in take-profit/stop-loss protection: stop_loss, take_profit (see 3.1.3)
executionNoObjectExecution configuration (optional, see 3.1.4)

3.1.1 Technical Indicators (indicators)​

The system evaluates the logic based on the conditions defined in indicators (multiple indicators default to AND logic).

ParameterRequiredTypeDescription
nameYesStringUnique identifier for the indicator (e.g., ma5, boll)
typeYesStringIndicator Type: BOLL, MA, EMA, KDJ, RSI, WR
paramsYesObjectIndicator calculation parameters (see 3.1.1.1)
conditionYesObjectTrigger threshold (see 3.1.1.2)
scopeYesStringScope of action: entry (for opening position), exit (for closing position)
3.1.1.1 Indicator Calculation Parameters (params)​
Indicator Typeparams Included ParametersNotes
CommonintervalRequired. Candlestick period: 1m, 5m, 15m, 30m, 1h, 4h, 1d, 1w
BOLLperiod, std ,intervalstd is the standard deviation multiplier for Bollinger Bands
MA / EMAperiod,interval-
KDJn, k_smoothing, d_smoothing,intervaln is the KDJ parameter, k_smoothing for K smoothing, d_smoothing for D smoothing
RSI / WRperiod,interval-
3.1.1.2 Trigger Condition Fields & Examples (condition)​

The condition object defines precise trigger logic by combining different fields.

ParameterRequiredTypeDescription
refYesStringIndicator reference field (e.g., boll.lower)
opYesStringComparison operator (<,>)
rightNoNumberComparison value (required for KDJ, RSI, WR indicators)
diff_priceNoNumberPrice difference between current price and indicator value
Scenariocondition ExampleBusiness Meaning
Indicator vs. Price Comparison
(boll omits right, only supports market price comparison)
{"ref": "boll.lower", "op": "<"}Current market price is higher than the Bollinger Bands lower band.
Indicator vs. Fixed Value Comparison
(using right)
{"ref": "kdj.k", "op": ">", "right": 80}The KDJ indicator's K value is greater than 80.
Indicator vs. Price Difference Comparison
(using diff_price)
{"ref": "ma5.value", "op": ">", "diff_price": 100}The MA line value is 100 points higher than the current price.

3.1.2 Execution Actions (then)​

Contains entry (for opening) or exit (for closing) logic blocks.

Action Branch (on_true):

ParameterRequiredTypeDescription
actionNoStringAction: open(open position), close(close position)
sideNoStringDirection: long, short
volumeYesNumberOrder quantity in contracts

3.1.3 Risk Control (risk)​

ParameterRequiredTypeDescription
stop_lossNoObjectStop-loss configuration.{"value": 0.1} means 10%
take_profitNoObjectTake-profit configuration.{"value": 0.2} means 20%

3.1.4 Execution Configuration (execution)​

ParameterRequiredTypeDescription
fee_bpsNoNumberFee in basis points (e.g., 5 means 0.05%)

3.2 Data Source Configuration (data_source)​

ParameterRequiredTypeDescription
symbolYesStringTrading pair identifier (e.g., BTC-USDT-SWAP)
from_tsYesIntegerStart timestamp (Unix timestamp in seconds)
to_tsYesIntegerEnd timestamp (Unix timestamp in seconds)

3.3 Additional Parameters​

ParameterRequiredTypeDescription
include_tradesNoBooleanWhether to include detailed trade records in response; defaults to true

4. Response Parameters​

4.1 Basic Response​

FieldTypeDescription
codeIntegerBusiness status code. 0: success; others: failure
msgStringError or prompt message
dataObjectBacktest result data (see 4.2)

4.2 Backtest Result Data​

FieldTypeDescription
summaryObjectBacktest summary statistics (see 4.2.1)
tradesArrayArray of trade records (see 4.2.2)

4.2.1 Backtest Summary​

FieldTypeDescription
realized_pnlNumberRealized profit and loss
symbolStringTrading pair symbol
total_feeNumberTotal fees paid
tradesIntegerTotal number of trades

4.2.2 Trade Records​

FieldTypeDescription
feeNumberFee for this trade
order_idStringOrder ID
priceNumberTrade price
qtyNumberTrade quantity
reasonStringReason for the trade
sideStringTrade direction: buy, sell
tsIntegerTimestamp of the trade

5. Typical Application Examples​

5.1 Complete Request Example​

A comprehensive example showing all available parameters for a BOLL strategy backtest.

{
"dsl": {
"version": "1.0",
"indicators": [
{
"name": "boll",
"type": "BOLL",
"scope": "entry",
"params": {
"period": 15,
"std": 2,
"interval": "1m"
},
"condition": {
"ref": "boll.lower",
"op": "<",
"right": "price.close",
"diff_price": 10
}
}
],
"then": {
"entry": {
"on_true": {
"action": "open",
"side": "long",
"volume": 0.1
},
"on_false": {
"action": "none",
"side": "long",
"volume": 0
}
},
"exit": {
"on_true": {
"action": "close",
"side": "long",
"volume": 100
},
"on_false": {
"action": "none",
"side": "long",
"volume": 0
}
}
},
"execution": {
"fee_bps": 5
},
"risk": {
"stop_loss": {
"value": 0.1
},
"take_profit": {
"value": 0.1
}
}
},
"data_source": {
"symbol": "BTC-USDT-SWAP",
"from_ts": 1772054911,
"to_ts": 1772090911
}
}

5.2 Combined Indicators (BOLL + KDJ) Backtest​

Backtest a strategy where a long position is opened when the price breaks below the Bollinger lower band and the KDJ K-value is below 30.

{
"dsl": {
"version": "1.0",
"indicators": [
{
"name": "boll",
"type": "BOLL",
"scope": "entry",
"params": {
"period": 20,
"std": 2,
"interval": "1m"
},
"condition": {
"ref": "boll.lower",
"op": "<",
"right": "price.close"
}
},
{
"name": "kdj",
"type": "KDJ",
"scope": "entry",
"params": {
"n": 9,
"k_smoothing": 3,
"d_smoothing": 3,
"interval": "1m"
},
"condition": {
"ref": "kdj.k",
"op": "<",
"right": 30
}
}
],
"then": {
"entry": {
"on_true": {
"action": "open",
"side": "long",
"volume": 100
},
"on_false": {
"action": "none",
"side": "long",
"volume": 0
}
},
"exit": {
"on_true": {
"action": "close",
"side": "long",
"volume": 0
},
"on_false": {
"action": "none",
"side": "long",
"volume": 0
}
}
},
"risk": {
"stop_loss": {
"value": 0.1
},
"take_profit": {
"value": 0.5
}
}
},
"data_source": {
"symbol": "BTC-USDT-SWAP",
"from_ts": 1704067200,
"to_ts": 1706745600
}
}

5.3 MA Crossover Strategy with Full Risk Control​

Backtest a strategy using MA crossover for entry and exit signals.

{
"dsl": {
"version": "1.0",
"indicators": [
{
"name": "ma5",
"type": "MA",
"scope": "entry",
"params": {
"period": 5,
"interval": "1h"
},
"condition": {
"ref": "ma5.value",
"op": "<",
"right": "price.close"
}
},
{
"name": "ma20",
"type": "MA",
"scope": "exit",
"params": {
"period": 20,
"interval": "1h"
},
"condition": {
"ref": "ma20.value",
"op": ">",
"right": "price.close"
}
}
],
"then": {
"entry": {
"on_true": {
"action": "open",
"side": "long",
"volume": 50
},
"on_false": {
"action": "none",
"side": "long",
"volume": 0
}
},
"exit": {
"on_true": {
"action": "close",
"side": "long",
"volume": 50
},
"on_false": {
"action": "none",
"side": "long",
"volume": 0
}
}
},
"execution": {
"fee_bps": 5
},
"risk": {
"stop_loss": {
"value": 0.05
},
"take_profit": {
"value": 0.15
}
}
},
"data_source": {
"symbol": "ETH-USDT-SWAP",
"from_ts": 1704067200,
"to_ts": 1706745600
}
}

6. Usage Notes​

  1. Indicator Logic: All indicators with scope: "entry" must be met simultaneously (when entry_condition_mode is ALL) to trigger the then.entry action.
  2. Exit Logic: Similarly, all indicators with scope: "exit" must be met to trigger the then.exit action.
  3. Data Range: Ensure from_ts and to_ts cover sufficient historical data for meaningful backtesting results.
  4. Risk Management: Always configure appropriate stop-loss and take-profit levels to manage risk in your strategy.
  5. Backtesting Limitations: Past performance does not guarantee future results. Use backtesting as one tool among many for strategy validation.