Starting strategies through API

Thank you for clarifying. This is very helpful.

I have one more question. Is Tradovate working on a solution to communicate with scripts built on TradingView (pine script)? The two companies already work together and I would assume that many people have written solutions in pine script that are just waiting to get deployed.

Hello All, I am trying to get a WebSocket strategy going, using the GitHub tutorial and sample rsiStrategyFP. I cannot for the life of me get the startorderstrategy to throw anything but 404. For comparison I used network monitor to grab a post from Tradovate:
orderStrategy/startorderstrategy
62

{“accountId”:123456,“symbol”:“MESZ1”,“orderStrategyTypeId”:2,“action”:“Sell”,“params”:"{“entryVersion”:{“orderId”:0,“orderQty”:1,“orderType”:“Market”,“timeInForce”:“GTC”},“brackets”:[{“qty”:1,“profitTarget”:-1.5,“stopLoss”:1,“trailingStop”:true}]}"} 1634681685.7525158

Compared to what I am sending:
orderStrategy/startorderstrategy
2

{“accountId”:123456,“symbol”:“MESZ1”,“orderStrategyTypeId”:2,“action”:“Sell”,“params”:"{“entryVersion”:{“orderId”:0,“orderQty”:1,“orderType”:“Market”,“timeInForce”:“GTC”},“brackets”:[{“qty”:1,“profitTarget”:-2,“stopLoss”:0.5,“trailingStop”:true}]}"}

I tried with and without accountSpec… Outside of a timestamp(?) at the end of the Tradovate post and values the parameters and order appear the same.
Thoughts? Suggestions?

Hello @Mr.Cage,

Can you please provide the the URL you’re using to connect the socket, and also the response that you’re getting from that request?

Hey @Alexander
The WebSocket is connected to ‘wss://demo.tradovateapi.com/v1/websocket’
The response from code block (below) is {s:404, i:2, d:’’}

let dispose = socket.request({
            url: 'orderStrategy/startOrderStrategy',
            body,
            callback: (id, r) => {
                if(id === r.i) {
                    console.log(JSON.stringify(r, null, 2))
                    dispose()
                }
            }
        })

@Alexander I’ve simplified the code a bit see below. I used the sample orderStrategy/startOrderStrategy example from the API documents and it failed with a 404… To prove that something works I kept the same acquire token code and used the sample /order/placeorder from the API documents. placeorder was successful. This is very curious.

import axios from 'axios';

interface AccessTokenResponse {
    errorText: string,
    accessToken: string,
    expirationTime: string,
    passwordExpirationTime: string,
    userStatus: string,
    userId: number,
    name:string,
    hasLive: boolean
}

const DEMO_URL = 'https://demo.tradovateapi.com/v1';

const connect = async (data) => {
        
        const response = await axios.post<AccessTokenResponse>(`${DEMO_URL}/auth/accesstokenrequest`, data);

        const bracket1 = {
            qty: 1,
            profitTarget: -30,
            stopLoss: 5.5,
            trailingStop: false
        }
        
        const bracket2 = {
            qty: 1,
            profitTarget: 40.75,
            stopLoss: -5.5,
            trailingStop: false
        }
        
        const params = {
            entryVersion: {
                orderQty: 1,
                orderType: "Stop",
                stopPrice: 4174.50,
            },
            brackets: [bracket1, bracket2]
        }

        const body = {
            accountId: 480000,
            accountSpec: 'DEMO240000',
            symbol: "MESZ1",
            action: "Sell",
            orderStrategyTypeId: 2,                        
            params: JSON.stringify(params)
        }

        const config = {            
            headers: {
                'Accept': 'application/json',
                'Authorization': `Bearer ${response.data.accessToken}`,
            }
        };

        const orderResponse = await axios
                    .post(`${DEMO_URL}/orderStrategy/startOrderStrategy`
                            , body
                            , config)
                    .catch(ex => {
                                    let r = ex.response;
                                });
};

connect({
    name:       "username",
    password:   "api_pwd",
    appId:      "Sample App",
    appVersion: "1.0",
    cid:        123,
    sec:        'secrets',
});

Hi,

would it be possible to share the json structure for ‘Limit’ ordertype in startorderstrategy