Access Tradovate API using Tradingview Webhooks

I am intended in using the webhooks that Tradingview provides with its alarms, just to place orders in Tradovate using the API. I have a very clear idea of the payload the webhook must have. However, I do not know how to manage the authentication using that webhook. Could someone give an example of how to include the API key/password or whatever authorization method would be convenient in the Tradingview webhook payload to get it working?

Thanks

Hello @Pablo_Gonzalez,

I just briefly looked at the Webhooks API Tradingview provides, and it appears that you can send JSON data via the post request. It looks like it is possible to do this if you can figure out how to get the initial access token. First check out this post to make sure you can get access to the API. Once you’ve got that all set, you can start trying to make requests.

Don’t forget, you can click the link next to your API key to test it on our documentation site.

To acquire an access token, send a request to 'https://demo.tradovateapi.com/auth/accessTokenRequest' for our demo environment, and 'https://live.tradovateapi.com/auth/accessTokenRequest' for our live environment. Here’s what your JSON body should look like for an authentication request:

{
  "name": "your username",
  "password": "your password",
  "appId": "generated with your API key",
  "appVersion": "1.0",
  "cid": 8, //generated with your API key
  "sec": "12345-abcdef-67890-abcd..." //the API key you generated
}

You receive a response from that request:

{
    "accessToken": "<your access token response here>",
    "mdAccessToken": "<your md access token response here>",
    "expirationTime": "2021-06-15T15:40:30.056Z",
    "userStatus": "Active",
    "userId": 15460,
    "name": "alennert02",
    "hasLive": true,
    "outdatedTaC": false,
    "hasFunded": true,
    "hasMarketData": true,
    "outdatedLiquidationPolicy": false
}

When you send future requests, such as placeOrder or startOrderStrategy you’ll need to provide the accessToken field from the JSON above in the Bearer authorization schema of the headers:

{
  "headers": {
    "Accept": "application/json",
    "Authorization": "Bearer <your access token (no brackets)>"
  }
}

You’ll need to figure out how to store that token and inject it into your webhooks requests. But it definitely seems possible. I hope this has helped out, and best of luck to you!

1 Like

I see. This is great help, indeed!

Would it be possible to get this acces token using a request from another software in my computer (Postman, for instance) and stick it in the tradingview webhook header given the requests will be sent from a different IP? Is this an issue?

It should be 100% possible to run this from your PC, or from a remote server/cloud service (so you can be fully automated). My theoretical solution is this:

Problem - TradingView doesn’t let you inject authorization headers.

Solution - Send requests to an ‘adapter’ service.

This would be an node application that you would send the POST requests to (from TradingView). You would just have to catch the data, inject your auth header, and then forward the request to the Tradovate REST API. I’d suggest using the popular express node package for this, accompanied with something like Heroku for serving the adapter application.

Yes, this sounds like what I had in mind. I am looking at a service like webhookrelay.com.

Thanks for taking the time to reply and sharing your knowledge.

Alexander,
Is there a way to see what the Tradovate API is receiving? I setup an http post and says it is “ok” but It does not show up in the orders tab.

From a google search, I found your post from July 2021 entitled ’ Access Tradovate API using Tradingview Webhooks. I am a developer who just finished a pinescript strategy that I want to start trading live. I was planning on recoding the strategy in NinjaScript to run on NinjaTrader, then I saw your post, hoping there was a Tradovate solution, as I already have a Tradovate account that I have been using, just to get live data. I don’t want to reinvent the solution as it may be easier for me to convert my 1.5k pinescript to NinjaScript , which which I am intimately familiar. On the other hand, I cherish the idea of actually trading with TradingView, so I am wondering if your solution is up and running and if there is posted anywhere your solution or a similar one that would avoid me having to reinvent the webhook-tradingview api interface? Even a prototype or just plain examples of the necessary components would great. Thanks in advance! Scott

Did you manage to get this to work? I am also interested in setting something like this up and would like guidance on what are the services you used eventually.