Trouble Submitting Bracket Order via API

@Alexander said

This Weekend’s release

That was 5 days. Try again after Sunday open.

This should be working now, can anyone verify that this is currently working or reproduce Arthur’s error? And @Arthur if you could share more info about your request body and the response, that would be helpful.

Sure, here is the exact request body followed by the response, lifted directly from the GitHub example to make sure nothing was lost in translation:

See that collapsed property, sync data? Open that up and look at the orderStrategyTypes field for me.

I’m afraid it is just the server response, and not what you’re looking for:

I just tried the feature and is working fine for me.

As a suggestion, double check that you’re connecting your socket to ‘wss://demo.tradovateapi.com/v1/websocket’ (same url used for sync requests) instead of the one used for market data.

Also, avoid using ‘socket.subscribe()’ (in case you’re using the tutorial tradovate socket files), make sure to use the ‘socket.send()’ method instead.

Let us know your results… :crossed_fingers:

The other thing that should be considered is the deviceId field when you are requesting an access token. On Live, you strictly need to provide the deviceId or operations with that token may fail.

Thanks for the suggestions, @gustrom and @Alexander. I’m glad it is working for others, but I’m still having issues.

I’ve broken down this sequence to show the following:

  • Successful storage of device id before requesting access token (I can send commands via POST in my live account)
  • Proper URL of webSocket connection
  • Message body passed into Socket’s send method, which mirrors the FAQ example parameters

It seems to me that you have 1 missing element in your body message, besides accountId you need to provide accountSpec which for demo accounts is something like DEMOXXXXXX (where Xs are numbers).

Thanks @gustrom, I just tried adding accountSpec to the body, using both my user name and DEMO######. No luck.

The strange thing is that the the reason string is empty. If it was missing a user name or other property, it normally gives you some sort of feedback so you know what to do, but the error message is just an empty string.

Here’s a screenshot of my message for your reference:

Maybe you could find this line in you socket.send method:

this.ws.send(`${url}\n${id}\n${query || ''}\n${JSON.stringify(body)}`)

do a console.log like this:

console.log(`${url}\n${id}\n${query || ''}\n${JSON.stringify(body)}`)

and compare it directly to the one I posted here

Sure thing. Here are the two logs side-by-side:

And the text is below:

orderstrategy/startorderstrategy
2

{"accountId":******,"accountSpec":"DEMO******","symbol":"NQH2","action":"Buy","orderStrategyTypeId":2,"params":"{\"entryVersion\":{\"orderQty\":1,\"orderType\":\"Market\"},\"brackets\":[{\"qty\":1,\"profitTarget\":30,\"stopLoss\":-15,\"trailingStop\":false}]}"}

Let me know if you see any discrepancies other than the iterator after the endpoint on line 2, which shouldn’t matter.

I don’t see anything, and I’m just about ready to give up.

I’m experiencing exactly the same issue, the following is an error I get back when submitting EXACTLY the same string as in the API docs and what Alexander mentions here:

a[{"s":404,"i":1,"d":""}]

Any recommendations?

Yeah same here. I’ve been getting the exact error for the last couple weeks testing out the alleged bracket order fix.

@Alexander any help?

One thing I’ve seen people having issues with a lot recently is the deviceId property. When you request access it’s one of the fields that you can send. The purpose of the deviceId is to identify the app instance that asked for a token. If you haven’t configured a device ID then your orders are likely to fail.

My other question is, everyone is trying to use the bracket order via WebSocket correct? The /orderStrategy/startOrderStrategy endpoint should be called from a WebSocket.

Understood. Here is a screenshot of the login body I am using to request an access token:

The startOrderStrategy endpoint is being sent through the TradovateSocket.send() method.

Same 404 response.

I recently converted my engine to send all trade orders through the WebSocket . It was relatively painless and everything is working fine, so I know there are no syntax or other issues on my part when sending orders to WebSocket endpoints.

But startOrderStrategy is broken. As a test, here it is with a 200 response when sending with orderStrategyType: 1 using similar parameters as previous examples:

And here is the same thing with orderStrategyType: 2

There is clearly something wrong server-side. Please take another look or tell me what I am doing wrong.

1 Like

Hey @Arthur, for your WebSocket - when you get the initial user data response (so you call user/syncrequest, the first response that comes back is the huge user data response object) there should be an orderStrategyTypes array field. Does the orderStrategyTypes array contain a strategy with the id of 2? It’s possible that for you it doesn’t. If that’s the case, it will have a different ID - notice it finds that strategy with ID = 1 no problem.

This may return a 401 (its a part of the Configuration portion of the API which typically has restricted access for retail users), but you could try to find all the orderStrategyType entites using orderstrategytype/list.

Thanks @Alexander, below is the orderStrategyTypes field. As you can see, the array does have an ID of strategy 2. I have also tried to fetch the endpoint /orderStrategyType/list and, like you expected, it did return a 401.

"orderStrategyTypes": [
    {
      "id": 1,
      "name": "ofa:multibracket",
      "enabled": false
    },
    {
      "id": 2,
      "name": "multibracket",
      "enabled": true
    }
  ]

The whole point of my previous post was to show that my request using orderStrategyTypeId: 1 had no problem and that all previous suggestions for what could be wrong have all been exhausted. Please let me know if you have any other ideas or if someone will debug on your side.

Alright one more check - what does your API Key permission set look like? If that looks OK, I think I am going to put in a ticket for this particular case. I have confirmations that this is working for others after the fix (:pray:) so this appears to be some other issue related to the brackets orders.