示例#1
0
        public static bool Inspectorder(string module, bool sell, bool refine, bool undersell, double RefiningEff)
        {
            // Let the order window stay open for a few seconds
            if (DateTime.UtcNow.Subtract(_lastExecute).TotalSeconds < Time.Instance.Marketbuyorderdelay_seconds)
            {
                return(false);
            }

            DirectMarketActionWindow sellWindow = Cache.Instance.Windows.OfType <DirectMarketActionWindow>().FirstOrDefault(w => w.IsSellAction);

            if (sellWindow != null && (!sellWindow.OrderId.HasValue || !sellWindow.Price.HasValue || !sellWindow.RemainingVolume.HasValue))
            {
                Logging.Log(module, "No order available for " + _currentItem.Name, Logging.White);

                sellWindow.Cancel();
                //
                // next state.
                //
                return(true);
            }

            if (sellWindow != null)
            {
                double price      = sellWindow.Price.Value;
                int    quantity   = (int)Math.Min(_currentItem.Quantity - _currentItem.QuantitySold, sellWindow.RemainingVolume.Value);
                double totalPrice = quantity * price;

                string otherPrices = " ";
                if (_currentItem.InvType.MedianBuy.HasValue)
                {
                    otherPrices += "[Median buy price: " + (_currentItem.InvType.MedianBuy.Value * quantity).ToString("#,##0.00") + "]";
                }
                else
                {
                    otherPrices += "[No median buy price]";
                }

                if (refine)
                {
                    int    portions    = quantity / _currentItem.PortionSize;
                    double refinePrice = _currentItem.RefineOutput.Any()
                                             ? _currentItem.RefineOutput.Sum(
                        m => m.Quantity * m.InvType.MedianBuy ?? 0) * portions
                                             : 0;
                    refinePrice *= RefiningEff / 100;

                    otherPrices += "[Refine price: " + refinePrice.ToString("#,##0.00") + "]";

                    if (refinePrice > totalPrice)
                    {
                        Logging.Log(module, "InspectRefinery [" + _currentItem.Name + "[" + quantity + "units] is worth more as mins [Refine each: " + (refinePrice / portions).ToString("#,##0.00") + "][Sell each: " + price.ToString("#,##0.00") + "][Refine total: " + refinePrice.ToString("#,##0.00") + "][Sell total: " + totalPrice.ToString("#,##0.00") + "]", Logging.White);

                        // Add it to the refine list
                        ItemsToRefine.Add(_currentItem);

                        sellWindow.Cancel();
                        //
                        // next state.
                        //
                        return(true);
                    }
                }

                if (!undersell)
                {
                    if (!_currentItem.InvType.MedianBuy.HasValue)
                    {
                        Logging.Log(module, "No historical price available for " + _currentItem.Name,
                                    Logging.White);

                        sellWindow.Cancel();
                        //
                        // next state.
                        //
                        return(true);
                    }

                    double perc  = price / _currentItem.InvType.MedianBuy.Value;
                    double total = _currentItem.InvType.MedianBuy.Value * _currentItem.Quantity;

                    // If percentage < 85% and total price > 1m isk then skip this item (we don't undersell)
                    if (perc < 0.85 && total > 1000000)
                    {
                        Logging.Log(module, "Not underselling item " + _currentItem.Name +
                                    Logging.Orange + " [" + Logging.White +
                                    "Median buy price: " +
                                    _currentItem.InvType.MedianBuy.Value.ToString("#,##0.00") +
                                    Logging.Orange + "][" + Logging.White +
                                    "Sell price: " + price.ToString("#,##0.00") +
                                    Logging.Orange + "][" + Logging.White +
                                    perc.ToString("0%") +
                                    Logging.Orange + "]", Logging.White);

                        sellWindow.Cancel();
                        //
                        // next state.
                        //
                        return(true);
                    }
                }

                // Update quantity sold
                _currentItem.QuantitySold += quantity;

                // Update station price
                if (!_currentItem.StationBuy.HasValue)
                {
                    _currentItem.StationBuy = price;
                }

                _currentItem.StationBuy = (_currentItem.StationBuy + price) / 2;

                if (sell)
                {
                    Logging.Log(module, "Selling " + quantity + " of " + _currentItem.Name +
                                Logging.Orange + " [" + Logging.White +
                                "Sell price: " + (price * quantity).ToString("#,##0.00") +
                                Logging.Orange + "]" + Logging.White +
                                otherPrices, Logging.White);
                    sellWindow.Accept();

                    // Update quantity sold
                    _currentItem.QuantitySold += quantity;

                    // Re-queue to check again
                    if (_currentItem.QuantitySold < _currentItem.Quantity)
                    {
                        ItemsToSell.Add(_currentItem);
                    }

                    _lastExecute = DateTime.UtcNow;
                    //
                    // next state
                    //
                    return(true);
                }
            }
            return(true); //how would we get here with no sell window?
        }
