I just used ChatGPT to help me structure an OSO JSON. I am passing this along to others here that may find it useful. It is not correct all the time. It depends on how detailed your question is.
Here is what I asked:
I wrote the following JSON to place a Tradovate OSO order. It should place a Buy Stop order at 4151, a take profit limit order at 4152, and a stop loss limit order at 4150, but it is not doing that.
{
“accountSpec”: [USERNAME],
“accountId”: [“ACCOUNTID”],
“action”: Buy,
“symbol”: MESM3,
“orderQty”: 1,
“orderType”: “StopLimit”,
“price”: 4151,
“stopPrice”: 4151,
“isAutomated”: True
“bracket1”: {
“action”: Sell,
“orderType”: “Limit”,
“price”: 4152
},
“bracket2”: {
action": Sell,
“orderType”: “Stop”,
“stopPrice”: 4150
}
}
Can you fix it?
Here is ChatGPT’s response:
There are a few syntax errors and missing key-value pairs in the JSON code you provided that need to be addressed to place the OSO order correctly. Here is the corrected JSON code:
{
“accountSpec”: “[USERNAME]”,
“accountId”: “[ACCOUNTID]”,
“action”: “Buy”,
“symbol”: “MESM3”,
“orderQty”: 1,
“orderType”: “StopLimit”,
“price”: 4151,
“stopPrice”: 4151,
“isAutomated”: true,
“bracket”: {
“bracket1”: {
“action”: “Sell”,
“orderType”: “Limit”,
“price”: 4152
},
“bracket2”: {
“action”: “Sell”,
“orderType”: “StopLimit”,
“price”: 4150,
“stopPrice”: 4150
}
}
}
The changes include:
- Adding quotes around the
accountSpecandaccountIdvalues. - Adding quotes around the
actionvalues for both the main order and the bracket orders. - Adding a missing comma after the
isAutomatedkey-value pair. - Combining the
bracket1andbracket2keys into a singlebracketobject. - Changing the
orderTypeof the stop loss order fromStoptoStopLimitto match the requirements for an OSO order.
With these changes, the JSON code should correctly place the Buy Stop order at 4151, the take profit limit order at 4152, and the stop loss limit order at 4150.
I think this is cool! ![]()