Starting strategies through API

Hello,

I am currently having a hard time trying to execute the strategy from the API request (/v1/orderStrategy/startorderstrategy). I tried params formatting as an example from docs and also tried to reproduce values strategies, created by Trader. No luck so far, I received only 404 or 400 errors. OSO order placing works fine, but I want to use relative tick targets for profit/loss.
Does anybody have success with it? If yes, can you please share the request example?

Thanks!

1 Like

Hi @trevize,

Please ensure that you’re using your account entity ID and your account name fields for accountId and accountSpec, respectively. You can acquire these by making a request to /account/list. This will return an array of all accounts associated with your user. Using one of those accounts, choose the id field for the actual account entity ID and the name field for the accountSpec parameter.

P.S. also ensure that you’re using the correct API base URL for live or demo access - you can’t use LIVE account info on demo and vice-versa.

  • demo: https://demo.tradovateapi.com/v1
  • live: https://live.tradovateapi.com/v1

Hi Alexander,

According to your post (How Do I Access the API?) users are required to pay 25$ monthly to have access to the API. Is there a trial period of some sort where we could test it out to see if it works properly, or is that what the demo API is for? It seems unreasonable to pay without being able to test it first.

Thanks.

1 Like

Hello @Lol,

First of all, welcome to the Tradovate community!

We do not have a trial period for live accounts, however you can use the API via your simulation account for as long as you like. Use the demo.tradovateapi.com base URL to trade, monitor data, subscribe to data streams, and more, using your demo account.

This allows you to test strategies or build an application (or whatever your goal may be) until you’re ready to move to the Live Environment.

Hope that helps!

Hi, @Alexander
Thank you, but everything seems to be set just fine. I ended up capturing the WebSocket request from the browser Trader app and getting the correct JSON object structure that I need. However, when I am trying to send it to https://demo.tradovateapi.com/v1/orderStrategy/startorderstrategy - I am receiving 404 (which seems to be suppressed backend error). Can it be that this specific endpoint doesn’t process requests correctly?

Hello again @trevize,
I use this endpoint daily for my current project. Although it was difficult to get it setup, startOrderStrategy does work when correctly parameterized. Could you please attach some info, such as the error message, your response from the network, or possibly your code?

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.