Ejemplo n.º 1
0
        public void Flush()
        {
            if (IsStopped)
            {
                return;
            }

            IsStopped = true;

            Thread.Sleep(30 * 1000);

            Model.Flush();

            FlushOrder fo = new FlushOrder();

            fo.Flush((sb, nk) =>
            {
                foreach (var v in Matcher.Container.Orders.Values)
                {
                    foreach (var s in v.BuyQueue)
                    {
                        if (s.State == OrderState.部分成交 || s.State == OrderState.等待中)
                        {
                            fo.FlushTempOrder(sb, s, nk);
                        }
                    }
                    foreach (var b in v.SellQueue)
                    {
                        if (b.State == OrderState.部分成交 || b.State == OrderState.等待中)
                        {
                            fo.FlushTempOrder(sb, b, nk);
                        }
                    }
                }
            });
            Singleton <TextLog> .Instance.Info("期权交易系统成功停止");

            log.Flush();
        }
Ejemplo n.º 2
0
        void RestoreUndealOrders(Dictionary <int, Order> od,
                                 Dictionary <int, Trader> td, Dictionary <int, Contract> cond)
        {
            FlushOrder fo = new FlushOrder();

            var k = fo.GetOldGeneration();

            if (k == null)
            {
                return;
            }
            string f = @"select * from temporders where 
id in(
select id from TempOrders where
 detail='{0}'  except select id from Orders)";

            string sql = string.Format(f, (int)k);

            using (var db = new OptionDbCtx())
            {
                var q = db.Database.SqlQuery <Order>(sql);
                foreach (var v in q)
                {
                    if (!cond.ContainsKey(v.ContractId))
                    {
                        continue;
                    }
                    if (!td.ContainsKey(v.TraderId))
                    {
                        continue;
                    }
                    var o = new Order
                    {
                        Id             = v.Id,
                        State          = v.State,
                        Count          = v.Count,
                        Contract       = cond[v.ContractId],
                        Direction      = v.Direction,
                        DoneCount      = v.DoneCount,
                        OrderPolicy    = v.OrderPolicy,
                        OrderTime      = v.OrderTime,
                        OrderType      = v.OrderType,
                        Price          = v.Price,
                        RequestStatus  = v.RequestStatus,
                        Trader         = td[v.TraderId],
                        TraderId       = v.TraderId,
                        ContractId     = v.ContractId,
                        Detail         = v.Detail,
                        DonePrice      = v.DonePrice,
                        IsBySystem     = v.IsBySystem,
                        ReportCount    = v.ReportCount,
                        TotalDoneCount = v.TotalDoneCount,
                        TotalDoneSum   = v.TotalDoneSum,
                    };
                    if (o.State == OrderState.部分成交 || o.State == OrderState.等待中)
                    {
                        if (!o.IsBySystem)
                        {
                            legcy.Add(o);
                            od.Add(v.Id, o);
                            o.Trader.Orders().Add(o);
                        }
                    }
                }
            }
        }