public void UpdateBuyOrder(DirectOrder order, List <DirectOrder> sellOrders, List <DirectOrder> buyOrders) { if (order == null) { return; } DirectOrder highestBuyOrder = buyOrders.OrderByDescending(o => o.Price).FirstOrDefault(o => o.StationId == order.StationId); DirectOrder lowestSellOrder = sellOrders.OrderBy(o => o.Price).FirstOrDefault(o => o.StationId == order.StationId); double profit = lowestSellOrder.Price - highestBuyOrder.Price; double tax = lowestSellOrder.Price * .01 + highestBuyOrder.Price * 0.015; double profitPct = lowestSellOrder.Price / highestBuyOrder.Price; if (highestBuyOrder != null && lowestSellOrder != null && ((profit < 10000000 && profitPct < 1.25) || (profit >= 10000000 && tax > profit * 0.5))) { Logging.Log("UpdateAllOrders:Process", "Canceling order for Order Id - " + order.OrderId, Logging.White); order.CancelOrder(); } // Don't modify if there isn't a lowest order and don't modify if the lowest order is our own else if (highestBuyOrder != null && highestBuyOrder.OrderId != order.OrderId && highestBuyOrder.Price >= order.Price) { double priceDifference = highestBuyOrder.Price - order.Price; double priceDifferencePct = priceDifference / order.Price; double price = double.Parse((decimal.Parse(highestBuyOrder.Price.ToString()) + 0.01m).ToString()); bool createUpdateOrder = false; if (priceDifferencePct < 0.05 && priceDifference < 5000000) { createUpdateOrder = true; } else if (lowestSellOrder != null && lowestSellOrder.Price / highestBuyOrder.Price >= 1.5 && priceDifferencePct < 0.25) { createUpdateOrder = true; } if (createUpdateOrder == true) { Logging.Log("UpdateAllOrders:Process", "Modifying order for Order Id - " + order.OrderId + " Price - " + price, Logging.White); bool success = order.ModifyOrder(price); } } }
public void Process() { if (!Status.Instance.InStation) { return; } if (Status.Instance.InSpace) { return; } DirectMarketWindow marketWindow = Cache.Instance.DirectEve.Windows.OfType <DirectMarketWindow>().FirstOrDefault(); switch (_state) { case State.Idle: break; case State.Done: _done = true; if (OnCancelOrderFinished != null) { OnCancelOrderFinished(OrderId); } break; case State.Begin: // Don't close the market window if its already up if (marketWindow != null) { Logging.Log("CancelOrder:Process", "Market already open no need to open the market", Logging.White); } _state = State.OpenMarket; break; case State.OpenMarket: if (marketWindow == null) { Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket); Logging.Log("CancelOrder:Process", "Opening Market", Logging.White); break; } if (!marketWindow.IsReady) { break; } _state = State.LoadOrders; break; case State.LoadOrders: if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2) { break; } _lastAction = DateTime.UtcNow; if (marketWindow != null) { Logging.Log("CancelOrder:Process", "Load orders", Logging.White); if (marketWindow.LoadOrders() == true) { _state = State.Cancel; } break; } else { Logging.Log("CancelOrder:Process", "MarketWindow is not open, going back to open market state", Logging.White); _state = State.OpenMarket; } break; case State.Cancel: // We keep getting the popup saying we can't modify many orders in a minute, so this needs to be at 6 or higher, probably higher if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2) { break; } if (marketWindow != null) { try { _lastAction = DateTime.UtcNow; List <DirectOrder> orders = marketWindow.GetMyOrders(IsBid).ToList(); DirectOrder order = orders.FirstOrDefault(o => o.OrderId == OrderId); if (order != null) { Logging.Log("CancelOrder:Process", "Loaded order, OrderId - " + order.OrderId, Logging.White); bool success = order.CancelOrder(); if (success) { Logging.Log("CancelOrder:Process", "Canceling order successful", Logging.White); } else { Logging.Log("CancelOrder:Process", "Canceling order failure", Logging.White); } } else { Logging.Log("CancelOrder:Process", "Order no longer exists, exiting modify action", Logging.White); } } catch (Exception ex) { Logging.Log("CancelOrder:Process", "Exception [" + ex + "] - Ending modify order script", Logging.Debug); } _state = State.Done; } else { _state = State.OpenMarket; } break; } }