{
  "version": 1,
  "categories": {
    "custom_logic": [
      {
        "id": "01-wait-after-cross",
        "file": "01-wait-after-cross.json",
        "title": "Wait after cross",
        "summary": "Arm on EMA cross-down, wait N bars, then buy (classic stateful customLogic).",
        "payload": {
          "enabled": true,
          "invert": false,
          "params": {
            "version": 1,
            "summary": "- Setup when close crosses below EMA(20)\n- Wait 4 closed candles while still below the EMA\n- Buy on the next bar if still watching\n- Cancel if price reclaims the EMA before buy",
            "vars": {
              "ma": {
                "fn": "ema",
                "args": [
                  {
                    "series": "close"
                  },
                  {
                    "const": 20
                  }
                ]
              }
            },
            "state": {
              "armed": {
                "type": "bool",
                "default": false
              },
              "barsWaited": {
                "type": "int",
                "default": 0
              }
            },
            "onBar": [
              {
                "if": {
                  "fn": "and",
                  "args": [
                    {
                      "state": "armed"
                    },
                    {
                      "fn": "gt",
                      "args": [
                        {
                          "series": "close"
                        },
                        {
                          "var": "ma"
                        }
                      ]
                    }
                  ]
                },
                "then": [
                  {
                    "set": "armed",
                    "value": {
                      "const": false
                    }
                  },
                  {
                    "set": "barsWaited",
                    "value": {
                      "const": 0
                    }
                  }
                ]
              },
              {
                "if": {
                  "fn": "and",
                  "args": [
                    {
                      "fn": "not",
                      "args": [
                        {
                          "state": "armed"
                        }
                      ]
                    },
                    {
                      "fn": "crossDown",
                      "args": [
                        {
                          "series": "close"
                        },
                        {
                          "var": "ma"
                        }
                      ]
                    }
                  ]
                },
                "then": [
                  {
                    "set": "armed",
                    "value": {
                      "const": true
                    }
                  },
                  {
                    "set": "barsWaited",
                    "value": {
                      "const": 0
                    }
                  }
                ]
              },
              {
                "if": {
                  "state": "armed"
                },
                "then": [
                  {
                    "if": {
                      "fn": "gte",
                      "args": [
                        {
                          "state": "barsWaited"
                        },
                        {
                          "const": 4
                        }
                      ]
                    },
                    "then": [
                      {
                        "emit": "buy"
                      },
                      {
                        "set": "armed",
                        "value": {
                          "const": false
                        }
                      },
                      {
                        "set": "barsWaited",
                        "value": {
                          "const": 0
                        }
                      }
                    ],
                    "else": [
                      {
                        "set": "barsWaited",
                        "value": {
                          "fn": "add",
                          "args": [
                            {
                              "state": "barsWaited"
                            },
                            {
                              "const": 1
                            }
                          ]
                        }
                      }
                    ]
                  }
                ]
              }
            ]
          }
        }
      },
      {
        "id": "02-per-leg-series-filter",
        "file": "02-per-leg-series-filter.json",
        "title": "Per leg series filter",
        "summary": "Gate on another market’s series via `\"leg\"`; emit without leg → strategy stamp / `targetLeg`.",
        "payload": {
          "enabled": true,
          "invert": false,
          "params": {
            "version": 1,
            "summary": "- Watch ETH on Binance via markets label eth_binance\n- Buy when that leg's close is above EMA(8)\n- Place uses strategy stamp / targetLeg (emit has no leg)",
            "vars": {
              "ma": {
                "fn": "ema",
                "args": [
                  {
                    "series": "close",
                    "leg": "eth_binance"
                  },
                  {
                    "const": 8
                  }
                ]
              }
            },
            "state": {},
            "onBar": [
              {
                "if": {
                  "fn": "gt",
                  "args": [
                    {
                      "series": "close",
                      "leg": "eth_binance"
                    },
                    {
                      "var": "ma"
                    }
                  ]
                },
                "then": [
                  {
                    "emit": "buy"
                  }
                ]
              }
            ]
          }
        }
      },
      {
        "id": "03-cheaper-venue-entry",
        "file": "03-cheaper-venue-entry.json",
        "title": "Cheaper venue entry",
        "summary": "Compare two venue closes; `{\"emit\":\"buy\",\"leg\":\"…\"}` places on the cheaper book.",
        "payload": {
          "enabled": true,
          "invert": false,
          "params": {
            "version": 1,
            "summary": "- Compare Binance vs OKX BTC closes\n- Buy on OKX when Binance close is higher\n- Otherwise buy on Binance",
            "vars": {},
            "state": {},
            "onBar": [
              {
                "if": {
                  "fn": "gt",
                  "args": [
                    {
                      "series": "close",
                      "leg": "btc_binance"
                    },
                    {
                      "series": "close",
                      "leg": "btc_okx"
                    }
                  ]
                },
                "then": [
                  {
                    "emit": "buy",
                    "leg": "btc_okx"
                  }
                ],
                "else": [
                  {
                    "emit": "buy",
                    "leg": "btc_binance"
                  }
                ]
              }
            ]
          }
        }
      },
      {
        "id": "04-funding-spread-legs",
        "file": "04-funding-spread-legs.json",
        "title": "Funding spread legs",
        "summary": "Compare `fundingRate` (8h-eq, candle-aligned) on two labels; buy the lower-funding book.",
        "payload": {
          "enabled": true,
          "invert": false,
          "params": {
            "version": 1,
            "summary": "- Compare eightHour-equivalent funding on two markets labels\n- Buy the leg with lower funding (receive bias)\n- Place on that book via emit.leg",
            "vars": {},
            "state": {},
            "onBar": [
              {
                "if": {
                  "fn": "gt",
                  "args": [
                    {
                      "series": "fundingRate",
                      "leg": "skhy"
                    },
                    {
                      "series": "fundingRate",
                      "leg": "skhynix"
                    }
                  ]
                },
                "then": [
                  {
                    "emit": "buy",
                    "leg": "skhynix"
                  }
                ],
                "else": [
                  {
                    "emit": "buy",
                    "leg": "skhy"
                  }
                ]
              }
            ]
          }
        }
      },
      {
        "id": "05-wait-after-cross-limit-on-trigger",
        "file": "05-wait-after-cross-limit-on-trigger.json",
        "title": "Wait after cross limit on trigger",
        "summary": "Same as 01, but buy with a deferred limit (`on_trigger`) after a % pullback from the signal.",
        "payload": {
          "enabled": true,
          "invert": false,
          "params": {
            "version": 1,
            "summary": "- Setup when close crosses below EMA(20)\n- Wait 4 closed candles while still below the EMA\n- Buy with a resting limit after a 1% pullback from the signal\n- Cancel if price reclaims the EMA before buy",
            "orderType": "limit",
            "limitArmFrom": "signal",
            "limitSendWhen": "on_trigger",
            "triggerType": "percentage",
            "triggerValue": 1,
            "targetType": "percentage",
            "targetValue": 0.5,
            "vars": {
              "ma": {
                "fn": "ema",
                "args": [
                  {
                    "series": "close"
                  },
                  {
                    "const": 20
                  }
                ]
              }
            },
            "state": {
              "armed": {
                "type": "bool",
                "default": false
              },
              "barsWaited": {
                "type": "int",
                "default": 0
              }
            },
            "onBar": [
              {
                "if": {
                  "fn": "and",
                  "args": [
                    {
                      "state": "armed"
                    },
                    {
                      "fn": "gt",
                      "args": [
                        {
                          "series": "close"
                        },
                        {
                          "var": "ma"
                        }
                      ]
                    }
                  ]
                },
                "then": [
                  {
                    "set": "armed",
                    "value": {
                      "const": false
                    }
                  },
                  {
                    "set": "barsWaited",
                    "value": {
                      "const": 0
                    }
                  }
                ]
              },
              {
                "if": {
                  "fn": "and",
                  "args": [
                    {
                      "fn": "not",
                      "args": [
                        {
                          "state": "armed"
                        }
                      ]
                    },
                    {
                      "fn": "crossDown",
                      "args": [
                        {
                          "series": "close"
                        },
                        {
                          "var": "ma"
                        }
                      ]
                    }
                  ]
                },
                "then": [
                  {
                    "set": "armed",
                    "value": {
                      "const": true
                    }
                  },
                  {
                    "set": "barsWaited",
                    "value": {
                      "const": 0
                    }
                  }
                ]
              },
              {
                "if": {
                  "state": "armed"
                },
                "then": [
                  {
                    "if": {
                      "fn": "gte",
                      "args": [
                        {
                          "state": "barsWaited"
                        },
                        {
                          "const": 4
                        }
                      ]
                    },
                    "then": [
                      {
                        "emit": "buy"
                      },
                      {
                        "set": "armed",
                        "value": {
                          "const": false
                        }
                      },
                      {
                        "set": "barsWaited",
                        "value": {
                          "const": 0
                        }
                      }
                    ],
                    "else": [
                      {
                        "set": "barsWaited",
                        "value": {
                          "fn": "add",
                          "args": [
                            {
                              "state": "barsWaited"
                            },
                            {
                              "const": 1
                            }
                          ]
                        }
                      }
                    ]
                  }
                ]
              }
            ]
          }
        }
      },
      {
        "id": "06-pairs-relative-legs",
        "file": "06-pairs-relative-legs.json",
        "title": "Pairs relative legs",
        "summary": "1-bar BTC vs SOL returns; `each_trade_leg` stamps both books (omit `emit.leg`; `eq` unlabeled close vs `leg:\"btc\"` detects the current book).",
        "payload": {
          "enabled": true,
          "invert": false,
          "params": {
            "version": 1,
            "summary": "- Compare 1-bar returns on BTC vs SOL\n- Short the outperformer and long the laggard\n- each_trade_leg places on both books (omit emit.leg)\n- Identify current book with eq(ctx.label, const)",
            "vars": {
              "btcRet": {
                "fn": "div",
                "args": [
                  {
                    "series": "close",
                    "leg": "btc"
                  },
                  {
                    "fn": "ref",
                    "args": [
                      {
                        "series": "close",
                        "leg": "btc"
                      },
                      {
                        "const": 1
                      }
                    ]
                  }
                ]
              },
              "solRet": {
                "fn": "div",
                "args": [
                  {
                    "series": "close",
                    "leg": "sol"
                  },
                  {
                    "fn": "ref",
                    "args": [
                      {
                        "series": "close",
                        "leg": "sol"
                      },
                      {
                        "const": 1
                      }
                    ]
                  }
                ]
              },
              "onBtc": {
                "fn": "eq",
                "args": [
                  {
                    "ctx": "label"
                  },
                  {
                    "const": "btc"
                  }
                ]
              }
            },
            "state": {},
            "onBar": [
              {
                "if": {
                  "var": "onBtc"
                },
                "then": [
                  {
                    "if": {
                      "fn": "gt",
                      "args": [
                        {
                          "var": "btcRet"
                        },
                        {
                          "var": "solRet"
                        }
                      ]
                    },
                    "then": [
                      {
                        "emit": "sell"
                      }
                    ],
                    "else": [
                      {
                        "emit": "buy"
                      }
                    ]
                  }
                ],
                "else": [
                  {
                    "if": {
                      "fn": "gt",
                      "args": [
                        {
                          "var": "btcRet"
                        },
                        {
                          "var": "solRet"
                        }
                      ]
                    },
                    "then": [
                      {
                        "emit": "buy"
                      }
                    ],
                    "else": [
                      {
                        "emit": "sell"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        }
      },
      {
        "id": "07-funding-limit-then-sibling-market",
        "file": "07-funding-limit-then-sibling-market.json",
        "title": "Funding limit then sibling market",
        "summary": "Array of two `customLogic` instances: (1) limit short funding winner while both flat; (2) market hedge opposite when sibling `ctx.position` is open. Use `placementMode: each_trade_leg` + `legSizing: equal_notional`. Optional `siblingHedgeOnEntryFill` for fill-instant OE hedge.",
        "payload": [
          {
            "enabled": true,
            "invert": false,
            "params": {
              "version": 1,
              "summary": "- Both books flat: short the higher eightHour funding leg via limit + small offset\n- Place only on the funding winner book this tick",
              "orderType": "limit",
              "limitArmFrom": "signal",
              "limitSendWhen": "now",
              "limitOffsetType": "percentage",
              "limitOffsetValue": -0.05,
              "limitStackPolicy": "stack",
              "vars": {
                "onDoge": {
                  "fn": "eq",
                  "args": [
                    {
                      "series": "close"
                    },
                    {
                      "series": "close",
                      "leg": "doge"
                    }
                  ]
                },
                "dogePaysMore": {
                  "fn": "gt",
                  "args": [
                    {
                      "series": "fundingRate",
                      "leg": "doge"
                    },
                    {
                      "series": "fundingRate",
                      "leg": "xrp"
                    }
                  ]
                },
                "bothFlat": {
                  "fn": "and",
                  "args": [
                    {
                      "fn": "eq",
                      "args": [
                        {
                          "ctx": "position",
                          "leg": "doge"
                        },
                        {
                          "const": 0
                        }
                      ]
                    },
                    {
                      "fn": "eq",
                      "args": [
                        {
                          "ctx": "position",
                          "leg": "xrp"
                        },
                        {
                          "const": 0
                        }
                      ]
                    }
                  ]
                }
              },
              "state": {},
              "onBar": [
                {
                  "if": {
                    "fn": "and",
                    "args": [
                      {
                        "var": "bothFlat"
                      },
                      {
                        "fn": "and",
                        "args": [
                          {
                            "var": "onDoge"
                          },
                          {
                            "var": "dogePaysMore"
                          }
                        ]
                      }
                    ]
                  },
                  "then": [
                    {
                      "emit": "sell"
                    }
                  ]
                },
                {
                  "if": {
                    "fn": "and",
                    "args": [
                      {
                        "var": "bothFlat"
                      },
                      {
                        "fn": "and",
                        "args": [
                          {
                            "fn": "eq",
                            "args": [
                              {
                                "series": "close"
                              },
                              {
                                "series": "close",
                                "leg": "xrp"
                              }
                            ]
                          },
                          {
                            "fn": "not",
                            "args": [
                              {
                                "var": "dogePaysMore"
                              }
                            ]
                          }
                        ]
                      }
                    ]
                  },
                  "then": [
                    {
                      "emit": "sell"
                    }
                  ]
                }
              ]
            }
          },
          {
            "enabled": true,
            "invert": false,
            "params": {
              "version": 1,
              "summary": "- This book flat and sibling open: market hedge opposite the sibling position\n- Latency is next execution_interval unless siblingHedgeOnEntryFill is also enabled",
              "orderType": "market",
              "vars": {
                "onDoge": {
                  "fn": "eq",
                  "args": [
                    {
                      "series": "close"
                    },
                    {
                      "series": "close",
                      "leg": "doge"
                    }
                  ]
                }
              },
              "state": {},
              "onBar": [
                {
                  "if": {
                    "fn": "and",
                    "args": [
                      {
                        "var": "onDoge"
                      },
                      {
                        "fn": "and",
                        "args": [
                          {
                            "fn": "eq",
                            "args": [
                              {
                                "ctx": "position"
                              },
                              {
                                "const": 0
                              }
                            ]
                          },
                          {
                            "fn": "lt",
                            "args": [
                              {
                                "ctx": "position",
                                "leg": "xrp"
                              },
                              {
                                "const": 0
                              }
                            ]
                          }
                        ]
                      }
                    ]
                  },
                  "then": [
                    {
                      "emit": "buy"
                    }
                  ]
                },
                {
                  "if": {
                    "fn": "and",
                    "args": [
                      {
                        "var": "onDoge"
                      },
                      {
                        "fn": "and",
                        "args": [
                          {
                            "fn": "eq",
                            "args": [
                              {
                                "ctx": "position"
                              },
                              {
                                "const": 0
                              }
                            ]
                          },
                          {
                            "fn": "gt",
                            "args": [
                              {
                                "ctx": "position",
                                "leg": "xrp"
                              },
                              {
                                "const": 0
                              }
                            ]
                          }
                        ]
                      }
                    ]
                  },
                  "then": [
                    {
                      "emit": "sell"
                    }
                  ]
                },
                {
                  "if": {
                    "fn": "and",
                    "args": [
                      {
                        "fn": "eq",
                        "args": [
                          {
                            "series": "close"
                          },
                          {
                            "series": "close",
                            "leg": "xrp"
                          }
                        ]
                      },
                      {
                        "fn": "and",
                        "args": [
                          {
                            "fn": "eq",
                            "args": [
                              {
                                "ctx": "position"
                              },
                              {
                                "const": 0
                              }
                            ]
                          },
                          {
                            "fn": "lt",
                            "args": [
                              {
                                "ctx": "position",
                                "leg": "doge"
                              },
                              {
                                "const": 0
                              }
                            ]
                          }
                        ]
                      }
                    ]
                  },
                  "then": [
                    {
                      "emit": "buy"
                    }
                  ]
                },
                {
                  "if": {
                    "fn": "and",
                    "args": [
                      {
                        "fn": "eq",
                        "args": [
                          {
                            "series": "close"
                          },
                          {
                            "series": "close",
                            "leg": "xrp"
                          }
                        ]
                      },
                      {
                        "fn": "and",
                        "args": [
                          {
                            "fn": "eq",
                            "args": [
                              {
                                "ctx": "position"
                              },
                              {
                                "const": 0
                              }
                            ]
                          },
                          {
                            "fn": "gt",
                            "args": [
                              {
                                "ctx": "position",
                                "leg": "doge"
                              },
                              {
                                "const": 0
                              }
                            ]
                          }
                        ]
                      }
                    ]
                  },
                  "then": [
                    {
                      "emit": "sell"
                    }
                  ]
                }
              ]
            }
          }
        ]
      },
      {
        "id": "08-bullish-engulfing",
        "file": "08-bullish-engulfing.json",
        "title": "Bullish engulfing",
        "summary": "Educational AST using `series:open` + `ref` for bullish engulfing. Prefer named `candlePattern` (`pattern: bullishEngulfing`) for create/Ask AI.",
        "payload": {
          "enabled": true,
          "invert": false,
          "params": {
            "version": 1,
            "summary": "- Prefer named candlePattern for engulfing in production bots\n- This tree buys when a bullish engulfing forms using open/close + ref\n- Prior bar must be bearish; current body engulfs prior body",
            "vars": {},
            "state": {},
            "onBar": [
              {
                "if": {
                  "fn": "and",
                  "args": [
                    {
                      "fn": "and",
                      "args": [
                        {
                          "fn": "lt",
                          "args": [
                            {
                              "fn": "ref",
                              "args": [
                                {
                                  "series": "close"
                                },
                                {
                                  "const": 1
                                }
                              ]
                            },
                            {
                              "fn": "ref",
                              "args": [
                                {
                                  "series": "open"
                                },
                                {
                                  "const": 1
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "fn": "gt",
                          "args": [
                            {
                              "series": "close"
                            },
                            {
                              "series": "open"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "fn": "and",
                      "args": [
                        {
                          "fn": "lte",
                          "args": [
                            {
                              "series": "open"
                            },
                            {
                              "fn": "ref",
                              "args": [
                                {
                                  "series": "close"
                                },
                                {
                                  "const": 1
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "fn": "gte",
                          "args": [
                            {
                              "series": "close"
                            },
                            {
                              "fn": "ref",
                              "args": [
                                {
                                  "series": "open"
                                },
                                {
                                  "const": 1
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                "then": [
                  {
                    "emit": "buy"
                  }
                ]
              }
            ]
          }
        }
      },
      {
        "id": "09-ladder-exit-shrinking-tp",
        "file": "09-ladder-exit-shrinking-tp.json",
        "title": "Ladder exit shrinking tp",
        "summary": "Exit rule for an averaging-down ladder: take profit from `ctx avgEntry` that tightens with `ctx steps` (filled increase steps): 0.8%, then 0.55%, then 0.3%. Pair with `increase.rules.incrementalScaling`.",
        "payload": {
          "enabled": true,
          "invert": false,
          "params": {
            "version": 1,
            "summary": "- Exit rule for an averaging-down ladder (put under exit.rules)\n- Take profit 0.8% from the average entry with no adds\n- Tighten by 0.25% per filled add: 0.55% after one, 0.3% after two\n- Works long and short",
            "vars": {},
            "state": {},
            "onBar": [
              {
                "if": {
                  "fn": "and",
                  "args": [
                    {
                      "fn": "gt",
                      "args": [
                        {
                          "ctx": "position"
                        },
                        {
                          "const": 0
                        }
                      ]
                    },
                    {
                      "fn": "gte",
                      "args": [
                        {
                          "ctx": "price"
                        },
                        {
                          "fn": "mul",
                          "args": [
                            {
                              "ctx": "avgEntry"
                            },
                            {
                              "fn": "sub",
                              "args": [
                                {
                                  "const": 1.008
                                },
                                {
                                  "fn": "mul",
                                  "args": [
                                    {
                                      "const": 0.0025
                                    },
                                    {
                                      "ctx": "steps"
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                "then": [
                  {
                    "emit": "sell"
                  }
                ]
              },
              {
                "if": {
                  "fn": "and",
                  "args": [
                    {
                      "fn": "lt",
                      "args": [
                        {
                          "ctx": "position"
                        },
                        {
                          "const": 0
                        }
                      ]
                    },
                    {
                      "fn": "lte",
                      "args": [
                        {
                          "ctx": "price"
                        },
                        {
                          "fn": "mul",
                          "args": [
                            {
                              "ctx": "avgEntry"
                            },
                            {
                              "fn": "add",
                              "args": [
                                {
                                  "const": 0.992
                                },
                                {
                                  "fn": "mul",
                                  "args": [
                                    {
                                      "const": 0.0025
                                    },
                                    {
                                      "ctx": "steps"
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                "then": [
                  {
                    "emit": "buy"
                  }
                ]
              }
            ]
          }
        }
      },
      {
        "id": "10-exit-at-band-middle",
        "file": "10-exit-at-band-middle.json",
        "title": "Exit at band middle",
        "summary": "Exit rule for range bots: close when price returns to `bb_middle` (the 20-bar mean), long or short.",
        "payload": {
          "enabled": true,
          "invert": false,
          "params": {
            "version": 1,
            "summary": "- Exit rule for a range / mean-reversion bot (put under exit.rules)\n- Close a long once price is back at the Bollinger middle line (20-bar mean)\n- Close a short the same way from below",
            "vars": {
              "mid": {
                "fn": "bb_middle",
                "args": [
                  {
                    "series": "close"
                  },
                  {
                    "const": 20
                  }
                ]
              }
            },
            "state": {},
            "onBar": [
              {
                "if": {
                  "fn": "and",
                  "args": [
                    {
                      "fn": "gt",
                      "args": [
                        {
                          "ctx": "position"
                        },
                        {
                          "const": 0
                        }
                      ]
                    },
                    {
                      "fn": "gte",
                      "args": [
                        {
                          "ctx": "price"
                        },
                        {
                          "var": "mid"
                        }
                      ]
                    }
                  ]
                },
                "then": [
                  {
                    "emit": "sell"
                  }
                ]
              },
              {
                "if": {
                  "fn": "and",
                  "args": [
                    {
                      "fn": "lt",
                      "args": [
                        {
                          "ctx": "position"
                        },
                        {
                          "const": 0
                        }
                      ]
                    },
                    {
                      "fn": "lte",
                      "args": [
                        {
                          "ctx": "price"
                        },
                        {
                          "var": "mid"
                        }
                      ]
                    }
                  ]
                },
                "then": [
                  {
                    "emit": "buy"
                  }
                ]
              }
            ]
          }
        }
      }
    ],
    "create_automation": [
      {
        "id": "01-pairs-btc-sol-paper",
        "file": "01-pairs-btc-sol-paper.json",
        "title": "Pairs btc sol paper",
        "summary": "Paper Bybit linear BTC+SOL relative-value bot. Top-level `markets[]` omits `leg_index` (server assigns 0, 1). `placementMode` is on the tool args (server copies it into `params`). `stopLoss` is a sibling `params.exit.rules` — never `params.entry.exit`. customLogic tree matches [`../custom_logic/06-pairs-relative-legs.json`](../custom_logic/06-pairs-relative-legs.json).",
        "payload": {
          "type": "bot",
          "name": "Paper BTC/SOL Perp Arbitrage",
          "exchange": "bybit_linear",
          "symbol": "BTCUSDT",
          "candle_timeframe": "5m",
          "execution_interval": 300000,
          "initial_capital": 10000,
          "trading_mode": "paper",
          "placementMode": "each_trade_leg",
          "markets": [
            {
              "label": "btc",
              "exchange": "bybit_linear",
              "symbol": "BTCUSDT"
            },
            {
              "label": "sol",
              "exchange": "bybit_linear",
              "symbol": "SOLUSDT"
            }
          ],
          "params": {
            "legSizing": "equal_notional",
            "entry": {
              "rules": {
                "customLogic": {
                  "enabled": true,
                  "invert": false,
                  "params": {
                    "version": 1,
                    "summary": "- Compare 1-bar returns on BTC vs SOL\n- Short the outperformer and long the laggard\n- each_trade_leg places on both books (omit emit.leg)",
                    "vars": {
                      "btcRet": {
                        "fn": "div",
                        "args": [
                          {
                            "series": "close",
                            "leg": "btc"
                          },
                          {
                            "fn": "ref",
                            "args": [
                              {
                                "series": "close",
                                "leg": "btc"
                              },
                              {
                                "const": 1
                              }
                            ]
                          }
                        ]
                      },
                      "solRet": {
                        "fn": "div",
                        "args": [
                          {
                            "series": "close",
                            "leg": "sol"
                          },
                          {
                            "fn": "ref",
                            "args": [
                              {
                                "series": "close",
                                "leg": "sol"
                              },
                              {
                                "const": 1
                              }
                            ]
                          }
                        ]
                      },
                      "onBtc": {
                        "fn": "eq",
                        "args": [
                          {
                            "ctx": "label"
                          },
                          {
                            "const": "btc"
                          }
                        ]
                      }
                    },
                    "state": {},
                    "onBar": [
                      {
                        "if": {
                          "var": "onBtc"
                        },
                        "then": [
                          {
                            "if": {
                              "fn": "gt",
                              "args": [
                                {
                                  "var": "btcRet"
                                },
                                {
                                  "var": "solRet"
                                }
                              ]
                            },
                            "then": [
                              {
                                "emit": "sell"
                              }
                            ],
                            "else": [
                              {
                                "emit": "buy"
                              }
                            ]
                          }
                        ],
                        "else": [
                          {
                            "if": {
                              "fn": "gt",
                              "args": [
                                {
                                  "var": "btcRet"
                                },
                                {
                                  "var": "solRet"
                                }
                              ]
                            },
                            "then": [
                              {
                                "emit": "buy"
                              }
                            ],
                            "else": [
                              {
                                "emit": "sell"
                              }
                            ]
                          }
                        ]
                      }
                    ]
                  }
                }
              }
            },
            "increase": {
              "rules": {}
            },
            "decrease": {
              "rules": {}
            },
            "reversal": {
              "rules": {}
            },
            "exit": {
              "rules": {
                "stopLoss": {
                  "enabled": true,
                  "params": {
                    "type": "percentage",
                    "value": 2
                  }
                }
              }
            }
          }
        }
      },
      {
        "id": "02-aster-doge-xrp-sibling-hedge-paper",
        "file": "02-aster-doge-xrp-sibling-hedge-paper.json",
        "title": "Aster doge xrp sibling hedge paper",
        "summary": "Paper Aster DOGE+XRP funding limit → sibling market hedge. Dual `customLogic` ARRAY (from [`../custom_logic/07-funding-limit-then-sibling-market.json`](../custom_logic/07-funding-limit-then-sibling-market.json)) + `siblingHedgeOnEntryFill`, equal_notional, fill-armed TP 0.7% + scale-in amend. Ask AI embeds this recipe in the params hint.",
        "payload": {
          "type": "bot",
          "name": "Paper Aster DOGE/XRP Funding Sibling Hedge",
          "exchange": "aster_dex",
          "symbol": "DOGEUSDT",
          "candle_timeframe": "1h",
          "execution_interval": 300000,
          "initial_capital": 1000,
          "trading_mode": "paper",
          "placementMode": "each_trade_leg",
          "markets": [
            {
              "label": "doge",
              "exchange": "aster_dex",
              "symbol": "DOGEUSDT"
            },
            {
              "label": "xrp",
              "exchange": "aster_dex",
              "symbol": "XRPUSDT"
            }
          ],
          "params": {
            "legSizing": "equal_notional",
            "siblingHedgeOnEntryFill": {
              "enabled": true
            },
            "entry": {
              "rules": {
                "customLogic": [
                  {
                    "enabled": true,
                    "invert": false,
                    "params": {
                      "version": 1,
                      "summary": "- Both books flat: short the higher eightHour funding leg via limit + small offset\n- Place only on the funding winner book this tick\n- Pair with siblingHedgeOnEntryFill for fill-instant market hedge on the other book",
                      "orderType": "limit",
                      "limitArmFrom": "signal",
                      "limitSendWhen": "now",
                      "limitOffsetType": "percentage",
                      "limitOffsetValue": -0.05,
                      "limitStackPolicy": "stack",
                      "vars": {
                        "onDoge": {
                          "fn": "eq",
                          "args": [
                            {
                              "series": "close"
                            },
                            {
                              "series": "close",
                              "leg": "doge"
                            }
                          ]
                        },
                        "dogePaysMore": {
                          "fn": "gt",
                          "args": [
                            {
                              "series": "fundingRate",
                              "leg": "doge"
                            },
                            {
                              "series": "fundingRate",
                              "leg": "xrp"
                            }
                          ]
                        },
                        "bothFlat": {
                          "fn": "and",
                          "args": [
                            {
                              "fn": "eq",
                              "args": [
                                {
                                  "ctx": "position",
                                  "leg": "doge"
                                },
                                {
                                  "const": 0
                                }
                              ]
                            },
                            {
                              "fn": "eq",
                              "args": [
                                {
                                  "ctx": "position",
                                  "leg": "xrp"
                                },
                                {
                                  "const": 0
                                }
                              ]
                            }
                          ]
                        }
                      },
                      "state": {},
                      "onBar": [
                        {
                          "if": {
                            "fn": "and",
                            "args": [
                              {
                                "var": "bothFlat"
                              },
                              {
                                "fn": "and",
                                "args": [
                                  {
                                    "var": "onDoge"
                                  },
                                  {
                                    "var": "dogePaysMore"
                                  }
                                ]
                              }
                            ]
                          },
                          "then": [
                            {
                              "emit": "sell"
                            }
                          ]
                        },
                        {
                          "if": {
                            "fn": "and",
                            "args": [
                              {
                                "var": "bothFlat"
                              },
                              {
                                "fn": "and",
                                "args": [
                                  {
                                    "fn": "eq",
                                    "args": [
                                      {
                                        "series": "close"
                                      },
                                      {
                                        "series": "close",
                                        "leg": "xrp"
                                      }
                                    ]
                                  },
                                  {
                                    "fn": "not",
                                    "args": [
                                      {
                                        "var": "dogePaysMore"
                                      }
                                    ]
                                  }
                                ]
                              }
                            ]
                          },
                          "then": [
                            {
                              "emit": "sell"
                            }
                          ]
                        }
                      ]
                    }
                  },
                  {
                    "enabled": true,
                    "invert": false,
                    "params": {
                      "version": 1,
                      "summary": "- This book flat and sibling open: market hedge opposite the sibling position\n- Strategy-listen latency is next execution_interval; with siblingHedgeOnEntryFill OE hedges on entry fill",
                      "orderType": "market",
                      "vars": {
                        "onDoge": {
                          "fn": "eq",
                          "args": [
                            {
                              "series": "close"
                            },
                            {
                              "series": "close",
                              "leg": "doge"
                            }
                          ]
                        }
                      },
                      "state": {},
                      "onBar": [
                        {
                          "if": {
                            "fn": "and",
                            "args": [
                              {
                                "var": "onDoge"
                              },
                              {
                                "fn": "and",
                                "args": [
                                  {
                                    "fn": "eq",
                                    "args": [
                                      {
                                        "ctx": "position"
                                      },
                                      {
                                        "const": 0
                                      }
                                    ]
                                  },
                                  {
                                    "fn": "lt",
                                    "args": [
                                      {
                                        "ctx": "position",
                                        "leg": "xrp"
                                      },
                                      {
                                        "const": 0
                                      }
                                    ]
                                  }
                                ]
                              }
                            ]
                          },
                          "then": [
                            {
                              "emit": "buy"
                            }
                          ]
                        },
                        {
                          "if": {
                            "fn": "and",
                            "args": [
                              {
                                "var": "onDoge"
                              },
                              {
                                "fn": "and",
                                "args": [
                                  {
                                    "fn": "eq",
                                    "args": [
                                      {
                                        "ctx": "position"
                                      },
                                      {
                                        "const": 0
                                      }
                                    ]
                                  },
                                  {
                                    "fn": "gt",
                                    "args": [
                                      {
                                        "ctx": "position",
                                        "leg": "xrp"
                                      },
                                      {
                                        "const": 0
                                      }
                                    ]
                                  }
                                ]
                              }
                            ]
                          },
                          "then": [
                            {
                              "emit": "sell"
                            }
                          ]
                        },
                        {
                          "if": {
                            "fn": "and",
                            "args": [
                              {
                                "fn": "eq",
                                "args": [
                                  {
                                    "series": "close"
                                  },
                                  {
                                    "series": "close",
                                    "leg": "xrp"
                                  }
                                ]
                              },
                              {
                                "fn": "and",
                                "args": [
                                  {
                                    "fn": "eq",
                                    "args": [
                                      {
                                        "ctx": "position"
                                      },
                                      {
                                        "const": 0
                                      }
                                    ]
                                  },
                                  {
                                    "fn": "lt",
                                    "args": [
                                      {
                                        "ctx": "position",
                                        "leg": "doge"
                                      },
                                      {
                                        "const": 0
                                      }
                                    ]
                                  }
                                ]
                              }
                            ]
                          },
                          "then": [
                            {
                              "emit": "buy"
                            }
                          ]
                        },
                        {
                          "if": {
                            "fn": "and",
                            "args": [
                              {
                                "fn": "eq",
                                "args": [
                                  {
                                    "series": "close"
                                  },
                                  {
                                    "series": "close",
                                    "leg": "xrp"
                                  }
                                ]
                              },
                              {
                                "fn": "and",
                                "args": [
                                  {
                                    "fn": "eq",
                                    "args": [
                                      {
                                        "ctx": "position"
                                      },
                                      {
                                        "const": 0
                                      }
                                    ]
                                  },
                                  {
                                    "fn": "gt",
                                    "args": [
                                      {
                                        "ctx": "position",
                                        "leg": "doge"
                                      },
                                      {
                                        "const": 0
                                      }
                                    ]
                                  }
                                ]
                              }
                            ]
                          },
                          "then": [
                            {
                              "emit": "sell"
                            }
                          ]
                        }
                      ]
                    }
                  }
                ]
              }
            },
            "increase": {
              "rules": {
                "incrementalScaling": {
                  "enabled": true,
                  "invert": false,
                  "params": {
                    "type": "percentage",
                    "trendSide": false,
                    "levels": [
                      0.5,
                      1,
                      2,
                      3,
                      4
                    ],
                    "multipliers": [
                      1,
                      1,
                      2,
                      4,
                      8
                    ],
                    "orderType": "limit",
                    "limitArmFrom": "fill",
                    "limitSendWhen": "now",
                    "limitStackPolicy": "amend"
                  }
                }
              }
            },
            "decrease": {
              "rules": {}
            },
            "reversal": {
              "rules": {}
            },
            "exit": {
              "rules": {
                "takeProfit": {
                  "enabled": true,
                  "invert": false,
                  "params": {
                    "type": "percentage",
                    "value": 0.7,
                    "orderType": "limit",
                    "limitArmFrom": "fill",
                    "limitSendWhen": "now",
                    "limitStackPolicy": "amend"
                  }
                },
                "stopLoss": {
                  "enabled": true,
                  "invert": false,
                  "params": {
                    "type": "percentage",
                    "value": 10
                  }
                }
              }
            }
          }
        }
      },
      {
        "id": "03-pairs-spread-btc-sol-paper",
        "file": "03-pairs-spread-btc-sol-paper.json",
        "title": "Pairs spread btc sol paper",
        "summary": "Paper Bybit BTC+SOL using named `pairsSpread` (not customLogic) with `each_trade_leg` + equal_notional. Prefer this when the named rule already covers the spread idea.",
        "payload": {
          "type": "bot",
          "name": "Paper BTC/SOL Pairs Spread",
          "exchange": "bybit_linear",
          "symbol": "BTCUSDT",
          "candle_timeframe": "5m",
          "execution_interval": 300000,
          "initial_capital": 10000,
          "trading_mode": "paper",
          "placementMode": "each_trade_leg",
          "markets": [
            {
              "label": "btc",
              "exchange": "bybit_linear",
              "symbol": "BTCUSDT"
            },
            {
              "label": "sol",
              "exchange": "bybit_linear",
              "symbol": "SOLUSDT"
            }
          ],
          "params": {
            "legSizing": "equal_notional",
            "placementMode": "each_trade_leg",
            "entry": {
              "rules": {
                "pairsSpread": {
                  "enabled": true,
                  "invert": false,
                  "params": {
                    "metric": "priceReturn",
                    "mode": "meanRevert",
                    "legA": "btc",
                    "legB": "sol",
                    "lookbackBars": 1,
                    "zScoreWindow": 48,
                    "threshold": 0.005,
                    "convergeExitEnabled": false,
                    "exitThreshold": 0.001
                  }
                }
              }
            },
            "increase": {
              "rules": {}
            },
            "decrease": {
              "rules": {}
            },
            "reversal": {
              "rules": {}
            },
            "exit": {
              "rules": {
                "stopLoss": {
                  "enabled": true,
                  "params": {
                    "type": "percentage",
                    "value": 2
                  }
                },
                "takeProfit": {
                  "enabled": true,
                  "params": {
                    "type": "percentage",
                    "value": 3
                  }
                }
              }
            }
          }
        }
      }
    ],
    "order_execution": [
      {
        "id": "01-reactive-tp-skip",
        "file": "01-reactive-tp-skip.json",
        "title": "Reactive tp skip",
        "summary": "`skip` (TP default) — Classic reactive limit TP — do not stack another GTC while one rests",
        "payload": {
          "enabled": true,
          "params": {
            "type": "percentage",
            "value": 2,
            "exitQuantityMode": "full",
            "orderType": "limit",
            "limitArmFrom": "signal",
            "limitSendWhen": "now",
            "limitOffsetType": "distance",
            "limitOffsetValue": 0,
            "limitStackPolicy": "skip"
          }
        }
      },
      {
        "id": "02-entry-limit-stack",
        "file": "02-entry-limit-stack.json",
        "title": "Entry limit stack",
        "summary": "`stack` (entry default) — Place another entry-style limit while a prior GTC still rests",
        "payload": {
          "enabled": true,
          "params": {
            "period": 14,
            "oversold": 30,
            "overbought": 70,
            "orderType": "limit",
            "limitArmFrom": "signal",
            "limitSendWhen": "now",
            "limitOffsetType": "percentage",
            "limitOffsetValue": -0.5,
            "limitStackPolicy": "stack"
          }
        }
      },
      {
        "id": "03-scale-in-replace",
        "file": "03-scale-in-replace.json",
        "title": "Scale in replace",
        "summary": "`replace` — Cancel the resting scale limit, then park updated price/qty",
        "payload": {
          "enabled": true,
          "params": {
            "type": "percentage",
            "trendSide": false,
            "levels": [
              1,
              2,
              3
            ],
            "multipliers": [
              1,
              1,
              1
            ],
            "orderType": "limit",
            "limitArmFrom": "fill",
            "limitSendWhen": "now",
            "limitStackPolicy": "replace"
          }
        }
      }
    ]
  }
}
