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 } }