private List <DirectOrder> CreateModifyBuyOrdersList() { List <DirectOrder> buyOrders = new List <DirectOrder>(); buyingGrid.Invoke((MethodInvoker) delegate { foreach (DataGridViewRow row in buyingGrid.Rows) { try { if (Convert.ToBoolean(row.Cells["Buying_Select"].Value) == true) { long orderId = (long)row.Cells["Buying_OrderId"].Value; DirectOrder order = Cache.Instance.MyBuyOrders.FirstOrDefault(o => o.OrderId == orderId); if (order != null) { buyOrders.Add(order); Logging.Log("OmniEveUI:CreateModifyBuyOrdersList", "Adding buy order to list of orders that need to be modified OrderId - " + orderId, Logging.Debug); } } } catch (Exception ex) { Logging.Log("OmniEveUI:ModifyBuyOrders", "Exception [" + ex + "]", Logging.Debug); } } }); return(buyOrders); }
public void UpdateSellOrder(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); if (lowestSellOrder != null && lowestSellOrder.Price <= order.Price && lowestSellOrder.OrderId != order.OrderId) { double priceDifference = order.Price - lowestSellOrder.Price; double priceDifferencePct = priceDifference / order.Price; double price = double.Parse((decimal.Parse(lowestSellOrder.Price.ToString()) - 0.01m).ToString()); bool UpdateOrder = false; if (priceDifferencePct < 0.05 && priceDifference < 5000000) { UpdateOrder = true; } else if (highestBuyOrder != null && lowestSellOrder.Price / highestBuyOrder.Price >= 1.5 && priceDifferencePct < 0.25) { UpdateOrder = true; } if (UpdateOrder == true) { Logging.Log("UpdateOrder:UpdateSellOrder", "Modifying order for Order Id - " + order.OrderId + " Price - " + price, Logging.White); bool success = order.ModifyOrder(price); } } }
private void OnCheckMyOrdersAgainstItemHangerFinished(List <DirectOrder> sellOrders, List <DirectOrder> buyOrders) { itemHangerGrid.Invoke((MethodInvoker) delegate { int orderCap = Cache.Instance.DirectEve.GetOrderCap(); int maxSellOrders = (int)((decimal)orderCap * 0.66m); int newSellOrders = 0; foreach (DataGridViewRow row in itemHangerGrid.Rows) { int typeId = (int)row.Cells["ItemHanger_TypeId"].Value; DirectOrder order = sellOrders.FirstOrDefault(o => o.TypeId == typeId); if (order == null) { newSellOrders++; row.DefaultCellStyle.BackColor = Color.LightGreen; row.DefaultCellStyle.ForeColor = Color.Black; if (sellOrders.Count + newSellOrders <= maxSellOrders && buyOrders.Count + sellOrders.Count + newSellOrders <= orderCap) { row.Cells["ItemHanger_Select"].Value = true; } } } }); //CheckState(); }
private void OnCheckMyOrdersAgainstMarketFinished(List <DirectOrder> mySellOrders, List <DirectOrder> myBuyOrders) { int orderCap = Cache.Instance.DirectEve.GetOrderCap(); Logging.Log("OmniEveUI:OnCheckMyOrdersAgainstMarketFinished", "Buy Order Count - " + myBuyOrders.Count + " Sell Order Count - " + mySellOrders.Count + " Order Cap - " + orderCap, Logging.White); int maxBuyOrders = (int)((decimal)orderCap * 0.66m); int newBuyOrders = 0; marketGrid.Invoke((MethodInvoker) delegate { foreach (DataGridViewRow row in marketGrid.Rows) { int typeId = (int)row.Cells["Market_TypeId"].Value; DirectOrder order = myBuyOrders.FirstOrDefault(o => o.TypeId == typeId); if (order == null) { newBuyOrders++; row.DefaultCellStyle.BackColor = Color.LightGreen; row.DefaultCellStyle.ForeColor = Color.Black; if (myBuyOrders.Count + newBuyOrders <= maxBuyOrders && myBuyOrders.Count + mySellOrders.Count + newBuyOrders <= (orderCap - 5)) { row.Cells["Market_Select"].Value = true; } } } }); //CheckState(); }
private void OnMarketInfoFinished(MarketItem marketItem) { List <DirectOrder> sellOrders = marketItem.SellOrders.Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId).OrderBy(o => o.Price).ToList(); List <DirectOrder> buyOrders = marketItem.BuyOrders.Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId).OrderByDescending(o => o.Price).ToList(); DirectOrder sellOrder = sellOrders.FirstOrDefault(); DirectOrder buyOrder = buyOrders.FirstOrDefault(); sellingGrid.Invoke((MethodInvoker) delegate { UpdateMySellOrdersGrid_LowestMarketOrder(marketItem.TypeId, sellOrder); }); buyingGrid.Invoke((MethodInvoker) delegate { UpdateMyBuyOrdersGrid_HighestMarketOrder(marketItem.TypeId, buyOrder); }); //CheckState(); }
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); } } }
private void UpdateMyBuyOrdersGrid_HighestMarketOrder(int typeId, DirectOrder buyOrder) { if (buyOrder != null) { foreach (DataGridViewRow row in buyingGrid.Rows) { if (int.Parse(row.Cells["Buying_TypeId"].Value.ToString()) == typeId) { Logging.Log("OmniEveUI:UpdateMarketInfoBuyOrder", "Row has been found, adding market info to row", Logging.White); long orderId = (long)row.Cells["Buying_OrderId"].Value; string orderPriceStr = (string)row.Cells["Buying_OrderPrice"].Value; string marketPriceStr = buyOrder.Price.ToString(); row.Cells["Buying_MarketPrice"].Value = marketPriceStr; double orderPrice = double.Parse(orderPriceStr); if (orderPrice < buyOrder.Price) { double priceDifference = buyOrder.Price - orderPrice; double priceDifferencePct = priceDifference / orderPrice; if (priceDifferencePct < 0.05 && priceDifference < 5000000) { row.Cells["Buying_Select"].Value = true; row.DefaultCellStyle.BackColor = Color.Red; row.DefaultCellStyle.ForeColor = Color.Black; } else { row.DefaultCellStyle.BackColor = Color.Yellow; row.DefaultCellStyle.ForeColor = Color.Black; } } } } } }
/// <summary> /// Check if we have kernite in station /// </summary> /// <returns></returns> public StorylineState PreAcceptMission(Storyline storyline) { DirectEve directEve = Cache.Instance.DirectEve; if (_nextAction > DateTime.UtcNow) { return(StorylineState.PreAcceptMission); } // the ore and ore quantity can be stored in the characters settings xml this is to facility mission levels other than 4. //The defaults are for level 4 so it will not break for those people that do not include these in their settings file // Level 1 <MaterialsForWarOreID>1230</MaterialsForWarOreID> // <MaterialsForWarOreQty>999</MaterialsForWarOreQty> // Level 4 <MaterialsForWarOreID>20</MaterialsForWarOreID> // <MaterialsForWarOreQty>8000</MaterialsForWarOreQty> int oreid = Settings.Instance.MaterialsForWarOreID; //1230; int orequantity = Settings.Instance.MaterialsForWarOreQty; //999 // Open the item hangar if (Cache.Instance.ItemHangar == null) { return(StorylineState.PreAcceptMission); } //if (Cache.Instance.ItemHangar.Window == null) //{ // Logging.Log("MaterialsForWar", "PreAcceptMission: ItemHangar is null", Logging.Orange); // if (!Cache.Instance.ReadyItemsHangar("MaterialsForWarPreparation")) return StorylineState.PreAcceptMission; // return StorylineState.PreAcceptMission; //} // Is there a market window? DirectMarketWindow marketWindow = directEve.Windows.OfType <DirectMarketWindow>().FirstOrDefault(); // Do we have the ore we need in the Item Hangar?. if (Cache.Instance.ItemHangar.Items.Where(i => i.TypeId == oreid).Sum(i => i.Quantity) >= orequantity) { DirectItem thisOreInhangar = Cache.Instance.ItemHangar.Items.FirstOrDefault(i => i.TypeId == oreid); if (thisOreInhangar != null) { Logging.Log("MaterialsForWarPreparation", "We have [" + Cache.Instance.ItemHangar.Items.Where(i => i.TypeId == oreid).Sum(i => i.Quantity).ToString(CultureInfo.InvariantCulture) + "] " + thisOreInhangar.TypeName + " in the item hangar accepting mission", Logging.White); } // Close the market window if there is one if (marketWindow != null) { marketWindow.Close(); } return(StorylineState.AcceptMission); } if (Cache.Instance.CurrentShipsCargo == null) { return(StorylineState.PreAcceptMission); } if (Cache.Instance.CurrentShipsCargo.Items.Where(i => i.TypeId == oreid).Sum(i => i.Quantity) >= orequantity) { DirectItem thisOreInhangar = Cache.Instance.CurrentShipsCargo.Items.FirstOrDefault(i => i.TypeId == oreid); if (thisOreInhangar != null) { Logging.Log("MaterialsForWarPreparation", "We have [" + Cache.Instance.CurrentShipsCargo.Items.Where(i => i.TypeId == oreid).Sum(i => i.Quantity).ToString(CultureInfo.InvariantCulture) + "] " + thisOreInhangar.TypeName + " in the CargoHold accepting mission", Logging.White); } // Close the market window if there is one if (marketWindow != null) { marketWindow.Close(); } return(StorylineState.AcceptMission); } if (Cache.Instance.DirectEve.HasSupportInstances()) { // We do not have enough ore, open the market window if (marketWindow == null) { _nextAction = DateTime.UtcNow.AddSeconds(10); Logging.Log("MaterialsForWarPreparation", "Opening market window", Logging.White); directEve.ExecuteCommand(DirectCmd.OpenMarket); return(StorylineState.PreAcceptMission); } // Wait for the window to become ready (this includes loading the ore info) if (!marketWindow.IsReady) { return(StorylineState.PreAcceptMission); } // Are we currently viewing ore orders? if (marketWindow.DetailTypeId != oreid) { // No, load the ore orders marketWindow.LoadTypeId(oreid); Logging.Log("MaterialsForWarPreparation", "Loading market window", Logging.White); _nextAction = DateTime.UtcNow.AddSeconds(5); return(StorylineState.PreAcceptMission); } // Get the median sell price InvType type = Cache.Instance.InvTypesById[20]; double? maxPrice = type.MedianSell * 4; // Do we have orders that sell enough ore for the mission? IEnumerable <DirectOrder> orders = marketWindow.SellOrders.Where(o => o.StationId == directEve.Session.StationId && o.Price < maxPrice).ToList(); if (!orders.Any() || orders.Sum(o => o.VolumeRemaining) < orequantity) { Logging.Log("MaterialsForWarPreparation", "Not enough (reasonably priced) ore available! Blacklisting agent for this Questor session!", Logging.Orange); // Close the market window marketWindow.Close(); // No, black list the agent in this Questor session (note we will never decline storylines!) return(StorylineState.BlacklistAgent); } // How much ore do we still need? int neededQuantity = orequantity - Cache.Instance.ItemHangar.Items.Where(i => i.TypeId == oreid).Sum(i => i.Quantity); if (neededQuantity > 0) { // Get the first order DirectOrder order = orders.OrderBy(o => o.Price).FirstOrDefault(); if (order != null) { // Calculate how much ore we still need int remaining = Math.Min(neededQuantity, order.VolumeRemaining); order.Buy(remaining, DirectOrderRange.Station); Logging.Log("MaterialsForWarPreparation", "Buying [" + remaining + "] ore", Logging.White); // Wait for the order to go through _nextAction = DateTime.UtcNow.AddSeconds(10); } } return(StorylineState.PreAcceptMission); } Logging.Log("MaterialsForWarPreparation", "No DirectEVE Instances Available: free version detected. Buy/Sell support not available. Blacklisting agent for this Questor session!", Logging.Orange); // Close the market window if (marketWindow != null) { marketWindow.Close(); } // No, black list the agent in this Questor session (note we will never decline storylines!) return(StorylineState.BlacklistAgent); }
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 (OnUpdateOrderFinished != null) { OnUpdateOrderFinished(OrderId); } break; case State.Begin: // Don't close the market window if its already up if (marketWindow != null) { Logging.Log("UpdateOrder: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("UpdateOrder:Process", "Opening Market", Logging.White); break; } if (!marketWindow.IsReady) { break; } _state = State.LoadOrders; break; case State.LoadOrders: if (marketWindow != null) { if (!marketWindow.IsReady) { break; } Logging.Log("UpdateOrder:Process", "Load orders", Logging.White); if (marketWindow.LoadOrders() == true) { _state = State.MarketInfo; } break; } else { Logging.Log("UpdateOrder:Process", "MarketWindow is not open, going back to open market state", Logging.White); _state = State.OpenMarket; } break; case State.MarketInfo: if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 1) { break; } _lastAction = DateTime.UtcNow; if (marketWindow != null) { if (!marketWindow.IsReady) { break; } List <DirectOrder> orders = marketWindow.GetMyOrders(IsBid).ToList(); if (orders == null) { Logging.Log("UpdateOrder:Process", "Something is wrong, order list is empty, ending update order action", Logging.White); _state = State.Done; } DirectOrder order = orders.FirstOrDefault(o => o.OrderId == OrderId); if (order == null) { Logging.Log("UpdateOrder:Process", "Order doesn't exist, ending update order action OrderId - " + OrderId, Logging.White); _state = State.Done; break; } Logging.Log("UpdateOrder:Process", "Load orders for TypeId - " + order.TypeId.ToString(), Logging.White); if (marketWindow.DetailTypeId != order.TypeId) { if (marketWindow.LoadTypeId(order.TypeId) == true) { _state = State.Update; } } else { _state = State.Update; } break; } else { Logging.Log("MarketItemInfo:Process", "MarketWindow is not open, going back to open market state", Logging.White); _state = State.OpenMarket; } break; case State.Update: // 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 < 1) { break; } if (marketWindow != null) { if (!marketWindow.IsReady) { break; } try { _lastAction = DateTime.UtcNow; List <DirectOrder> orders = marketWindow.GetMyOrders(IsBid).ToList(); DirectOrder order = orders.FirstOrDefault(o => o.OrderId == OrderId); if (order != null) { Logging.Log("UpdateOrder:Process", "Loaded order, OrderId - " + order.OrderId + " OrderPrice - " + order.Price, Logging.White); if (IsBid) { UpdateBuyOrder(order, marketWindow.SellOrders, marketWindow.BuyOrders); } else { UpdateSellOrder(order, marketWindow.SellOrders, marketWindow.BuyOrders); } } else { Logging.Log("UpdateOrder:Process", "Order no longer exists, exiting modify action", Logging.White); } } catch (Exception ex) { Logging.Log("UpdateOrder:Process", "Exception [" + ex + "] - Ending modify order script", Logging.Debug); } _state = State.Done; } else { _state = State.OpenMarket; } break; } }
public void ProcessState() { if (!Cache.Instance.InStation) { return; } if (Cache.Instance.InSpace) { return; } if (DateTime.UtcNow < Cache.Instance.LastInSpace.AddSeconds(20)) // we wait 20 seconds after we last thought we were in space before trying to do anything in station { return; } DirectMarketWindow marketWindow = Cache.Instance.Windows.OfType <DirectMarketWindow>().FirstOrDefault(); switch (_States.CurrentBuyState) { case BuyState.Idle: case BuyState.Done: break; case BuyState.Begin: // Close the market window if there is one if (marketWindow != null) { marketWindow.Close(); } _States.CurrentBuyState = BuyState.OpenMarket; break; case BuyState.OpenMarket: // Close the market window if there is one //if (marketWindow != null) // marketWindow.Close(); if (marketWindow == null) { Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket); break; } if (!marketWindow.IsReady) { break; } Logging.Log("Buy", "Opening Market", Logging.White); _States.CurrentBuyState = BuyState.LoadItem; break; case BuyState.LoadItem: _lastAction = DateTime.UtcNow; if (marketWindow != null && marketWindow.DetailTypeId != Item) { marketWindow.LoadTypeId(Item); if (useOrders) { _States.CurrentBuyState = BuyState.CreateOrder; } else { _States.CurrentBuyState = BuyState.BuyItem; } break; } break; case BuyState.CreateOrder: if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 5) { break; } _lastAction = DateTime.UtcNow; if (marketWindow != null) { IEnumerable <DirectOrder> orders = marketWindow.BuyOrders.Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId); DirectOrder order = orders.OrderByDescending(o => o.Price).FirstOrDefault(); if (order != null) { double price = order.Price + 0.01; if (Cache.Instance.DirectEve.Session.StationId != null) { Cache.Instance.DirectEve.Buy((int)Cache.Instance.DirectEve.Session.StationId, Item, price, Unit, DirectOrderRange.Station, 1, 30); } } useOrders = false; _States.CurrentBuyState = BuyState.Done; } break; case BuyState.BuyItem: if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 5) { break; } if (marketWindow != null) { IEnumerable <DirectOrder> orders = marketWindow.SellOrders.Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId); DirectOrder order = orders.OrderBy(o => o.Price).FirstOrDefault(); if (order != null) { // Calculate how much we still need if (order.VolumeEntered >= Unit) { order.Buy(Unit, DirectOrderRange.Station); _States.CurrentBuyState = BuyState.WaitForItems; } else { order.Buy(Unit, DirectOrderRange.Station); Unit = Unit - order.VolumeEntered; Logging.Log("Buy", "Missing " + Convert.ToString(Unit) + " units", Logging.White); _returnBuy = true; _States.CurrentBuyState = BuyState.WaitForItems; } } } break; case BuyState.WaitForItems: // Wait 5 seconds after moving if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 5) { break; } // Close the market window if there is one if (marketWindow != null) { marketWindow.Close(); } if (_returnBuy) { Logging.Log("Buy", "Return Buy", Logging.White); _returnBuy = false; _States.CurrentBuyState = BuyState.OpenMarket; break; } Logging.Log("Buy", "Done", Logging.White); _States.CurrentBuyState = BuyState.Done; break; } }
public void Process() { if (!Status.Instance.InStation) { return; } if (Status.Instance.InSpace) { return; } DirectMarketWindow marketWindow = Cache.Instance.DirectEve.Windows.OfType <DirectMarketWindow>().FirstOrDefault(); DirectSellMultiWindow sellWindow = Cache.Instance.DirectEve.Windows.OfType <DirectSellMultiWindow>().FirstOrDefault(); switch (_state) { case State.Idle: break; case State.Done: _done = true; if (OnSellItemFinished != null) { OnSellItemFinished(_item, _sold); } break; case State.Begin: // Close the market window if there is one if (marketWindow != null) { marketWindow.Close(); } _state = State.OpenMarket; break; case State.OpenMarket: if (marketWindow == null) { _lastAction = DateTime.UtcNow; Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket); break; } if (!marketWindow.IsReady) { Logging.Log("SellItem:Process", "Market window is not ready", Logging.White); break; } Logging.Log("SellItem:Process", "Opening Market", Logging.White); _state = State.LoadItem; break; case State.LoadItem: if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2) { break; } _lastAction = DateTime.UtcNow; if (marketWindow != null) { Logging.Log("SellItem:Process", "Load orders for TypeId - " + _item.TypeId.ToString(), Logging.White); if (marketWindow.DetailTypeId != _item.TypeId) { if (marketWindow.LoadTypeId(_item.TypeId)) { _state = State.GetPrice; } } break; } else { Logging.Log("SellItem:Process", "MarketWindow is not open, going back to open market state", Logging.White); _state = State.OpenMarket; } break; case State.GetPrice: if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2) { break; } _lastAction = DateTime.UtcNow; if (marketWindow != null) { if (!marketWindow.IsReady) { Logging.Log("SellItem:Process", "Market window is not ready", Logging.White); break; } if (marketWindow.DetailTypeId != _item.TypeId) { _state = State.LoadItem; break; } List <DirectOrder> sellOrders = marketWindow.SellOrders.OrderBy(o => o.Price).Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId).ToList(); List <DirectOrder> buyOrders = marketWindow.BuyOrders.OrderByDescending(o => o.Price).Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId).ToList(); DirectOrder firstSellOrder = sellOrders.FirstOrDefault(); DirectOrder firstBuyOrder = buyOrders.FirstOrDefault(); if (firstSellOrder != null) { sellOrders.Remove(firstSellOrder); DirectOrder secondSellOrder = sellOrders.FirstOrDefault(); if (secondSellOrder != null) { decimal priceDifference = decimal.Parse(secondSellOrder.Price.ToString()) - decimal.Parse(firstSellOrder.Price.ToString()); decimal priceDifferencePct = priceDifference / decimal.Parse(firstSellOrder.Price.ToString()); if (priceDifferencePct > 0.05m || priceDifference > 5000000) { // Check if the first buy order is close enough to the sell order that we no longer want to sell, otherwise the jump between the two sell orders doesn't matter. // If there is no first buy order then create the order anyway if (firstBuyOrder != null && firstSellOrder.Price / firstBuyOrder.Price < 1.5) { Logging.Log("SellItem:Process", "No sale, price difference between the first two orders is too high Pct - " + priceDifferencePct + " Diff - " + priceDifference, Logging.White); _state = State.Done; break; } } } _price = double.Parse((decimal.Parse(firstSellOrder.Price.ToString()) - 0.01m).ToString()); _state = State.OpenSellWindow; Logging.Log("SellItem:Process", "Lowest sell price, Name - " + _item.Name + " Price - " + _price, Logging.White); } else { Logging.Log("SellItem:Process", "No current sell orders, can't create lowest order for Name - " + _item.Name, Logging.White); _state = State.Done; } } else { Logging.Log("SellItem:Process", "MarketWindow is not open, going back to open market state", Logging.White); _state = State.OpenMarket; } break; case State.OpenSellWindow: _sellWindowNotReadyCount = 0; if (Cache.Instance.DirectEve.OpenSellItems(_item) == true) { Logging.Log("SellItem:Process", "Opening sell window for Name - " + _item.Name, Logging.White); if (_createOrder) { _state = State.SetPrice; } else { _state = State.SellItem; } } else { Logging.Log("SellItem:Process", "Failed to open sell window for Name - " + _item.Name, Logging.White); _state = State.Done; } break; case State.SetPrice: if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 1) { break; } _lastAction = DateTime.UtcNow; if (sellWindow != null) { if (!sellWindow.IsReady) { _sellWindowNotReadyCount++; Logging.Log("SellItem:Process", "Sell window is not ready", Logging.White); if (_sellWindowNotReadyCount >= 5) { Logging.Log("SellItem:Process", "Something is wrong trying to sell this item, quitting the sell", Logging.White); _state = State.Done; } break; } sellWindow.SetPrice(_item.ItemId, _price); Logging.Log("SellItem:Process", "Sell window setting price to " + _price, Logging.White); _state = State.SellItem; } else { Logging.Log("SellItem:Process", "Sell Window is not open going back to open sell window state", Logging.White); _state = State.OpenSellWindow; } break; case State.SellItem: if (sellWindow != null) { if (!sellWindow.IsReady) { _sellWindowNotReadyCount++; Logging.Log("SellItem:Process", "Sell window is not ready", Logging.White); if (_sellWindowNotReadyCount >= 5) { _state = State.OpenSellWindow; } break; } sellWindow.SellItems(); Logging.Log("SellItem:Process", "Selling item Name - " + _item.Name, Logging.White); _sold = true; _state = State.Done; } else { Logging.Log("SellItem:Process", "Sell Window is not open going back to open sell window state", Logging.White); _state = State.OpenSellWindow; } break; } }
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 (OnBuyItemFinished != null) { OnBuyItemFinished(_typeId, _createOrder); } break; case State.Begin: // Close the market window if there is one if (marketWindow != null) { marketWindow.Close(); } _state = State.OpenMarket; break; case State.OpenMarket: if (marketWindow == null) { _lastAction = DateTime.UtcNow; Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket); break; } if (!marketWindow.IsReady) { Logging.Log("BuyItem:Process", "Market window is not ready", Logging.White); break; } Logging.Log("BuyItem:Process", "Opening Market", Logging.White); _state = State.LoadItem; break; case State.LoadItem: if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2) { break; } _lastAction = DateTime.UtcNow; if (marketWindow != null) { Logging.Log("BuyItem:Process", "Load orders for TypeId - " + _typeId.ToString(), Logging.White); if (marketWindow.DetailTypeId != _typeId) { if (marketWindow.LoadTypeId(_typeId)) { if (_createOrder == true) { _state = State.CreateOrder; } else { _state = State.BuyItem; } } } break; } else { Logging.Log("BuyItem:Process", "Market Window is not open, going back to open market state", Logging.White); _state = State.OpenMarket; } break; case State.CreateOrder: if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 5) { break; } _lastAction = DateTime.UtcNow; if (marketWindow != null) { if (!marketWindow.IsReady) { Logging.Log("BuyItem:Process", "Market window is not ready", Logging.White); break; } if (marketWindow.DetailTypeId != _typeId) { _state = State.LoadItem; break; } List <DirectOrder> buyOrders = marketWindow.BuyOrders.Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId).ToList(); List <DirectOrder> sellOrders = marketWindow.SellOrders.Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId).ToList(); DirectOrder highestBuyOrder = buyOrders.OrderByDescending(o => o.Price).FirstOrDefault(); DirectOrder lowestSellOrder = sellOrders.OrderBy(o => o.Price).FirstOrDefault(); if (highestBuyOrder != null) { bool createBuyOrder = (lowestSellOrder == null); if (lowestSellOrder != null) { double profit = lowestSellOrder.Price - highestBuyOrder.Price; double tax = lowestSellOrder.Price * .01 + highestBuyOrder.Price * 0.015; double profitPct = lowestSellOrder.Price / highestBuyOrder.Price; if ((profit < 10000000 && profitPct > 1.50) || (profit >= 10000000 && tax < profit * 0.25)) { createBuyOrder = true; } } if (createBuyOrder == true) { double price = double.Parse((decimal.Parse(highestBuyOrder.Price.ToString()) + 0.01m).ToString()); if (Cache.Instance.DirectEve.Session.StationId != null) { Cache.Instance.DirectEve.Buy((int)Cache.Instance.DirectEve.Session.StationId, _typeId, price, _volume, DirectOrderRange.Station, 1, 90); } } } _state = State.Done; } break; case State.BuyItem: if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 5) { break; } if (marketWindow != null) { if (!marketWindow.IsReady) { Logging.Log("BuyItem:Process", "Market window is not ready", Logging.White); break; } if (marketWindow.DetailTypeId != _typeId) { _state = State.LoadItem; break; } List <DirectOrder> orders = marketWindow.SellOrders.Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId).ToList(); DirectOrder order = orders.OrderBy(o => o.Price).FirstOrDefault(); if (order != null) { // Calculate how much we still need if (order.VolumeEntered >= _volume) { order.Buy(_volume, DirectOrderRange.Station); _state = State.WaitForItems; } else { order.Buy(_volume, DirectOrderRange.Station); _volume = _volume - order.VolumeEntered; Logging.Log("BuyItem:Process", "Missing " + Convert.ToString(_volume) + " units", Logging.White); _returnBuy = true; _state = State.WaitForItems; } } } break; case State.WaitForItems: // Wait 5 seconds after moving if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 5) { break; } // Close the market window if there is one if (marketWindow != null) { marketWindow.Close(); } if (_returnBuy) { Logging.Log("BuyItem:Process", "Return Buy", Logging.White); _returnBuy = false; _state = State.OpenMarket; break; } Logging.Log("BuyItem:Process", "Done", Logging.White); _state = State.Done; break; } }