Support Board
Date/Time: Fri, 14 Mar 2025 13:02:35 +0000
[Programming Help] - Sub-second order fills not shown when using GetOrderFillEntry
View Count: 612
[2022-06-02 10:25:14] |
ray42 - Posts: 21 |
Hi, I'm trying to print out all the executed fills, but I'm not able to print out the orders that were executed within 1-sec. if (sc.SetDefaults){
sc.GraphName = "PrintFills"; sc.AllowMultipleEntriesInSameDirection = false; sc.SupportReversals = true; sc.AllowOppositeEntryWithOpposingPositionOrOrders = true; sc.CancelAllOrdersOnEntriesAndReversals = false; sc.AllowEntryWithWorkingOrders = false; sc.CancelAllWorkingOrdersOnExit = true; sc.AllowOnlyOneTradePerBar = false; sc.MaintainTradeStatisticsAndTradesData = true; sc.AutoLoop = true; sc.HideStudy = 1; return; } sc.SupportTradingScaleIn = 0; sc.SupportTradingScaleOut = 0; int& PriorOrderFillEntrySize = sc.GetPersistentInt(1); int CurrentOrderFillEntrySize = sc.GetOrderFillArraySize(); if (CurrentOrderFillEntrySize != PriorOrderFillEntrySize){ PriorOrderFillEntrySize = CurrentOrderFillEntrySize; if (CurrentOrderFillEntrySize > 0){ s_SCOrderFillData OrderFillData; sc.GetOrderFillEntry(CurrentOrderFillEntrySize - 1, OrderFillData); SCString OrderFillMessage; s_SCPositionData SCPositionData; int got_position = sc.GetTradePosition(SCPositionData); SCString LogMessage; LogMessage.Format("[%s] %s [x %u] @ %f [Side: %d]", sc.DateTimeToString(OrderFillData.FillDateTime, FLAG_DT_COMPLETE_DATETIME_MS).GetChars(), OrderFillData.Symbol.GetChars(), static_cast<uint32_t>(OrderFillData.Quantity), OrderFillData.FillPrice, OrderFillData.BuySell ); sc.AddMessageToLog(LogMessage, 0); } } For example, when I export the fills to .txt I see orders like this: Fills 2022-06-02 08:24:59.635377 2022-06-02 08:24:59.635250 [Sim]ESM22-CME Trade simulation fill.... Fills 2022-06-02 08:24:59.635602 2022-06-02 08:24:59.635275 [Sim]ESM22-CME Trade simulation fill.... But in the logs output, I only see the first filled order. Am I missing a setting or show can I handle these type of filled orders? Thank you! |
[2022-06-02 14:20:53] |
|
They must all be there in the list. Iterate through them all.
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: 2022-06-02 14:21:04
|
[2022-06-02 14:40:21] |
ray42 - Posts: 21 |
Hi Sierra Team, Thank you for your response! My assumption was that the code is supposed to print out every single order whenever a new order is added to the list (size comparison using `CurrentOrderFillEntrySize` and `PriorOrderFillEntrySize`). Should I still iterate through the list (using `GetOrderFillEntry`) despite this? or have I misunderstood the purpose of comparing the order list size? I took this code from the `TradingSytem.cpp` sample in the SierraChart folder. Edit: I just checked again and it's only able to get the last order and the conditions are not triggering for the previous orders Printed: {'symbol': 'ESM22-CME', 'quantity': '1', 'price': '4088.750000', 'time': '2022-06-02 14:35:42.148', 'time_utc': '2022-06-02 13:35:42.148'} Orders: Fills 2022-06-02 14:35:42.130633 2022-06-02 14:35:42.130614 [Sim]ESM22-CME Fills 2022-06-02 14:35:42.148016 2022-06-02 14:35:42.147959 [Sim]ESM22-CME Fills 2022-06-02 14:35:42.148292 2022-06-02 14:35:42.148258 [Sim]ESM22-CME Shouldn't the print statement be triggered even for the .147959 and .130614 trade? Can you please let me know if I'm missing something here? Date Time Of Last Edit: 2022-06-02 16:03:40
|
[2022-06-02 17:36:48] |
ray42 - Posts: 21 |
Hi, I figured out the reason for "delay" - I have a HTTP POST (`MakeHTTPPOSTRequest`) method sending data to the server before printing. This works well if the orders are placed ~1-2 secs apart, but the closer they are, only the most recent order is sent if multiple orders are executed within the same second. Is there any way around this? Like using an asynchronous method for POST request? |
[2022-06-02 17:47:48] |
|
MakeHTTPPOSTRequest is asynchronous. And returns right away, and then the request is made in the background and the data received comes later.
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 |
[2022-06-02 18:21:18] |
ray42 - Posts: 21 |
Hi Team, Thank you for the clarification. Then the problem seems to be that it still sometimes misses sending the info/showing the print statement. Is there anything I should optimize in the code? Right now, the way I'm testing this is by almost spamming the buy/sell market button but this is to make sure that ALL the orders are sent successfully to the server. I verified the server logs also and it has processed everything it gets from SierraChart, but SierraChart sometimes does not send ALL the orders - especially if the order execution on the platform is done very fast. if (CurrentOrderFillEntrySize != PriorOrderFillEntrySize){
PriorOrderFillEntrySize = CurrentOrderFillEntrySize; if (CurrentOrderFillEntrySize > 0){ s_SCOrderFillData OrderFillData; sc.GetOrderFillEntry(CurrentOrderFillEntrySize - 1, OrderFillData); SCString OrderFillMessage; s_SCPositionData SCPositionData; int got_position = sc.GetTradePosition(SCPositionData); OrderFillMessage.Format("...",...); SCString LogMessage; LogMessage.Format("[%s] %s [x %u] @ %f [Side: %d] [fill id: %s]", sc.DateTimeToString(OrderFillData.FillDateTime, FLAG_DT_COMPLETE_DATETIME_MS).GetChars(), OrderFillData.Symbol.GetChars(), static_cast<uint32_t>(OrderFillData.Quantity), OrderFillData.FillPrice, OrderFillData.BuySell, OrderFillData.FillExecutionServiceID.GetChars() ); sc.AddMessageToLog(LogMessage, 0); sc.AddMessageToLog("Preparing to send message", 0); if (RequestState == REQUEST_NOT_SENT){ if (!sc.MakeHTTPPOSTRequest(PostURL, OrderFillMessage, &HTTPHeader, NumberOfHeaders)){ sc.AddMessageToLog("Error making HTTP request.", 0); RequestState = REQUEST_NOT_SENT; }else{ RequestState = REQUEST_SENT; sc.AddMessageToLog("HTTP Request Sent Successfully!", 0); } } if (RequestState == REQUEST_SENT && sc.HTTPResponse != ""){ RequestState = REQUEST_RECEIVED; sc.AddMessageToLog(sc.HTTPResponse, 0); }else if (RequestState == REQUEST_SENT && sc.HTTPResponse == ""){ sc.AddMessageToLog("HTTP req NOT complete yet", 0); } sc.AddMessageToLog(sc.HTTPResponse, 0); } } The above is the full code including the print to message log code + send to server code. If it's asynchronous, then I should be able to see ALL messages being sent even if the server is slow right? But that is not the case here. Is this a problem of the code I've written above being inefficient/slow? Edit: I've removed almost all the print code and only kept `sc.MakeHTTPPOSTRequest(PostURL, OrderFillMessage, &HTTPHeader, NumberOfHeaders)` - the result is still missing ~10 orders. I'm simply comparing the no. of "Making HTTTP POST request" to the no. of fills in the activity log. Most recent comparison: 88 vs 98. Date Time Of Last Edit: 2022-06-02 18:43:33
|
[2022-06-03 16:50:22] |
ray42 - Posts: 21 |
Hi, Is there any solution for this? or am I doing something incorrectly? I would really appreciate some help with this I can also send videos if necessary! Thank you! |
[2022-06-03 19:17:30] |
User431178 - Posts: 613 |
You need to iterate through all the newly added order fills. With the code as it is, if there are multiple fills between calls to the study function, you only ever log the latest fill.
Date Time Of Last Edit: 2022-06-03 19:18:05
|
[2022-06-03 19:53:27] |
ray42 - Posts: 21 |
@User431178 Thank you for your reply! How can I filter by newly added order fills only? Is iterating the orders array backward from the last order the only way? I'm not sure how to handle "when to stop" - any suggestions for this? |
[2022-06-04 08:49:15] |
User431178 - Posts: 613 |
You already have the prior list size in your code, PriorOrderFillEntrySize, so this tells you where to stop. Anything in the list from PriorOrderFillEntrySize to CurrentOrderFillEntrySize - 1 must be a new order fill. |
[2022-06-04 08:59:03] |
ray42 - Posts: 21 |
@User431178 Thank you! I will try this!
|
To post a message in this thread, you need to log in with your Sierra Chart account: