コード例 #1
0
        private static IEnumerable<UnOrders> CreateBestTradeList(Stock.StockTradeInfo item)
        {
            // 依照買價、買量、賣價、賣量順序,將這四個列舉物件組成一個為四種屬性的臨時類別
            var bidPairs = item.GetBestBidPrices().Zip(item.GetBestBidVolumes(), (bidPrice, bidVolume) => new Tuple<float, int>(bidPrice, bidVolume));
            var askPairs = item.GetBestAskPrices().Zip(item.GetBestAskVolumes(), (askPrice, askVolume) => new Tuple<float, int>(askPrice, askVolume));
            var bidAskParis = bidPairs.Zip(askPairs, (bid, ask) => new Tuple<float, int, float, int>(bid.Item1, bid.Item2, ask.Item1, ask.Item2));

            // 將最佳五檔附加於該成交明細上
            return bidAskParis.Select(bidAsk => new UnOrders()
                {
                    TradeID = item.TradeID,
                    BestBidPrice = bidAsk.Item1,
                    BestBidVolume = bidAsk.Item2,
                    BestAskPrice = bidAsk.Item3,
                    BestAskVolume = bidAsk.Item4
                });
        }