Exemple #1
0
        public Result <List <Position> > ListPosition(int unit_id)
        {
            IEnumerable <Position> list = PositionRA.List4Unit(unit_id);

            DataBiz.PositionMerge(ref list);
            return(Result(list.ToList()));
        }
Exemple #2
0
 public static void RunUnitCapitalMonitor()
 {
     string[] keys = TradeRA.KeySearch("U_*");
     foreach (string key in keys)
     {
         Unit unit = UnitRA.Get(key);
         if (unit.user_id > 0 && unit.ratio_warning > 0)
         {
             if (unit.capital_total < unit.ratio_warning * unit.capital_scale && unit.status_order_enum == StatusOrderEnum.Allowed)
             {
                 StatusOrder model = new StatusOrder(unit.id, StatusOrderEnum.NoBuying);
                 UnitDA.UpdateStatusOrder(model);
                 UnitRA.UpdateStatusOrder(model.status, "U_" + model.id);
                 UserDA.ListParents(unit.user_id).ForEach(user_id =>
                 {
                     MessageBiz.Send(user_id.ToString(), MessageTypeEnum.Unit_Warning, "单元[" + unit.code + "]资产已低于预警线,被禁止买入");
                 });
                 NLog.Info(string.Format("单元[{0}]资产已低于预警线,被禁止买入。总资产:{1}", unit.code, unit.capital_total));
             }
             else if (unit.capital_total > unit.ratio_warning * unit.capital_scale && unit.status_order_enum == StatusOrderEnum.NoBuying)
             {
                 StatusOrder model = new StatusOrder(unit.id, StatusOrderEnum.Allowed);
                 UnitDA.UpdateStatusOrder(model);
                 UnitRA.UpdateStatusOrder(model.status, "U_" + model.id);
                 MessageBiz.Send(unit.user_id.ToString(), MessageTypeEnum.Unit_Recovery, "单元[" + unit.code + "]资产已高于预警线,恢复交易");
             }
         }
         if (unit.user_id > 0 && unit.ratio_close_position > 0 && unit.capital_total < unit.ratio_close_position * unit.capital_scale)
         {
             List <Position> list = PositionRA.List4Unit(unit.id).Where(p => p.count_sellable > 0).ToList();
             if (list.Count > 0)
             {
                 list.ForEach(p =>
                 {
                     Order order = new Order()
                     {
                         code      = p.code,
                         count     = p.count_sellable,
                         type_enum = OrderTypeEnum.Sell,
                         unit_id   = unit.id,
                         price     = DataBiz.GetPriceByPriceType(p.code, OrderPriceEnum.Buy5),
                         user_id   = 1,
                         platform  = 1
                     };
                     Order(order);
                 });
                 UserDA.ListParents(unit.user_id).ForEach(user_id =>
                 {
                     MessageBiz.Send(unit.id.ToString(), MessageTypeEnum.Unit_Close_Position, "单元[" + unit.code + "]资产已低于平仓线,被强制平仓");
                 });
                 NLog.Info(string.Format("单元[{0}]资产已低于平仓线,被强制平仓。总资产:{1}", unit.code, unit.capital_total));
             }
         }
     }
 }
Exemple #3
0
        public Result <List <Position> > ListPositionDetailed(int unit_id)
        {
            IEnumerable <Position> list = PositionRA.List4Unit(unit_id);

            return(Result(list.ToList()));
        }