Beispiel #1
0
 public static void UpdateStrategy(BaseStrategy stg)
 {
     loadStrategy();
     using (MyDbContext ctx = new MyDbContext()) {
         T_Strategy tStg;
         if (!mStgDic.TryGetValue(stg.GetType().FullName, out tStg))
         {
             tStg           = new T_Strategy();
             tStg.Name      = stg.Name;
             tStg.ClassName = stg.GetType().FullName;
             tStg.Enable    = stg.Enable;
             ctx.Strategys.Add(tStg);
             mStgDic[tStg.ClassName] = tStg;
         }
         tStg.Enable = stg.Enable;
         ctx.SaveChanges();
     }
 }
Beispiel #2
0
        //position
        public static void UpdatePosition(StrategyPosition pos)
        {
            T_Strategy stg = mStgDic[pos.Strategy.GetType().FullName];

            using (MyDbContext ctx = new MyDbContext()) {
                T_Position tp = (from p in stg.Positions
                                 where p.InstrumentID == pos.Instrument.InstrumentID
                                 select p).First();
                if (tp == null)
                {
                    tp = new T_Position();
                    tp.InstrumentID = pos.Instrument.InstrumentID;
                    tp.Strategy     = stg;
                    stg.Positions.Add(tp);
                }
                tp.Position = pos.Vol;
                tp.LastTime = DateTime.Now;
                ctx.SaveChanges();
            }
        }
Beispiel #3
0
        //order
        public static void UpdateOrder(Order order)
        {
            T_Strategy stg = mStgDic[order.Strategy.GetType().FullName];

            using (MyDbContext ctx = new MyDbContext()) {
                T_Order to = (from o in stg.Orders
                              where o.OrderId == order.OrderId
                              select o).First();
                if (to == null)
                {
                    to              = new T_Order();
                    to.Direction    = order.Direction.ToString();
                    to.InstrumentID = order.Instrument.InstrumentID;
                    to.OrderId      = order.OrderId;
                    to.OrderTime    = order.OrderTime;
                    to.Price        = order.Price;
                    to.Strategy     = stg;
                    to.Volume       = order.Qty;
                    stg.Orders.Add(to);
                }
                to.VolumeTraded = order.QtyTraded;
                ctx.SaveChanges();
            }
        }