private TradeResult MakeMatch(BidOrder bid, List <AskOrder> asks) { asks = asks.OrderBy(e => e.Price).ThenBy(e => e.Date).ToList(); var items = new List <TradeLog>(); foreach (var ask in asks) { if (bid.Remain() == 0) { break; } var item = MakeMatch(bid, ask); items.Add(item); } return(items.Count > 0 ? TradeResult.Success(items) : TradeResult.None()); }
private TradeResult MakeMatch(AskOrder ask, List <BidOrder> bids) { bids = bids.OrderByDescending(e => e.Price).ThenBy(e => e.Date).ToList(); var items = new List <TradeLog>(); foreach (var bid in bids) { if (ask.Remain() == 0) { break; } var item = MakeMatch(bid, ask); items.Add(item); } return(items.Count > 0 ? TradeResult.Success(items) : TradeResult.None()); }
public TradeResult Do() { TradeOrder order; if (TradeQueue.Instance.TryDequeue(out order)) { var result = MakeMacth(order); //如果交易未完成,则重新加入待交易队列 if (order.Remain() > 0) { TradeQueue.Instance.Add(order); } return(result); } else { TradeLogger.Instance.Update(); } return(TradeResult.None()); }