ox-charts

resolveOptionContract

How a script's option.leg(...) becomes a tradable contract, and why nothing falls back to a guess.

A strategy can trade option legs instead of the chart's symbol. The worker carries the legs as data; the host decides which contract each one means.

In the script
strategy.entry("straddle", strategy.short,
  legs=[option.leg("CE", option.atm, option.current), option.leg("PE", option.atm, option.current, side="sell")])
In the host
tradingOptions={{
  automation: {
    resolveOptionContract: async ({ underlying, right, strike, expiry, lastPrice }) => {
      // strike: "atm" | "atm+1" | "atm-2" | "24500"
      // expiry: "current" | "next" | "monthly" | an ISO date
      const c = await chain.resolve(underlying, right, strike, expiry, lastPrice);
      return c ? { symbol: c.tradingsymbol, lotSize: c.lotSize } : null;
    },
  },
}}
  • Each leg becomes its own placeOrder with symbol set and the leg's side.
  • Without a resolver every option intent is denied with the reason no option contract resolver is configured.
  • A null result denies that intent. Nothing falls back to a nearest match, because a wrong strike is worse than no order.