Hi Alexander, I am trying to McGyver an OSO order that triggers an OCO order.
I would like to go long NQZ1 at 14,700. When filled, I want to trigger an OCO order with a stop loss at 14,600 and a target of 14,800. Can you please help me figuring out what I am doing wrong and which approach is more efficient?:
'''
//Code Example 1:
const URL = 'demo.tradovateapi.com/v1'
const oco = {
qty: 1,
profitTarget: 100,
stopLoss: -100,
trailingStop: false
}
const params = {
entryVersion: {
orderQty: 1,
orderType: "Limit",
limitPrice: 14700,
},
brackets: oco
}
const body = {
accountId: id,
accountSpec: name,
symbol: 'NQZ1',
action: 'Buy',
orderStrategyTypeId: 1,
params: JSON.stringify(params)
}
const response = await fetch(URL + '/orderStrategy/startOrderStrategy', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${myAccessToken}`,
},
body: JSON.stringify(body)
})
const json = await response.json()
//Code Example 2:
const URL = 'demo.tradovateapi.com/v1'
const limit = {
action: 'Sell',
orderType: 'Limit',
price: 14800.00
}
const oco = {
action: 'Sell',
orderType: 'Stop',
price: 14600.00,
other: limit
}
const initial = {
accountSpec: yourUserName,
accountId: yourAcctId,
action: "Buy",
symbol: "NQZ1",
orderQty: 1,
orderType: "Limit",
price: 14700.00,
isAutomated: true
brackets: oco
}
const response = await fetch(URL + '/order/placeorder', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${myAccessToken}`,
},
body: JSON.stringify(initial)
})
const json = await response.json() // { orderId: 0000000 }`