private void CancelPendingCallback(TradeResult tr) { if (tr.IsSuccessful) { cancelPedingList.Remove(tr.PendingOrder.Label); } else { var tr2 = CancelPendingOrder(tr.PendingOrder); if (tr2.IsSuccessful) { cancelPedingList.Remove(tr.PendingOrder.Label); } else { if (PendingOrders.Where(x => x.SymbolCode == Symbol.Code && x.Label == tr.PendingOrder.Label).Count() > 0) { Print("ERROR!!! ไม่สามารถยกเลิก pending >>>" + tr.PendingOrder.Label); cancelPedingList.Remove(tr.PendingOrder.Label); } else { cancelPedingList.Remove(tr.PendingOrder.Label); } } } }
private void UpdateOrderInformation(Order order) { PendingOrders = new ObservableCollection <Order>(PendingOrders.Where(x => !x.Id.Equals(order.Id) && x.Status != OrderStatus.DONE)); if (order.Status != OrderStatus.DONE) { PendingOrders.Add(order); } }
private void UpdateWork(object sender, DoWorkEventArgs e) { var obj = new WorkOrder(cfg); obj.OnLog += WO_OnLog; obj.ChangeDateScheduled(PendingOrders.Where(k => k.Update).Select(x => x.h.OrderNum).ToList(), toChange); RaisePropertyChanged("PendingOrders"); }
private void ReQueryOrders(object sender, EventArgs e) { var oldMergeOption = DataService.MergeOption; DataService.MergeOption = MergeOption.OverwriteChanges; var orders = DataService.Orders.Expand("OrderItems").Where(x => x.OrderStateId == OrderStates.Cooking).ToList(); foreach (var order in orders.Where(order => !PendingOrders.Contains(order))) { PendingOrders.Add(order); } foreach (var pendingOrder in PendingOrders.Where(pendingOrder => !orders.Contains(pendingOrder))) { PendingOrders.Remove(pendingOrder); } DataService.MergeOption = oldMergeOption; }
private void ClearPending(TradeType tradeType, string presentLabel, bool isWait) { var pes = PendingOrders.Where(x => x.SymbolCode == Symbol.Code && x.TradeType == tradeType && x.Label != presentLabel); foreach (var pe in pes) { cancelPedingList.Add(pe.Label); CancelPendingOrderAsync(pe, CancelPendingCallback); } int countWait = 0; while (cancelPedingList.Count > 0 && isWait && countWait < 10) { Print("รอกำลังยกเลิก pending ขา>>" + tradeType + " เหลือ>>" + cancelPedingList.Count); System.Threading.Thread.Sleep(1000); } Print("ครบ10วินาที pending ขา>>" + tradeType + " เหลือ>>" + cancelPedingList.Count); cancelPedingList = new List <string>(); }
private void Positions_Opened(PositionOpenedEventArgs obj) { var pos = obj.Position; if (pos.TradeType == TradeType.Sell && pos.Label == (Sell + SymbolName)) { var buyOrder = PendingOrders.Where(x => x.Label == (Buy + SymbolName)).FirstOrDefault(); if (buyOrder != null) { var rc = CancelPendingOrder(buyOrder); if (!rc.IsSuccessful) { Print("Cancel Penidng Order Failed: " + rc.Error.Value); } } Log.WriteRpt(Server.Time, pos.Label, TradeType.Sell.ToString(), "Open", pos.EntryPrice.ToString(), pos.StopLoss.HasValue ? ((double)pos.StopLoss).ToString() : "", pos.TakeProfit.HasValue ? ((double)pos.TakeProfit).ToString() : "", pos.VolumeInUnits.ToString(), Account.Balance.ToString(), pos.Pips.ToString(), high.ToString(), low.ToString(), ""); } else if (pos.TradeType == TradeType.Buy && pos.Label == (Buy + SymbolName)) { var sellOrder = PendingOrders.Where(x => x.Label == (Sell + SymbolName)).FirstOrDefault(); if (sellOrder != null) { var rc = CancelPendingOrder(sellOrder); if (!rc.IsSuccessful) { Print("Cancel Penidng Order Failed: " + rc.Error.Value); } } Log.WriteRpt(Server.Time, pos.Label, TradeType.Buy.ToString(), "Open", pos.EntryPrice.ToString(), pos.StopLoss.HasValue ? ((double)pos.StopLoss).ToString() : "", pos.TakeProfit.HasValue ? ((double)pos.TakeProfit).ToString() : "", pos.VolumeInUnits.ToString(), Account.Balance.ToString(), pos.Pips.ToString(), high.ToString(), low.ToString(), ""); } }
/// <summary> /// Cancels a specific order by order id. /// </summary> /// <param name="orderid">The orderid.</param> public void CancelOrder(long orderid) => PendingOrders.Where(x => x.OrderId == orderid).Cancel();
/// <summary> /// Cancel all open orders related to the specified security. /// </summary> /// <param name="security">The security.</param> public void CancelOpenOrders(Security security) => PendingOrders.Where(x => x.Security == security).Cancel();