private void ShowLimitConfigWindow() { LimitConfigViewModel limitVM = new LimitConfigViewModel(StartPoint, EndPoint, LimitLineSeries, CurrentLoadedSymbol, CurrentMinTradeSize); LimitCondig lc = new LimitCondig(limitVM); lc.ShowDialog(); if (limitVM.LineOrder != null) { ActiveLineOrders.Insert(0, limitVM.LineOrder); OverrideAddingUpcoming(); LimitLineSeries = limitVM.LineOrder.LimitLineSeries; plotmodel.InvalidatePlot(true); OnPropertyChanged("ActiveLineOrders"); } else { if (plotmodel.Series.Any(l => l.Title == "Limit Line")) { var match = plotmodel.Series.First(l => l.Title == "Limit Line"); plotmodel.Series.Remove(LimitLineSeries); } LimitLineSeries = null; } }
private void CancelLineOrder() { var orderToRemove = (LineOrder)activeordersLB.SelectedItem; RemoveLimitLine(); ActiveLineOrders.Remove(orderToRemove); if (UpcomingOrders.FirstOrDefault(l => l.Order.LimitLineSeries == orderToRemove.LimitLineSeries) != null) { UpcomingOrders.Remove(UpcomingOrders.FirstOrDefault(l => l.Order.LimitLineSeries == orderToRemove.LimitLineSeries)); OnPropertyChanged("UpcomingOrders"); } OnPropertyChanged("ActiveLineOrders"); }
public void MakeOrder(LineOrder order) { DateTime currenttime; decimal currentlimitprice; WebCallResult <BittrexOrderV3> linePointOrder; currenttime = DateTime.Now; var limit = CalculateLimitAtSpecificTime(DateTimeAxis.ToDouble(currenttime), order); //cancel the previous order if needed if (order.TimeInForce == TimeInForce.GoodTillCancelled) { if (order.LastPlacedOrderId != null)//cancel previous open order { var or = client.GetOrder(order.LastPlacedOrderId); if (or.Error == null) { if (or.Data.Status == OrderStatus.Closed) { order.ActiveTotal += double.Parse(or.Data.Proceeds.ToString()); //increase the active total for this order based on the previous orders proceeds if (order.ActiveTotal > order.FulfilmentThreshold) { FulfilledOrders.Add(order); ActiveLineOrders.Remove(order); ActionHistory += DateTime.Now.TimeOfDay.ToString() + " - " + (order.OrderSide == OrderSide.Buy ? "Buy Line" : "Sell Line") + order.Symbol + " Fulfilled" + "\n"; } else { ActiveLineOrders.Add(order); } } } //cancel order var res = client.CancelConditionalOrder(order.LastPlacedOrderId); if (res.Error != null) { Application.Current.Dispatcher.Invoke(() => { ActionHistory += DateTime.Now.TimeOfDay.ToString() + " - " + "Error: " + " Failed to Cancel Order" + res.Error.Message + "\n"; }); } else { Application.Current.Dispatcher.Invoke(() => { ActionHistory += DateTime.Now.TimeOfDay.ToString() + " - " + "Order Cancelled: ID = " + order.LastPlacedOrderId + "\n"; }); } } } if (limit != 0) { currentlimitprice = Convert.ToDecimal(limit); currentlimitprice = Convert.ToDecimal(currentlimitprice.ToString("F5")); //place order linePointOrder = client.PlaceOrder(CurrentLoadedSymbol, order.OrderSide, order.OrderType, order.TimeInForce, order.QuantityPerOrder, currentlimitprice); if (linePointOrder.Error != null) {//error occured, log it Application.Current.Dispatcher.Invoke(() => { ActionHistory += DateTime.Now.TimeOfDay.ToString() + " - " + "Error: " + linePointOrder.Error.Message + "\n"; }); } else { order.OrderIDs.Add(linePointOrder.Data.Id); order.LastPlacedOrderId = linePointOrder.Data.Id; if (linePointOrder.Data.Status == OrderStatus.Closed) { order.ActiveTotal += double.Parse(linePointOrder.Data.Proceeds.ToString()); //increase the active total for this order based on the previous orders proceeds } //log the order Application.Current.Dispatcher.Invoke(() => { ActionHistory += DateTime.Now.TimeOfDay.ToString() + " - " + (order.OrderSide == OrderSide.Buy ? "Buy" : "Sell") + order.Symbol + " at $" + currentlimitprice + "\n"; //new Popup("Order Placed", order.Symbol + " at $" + currentlimitprice).Show(); if (order.ActiveTotal > order.FulfilmentThreshold) { FulfilledOrders.Add(order); ActiveLineOrders.Remove(order); ActionHistory += DateTime.Now.TimeOfDay.ToString() + " - " + (order.OrderSide == OrderSide.Buy ? "Buy Line" : "Sell Line") + order.Symbol + " Fulfilled" + "\n"; } else { ActiveLineOrders.Add(order); } }); } } else { Application.Current.Dispatcher.Invoke(() => { ActionHistory += DateTime.Now.TimeOfDay.ToString() + " - " + "Limit price could not be calculated" + "\n"; }); OnPropertyChanged("FulfilledOrders"); Thread.Sleep(10000); //keep running every 10 seconds } }