Login Page - Create Account

Support Board


Date/Time: Mon, 23 Dec 2024 14:50:59 +0000



IsWorkingOrderStatus() with server-side bracket OCO

View Count: 1612

[2015-10-07 02:06:34]
User35525 - Posts: 181
The given examples for walking orders, and continuing if a working order, are this:

if (!IsWorkingOrderStatus(OrderDetails.OrderStatusCode))
continue;

But that doesn't work if it's a server-side bracket OCO parent at CTS, because the order status is always SCT_OSC_FILLED; in case it matters, my parent order type is SCT_ORDERTYPE_MARKET_IF_TOUCHED.

I hacked the following together, however it makes assumptions that aren't always true. Just because a parent has active children, doesn't mean the parent is still active; and just because the parent doesn't have active children, doesn't mean the parent isn't active still. These are bad assumptions in my code. TST told me it's possible for an auto-OCO in T4 (server side bracket in SC) to fill as naked (without a SL), so we cannot always assume the bracket OCO filled perfectly. We need a way to actually determine if a parent order ID is working (via FIX message, passed along to SC API?), so we can monitor the status for problems.


bool IsWorkingBracketOrderIDStatus(int oid, SCStudyGraphRef sc)
{
// Given an order ID, return working order status.
// (This is fine for the working order status of a child, but assumes parents with working children are working, which
// isn't safe, as parents may be non-working but children working, and visa-versa)

// return true if working child order.
// return true if parent with a working child.
// return false if non-working child.
// return false if parent with no working children.
// return false if cannot get order details from passed oid arg.

s_SCTradeOrder OD, CHILD;
if (sc.GetOrderByOrderID(oid, OD) == 1) {
if (OD.ParentInternalOrderID != 0)
return IsWorkingOrderStatus(OD.OrderStatusCode); // return child order status.

// CHECK STATUS OF PARENT (true if any child is still working).
int TargetInternalOrderID= -1;
int StopInternalOrderID= -1;

sc.GetAttachedOrderIDsForParentOrder(oid, TargetInternalOrderID, StopInternalOrderID);
if (TargetInternalOrderID != -1 && sc.GetOrderByOrderID(TargetInternalOrderID, CHILD) == 1) {
if (IsWorkingOrderStatus(CHILD.OrderStatusCode)) return true; // found working child.
}

if (StopInternalOrderID != -1 && sc.GetOrderByOrderID(StopInternalOrderID, CHILD) == 1) {
if (IsWorkingOrderStatus(CHILD.OrderStatusCode)) return true; // found working child.
}

// assume bracket's parent ID non-working just because no working children?
return false;

} else {
return false; // cannot get order details.
}
}

SC needs to have a way to determine if an order ID is working or not, even if it's a server-side order. I'm assuming that we can do that with child orders now, but we need a way to determine if a server-side parent order is working.
Date Time Of Last Edit: 2015-10-07 03:43:40
[2015-10-07 03:42:56]
Sierra Chart Engineering - Posts: 104368
What is very difficult about this is there are numerous statements from you that do not make sense based on how orders actually work.

To start off with, this is not correct:
The given examples for walking orders, and continuing if a working order, are this:

It continues, if it is not a working order.

This is simply not true:
But that doesn't work if it's a server-side bracket OCO parent at CTS, because the order status is always SCT_OSC_FILLED;
The order will initially have a working order status and maintain that status until it is filled.

This also does not make sense:
in the event that the server-side bracket is completely childless; note, TST told me it's possible for a server-side bracket OCO to fill without an attached SL child,
If you have an order without child orders, it is not a bracket order. So this cannot be true either. If the order set does not contain a Stop order, it is not a bracket to begin with.

If you know the Internal Order ID of the parent order, simply iterate through the orders looking for the order with that same Internal Order ID and then see if it is working. Why would that be difficult?
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2015-10-07 03:45:00
[2015-10-07 03:53:46]
User35525 - Posts: 181

If you know the order ID of the parent order, simply iterate through the orders looking for the order with that same ID and then see if it is working. Why would that be difficult?

Thanks, I will have to do some more testing I guess. From my tests so far, the order status is always SCT_OSC_FILLED, and because of that, IsWorkingOrderStatus() ALWAYS returns false. This happens in scconstants.h in ASC_Source:

inline bool IsWorkingOrderStatus(SCOrderStatusCodeEnum OrderStatusCode)
{
  switch (OrderStatusCode)
  {
    case SCT_OSC_ORDERSENT:
    case SCT_OSC_PENDINGOPEN:
    case SCT_OSC_OPEN:
    case SCT_OSC_PENDINGCANCEL:
    case SCT_OSC_PENDINGMODIFY:
    case SCT_OSC_PENDINGCHILD:
    case SCT_OSC_PENDING_CANCEL_FOR_REPLACE:
    return true;
    
    default:
    return false;
  }
}

I know SC doesn't do any management of server-side bracket orders, once accepted by the broker, but there does need to be a way to monitor those orders using FIX messaging, to determine if they're still working.

Let me get back with you after I've done more live testing, as I was doing a lot of coding with simulated orders earlier
Date Time Of Last Edit: 2015-10-07 04:09:59
[2015-10-07 04:18:12]
User35525 - Posts: 181
My language was incorrect, and it's easy indeed to tell if an order is working or not.

My question should have been, is there a way to tell if a bracket's parent order is "active"? I want to know if it's still alive at the broker or not. I probably incorrectly assumed since the status is always SCT_OSC_FILLED, I couldn't monitor it for problems, such as a child being non-working and the parent still existing (still have a position)...or the child still working and the parent non-existent. I'll see if I can query the OrderQuantity of the parent or check if InternalOrderID is zero. Thanks, I understand now.
Date Time Of Last Edit: 2015-10-07 04:30:34
[2015-10-07 04:33:50]
Sierra Chart Engineering - Posts: 104368
is there a way to tell if a bracket's parent order is "active"
What is your definition of "active"?
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2015-10-07 05:28:57]
User35525 - Posts: 181
I should have said appears in the "Trade Orders and Positions" window, and will try checking the OrderQuantity of the parent, which hopefully changes based on the actual position quantity.

I had some questions about split orders too (didn't see it documented), but could do my own investigating I guess. I assume that they get different parent ID's? And for server-side brackets, I assume I don't ever need to check FilledQuantity, but checking OrderQuantity is okay? (Last time I checked both FilledQuantity and OrderQuantity, they were different if I remember, even though it wasn't a split order; the docs say you can check FilledQuantity on split orders, but that is for non-bracket server-side OCO's, right? Or is it for server-side bracket OCO's too?)
Date Time Of Last Edit: 2015-10-07 06:22:34
[2015-10-07 19:18:11]
Sierra Chart Engineering - Posts: 104368
the OrderQuantity of the parent, which hopefully changes based on the actual position quantity.
No it will not.

If you are asking about when the entire bracket order set, which consists of three orders, is all complete and the Trade Position that was created by the Parent order has been offset and no longer exists, you can determine this by checking the Order Status of all three of the orders. None of them should be working and the Trade Position Quantity should have returned back to its previous quantity.

I assume that they get different parent ID's?
Yes they do.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2015-10-08 02:40:30]
Sierra Chart Engineering - Posts: 104368
Once the parent order fills, then the child orders become active. The parent order will have a status of SCT_OSC_FILLED but not previous to that. After the parent order fills, you need to check the status of the child orders to see the status of those.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account