Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        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());
        }
Esempio n. 3
0
        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());
        }