API Json syntax

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

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

Hello @kaygee,

One way that you can liquidate your position is through the /order/liquidatePosition endpoint, you can view the JSON syntax details here 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!

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

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.

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!

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

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. 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. 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 OSOs (order-sends-order) and OCOs (order-cancels-order) for alternative order strategies, from which you could build your own bracket-like strategies if you wanted.

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

1 Like

No problem, happy to help out!

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

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.

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

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.

Do you have any suggestion about what to try?

Thanks in advance.

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.

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.

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

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

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.

2 Likes

You are the boss @Arthur , it worked indeed!

Thanks man! :+1:

1 Like