Esempio n. 1
0
        public double GetRecommendedPrice(MyMarketOrder order)
        {
            Log.WriteLog("Trying to find new price for picked order.");

            // get order situation (not mine)
            MarketSituation situation = order.GetMarketSituation();

            if (situation != null)
            {
                // filter orders by distance(currently compete with orders in same station.)
                //Temporaty only compete with same station.
                int StationID = _character.CurrentStationID;

                double HighestBuy = 0;
                List <MarketOrderBase> buyOrders = situation.BuyOrdersInMarket.OrderByDescending(o => o.Price).ToList();
                if (buyOrders.Any())
                {
                    HighestBuy = buyOrders.First().Price;
                    //  InnerSpace.Echo("highest buy" + HighestBuy.ToString());
                }

                double LowestSell = 0;
                List <MarketOrderBase> sellOrders = situation.SellOrdersInMarket.OrderBy(o => o.Price).ToList();
                if (sellOrders.Any())
                {
                    LowestSell = sellOrders.First().Price;
                    // InnerSpace.Echo("lowest sell" + LowestSell.ToString());
                }
                if (HighestBuy != 0 && LowestSell != 0)
                {
                    double score = (LowestSell - HighestBuy) / ((HighestBuy + LowestSell) / 2) * 100;

                    // InnerSpace.Echo("score" + score.ToString());

                    if (score > _config.ValidGapSizeRatio)
                    {
                        if (order.OrderType == OrderType.Sell)
                        {
                            return(LowestSell - 0.01);
                        }
                        else
                        {
                            return(HighestBuy + 0.01);
                        }
                    }
                }

                if (HighestBuy != 0)//means no sell order
                {
                    if (order.OrderType == OrderType.Buy)
                    {
                        return(HighestBuy + 0.01);
                    }
                }

                if (LowestSell != 0)//means no buy order
                {
                    if (order.OrderType == OrderType.Sell)
                    {
                        return(LowestSell - 0.01);
                    }
                }
            }

            Log.WriteLog("Done finding new price for picked order.");
            return(-1);
        }
Esempio n. 2
0
        public MarketSituation GetMarketSituation()
        {
            Log.WriteLog("Trying to get the market situation of  \"" + this.Type.ToString() + "\".");

            List <EVE.ISXEVE.MarketOrder> retrivedOrders = null;
            MarketSituation result = null;

            bool success;

            using (new FrameLock(true))
            {
                EVE.ISXEVE.EVE eve = new EVE.ISXEVE.EVE();

                success = eve.FetchMarketOrders(this.TypeID);
            }

            if (success)
            {
                Log.WriteLog("Fired fetching orders request, wait to get result.");

                int counter = 0;

                while (retrivedOrders == null && counter < 100)
                {
                    Frame.Wait(false);
                    using (new FrameLock(true))
                    {
                        counter++;

                        EVE.ISXEVE.EVE eve = new EVE.ISXEVE.EVE();

                        // IMPORTANT: This is shallow copy, we need to finish all DEEP copy value operations while locked, otherwise the memory will be flushed;
                        retrivedOrders = eve.GetMarketOrders(this.TypeID);

                        if (retrivedOrders != null)
                        {
                            if (MarketOrderSet.ValidateOrderData(retrivedOrders))
                            {
                                // Prepare my own order id list to speed up the combine.
                                List <long> MyOwnOrderIds = new List <long>();
                                foreach (MyMarketOrder mmo in _orderList)
                                {
                                    if (mmo.TypeID == TypeID)
                                    {
                                        MyOwnOrderIds.Add(mmo.ID);
                                    }
                                }

                                result = new MarketSituation(retrivedOrders, MyOwnOrderIds);
                            }
                            else
                            {
                                Log.WriteLog("Found invalid data in retrived order, retrying.");
                                // Enter next loop;
                                retrivedOrders = null;
                            }
                        }
                    }
                }
                if (retrivedOrders != null)
                {
                    Log.WriteLog("Got " + retrivedOrders.Count.ToString() + " orders with (" + counter.ToString() + ") attempts.");
                }
                else
                {
                    Log.WriteLog("Failed to load orders with (" + counter.ToString() + ") attempts.");
                }
            }
            else
            {
                Log.WriteLog("Failed to send update order request.");
            }

            Log.WriteLog("Done loading market orders.");

            return(result);
        }
        public MarketSituation GetMarketSituation()
        {
            Log.WriteLog("Trying to get the market situation of  \"" + this.Type.ToString() + "\".");

            List<EVE.ISXEVE.MarketOrder> retrivedOrders = null;
            MarketSituation result = null;

            bool success;
            using (new FrameLock(true))
            {
                EVE.ISXEVE.EVE eve = new EVE.ISXEVE.EVE();

                success = eve.FetchMarketOrders(this.TypeID);
            }

            if (success)
            {
                Log.WriteLog("Fired fetching orders request, wait to get result.");

                int counter = 0;

                while (retrivedOrders == null && counter < 100)
                {
                    Frame.Wait(false);
                    using (new FrameLock(true))
                    {
                        counter++;

                        EVE.ISXEVE.EVE eve = new EVE.ISXEVE.EVE();

                        // IMPORTANT: This is shallow copy, we need to finish all DEEP copy value operations while locked, otherwise the memory will be flushed;
                        retrivedOrders = eve.GetMarketOrders(this.TypeID);

                        if (retrivedOrders != null)
                        {
                            if (MarketOrderSet.ValidateOrderData(retrivedOrders))
                            {
                                // Prepare my own order id list to speed up the combine.
                                List<long> MyOwnOrderIds = new List<long>();
                                foreach (MyMarketOrder mmo in _orderList)
                                {
                                    if (mmo.TypeID == TypeID)
                                    {
                                        MyOwnOrderIds.Add(mmo.ID);
                                    }
                                }

                                result = new MarketSituation(retrivedOrders, MyOwnOrderIds);
                            }
                            else
                            {
                                Log.WriteLog("Found invalid data in retrived order, retrying.");
                                // Enter next loop;
                                retrivedOrders = null;
                            }
                        }
                    }
                }
                if (retrivedOrders != null)
                {
                    Log.WriteLog("Got " + retrivedOrders.Count.ToString() + " orders with (" + counter.ToString() + ") attempts.");
                }
                else
                {
                    Log.WriteLog("Failed to load orders with (" + counter.ToString() + ") attempts.");
                }
            }
            else
            {
                Log.WriteLog("Failed to send update order request.");
            }

            Log.WriteLog("Done loading market orders.");

            return result;
        }