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!

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.