示例#2
0
文件: Sell.cs 项目: seb1707/Questor
        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();
            DirectMarketActionWindow sellWindow = Cache.Instance.Windows.OfType <DirectMarketActionWindow>().FirstOrDefault(w => w.IsSellAction);

            switch (_States.CurrentSellState)
            {
            case SellState.Idle:
            case SellState.Done:
                break;

            case SellState.Begin:
                _States.CurrentSellState = SellState.StartQuickSell;
                break;

            case SellState.StartQuickSell:

                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 1)
                {
                    break;
                }
                _lastAction = DateTime.UtcNow;

                if (Cache.Instance.ItemHangar == null)
                {
                    break;
                }

                DirectItem directItem = Cache.Instance.ItemHangar.Items.FirstOrDefault(i => (i.TypeId == Item));
                if (directItem == null)
                {
                    Logging.Log("Sell", "Item " + Item + " no longer exists in the hanger", Logging.White);
                    break;
                }

                // Update Quantity
                if (Unit == 00)
                {
                    Unit = directItem.Quantity;
                }

                Logging.Log("Sell", "Starting QuickSell for " + Item, Logging.White);
                if (!directItem.QuickSell())
                {
                    _lastAction = DateTime.UtcNow.AddSeconds(-5);

                    Logging.Log("Sell", "QuickSell failed for " + Item + ", retrying in 5 seconds", Logging.White);
                    break;
                }

                _States.CurrentSellState = SellState.WaitForSellWindow;
                break;

            case SellState.WaitForSellWindow:

                //if (sellWindow == null || !sellWindow.IsReady || sellWindow.Item.ItemId != Item)
                //    break;

                // Mark as new execution
                _lastAction = DateTime.UtcNow;

                Logging.Log("Sell", "Inspecting sell order for " + Item, Logging.White);
                _States.CurrentSellState = SellState.InspectOrder;
                break;

            case SellState.InspectOrder:
                // Let the order window stay open for 2 seconds
                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2)
                {
                    break;
                }
                if (sellWindow != null)
                {
                    if ((!sellWindow.OrderId.HasValue || !sellWindow.Price.HasValue || !sellWindow.RemainingVolume.HasValue))
                    {
                        Logging.Log("Sell", "No order available for " + Item, Logging.White);

                        sellWindow.Cancel();
                        _States.CurrentSellState = SellState.WaitingToFinishQuickSell;
                        break;
                    }

                    double price = sellWindow.Price.Value;

                    Logging.Log("Sell", "Selling " + Unit + " of " + Item + " [Sell price: " + (price * Unit).ToString("#,##0.00") + "]", Logging.White);
                    sellWindow.Accept();
                    _States.CurrentSellState = SellState.WaitingToFinishQuickSell;
                }
                _lastAction = DateTime.UtcNow;
                break;

            case SellState.WaitingToFinishQuickSell:
                if (sellWindow == null || !sellWindow.IsReady || sellWindow.Item.ItemId != Item)
                {
                    DirectWindow modal = Cache.Instance.Windows.FirstOrDefault(w => w.IsModal);
                    if (modal != null)
                    {
                        modal.Close();
                    }

                    _States.CurrentSellState = SellState.Done;
                    break;
                }
                break;
            }
        }