Support Board
Date/Time: Mon, 10 Mar 2025 07:55:04 +0000
Post From: Sample code for sc.SetAttachedOrders
[2022-01-22 11:03:31] |
User431178 - Posts: 612 |
I have no problem with this code on sim this morning, as evidenced by attached log. This is only a minimal demonstration of concept, clearly there is work to be done identifying the correct orders in different situations and there is no error handling or safety check of any kind. if (cancelAndReplace) { auto stopOrder = s_SCTradeOrder(); auto targetOrder = s_SCTradeOrder(); auto index{ 0 }; auto orderDetails = s_SCTradeOrder(); while (sc.GetOrderByIndex(index, orderDetails) != SCTRADING_ORDER_ERROR) { index++; if (orderDetails.OrderStatusCode != SCT_OSC_OPEN) continue; if (orderDetails.OrderType.CompareNoCase("Limit") == 0) targetOrder = orderDetails; else if (orderDetails.OrderType.CompareNoCase("Stop") == 0) stopOrder = orderDetails; if (stopOrder.InternalOrderID > 0 && targetOrder.InternalOrderID > 0) break; } if (stopOrder.OrderStatusCode == SCT_OSC_OPEN && targetOrder.OrderStatusCode == SCT_OSC_OPEN) { if (sc.CancelOrder(stopOrder.InternalOrderID) && sc.CancelOrder(targetOrder.InternalOrderID)) { auto newOrder = s_SCNewOrder(); newOrder.OrderType = SCT_ORDERTYPE_OCO_LIMIT_STOP; newOrder.OrderQuantity = targetOrder.OrderQuantity; newOrder.Price1 = targetOrder.Price1; newOrder.Price2 = stopOrder.Price1; if (targetOrder.BuySell == BSE_BUY) { const auto result = static_cast<int32_t>(sc.BuyOrder(newOrder)); if (result < 0) sc.AddMessageToTradeServiceLog(sc.GetTradingErrorTextMessage(result), 0, 1); } else if (targetOrder.BuySell == BSE_SELL) { const auto result = static_cast<int32_t>(sc.SellOrder(newOrder)); if (result < 0) sc.AddMessageToTradeServiceLog(sc.GetTradingErrorTextMessage(result), 0, 1); } } } } |
![]() |