示例#1
0
        public void CancelSellOrder(List <MyListingsSalesItem> itemsToCancel)
        {
            var       index          = 1;
            const int ThreadsCount   = 2;
            var       semaphore      = new Semaphore(ThreadsCount, ThreadsCount);
            var       timeTrackCount = SavedSettings.Get().Settings2FaItemsToConfirm;
            var       timeTracker    = new SellTimeTracker(timeTrackCount);

            PriceLoader.StopAll();
            PriceLoader.WaitForLoadFinish();

            foreach (var item in itemsToCancel)
            {
                try
                {
                    Program.WorkingProcessForm.AppendWorkingProcessInfo(
                        $"[{index++}/{itemsToCancel.Count}] Canceling - '{item.Name}'");

                    var realIndex = index;
                    semaphore.WaitOne();

                    Task.Run(
                        () =>
                    {
                        var response = this.MarketClient.CancelSellOrder(item.SaleId);

                        if (response == ECancelSellOrderStatus.Fail)
                        {
                            Program.WorkingProcessForm.AppendWorkingProcessInfo(
                                $"[{realIndex}/{itemsToCancel.Count}] Error on market cancel item");
                        }

                        if (realIndex % timeTrackCount == 0)
                        {
                            timeTracker.TrackTime(itemsToCancel.Count - realIndex);
                        }

                        semaphore.Release();
                    });
                }
                catch (Exception e)
                {
                    Program.WorkingProcessForm.AppendWorkingProcessInfo(
                        $"[{index++}/{itemsToCancel.Count}] Error on cancel market item - {e.Message}");
                }
            }
        }
示例#2
0
        public void SellOnMarket(ToSaleObject items)
        {
            PriceLoader.WaitForLoadFinish();

            var maxErrorsCount      = SavedSettings.Get().ErrorsOnSellToSkip;
            var currentItemIndex    = 1;
            var itemsToConfirmCount = SavedSettings.Get().Settings2FaItemsToConfirm;
            var totalItemsCount     = items.ItemsForSaleList.Sum(x => x.Items.Count());
            var timeTracker         = new SellTimeTracker(itemsToConfirmCount);

            foreach (var package in items.ItemsForSaleList)
            {
                var itemName = package.Items.First().Description.Name;
                if (!package.Price.HasValue)
                {
                    try
                    {
                        var task = Task.Run(async() => await items.GetPrice(package.Items.First(), this));
                        Program.WorkingProcessForm.AppendWorkingProcessInfo($"Processing price for '{itemName}'");
                        task.Wait();

                        var price = task.Result;
                        if (price != null)
                        {
                            package.Price = price;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex is ThreadAbortException)
                        {
                            return;
                        }

                        Logger.Error("Error on market price parse", ex);
                        Program.WorkingProcessForm.AppendWorkingProcessInfo(
                            $"ERROR on selling '{itemName}' - {ex.Message}{ex.InnerException?.Message}");

                        totalItemsCount -= package.Items.Sum(e => int.Parse(e.Asset.Amount));
                        continue;
                    }
                }

                var packageElementIndex    = 1;
                var packageTotalItemsCount = package.Items.Count();
                var errorsCount            = 0;
                foreach (var item in package.Items)
                {
                    try
                    {
                        Program.WorkingProcessForm.AppendWorkingProcessInfo(
                            $"[{currentItemIndex}/{totalItemsCount}] Selling - [{packageElementIndex++}/{packageTotalItemsCount}] - '{itemName}' for {package.Price}");
                        if (package.Price.HasValue)
                        {
                            this.SellOnMarket(item, package.Price.Value);
                        }
                        else
                        {
                            Program.WorkingProcessForm.AppendWorkingProcessInfo(
                                $"ERROR on selling '{itemName}' - Price is not loaded. Skipping item.");
                            currentItemIndex += package.Items.Count();
                            break;
                        }

                        if (currentItemIndex % itemsToConfirmCount == 0)
                        {
                            Task.Run(this.ConfirmMarketTransactions);

                            timeTracker.TrackTime(totalItemsCount - currentItemIndex);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex is ThreadAbortException)
                        {
                            return;
                        }

                        Logger.Error("Error on market sell", ex);
                        Program.WorkingProcessForm.AppendWorkingProcessInfo(
                            $"ERROR on selling '{itemName}' - {ex.Message}{ex.InnerException?.Message}");

                        if (++errorsCount == maxErrorsCount)
                        {
                            Program.WorkingProcessForm.AppendWorkingProcessInfo(
                                $"{maxErrorsCount} fails limit on sell {itemName} reached. Skipping item.");
                            totalItemsCount -= packageTotalItemsCount - packageElementIndex;
                            break;
                        }
                    }

                    currentItemIndex++;
                }
            }

            Task.Run(this.ConfirmMarketTransactions);
        }