Starting strategies through API

For reference, this is some real code that I use to send bracket strategy orders:

const longBracket = {
  qty: orderQuantity,
  profitTarget: takeProfitThreshold,
  stopLoss: -(Math.ceil(takeProfitThreshold/5)),
  trailingStop: true
}

const shortBracket = {
  qty: orderQuantity,
  profitTarget: -takeProfitThreshold,
  stopLoss: (Math.ceil(takeProfitThreshold/5)),
   trailingStop: true
}

const bracket = decision === RobotAction.Buy ? longBracket : shortBracket

const orderData = {
   entryVersion: {
      orderQty: orderQuantity,
      orderType: 'Market',
   },
   brackets: [bracket]
}

const body = {
  accountId: parseInt(process.env.ID, 10),
  accountSpec: process.env.SPEC,
  symbol: contract.name,
  action: decision,
  orderStrategyTypeId: 2,
  params: JSON.stringify(orderData)
}

It chooses long or short brackets based on a simple algorithm (that part’s not important). takeProfitThreshold, orderQuantity, and contract are user-set parameters, bracket is either the shortBracket or longBracket object, decision is the "Buy" or "Sell" string. The process.env variables are just vars I captured globally via node, but one important thing to notice is that accountId must be an integer, and the params must be a string. body then is the final JSON body data that you’d need to send with the request.