Esempio n. 1
0
        public FormattedTradesModel Trades(string typeID, string rawData)
        {
            string[] websiteData = rawData.Split(new[] { "tbody" }, StringSplitOptions.None);

            string[] tradeData = websiteData[3].Split(new[] { "</tr>" }, StringSplitOptions.None);

            List <string> TradeData = new List <string>(tradeData);

            TradeData.RemoveAt(tradeData.Length - 1);
            TradePerStation sellPerStation = MakeList(TradeData, 0);

            tradeData = websiteData[5].Split(new[] { "</tr>" }, StringSplitOptions.None);
            TradeData = new List <string>(tradeData);
            TradeData.RemoveAt(tradeData.Length - 1);
            TradePerStation buyPerStation = MakeList(TradeData, 1);

            FormattedTradesModel result = new FormattedTradesModel();

            result.type_id          = Convert.ToInt32(typeID);
            result.has_data         = true;
            result.sell_per_station = sellPerStation;
            result.buy_per_station  = buyPerStation;
            result.has_sell         = hasSell;
            result.has_buy          = hasBuy;
            result.sell_price       = sellPrice;
            result.buy_price        = buyPrice;

            return(result);
        }
Esempio n. 2
0
        private FormattedTradesModel downloadSite(string[] item)
        {
            startedItem++;

            FormattedTradesModel result = new FormattedTradesModel();

            result.type_id  = Convert.ToInt32(item[0]);
            result.has_data = false;

            try
            {
                ChromeDriverService service = ChromeDriverService.CreateDefaultService();
                service.HideCommandPromptWindow = true;

                var options = new ChromeOptions();
                options.AddArgument("headless");
                options.AddArgument("--no-sandbox");
                options.Proxy = null;

                IWebDriver driver = new ChromeDriver(service, options, TimeSpan.FromMinutes(5));

                driver.Url = "https://evemarketer.com/types/" + item[0];

                new WebDriverWait(driver, TimeSpan.FromSeconds(60)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementWithText(By.TagName("h2"), "No Type Selected"));

                if (!string.IsNullOrEmpty(driver.PageSource))
                {
                    ParseDownloadedString parseDownload = new ParseDownloadedString();
                    result = parseDownload.Trades(item[0], driver.PageSource);
                }

                driver.Quit();
            }
            catch (Exception)
            {
                finishedWithErrors = true;
            }

            finishedItem++;

            if (!token.IsCancellationRequested)
            {
                int progressPercentage = Convert.ToInt32(((double)finishedItem / totalItems) * 100);

                DownloadProgressReportModel report = new DownloadProgressReportModel();

                report.PercentageComplete = progressPercentage;
                report.MessageRemaining   = "Step 1/2: Downloading data" + StaticMethods.EstimatedTime(startTime, finishedItem, totalItems);

                progress.Report(report);
            }

            maxAsync--;

            return(result);
        }
        public CalculateTradeModel TradePrepare(int TypeID, string itemName, string itemVolume, FormattedTradesModel formattedTrades)
        {
            List <string> stationList = allStations;

            TradePerStation sellPerStation = formattedTrades.sell_per_station;
            TradePerStation buyPerStation  = formattedTrades.buy_per_station;

            hasSell = formattedTrades.has_sell;
            hasBuy  = formattedTrades.has_buy;

            sellPrice = formattedTrades.sell_price;
            buyPrice  = formattedTrades.buy_price;

            sellPrice = sellPrice + (sellPrice * minProfit);
            buyPrice  = buyPrice - (buyPrice * minProfit);

            if (hasBuy && hasSell && sellPrice < buyPrice)
            {
                string  sellStationName    = "";
                string  buyStationName     = "";
                int     tradeQuantity      = 0;
                decimal purchasePrice      = 0;
                decimal tradeProfit        = 0;
                decimal tradeROI           = 0;
                int     maxQuantity        = 0;
                bool    isMaxQuantityValid = true;

                if (filters.user_cargo_capacity > 0)
                {
                    string[] stringValue1 = (filters.user_cargo_capacity / Decimal.Parse(itemVolume, CultureInfo.InvariantCulture)).ToString(CultureInfo.InvariantCulture).Split('.');
                    maxQuantity = Convert.ToInt32(stringValue1[0]);
                }

                decimal userAvailableMoney = filters.user_available_money;

                for (int i = 0; i < sellPerStation.station_ids.Count; i++)
                {
                    if (filters.selected_hauling_station_id > 0 && filters.selected_hauling_station_id != sellPerStation.station_ids[i])
                    {
                        continue;
                    }

                    List <SingleTradeModel> sellTrades = sellPerStation.trades[i];

                    for (int j = 0; j < buyPerStation.station_ids.Count; j++)
                    {
                        List <SingleTradeModel> buyTrades = buyPerStation.trades[j];

                        int     newTradeQuantity = 0;
                        decimal newPurchasePrice = 0;
                        decimal newTradeProfit   = 0;

                        int currentSellOrder = 0;
                        int currentBuyOrder  = 0;

                        while (currentSellOrder < sellTrades.Count && currentBuyOrder < buyTrades.Count)
                        {
                            decimal adjustedSellTradePrice = sellTrades[currentSellOrder].Price + (sellTrades[currentSellOrder].Price * minProfit);
                            decimal adjustedBuyTradePrice  = buyTrades[currentBuyOrder].Price - (buyTrades[currentBuyOrder].Price * minProfit);

                            if (adjustedSellTradePrice < adjustedBuyTradePrice && isMaxQuantityValid)
                            {
                                if (filters.user_available_money > 0)
                                {
                                    if (maxQuantity == 0)
                                    {
                                        string[] stringValue2 = (userAvailableMoney / sellTrades[currentSellOrder].Price).ToString(CultureInfo.InvariantCulture).Split('.');
                                        maxQuantity = Convert.ToInt32(stringValue2[0]);
                                    }
                                    else
                                    {
                                        if ((maxQuantity * sellTrades[currentSellOrder].Price) > userAvailableMoney)
                                        {
                                            string[] stringValue3 = (userAvailableMoney / sellTrades[currentSellOrder].Price).ToString(CultureInfo.InvariantCulture).Split('.');
                                            maxQuantity = Convert.ToInt32(stringValue3[0]);
                                        }
                                    }
                                }

                                if (filters.user_cargo_capacity > 0 || filters.user_available_money > 0)
                                {
                                    if (sellTrades[currentSellOrder].Quantity > maxQuantity)
                                    {
                                        sellTrades[currentSellOrder].Quantity = maxQuantity;
                                    }

                                    if (buyTrades[currentBuyOrder].Quantity > maxQuantity)
                                    {
                                        buyTrades[currentBuyOrder].Quantity = maxQuantity;
                                    }
                                }

                                if (sellTrades[currentSellOrder].Quantity < buyTrades[currentBuyOrder].Quantity)
                                {
                                    newTradeQuantity += sellTrades[currentSellOrder].Quantity;

                                    if (filters.user_cargo_capacity > 0 || filters.user_available_money > 0)
                                    {
                                        maxQuantity -= sellTrades[currentSellOrder].Quantity;
                                    }

                                    newPurchasePrice += sellTrades[currentSellOrder].Price * sellTrades[currentSellOrder].Quantity;

                                    if (filters.user_available_money > 0)
                                    {
                                        userAvailableMoney -= sellTrades[currentSellOrder].Price * sellTrades[currentSellOrder].Quantity;
                                    }

                                    newTradeProfit += (buyTrades[currentBuyOrder].Price - sellTrades[currentSellOrder].Price) * sellTrades[currentSellOrder].Quantity;
                                    buyTrades[currentBuyOrder].Quantity -= sellTrades[currentSellOrder].Quantity;
                                    currentSellOrder++;
                                }
                                else if (sellTrades[currentSellOrder].Quantity == buyTrades[currentBuyOrder].Quantity)
                                {
                                    newTradeQuantity += sellTrades[currentSellOrder].Quantity;

                                    if (filters.user_cargo_capacity > 0 || filters.user_available_money > 0)
                                    {
                                        maxQuantity -= sellTrades[currentSellOrder].Quantity;
                                    }

                                    newPurchasePrice += sellTrades[currentSellOrder].Price * sellTrades[currentSellOrder].Quantity;

                                    if (filters.user_available_money > 0)
                                    {
                                        userAvailableMoney -= sellTrades[currentSellOrder].Price * sellTrades[currentSellOrder].Quantity;
                                    }

                                    newTradeProfit += (buyTrades[currentBuyOrder].Price - sellTrades[currentSellOrder].Price) * sellTrades[currentSellOrder].Quantity;
                                    buyTrades[currentBuyOrder].Quantity -= sellTrades[currentSellOrder].Quantity;
                                    currentBuyOrder++;
                                    currentSellOrder++;
                                }
                                else
                                {
                                    newTradeQuantity += buyTrades[currentBuyOrder].Quantity;

                                    if (filters.user_cargo_capacity > 0 || filters.user_available_money > 0)
                                    {
                                        maxQuantity -= buyTrades[currentBuyOrder].Quantity;
                                    }

                                    newPurchasePrice += sellTrades[currentSellOrder].Price * buyTrades[currentBuyOrder].Quantity;

                                    if (filters.user_available_money > 0)
                                    {
                                        userAvailableMoney -= sellTrades[currentSellOrder].Price * buyTrades[currentBuyOrder].Quantity;
                                    }

                                    newTradeProfit += (buyTrades[currentBuyOrder].Price - sellTrades[currentSellOrder].Price) * buyTrades[currentBuyOrder].Quantity;
                                    sellTrades[currentSellOrder].Quantity -= buyTrades[currentBuyOrder].Quantity;
                                    currentBuyOrder++;
                                }

                                if (filters.user_cargo_capacity > 0 || filters.user_available_money > 0)
                                {
                                    if (maxQuantity == 0)
                                    {
                                        isMaxQuantityValid = false;
                                    }
                                }
                            }
                            else
                            {
                                break;
                            }
                        }

                        if (newTradeProfit > tradeProfit)
                        {
                            sellStationName = stationList[i];
                            buyStationName  = stationList[j];
                            tradeQuantity   = newTradeQuantity;
                            purchasePrice   = newPurchasePrice;
                            tradeProfit     = newTradeProfit;
                            tradeROI        = (tradeProfit / purchasePrice) * 100;
                        }
                    }
                }

                if (tradeQuantity > 0)
                {
                    CalculateTradeModel newTrade = new CalculateTradeModel();
                    newTrade.Item = itemName;
                    string[] from = sellStationName.Split(new[] { " " }, StringSplitOptions.None);
                    newTrade.From     = from[0];
                    newTrade.FromFull = sellStationName;
                    string[] to = buyStationName.Split(new[] { " " }, StringSplitOptions.None);
                    newTrade.To       = to[0];
                    newTrade.ToFull   = buyStationName;
                    newTrade.NumItems = tradeQuantity;
                    newTrade.Price    = purchasePrice;
                    newTrade.Profit   = tradeProfit;
                    newTrade.ROI      = tradeROI;
                    newTrade.Link     = "https://evemarketer.com/types/" + TypeID.ToString();

                    return(newTrade);
                }
            }

            return(null);
        }
