# Starting strategies through API

**URL:** <https://community.tradovate.com/t/starting-strategies-through-api/2625>\
**Category:** Community Support\
**Created:** [June 30, 2021, 6:14pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625 "2021-06-30T18:14:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevize](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@trevize](https://community.tradovate.com/u/trevize)\
**Post date:** [June 30, 2021, 6:14pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/1 "2021-06-30T18:14:43Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Alexander](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/alexander/32/988_2.png) [@Alexander](https://community.tradovate.com/u/Alexander)\
**Post date:** [July 7, 2021, 3:18pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/2 "2021-07-07T15:18:05Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![Lol](https://avatars.discourse-cdn.com/v4/letter/l/5daacb/32.png) [@Lol](https://community.tradovate.com/u/Lol)\
**Post date:** [July 8, 2021, 10:17pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/3 "2021-07-08T22:17:41Z")

</div>

Hi Alexander,

According to your post ([How Do I Access the API?](https://community.tradovate.com/t/how-do-i-access-the-api/2380)) 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.

---

<div class="post-metadata">

**Author:** ![Alexander](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/alexander/32/988_2.png) [@Alexander](https://community.tradovate.com/u/Alexander)\
**Post date:** [July 9, 2021, 12:47pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/4 "2021-07-09T12:47:57Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![trevize](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@trevize](https://community.tradovate.com/u/trevize)\
**Post date:** [July 12, 2021, 5:13pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/5 "2021-07-12T17:13:18Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![Alexander](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/alexander/32/988_2.png) [@Alexander](https://community.tradovate.com/u/Alexander)\
**Post date:** [July 12, 2021, 6:19pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/6 "2021-07-12T18:19:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Alexander](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/alexander/32/988_2.png) [@Alexander](https://community.tradovate.com/u/Alexander)\
**Post date:** [July 12, 2021, 6:32pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/7 "2021-07-12T18:32:47Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![God](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@God](https://community.tradovate.com/u/God)\
**Post date:** [August 13, 2021, 5:14am UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/8 "2021-08-13T05:14:16Z")

</div>

Hi Alex,  
How would I access the simulation account? Do I have to pay for this to try the API demo?  
Thanks.

---

<div class="post-metadata">

**Author:** ![Alexander](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/alexander/32/988_2.png) [@Alexander](https://community.tradovate.com/u/Alexander)\
**Post date:** [August 13, 2021, 1:04pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/9 "2021-08-13T13:04:20Z")

</div>

Hello @God,

To gain access to the API you must have a funded live account, and you must purchase the API Access add-on. Once you have a live account, you can follow [this guide](https://community.tradovate.com/t/how-do-i-access-the-api/2380) to get started. When the API is available for your user, you will have unlimited access to testing via simulation mode. To access the simulation mode API, use the `demo.tradovateapi.com` base URL. For live access, use the `live.tradovateapi.com` base URL.

Hope that helps.

---

<div class="post-metadata">

**Author:** ![Savva](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/savva/32/1354_2.png) [@Savva](https://community.tradovate.com/u/Savva)\
**Post date:** [August 20, 2021, 5:33pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/10 "2021-08-20T17:33:28Z")

</div>

Hi @Alexander ,

Same issue for me. Here is the payload and response:

```auto
POST /v1/orderStrategy/startorderstrategy HTTP/1.1
Authorization: Bearer XXXxxxXXX
Host: demo.tradovateapi.com
Content-Type: application/json
Content-Length: 336

{
    "accountId": 123456,
    "accountSpec": "DEMO123456",
    "symbol": "MESU1",
    "action": "Buy",
    "orderStrategyTypeId": 2,
    "params": "{\"entryVersion\":{\"orderQty\":1,\"orderType\":\"Market\"},\"brackets\":[{\"qty\":1,\"profitTarget\":2,\"stopLoss\":-3,\"trailingStop\":false}]}"
}

```

```auto
HTTP/1.1 404 Not Found
content-length: 0
Date: Fri, 20 Aug 2021 16:57:43 GMT
Via: 1.1 google
Alt-Svc: clear

```

Placing regular order works, so **id** and **name** are correct.

Thank you!

---

<div class="post-metadata">

**Author:** ![Alexander](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/alexander/32/988_2.png) [@Alexander](https://community.tradovate.com/u/Alexander)\
**Post date:** [August 20, 2021, 6:35pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/11 "2021-08-20T18:35:31Z")

</div>

Hello @Savva,

I’m receiving a 200 response using your provided data and my own credentials. Ensure that you’re using your account entity ID and not your user ID. The account entity ID is shown from endpoints such as `/account/list` in the `id` field.

---

<div class="post-metadata">

**Author:** ![Savva](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/savva/32/1354_2.png) [@Savva](https://community.tradovate.com/u/Savva)\
**Post date:** [August 20, 2021, 8:03pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/12 "2021-08-20T20:03:44Z")

</div>

Yep, tried exactly those to no avail.

---

<div class="post-metadata">

**Author:** ![Lenz](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lenz](https://community.tradovate.com/u/Lenz)\
**Post date:** [October 3, 2021, 5:19pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/13 "2021-10-03T17:19:36Z")

</div>

Hi Alexander, I am trying to McGyver an OSO order that triggers an OCO order.

I would like to go long NQZ1 at 14,700. When filled, I want to trigger an OCO order with a stop loss at 14,600 and a target of 14,800. Can you please help me figuring out what I am doing wrong and which approach is more efficient?:

```auto
'''
//Code Example 1:

const URL = 'demo.tradovateapi.com/v1'

const oco = {
    qty: 1,
    profitTarget: 100,
    stopLoss: -100,
    trailingStop: false
}

const params = {
    entryVersion: {
        orderQty: 1,
        orderType: "Limit",
        limitPrice: 14700,
    },
    brackets: oco
}

const body = {
    accountId: id,
    accountSpec: name,
    symbol: 'NQZ1',
    action: 'Buy',
    orderStrategyTypeId: 1,
    params: JSON.stringify(params)
}

const response = await fetch(URL + '/orderStrategy/startOrderStrategy', {
    method: 'POST',
    headers: {
        'Accept': 'application/json',
        'Authorization': `Bearer ${myAccessToken}`,
    },
    body: JSON.stringify(body)
})

const json = await response.json() 

//Code Example 2:

const URL = 'demo.tradovateapi.com/v1'

const limit = {
    action: 'Sell',
    orderType: 'Limit',
    price: 14800.00
}

const oco = {
    action: 'Sell',
    orderType: 'Stop',
    price: 14600.00,
    other: limit
}

const initial = {
    accountSpec: yourUserName,
    accountId: yourAcctId,
    action: "Buy",
    symbol: "NQZ1",
    orderQty: 1,
    orderType: "Limit",
    price: 14700.00,
    isAutomated: true
    brackets: oco
}

const response = await fetch(URL + '/order/placeorder', {
    method: 'POST',
    headers: {
        'Accept': 'application/json',
        'Authorization': `Bearer ${myAccessToken}`,
    },
    body: JSON.stringify(initial)
})

const json = await response.json() // { orderId: 0000000 }`

```

---

<div class="post-metadata">

**Author:** ![Alexander](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/alexander/32/988_2.png) [@Alexander](https://community.tradovate.com/u/Alexander)\
**Post date:** [October 4, 2021, 12:17pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/14 "2021-10-04T12:17:06Z")

</div>

We actually have endpoints for OSOs and OCOs individually. You can find them in the official API docs [here](https://api.tradovate.com/#operation/placeOSO) and [here](https://api.tradovate.com/#operation/placeOCO). Also make sure you use the full URL (including `'https://'`).

---

<div class="post-metadata">

**Author:** ![Lenz](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lenz](https://community.tradovate.com/u/Lenz)\
**Post date:** [October 4, 2021, 2:50pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/15 "2021-10-04T14:50:18Z")

</div>

I have seen the documentation. My question is how would I combine the two in ONE order?

---

<div class="post-metadata">

**Author:** ![Alexander](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/alexander/32/988_2.png) [@Alexander](https://community.tradovate.com/u/Alexander)\
**Post date:** [October 4, 2021, 3:10pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/16 "2021-10-04T15:10:14Z")

</div>

Oh I see, you basically just want to start a brackets strategy where placing your entry order will trigger your orders for take profit and stop loss, which each will cancel one another. What you were doing with `'startOrderStrategy'` is probably your best bet for that, especially considering you can have more than one bracket entry. The interface will be easiest to use since it’s designed to do exactly that.

Were you also having a problem using one of these endpoints?

Edit:  
P.S. I noticed you are using `1` for `orderStrategyTypeId`. Currently the value `2` is what you want, it refers to the built-in Brackets strategy which is the only currently supported order strategy type.

---

<div class="post-metadata">

**Author:** ![Lenz](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lenz](https://community.tradovate.com/u/Lenz)\
**Post date:** [October 4, 2021, 4:56pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/17 "2021-10-04T16:56:15Z")

</div>

Thanks for getting back to me so quickly. Here is my situation. I have written a script on TradingView that triggers a webhook with the following data: entry limit, stop loss, target limit. The script only trades NQ. I am trying to find a simple solution, so I can format the alert in a way that the API can understand without jumping through too many hoops… Do you see a way to make this work?

---

<div class="post-metadata">

**Author:** ![Alexander](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/alexander/32/988_2.png) [@Alexander](https://community.tradovate.com/u/Alexander)\
**Post date:** [October 4, 2021, 5:47pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/18 "2021-10-04T17:47:41Z")

</div>

Check out this [other community post](https://community.tradovate.com/t/access-tradovate-api-using-tradingview-webhooks/2762/3). It’s about using tradingview webhooks.

TL;DR - To trigger Tradovate API calls you’d need to build an intermediary back-end application to catch the webhooks you create with tradingview and then forward those messages to the Tradovate API with the correct headers.

---

<div class="post-metadata">

**Author:** ![Lenz](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lenz](https://community.tradovate.com/u/Lenz)\
**Post date:** [October 4, 2021, 8:39pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/19 "2021-10-04T20:39:26Z")

</div>

Thanks, I am aware of this post. My question was simply how to place a limit buy order that triggers and OCO order with target and stop loss.

---

<div class="post-metadata">

**Author:** ![Alexander](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/alexander/32/988_2.png) [@Alexander](https://community.tradovate.com/u/Alexander)\
**Post date:** [October 6, 2021, 4:43pm UTC](https://community.tradovate.com/t/starting-strategies-through-api/2625/20 "2021-10-06T16:43:54Z")

</div>

You can do this, but you would basically be re-implementing your own bracket-like strategy. You could do something like this:

- subscribe to a `user/syncRequest` real-time websocket subscription and listen for the `"props"` event type.
- Place your entry order via API request, whatever order type you need. Hold onto the `orderId` from the response.
- Listen for a `"props"` type event with the `entityType` `'ExecutionReport'`. You want to find an execution report with the same `orderId` you kept from the placeOrder response, and which has an `ordStatus` of type `'Complete'` or `'Filled'` to know when it’s time to trigger your next order.
- Place your dependent OCO order based on the data from the related execution report.

But this is essentially what `startOrderStrategy` does for you already with less overhead, so I’d still advise trying to adapt your data to fit the `startOrderStrategy` mold.

[Next page](https://community.tradovate.com/t/starting-strategies-through-api/2625.md?page=2)
