示例#1
0
        public TradeAgent(MainWindow UIWindow)
        {
            Config = new Config();
            ActiveCharacter = new Character();
            OrderSet = new MarketOrderSet(Config);
            _decide = new Strategy(ActiveCharacter, Config);

            // Load non-character specific configs.
            _loadGeneralConfig();

            // hook with UI, and delete old logs.
            _UIWindow = UIWindow;
            Log.Initialize(_UIWindow.WriteLogToWindow);
            Log.WriteLog("Done initializing trade agent.");

            // init other parts
            // updateInfo()
        }
示例#2
0
        public TradeAgent(MainWindow UIWindow)
        {
            Config          = new Config();
            ActiveCharacter = new Character();
            OrderSet        = new MarketOrderSet(Config);
            _decide         = new Strategy(ActiveCharacter, Config);

            // Load non-character specific configs.
            _loadGeneralConfig();

            // hook with UI, and delete old logs.
            _UIWindow = UIWindow;
            Log.Initialize(_UIWindow.WriteLogToWindow);
            Log.WriteLog("Done initializing trade agent.");

            // init other parts
            // updateInfo()
        }
示例#3
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);
        }
示例#4
0
        public void Modify(double newPrice)
        {
            Debug.Assert(newPrice > 0);

            Log.WriteLog("Trying to confirm order " + this.ID.ToString() + ": \"" + this.Type.ToString() + "\" before modifying.");

            List <MyOrder> retrivedOrders = null;
            Me             me;
            bool           success;

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

                // me is not persistent, we can't just keep a static reference somewhere, have to renew every frame;
                me      = new Me();
                success = me.UpdateMyOrders();
            }

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

                int counter = 0;

                while (retrivedOrders == null && counter < 100)
                {
                    Frame.Wait(false);
                    using (new FrameLock(true))
                    {
                        counter++;
                        // me is not persistent, we can't just keep a static reference somewhere,have to renew every frame;
                        me = new Me();

                        EVE.ISXEVE.Character.OrderType orderType = this.OrderType == OrderType.Buy ? EVE.ISXEVE.Character.OrderType.Buy : EVE.ISXEVE.Character.OrderType.Sell;

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

                        if (retrivedOrders != null)
                        {
                            if (MarketOrderSet.ValidateOrderData(retrivedOrders))
                            {
                                MyOrder orderToModify = null;

                                foreach (MyOrder o in retrivedOrders)
                                {
                                    if (o.ID == ID)
                                    {
                                        orderToModify = o;
                                        break;
                                    }
                                }

                                if (orderToModify != null)
                                {
                                    Log.WriteLog("Confirmed order with (" + counter.ToString() + ") attempts.");

                                    DateTime lastModifiedTime = new System.DateTime(1601, 1, 1).AddSeconds(orderToModify.TimeStampWhenIssued / 10000000);

                                    //real cool down takes 5 minutes
                                    if (lastModifiedTime.AddMilliseconds(301000) < System.DateTime.UtcNow)
                                    {
                                        orderToModify.Modify(newPrice);

                                        Price = newPrice;
                                        ModifyCoolDownEndTime = System.DateTime.UtcNow.AddMilliseconds(_config.RandomizedOrderModifyIntervalInMilliSec);
                                        //I think the date, time and timestamp dont need updating.

                                        Log.WriteLog("Order " + this.ID.ToString() + ": \"" + this.Type.ToString() + "\" modified");
                                    }
                                    else
                                    {
                                        ModifyCoolDownEndTime = lastModifiedTime.AddMilliseconds(_config.RandomizedOrderModifyIntervalInMilliSec);
                                        Log.WriteLog("Order cooldown not finished yet. Job \"Modify\" cancelled.");
                                    }
                                }
                                else
                                {
                                    Log.WriteLog("Failed to find order to modify with (" + counter.ToString() + ") attempts. Job \"Modify\" cancelled.");
                                }
                            }
                            else
                            {
                                Log.WriteLog("Found invalid data in retrived order, retrying.");
                                // Enter next loop;
                                retrivedOrders = null;
                            }
                        }
                    }
                }
            }
            else
            {
                Log.WriteLog("Failed to send update order request. Job \"Modify\" cancelled.");
            }
        }