Beispiel #1
0
 public static void UpdatePosition(QuikConnectionManager.Position obj)
 {
     if (Positions.Any(k => k.AccountName == obj.AccountName && k.Instrument.Code == obj.SecurityCode))
     {
         Entities.Position p = Positions.First(k => k.AccountName == obj.AccountName && k.Instrument.Code == obj.SecurityCode);
         p.Update(obj.TotalNet, obj.BuyQty, obj.SellQty, obj.VarMargin);
         //p.TotalNet = obj.TotalNet;
         //p.BuyQty = obj.BuyQty;
         //p.SellQty = obj.SellQty;
         //p.VM = obj.VarMargin;
     }
     else
     {
         log.Warn("Update on unknown position {0} {1}", obj.AccountName, obj.SecurityCode);
     }
     // update portfolio
     try
     {
         Entities.Instrument i    = Instruments.First(k => k.Code == obj.SecurityCode);
         string             basec = i.Type == Entities.InstrumentType.Futures? i.Code:i.BaseContract;
         Entities.Portfolio p     = Portfolios.First(k => k.Account == obj.AccountName && k.BaseCode == basec);
         Entities.Position  pos   = p.Positions.First(k => k.AccountName == obj.AccountName && k.Instrument.Code == obj.SecurityCode);
         pos.Update(obj.TotalNet, obj.BuyQty, obj.SellQty, obj.VarMargin);
         //pos.TotalNet=obj.TotalNet;
         //pos.VM = obj.VarMargin;
         //pos.BuyQty = obj.BuyQty;
         //pos.SellQty = obj.SellQty;
     }
     catch { log.Warn("Can`t find portfolio for position update!"); }
 }
Beispiel #2
0
 public static void AddPosition(QuikConnectionManager.Position obj)
 {
     if (!Positions.Any(k => k.AccountName == obj.AccountName && k.Instrument.Code == obj.SecurityCode))
     {
         Entities.Instrument instr;
         if (obj.AccountName == "FOUXK_001")
         {
             Console.Write("fnfyng");
         }
         try
         {
             instr = Instruments.First(k => k.Code == obj.SecurityCode);
             var pos = new Entities.Position(obj.AccountName, instr, obj.TotalNet, obj.BuyQty, obj.SellQty, obj.VarMargin);
             Positions.Add(pos);
             log.Info("New position added. SecCode={0} Account={1}", obj.SecurityCode, obj.AccountName);
             if (pos.Instrument.Type == Entities.InstrumentType.Futures)
             {
                 if (Portfolios.Any(k => k.BaseCode == pos.Instrument.Code && k.Account == pos.AccountName))
                 {
                     Portfolios.First(k => k.BaseCode == pos.Instrument.Code && k.Account == pos.AccountName).Positions.Add(pos);
                     log.Info("Futures Position added to existing portfolio.");
                 }
                 else
                 {   // create new portfolio
                     Entities.Portfolio port = new Entities.Portfolio(pos.Instrument.Code, pos.AccountName);
                     port.Positions.Add(pos);
                     Portfolios.Add(port);
                     log.Info("New portfolio created. Name={0} Base={1} Account={2}", port.Name, port.BaseCode, port.Account);
                 }
             }
             else if (pos.Instrument.Type == Entities.InstrumentType.Option)
             {
                 if (Portfolios.Any(k => k.BaseCode == pos.Instrument.BaseContract && k.Account == pos.AccountName))
                 {
                     Portfolios.First(k => k.BaseCode == pos.Instrument.BaseContract && k.Account == pos.AccountName).Positions.Add(pos);
                     log.Info("Option Position added to existing portfolio.");
                 }
                 else
                 {   // create new portfolio
                     Entities.Portfolio port = new Entities.Portfolio(pos.Instrument.BaseContract, pos.AccountName);
                     port.Positions.Add(pos);
                     Portfolios.Add(port);
                     log.Info("New portfolio created. Name={0} Base={1} Account={2}", port.Name, port.BaseCode, port.Account);
                 }
             }
         }
         catch (SystemException exep)
         {
             log.Error("Try to add position for unknown instrument {0} {1} {2}", obj.SecurityCode, obj.AccountName, obj.TotalNet);
             log.Error(exep.Message);
         }
     }
     else
     {
         log.Warn("Try to add existing position. {0} {1}", obj.AccountName, obj.SecurityCode);
     }
 }