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); }
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); }
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); }
private TradePerStation MakeList(List <string> TradeData, int type) { List <StationModel> stationList = SqliteDataAccess.LoadStations(); TradePerStation tradePerStation = new TradePerStation(); tradePerStation.station_ids = new List <int>(); tradePerStation.trades = new List <List <SingleTradeModel> >(); foreach (StationModel station in stationList) { tradePerStation.station_ids.Add(station.id); tradePerStation.trades.Add(new List <SingleTradeModel>()); } int j = 0; foreach (string singleTrade in TradeData) { if (!singleTrade.Contains("td")) { continue; } string[] arr1 = singleTrade.Split(new[] { "</td>" }, StringSplitOptions.None); string[] arr2 = arr1[3].Split(new[] { "</span>" }, StringSplitOptions.None); string StationName = arr2[1].Trim(); int k = 0; foreach (StationModel station in stationList) { bool areEqual = String.Equals(station.name, StationName, StringComparison.Ordinal); if (areEqual) { string[] el2 = arr1[2].Split(new[] { "\">" }, StringSplitOptions.None); el2 = el2[1].Split(new[] { "ISK" }, StringSplitOptions.None); el2[0] = el2[0].Trim(); StringBuilder cPrice = new StringBuilder(); foreach (char c in el2[0]) { if ((c >= '0' && c <= '9') || (c == '.')) { cPrice.Append(c); } } decimal Price = decimal.Parse(cPrice.ToString(), CultureInfo.InvariantCulture); if (j == 0 && type == 0) { sellPrice = Price; j++; } else if (j == 0 && type == 1) { buyPrice = Price; j++; } string[] el21 = arr1[1].Split(new[] { "\">" }, StringSplitOptions.None); el21[1] = el21[1].Trim(); StringBuilder sQuantity = new StringBuilder(); foreach (char c in el21[1]) { if (c >= '0' && c <= '9') { sQuantity.Append(c); } } int Quantity = Int32.Parse(sQuantity.ToString()); if (type == 0) { el2 = arr1[5].Split(new[] { " ago" }, StringSplitOptions.None); } else { el2 = arr1[7].Split(new[] { " ago" }, StringSplitOptions.None); } el2 = el2[0].Split(new[] { "\">" }, StringSplitOptions.None); if (el2[1].Contains("s")) { el2[1] = "1"; } else { el2[1] = el2[1].Remove(el2[1].Length - 1, 1); } int age = Int32.Parse(el2[1]); if (age < 1000) { SingleTradeModel newTrade = new SingleTradeModel(); newTrade.Price = Price; newTrade.Quantity = Quantity; tradePerStation.trades[k].Add(newTrade); if (type == 1) { hasBuy = true; } else { hasSell = true; } } } k++; } } return(tradePerStation); }