I’m new to the API and I’m trying to figure out how to place a take profit and stop loss order in one order. Is that possible?
My order should be similar to the one in the mobile app (market order) where you place a tick based order with a take profit of let’s tay 10 ticks, and a stop loss at -10 ticks.
Could someone please give an example of such an order?
Hi there. Thank you for your reply. Much appreciated.
However, I have studied the API and also the examples in GitHub and none of them cover the example I’m looking for, a “take profit and stop loss” order via API. Also it does not state if you can place a market order based on ticks.
Do you mean you’ve already placed a marker order and now you want to place another separate bracket order? That would just be placeOCO instead of placeOSO.
What do you mean “based on ticks”? If you are receiving tick data you’ll have to process those packets into a more user friendly format. They give examples in the tick data section of the api on how to do that.
If you can share more specifics about what you are trying to do I’d be happy to help you further.
you are right. I realize its a bracket order I want to place. Thank you.
but just to follow up.
Is this the way to do it then, example of a buy order?
Just for this example, the price when placing the order is 17500.
// this I want to exit if reached upwards
const exitUp = {
action: ‘Buy’,
orderType: ‘Stop’,
price: +200
}
// this I want to exit if reached upwards
const exitDown = {
action: ‘Sell’,
orderType: ‘Stop’,
price: -200
}
// the order I place to enter the market
const oco = {
accountSpec: yourUserName,
accountId: yourAcctId,
action: “Buy”,
symbol: “NQH4”,
orderQty: 1,
orderType: “Market”,
isAutomated: true,
activationTime: theDateAndTimeIwantTheOrderToBePlaced?
other: exitDown,
other: exitUp,
}
Will this work?
Additional question.
activationTime: can I use this to schedule an order?
You’ll want to change your exit up order to be a Sell Limit inside of a Buy Stop.
You’ll also want to put in there the actual prices for your bracket order and not plus or minus 200.
On activation time, I don’t know what the purpose of that key is, there isn’t any documentation for it anywhere that I’ve seen. If you are interested in filtering out trades by time I would write the logic for that yourself.
// this I want to exit if reached upwards
const exitUp = {
action: ‘Sell’,
orderType: ‘Limit’,
price: +200
}
// this I want to exit if reached upwards
const exitDown = {
action: ‘Buy’,
orderType: ‘Stop’,
price: -200,
other: exitUp
}
// the order I place to enter the market
const oco = {
accountSpec: yourUserName,
accountId: yourAcctId,
action: “Buy”,
symbol: “NQH4”,
orderQty: 1,
orderType: “Market”,
isAutomated: true,
other: exitDown,
}
The problem with the actual prices is that I don’t have them since it is a “Market” order. I buy at any price at the given time.
Actually no. This forum is not very active besides Mr unsupervised, but I think he disappeared too. I’ve also emailed the support with the same questions but no answer yet and it’s been more than a week.
I have created a public Discord channel to help answer API specific questions for anyone that needs help since I am not always checking in here because of lack of activity.
It is free… and should be way more responsive than this community.
NOTE: I am not trying to steal people or advertise anything. I am happy to help since I have done a full implementation using the API and works really well.
It is so sad that there is no dev support here. I do not have time to check in here to help devs, but if they ask the question on my Discord, I will get to see it and respond. Cheers.