public Trader(Route route) { this.Route = route; this.First = new TraderPresence(route.First.Market); this.Second = new TraderPresence(route.Second.Market); }
private IEnumerable <(double, string)> GenerateBestTrades(TraderPresence src, TraderPresence dest) { return(Constants.TradableCommodities .Select(commodity => { var buyPrice = src.BuyPriceBeliefs.GetRandom(commodity); var sellPrice = dest.SellPriceBeliefs.GetRandom(commodity); var diff = sellPrice - buyPrice; return (diff, commodity); }) .Where(x => 0 < x.Item1) .OrderByDescending(x => x.Item1)); }
private IEnumerable <Offer> GenerateBuyOffers(TraderPresence src, TraderPresence dest) { var money = src.BuyInventory.Get(Constants.Money); var trades = GenerateBestTrades(src, dest).Take(3).ToList(); var ratio = 10 / trades.Sum(x => x.Item1); foreach (var trade in trades) { var diff = trade.Item1; var commodity = trade.Item2; var price = src.BuyPriceBeliefs.GetRandom(commodity); var amount = Math.Min(ratio * diff, money / price); yield return(new Offer( OfferType.Buy, commodity, price, amount )); money -= price * amount; } /* * var trades = GenerateBestTrades(src, dest).Where(x => PROFIT_THRESHOLD < x.Item1).Take(3).ToList(); * if (trades.Any()) { * var ratio = 10 / trades.Sum(x => x.Item1); * * foreach (var trade in trades) { * var diff = trade.Item1; * var commodity = trade.Item2; * * yield return new Offer( * OfferType.Buy, * commodity, * src.BuyPriceBeliefs.GetRandom(commodity), * ratio * diff * ); * } * } */ }