Esempio n. 4
0
        public CalculateStationTradeModel TradePrepare(int TypeID, string itemName, string itemVolume, FormattedTradesModel formattedTrades)
        {
            TradePerStation sellPerStation = formattedTrades.sell_per_station;
            TradePerStation buyPerStation  = formattedTrades.buy_per_station;

            hasSell = formattedTrades.has_sell;
            hasBuy  = formattedTrades.has_buy;

            if (hasBuy && hasSell)
            {
                for (int i = 0; i < sellPerStation.station_ids.Count; i++)
                {
                    if (filters.selected_station_trading_station_id.Equals(sellPerStation.station_ids[i]) && sellPerStation.trades[i].Count > 0)
                    {
                        List <SingleTradeModel> sellTrades = sellPerStation.trades[i];

                        buyPrice = sellTrades[0].Price; // this is now the price at which I will buy
                        buyPrice = buyPrice + (buyPrice * filters.user_brokers_fee);

                        for (int j = 0; j < buyPerStation.station_ids.Count; j++)
                        {
                            if (filters.selected_station_trading_station_id.Equals(buyPerStation.station_ids[i]) && buyPerStation.trades[j].Count > 0)
                            {
                                List <SingleTradeModel> buyTrades = buyPerStation.trades[j];

                                sellPrice = buyTrades[0].Price; // this is now the price at which I will sell
                                sellPrice = sellPrice - (sellPrice * (filters.user_brokers_fee + filters.user_sales_tax) / 100);

                                if (buyPrice < sellPrice)
                                {
                                    CalculateStationTradeModel newTrade = new CalculateStationTradeModel();
                                    newTrade.item           = itemName;
                                    newTrade.buy_price      = buyPrice;
                                    newTrade.sell_price     = sellPrice;
                                    newTrade.spread_isk     = sellPrice - buyPrice;
                                    newTrade.spread_percent = newTrade.spread_isk / sellPrice * 100;
                                    newTrade.link           = "https://evemarketer.com/types/" + TypeID.ToString();

                                    return(newTrade);
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }