using XFEEDToolBox.Core.Models;
namespace XFEEDToolBox.Core.Execution;
public sealed record CgBatchQuote(string Commodity,string Label,long Stock,long BuyPrice,long SellPrice);
public static class CgBatchPlanner
{
// Compare total proceeds for this flight, including a partially stocked
// high-margin commodity, rather than always assuming a full uranium hold.
public static TradeOrder Select(IEnumerable<CgBatchQuote> quotes,int capacity,decimal credits,decimal reserve)
{
if(capacity is <1 or >192||credits<0||reserve<0)throw new ArgumentOutOfRangeException(nameof(capacity));
var orders=new List<TradeOrder>();
foreach(var q in quotes)
{
if(!NativeTradeBatchPolicy.Allows(q.Commodity)||q.Stock<=0||q.BuyPrice is <=0 or >100000||q.SellPrice is <=0 or >100000||q.SellPrice<=q.BuyPrice)continue;
var affordable=Math.Max(0,decimal.Floor((credits-reserve)/q.BuyPrice));
var quantity=(int)Math.Min(Math.Min(capacity,q.Stock),affordable);
if(quantity>0)orders.Add(new(q.Commodity,q.Label,quantity,q.BuyPrice,q.SellPrice));
}
return orders.OrderByDescending(x=>(x.SellPrice-x.BuyPrice)*x.Quantity).ThenBy(x=>x.Commodity,StringComparer.Ordinal).FirstOrDefault()
??throw new InvalidOperationException("当前 CG 原始报价、库存或保留资金不足,未提交采购。");
}
}
using XFEEDToolBox.Core.Models;
namespace XFEEDToolBox.Core.Execution;
public sealed record CgBatchQuote(string Commodity,string Label,long Stock,long BuyPrice,long SellPrice);
public static class CgBatchPlanner
{
// Compare total proceeds for this flight, including a partially stocked
// high-margin commodity, rather than always assuming a full uranium hold.
public static TradeOrder Select(IEnumerable<CgBatchQuote> quotes,int capacity,decimal credits,decimal reserve)
{
if(capacity is <1 or >192||credits<0||reserve<0)throw new ArgumentOutOfRangeException(nameof(capacity));
var orders=new List<TradeOrder>();
foreach(var q in quotes)
{
if(!NativeTradeBatchPolicy.Allows(q.Commodity)||q.Stock<=0||q.BuyPrice is <=0 or >100000||q.SellPrice is <=0 or >100000||q.SellPrice<=q.BuyPrice)continue;
var affordable=Math.Max(0,decimal.Floor((credits-reserve)/q.BuyPrice));
var quantity=(int)Math.Min(Math.Min(capacity,q.Stock),affordable);
if(quantity>0)orders.Add(new(q.Commodity,q.Label,quantity,q.BuyPrice,q.SellPrice));
}
return orders.OrderByDescending(x=>(x.SellPrice-x.BuyPrice)*x.Quantity).ThenBy(x=>x.Commodity,StringComparer.Ordinal).FirstOrDefault()
??throw new InvalidOperationException("当前 CG 原始报价、库存或保留资金不足,未提交采购。");
}
}