# API Json syntax

**URL:** <https://community.tradovate.com/t/api-json-syntax/2773>\
**Category:** Community Support\
**Created:** [July 26, 2021, 6:11am UTC](https://community.tradovate.com/t/api-json-syntax/2773 "2021-07-26T06:11:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaygee](https://avatars.discourse-cdn.com/v4/letter/k/7993a0/32.png) [@kaygee](https://community.tradovate.com/u/kaygee)\
**Post date:** [July 26, 2021, 6:11am UTC](https://community.tradovate.com/t/api-json-syntax/2773/1 "2021-07-26T06:11:09Z")

</div>

Hi,  
Planning to test API in demo. While browsing the API document, no JSON syntax provided for closing a specific symbol position when there are multiple symbol position open and modify Stop Loss/Take Profit.

Appreciate your help on the required JSON syntax for Closing a position and placing/modifying stoploss & Take Profit.

Thanks  
Kaygee

---

<div class="post-metadata">

**Author:** ![kaygee](https://avatars.discourse-cdn.com/v4/letter/k/7993a0/32.png) [@kaygee](https://community.tradovate.com/u/kaygee)\
**Post date:** [July 26, 2021, 4:40pm UTC](https://community.tradovate.com/t/api-json-syntax/2773/2 "2021-07-26T16:40:05Z")

</div>

Hi there,  
Could you please help me to get the details of the required JSON syntax to be passed for closing an open position for a particular symbol, Modifying Stop Loss/ Take Profit for an order ?

Thanks  
KayGee

---

<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 26, 2021, 6:15pm UTC](https://community.tradovate.com/t/api-json-syntax/2773/3 "2021-07-26T18:15:18Z")

</div>

Hello @kaygee,

One way that you can liquidate your position is through the `/order/liquidatePosition` endpoint, you can view the JSON syntax details [here](https://api.tradovate.com/#operation/liquidatePosition) on our documentation site. Calling this endpoint will attempt to close any open positions you hold and pending orders placed for a given contract. Hope this helps!

---

<div class="post-metadata">

**Author:** ![kaygee](https://avatars.discourse-cdn.com/v4/letter/k/7993a0/32.png) [@kaygee](https://community.tradovate.com/u/kaygee)\
**Post date:** [July 26, 2021, 6:34pm UTC](https://community.tradovate.com/t/api-json-syntax/2773/4 "2021-07-26T18:34:28Z")

</div>

Thanks but i’m looking for a syntax to close a particular symbol position if i have two open positions in different symbol and would like to close only one.  
Example: 1 contract buy in NQ , 1 contract Sell in ES but close is only for 1 control Sell in ES ?

Thanks

---

<div class="post-metadata">

**Author:** ![kaygee](https://avatars.discourse-cdn.com/v4/letter/k/7993a0/32.png) [@kaygee](https://community.tradovate.com/u/kaygee)\
**Post date:** [July 26, 2021, 6:38pm UTC](https://community.tradovate.com/t/api-json-syntax/2773/5 "2021-07-26T18:38:27Z")

</div>

just looking the syntax in liquidate position. Is that contract id is same as symbol id: example: if Micros ES sep - MESU21 ?  
If yes then i should be able to close the particular contract ?

Sorry, i’m new to this forum/tradovate API.

Thanks for your help.

---

<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 26, 2021, 6:42pm UTC](https://community.tradovate.com/t/api-json-syntax/2773/6 "2021-07-26T18:42:51Z")

</div>

Not a problem, we are glad to see new users!

The `liquidatePosition` endpoint is for exactly this situation. You provide it a contract id (not the “symbol”) and it closes your positions for just that contract. If you liquidate on NQ, NQ positions will be closed (attempted to be closed, no guarantees in web work!) but ES positions will remain. It takes the `id` field of the contract in question.

If you don’t have the `id` field of the contract, you need to first acquire it using the `/contract/find` endpoint. This is easy though, simply send a GET request to `/contract/find?name=MNQU1` or whatever symbol you’re searching, and you’ll get a JSON response containing an `id` field for that contract. This `id` field is the one you are looking for to parameterize your `liquidatePosition` request.

Best of luck to you!

---

<div class="post-metadata">

**Author:** ![kaygee](https://avatars.discourse-cdn.com/v4/letter/k/7993a0/32.png) [@kaygee](https://community.tradovate.com/u/kaygee)\
**Post date:** [July 26, 2021, 6:45pm UTC](https://community.tradovate.com/t/api-json-syntax/2773/7 "2021-07-26T18:45:13Z")

</div>

Thanks so much for the details.  
One more follow up on placing the order:  
If I’m placing the market order - i do see a field for stop price. Is this the filed for Stop Loss price ? How about Take Profit value if i want to put along with the market order ?  
Will start testing the access and order from next week in 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:** [July 26, 2021, 7:27pm UTC](https://community.tradovate.com/t/api-json-syntax/2773/8 "2021-07-26T19:27:00Z")

</div>

There are many options when it comes to making orders with the API. You can place orders using the `/order/placeOrder` endpoint. You can view the docs [here](https://api.tradovate.com/#operation/placeOrder). You’ll notice many parameters are optional - this is because the parameters you use are determined by the type of order you’re placing. For example, a Stop would have a `stopPrice` field, where a Limit would have a `price` field. A Market order would simply require the naturally required parameters (you’ll see these marked _required_ in red text).

Now you also mentioned specifying take-profits. Rather than trying to work out your own way to place brackets algorithmically, you can piggyback off of Tradovate’s built-in Brackets trading algorithm. In order to do so, you can use the `/orderStrategy/startOrderStrategy` endpoint. You can read those docs [here](https://api.tradovate.com/#operation/startOrderStrategy). This allows you to create quite complex strategies for taking profit, stopping loss, and adding trailing stops without having to specify unique orders for each window you’d like to trade in - the Brackets algo does a lot of the work for you.

We also have endpoints for [OSO](https://api.tradovate.com/#operation/placeOSO)s (order-sends-order) and [OCO](https://api.tradovate.com/#operation/placeOCO)s (order-cancels-order) for alternative order strategies, from which you could build your own bracket-like strategies if you wanted.

---

<div class="post-metadata">

**Author:** ![kaygee](https://avatars.discourse-cdn.com/v4/letter/k/7993a0/32.png) [@kaygee](https://community.tradovate.com/u/kaygee)\
**Post date:** [July 26, 2021, 7:30pm UTC](https://community.tradovate.com/t/api-json-syntax/2773/9 "2021-07-26T19:30:09Z")

</div>

thanks so much. This helps and let me read all these and get back to you for any help or issues while testing.

---

<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 26, 2021, 7:30pm UTC](https://community.tradovate.com/t/api-json-syntax/2773/10 "2021-07-26T19:30:49Z")

</div>

No problem, happy to help out!

---

<div class="post-metadata">

**Author:** ![kaygee](https://avatars.discourse-cdn.com/v4/letter/k/7993a0/32.png) [@kaygee](https://community.tradovate.com/u/kaygee)\
**Post date:** [July 28, 2021, 4:43pm UTC](https://community.tradovate.com/t/api-json-syntax/2773/11 "2021-07-28T16:43:37Z")

</div>

Some follow up questions - sorry for the basic questions as I’m learning this API…  
username - account login name  
account id: respective account ID of Demo and Live as i appear in the account- if Demo DEMOXXXXX and LIVE VXXXXXX

Is my understanding correct ?

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 28, 2021, 5:12pm UTC](https://community.tradovate.com/t/api-json-syntax/2773/12 "2021-07-28T17:12:54Z")

</div>

The `accountId` field must be your account’s entity ID - this is just an integer value, not a string. To acquire the entity ID, use a call to `/account/list`. This will return all the accounts assoc. with your user. This data will be an array of account objects. To choose an account, you’d need to simply use one of those object’s `id` fields as the `accountId` field in your request.

---

<div class="post-metadata">

**Author:** ![kaygee](https://avatars.discourse-cdn.com/v4/letter/k/7993a0/32.png) [@kaygee](https://community.tradovate.com/u/kaygee)\
**Post date:** [July 28, 2021, 8:02pm UTC](https://community.tradovate.com/t/api-json-syntax/2773/13 "2021-07-28T20:02:02Z")

</div>

THanks. Let me get all this fixed once I activate my API keys by this week.

---

<div class="post-metadata">

**Author:** ![gustrom](https://avatars.discourse-cdn.com/v4/letter/g/71e660/32.png) [@gustrom](https://community.tradovate.com/u/gustrom)\
**Post date:** [January 8, 2022, 7:13pm UTC](https://community.tradovate.com/t/api-json-syntax/2773/14 "2022-01-08T19:13:46Z")

</div>

Hello @Alexander,

I’ve been trying to execute the `/order/liquidatePosition` endpoint, with no luck.

I’m using one of the tools provided in the tutorial, the tvPost function included in the services.js file. When I use it to place or cancel an order it works very well.

Below you may find the message body I’m sending and the reply I got.

 ![message](https://us1.discourse-cdn.com/flex015/uploads/tradingforum/original/2X/b/bc3335be7722594f40ea3a8d7bc9323320a0e2d4.png)

Do you have any suggestion about what to try?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Arthur](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Arthur](https://community.tradovate.com/u/Arthur)\
**Post date:** [January 8, 2022, 11:19pm UTC](https://community.tradovate.com/t/api-json-syntax/2773/15 "2022-01-08T23:19:34Z")

</div>

I was actually getting the same result yesterday, but I thought it was because markets were closed.

I would think that the `admin` value should be set to `false`, which results in a 404 response. Try it again when futures open again on Sunday night. I’ll do the same and report back.

---

<div class="post-metadata">

**Author:** ![gustrom](https://avatars.discourse-cdn.com/v4/letter/g/71e660/32.png) [@gustrom](https://community.tradovate.com/u/gustrom)\
**Post date:** [January 9, 2022, 12:25am UTC](https://community.tradovate.com/t/api-json-syntax/2773/16 "2022-01-09T00:25:01Z")

</div>

Hi @Arthur,

Just wanted to add that I tried again with `admin` set to `false` with same result.

Also did it under market replay mode which should work regardless of market hours.

---

<div class="post-metadata">

**Author:** ![Arthur](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Arthur](https://community.tradovate.com/u/Arthur)\
**Post date:** [January 9, 2022, 12:50am UTC](https://community.tradovate.com/t/api-json-syntax/2773/17 "2022-01-09T00:50:42Z")

</div>

Okay, good to know. And your order id was for a position that was filled?

---

<div class="post-metadata">

**Author:** ![gustrom](https://avatars.discourse-cdn.com/v4/letter/g/71e660/32.png) [@gustrom](https://community.tradovate.com/u/gustrom)\
**Post date:** [January 9, 2022, 1:12am UTC](https://community.tradovate.com/t/api-json-syntax/2773/18 "2022-01-09T01:12:59Z")

</div>

Well, I think in this case `liquidatePosition` doesn’t take order ids because it basically cancels all orders and closes all positions.

---

<div class="post-metadata">

**Author:** ![Arthur](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Arthur](https://community.tradovate.com/u/Arthur)\
**Post date:** [January 9, 2022, 3:38am UTC](https://community.tradovate.com/t/api-json-syntax/2773/19 "2022-01-09T03:38:22Z")

</div>

Ah okay, thanks for clarifying that for me.

So `liquidatePosition` doesn’t go through _all_ your positions and liquidate them, it takes in a specific contract as its value and closes all positions for that contract, and it seems what you are sending for that is correct.

If you delete the `customTag50` property you should get a 200 response.

---

<div class="post-metadata">

**Author:** ![gustrom](https://avatars.discourse-cdn.com/v4/letter/g/71e660/32.png) [@gustrom](https://community.tradovate.com/u/gustrom)\
**Post date:** [January 9, 2022, 4:32am UTC](https://community.tradovate.com/t/api-json-syntax/2773/20 "2022-01-09T04:32:56Z")

</div>

You are the boss @Arthur , it worked indeed!

Thanks man! 👍
