Example #1
0
 public MarketController(ProfileController profileCont)
 {
     _profileController            = profileCont;
     LinkManager.CurrentItemPrices = new List <CurrentItemPrice>();
     foreach (string itemTypeId in LinkManager.ItemsToLookFor.Keys)
     {
         var newItemPrice = new CurrentItemPrice
         {
             Id    = itemTypeId,
             Price = 0
         };
         LinkManager.CurrentItemPrices.Add(newItemPrice);
     }
 }
Example #2
0
        private void SearchForFirstItemOfType(List <BuyOfferPurchase> allPurchasingOffers, CurrentItemPrice currentPrice, string itemName)
        {
            var newSearchRequest = new SearchRequest(currentPrice.Id);
            var gameRequest      = new GameRequest(LinkManager._searchMarketEndPoint, newSearchRequest);
            var gameWebRequest   = new EFTWebRequest(Log, SessionCookie);

            Offer?offer = null;

            while (offer == null)
            {
                try
                {
                    var searchResp = gameWebRequest.EftGameRequest <SearchResponse>(gameRequest);
                    if (searchResp.Error != null)
                    {
                        Log(
                            $"Unable to process search request. Error: {searchResp.Error.ErrorMessage}. Data: {searchResp.Error.Data}");
                        break;
                    }

                    offer = searchResp.Data.data.offers?.OrderBy(o => o.requirementsCost).FirstOrDefault();
                }
                catch (Exception ex)
                {
                    Log(ex.ToString());
                }

                if (offer == null)
                {
                    Thread.Sleep(500);
                }
            }

            Log($"Found offer - costs {offer.requirementsCost} to buy {itemName} (can be sold for {currentPrice.Price})");
            AddPurchaseOffer(allPurchasingOffers, offer, itemName, 0);
        }
Example #3
0
        private void SearchForMultipleOfExistingType(List <BuyOfferPurchase> allPurchasingOffers, CurrentItemPrice currentPrice, string itemName)
        {
            var newSearchRequest = new SearchRequest(currentPrice.Id);
            var gameRequest      = new GameRequest(LinkManager._searchMarketEndPoint, newSearchRequest);
            var gameWebRequest   = new EFTWebRequest(Log, SessionCookie);

            SearchResponse?data = null;

            while (data == null)
            {
                var searchResp = gameWebRequest.EftGameRequest <SearchResponse>(gameRequest);
                if (!CanProcess(searchResp))
                {
                    break;
                }

                if (searchResp.Data?.data != null)
                {
                    data = searchResp.Data;
                }

                if (data == null)
                {
                    Thread.Sleep(LinkManager.Timer);
                }
            }

            //Get all offers, cheapest first. Gotta save those dollar bills yo
            //Ensure they only require roubles and no other items in order to buy.
            var allOffers = data.data.offers.OrderBy(o => o.requirementsCost)
                            .Where(offer => currentPrice.Price > offer.requirementsCost)
                            .Take(5)
                            .ToList();

            if (allOffers.Count <= 0)
            {
                Log($"Unable to find any offers that will make us profit for item {itemName}");
                //Thread.Sleep(LinkManager.Timer);
                return;
            }

            foreach (var offer in allOffers)
            {
                var itemProfit = currentPrice.Price - offer.requirementsCost;

                if (itemProfit <= 0)
                {
                    continue;
                }

                //TODO: Why is offer.items[0].id null???? Compare with working API... Majority of our buy requests are failing qq
                //TODO: Compare our buying with our selling properly in code to see where we're going wrong.
                Log($"Found offer - costs {offer.requirementsCost} to buy {itemName} (can be sold for {currentPrice.Price} - {itemProfit} profit)");
                AddPurchaseOffer(allPurchasingOffers, offer, itemName, itemProfit);
            }
        }