DSL Strategy Order
DSL (Domain Specific Language) Conditional Order is an advanced trading feature provided by Deepcoin, allowing users to define complex market-triggered logic via JSON, which is then executed automatically by the system.
1. API Information
- Endpoint Name: DSL Strategy Order (DSL Trigger Order)
- Request Method:
POST - Request URL:
/deepcoin/trade/dsl-trigger-order - Content-Type:
application/json
2. Overall Request Architecture
The request body consists of two core objects: account/trade configuration (trade_info) and strategy logic definition (dsl_json):
{
"trade_info": { ... }, // Defines: Where to place the order? What leverage to use? Which margin mode?
"dsl_json": { ... } // Defines: When to place the order? How much to buy? How to set take-profit/stop-loss?
}
3. Detailed Parameter Definitions
3.1 Account & Trading Layer (trade_info)
| Parameter | Required | Type | Description |
|---|---|---|---|
symbol | Yes | String | Trading pair identifier (e.g., BTC-USDT-SWAP) |
tradeMode | Yes | String | Margin Mode: isolated, cross |
mrgPosition | No | String | Position Mode: merge (one-way), split (two-way); defaults to merge |
3.2 Strategy Logic Layer (dsl_json)
| Parameter | Required | Type | Description |
|---|---|---|---|
version | No | String | DSL version, e.g., "1.0" |
indicators | Yes | Array | Array of technical indicators and their trigger conditions (see 3.2.1) |
then | Yes | Object | Execution actions after conditions are met: open/close position (see 3.2.2) |
risk | No | Object | Built-in take-profit/stop-loss protection: stop_loss, take_profit (see 3.2.3) |
3.2.1 Technical Indicators (indicators)
The system evaluates the logic based on the conditions defined in indicators (multiple indicators default to AND logic).
| Parameter | Required | Type | Description |
|---|---|---|---|
name | Yes | String | Unique identifier for the indicator (e.g., ma5, boll) |
type | Yes | String | Indicator Type: BOLL, MA, EMA, KDJ, RSI, WR |
params | Yes | Object | Indicator calculation parameters (see 3.2.1.1) |
condition | Yes | Object | Trigger threshold (see 3.2.1.2) |
scope | Yes | String | Scope of action: entry (for opening a position), exit (for closing a position) |
3.2.1.1 Indicator Calculation Parameters (params)
| Indicator Type | params Included Parameters | Notes |
|---|---|---|
| Common | interval | Required. Candlestick period: 1m, 5m, 15m, 30m, 1h, 4h, 1d, 1w |
| BOLL | period, std, interval | std is the standard deviation multiplier for Bollinger Bands |
| MA / EMA | period, interval | - |
| KDJ | n, k_smoothing, d_smoothing, interval | n is the KDJ parameter, k_smoothing for K smoothing, d_smoothing for D smoothing |
| RSI / WR | period, interval | - |
3.2.1.2 Trigger Condition Fields & Examples (condition)
The condition object defines precise trigger logic by combining different fields.
| Parameter | Required | Type | Description |
|---|---|---|---|
ref | Yes | String | Indicator reference field (e.g., boll.lower) |
op | Yes | String | Comparison operator (<, >) |
right | No | Number | Comparison value (required for KDJ, RSI, WR indicators) |
diff_price | No | Number | Price difference between the current price and the indicator value |
| Scenario | condition Example | Business Meaning |
|---|---|---|
| Indicator vs. Price Comparison ( boll supports only market price comparison when right is omitted) | {"ref": "boll.lower", "op": "<"} | The 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": "ma", "op": ">", "diff_price": 100} | The MA line value is 100 points higher than the current price. |
3.2.2 Execution Actions (then)
Contains entry (for opening) or exit (for closing) logic blocks.
Action Branch (on_true):
| Parameter | Required | Type | Description |
|---|---|---|---|
action | No | String | Action: open, close |
side | No | String | Direction: long, short |
volume | Yes | Number | Order quantity in contracts |
3.2.3 Risk Control (risk)
| Parameter | Required | Type | Description |
|---|---|---|---|
stop_loss | No | Object | Stop-loss configuration. {"value": 0.1} means 10% |
take_profit | No | Object | Take-profit configuration. {"value": 0.2} means 20% |
4. Response Parameters
| Field | Type | Description |
|---|---|---|
sCode | Integer | Business status code. 0: success; others: failure |
sMsg | String | Error or prompt message |
5. Typical Application Examples
5.1 Combined Indicators (BOLL + KDJ) Entry
When the price breaks below the Bollinger lower band and the KDJ K-value is below 30, open a long position of 100 contracts.
{
"trade_info": {"symbol": "BTC-USDT-SWAP","tradeMode": "cross","mrgPosition": "merge"}, // cross-margin, one-way mode
"dsl_json": {
"indicators": [
{
"name": "boll",
"type": "BOLL",
"params": { "period": 20, "std": 2, "interval": "1m" }, // 20-period Bollinger Bands, 2x std dev, 1-min chart
"condition": { "ref": "boll.lower", "op": ">" }, // Current price breaks below the Bollinger lower band
"scope": "entry"
},
{
"name": "kdj",
"type": "KDJ",
"params": { "n": 9, "k_smoothing": 3, "d_smoothing": 3, "interval": "1m" }, // 9-period KDJ, 3-smoothing for K, 3-smoothing for D, 1-min chart
"condition": { "ref": "kdj.k", "op": "<", "right": 30 }, // KDJ K-value is below 30
"scope": "entry"
}
],
"then": {
"entry": {
"on_true": { "action": "open", "side": "long", "volume": 100 } // Open a long position of 100 contracts
}
}
}
}
5.2 Entry + Exit + Full Risk Control
When the current price is above MA5, open a long position of 50 contracts. When the current price is below MA20, close the long position of 50 contracts.
{
"trade_info": { "symbol": "ETH-USDT-SWAP", "tradeMode":"isolated" }, // isolated margin mode
"dsl_json": {
"indicators": [
{ "name": "ma5",
"type": "MA",
"params": { "period": 5, "interval": "1h" }, // 5-period MA, 1-hour chart
"condition": { "ref": "ma", "op": "<" }, // Current price is above MA5
"scope": "entry" },
{ "name": "ma20",
"type": "MA",
"params": { "period": 20, "interval": "1h" }, // 20-period MA, 1-hour chart
"condition": { "ref": "ma", "op": ">" }, // Current price is below MA20
"scope": "exit" }
],
"then": {
"entry": { "on_true": { "action": "open", "side": "long", "volume": 50 } }, // Open a long position of 50 contracts
"exit": { "on_true": { "action": "close", "side": "long", "volume": 50 } } // Close a long position of 50 contracts
},
"risk": {
"stop_loss": { "value": 0.05 }, // 5% stop-loss
"take_profit": { "value": 0.15 } // 15% take-profit
}
}
}
6. Usage Notes
- Indicator Logic: All indicators with
scope: "entry"must be met simultaneously (AND logic) to trigger thethen.entryaction. - Exit Logic: Similarly, all indicators with
scope: "exit"must be met to trigger thethen.exitaction. - Backtesting Support: The API currently only supports
on_truefor live trading.