Skip to main content

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)​

ParameterRequiredTypeDescription
symbolYesStringTrading pair identifier (e.g., BTC-USDT-SWAP)
tradeModeYesStringMargin Mode: isolated, cross
mrgPositionNoStringPosition Mode: merge (one-way), split (two-way); defaults to merge

3.2 Strategy Logic Layer (dsl_json)​

ParameterRequiredTypeDescription
versionNoStringDSL version, e.g., "1.0"
indicatorsYesArrayArray of technical indicators and their trigger conditions (see 3.2.1)
thenYesObjectExecution actions after conditions are met: open/close position (see 3.2.2)
riskNoObjectBuilt-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).

ParameterRequiredTypeDescription
nameYesStringUnique identifier for the indicator (e.g., ma5, boll)
typeYesStringIndicator Type: BOLL, MA, EMA, KDJ, RSI, WR
paramsYesObjectIndicator calculation parameters (see 3.2.1.1)
conditionYesObjectTrigger threshold (see 3.2.1.2)
scopeYesStringScope of action: entry (for opening a position), exit (for closing a position)
3.2.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.2.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 the current price and the indicator value
Scenariocondition ExampleBusiness 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": "ma5.value", "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):

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

3.2.3 Risk Control (risk)​

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

4. Response Parameters​

FieldTypeDescription
sCodeIntegerBusiness status code. 0: success; others: failure
sMsgStringError 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": "ma5.value", "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": "ma20.value", "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​

  1. Indicator Logic: All indicators with scope: "entry" must be met simultaneously (AND logic) 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. Backtesting Support: The API currently only supports on_true for live trading.