Esempio n. 1
0
        //检查单元是否满足下单条件
        public static ApiResultEnum CheckUnit(Order order)
        {
            Unit unit = UnitRA.Get("U_" + order.unit_id);

            if (unit == null || unit.user_id != order.user_id)
            {
                return(ApiResultEnum.Order_Unit_Null);
            }

            if (order.type_enum == OrderTypeEnum.Buy && !string.IsNullOrWhiteSpace(unit.limit_no_buying) && unit.limit_no_buying.Contains(order.code))
            {
                return(ApiResultEnum.Order_Unit_NoBuying_Code);
            }

            if (unit.status_enum == StatusEnum.Forbidden)
            {
                return(ApiResultEnum.Order_Unit_Forbidden);
            }
            if (unit.status_order_enum == StatusOrderEnum.Forbidden)
            {
                return(ApiResultEnum.Order_Unit_Forbidden_Order);
            }
            if (order.type_enum == OrderTypeEnum.Buy && unit.status_order_enum == StatusOrderEnum.NoBuying)
            {
                return(ApiResultEnum.Order_Unit_NoBuying_Order);
            }

            string[] keys = TradeRA.KeySearch("P_" + order.code + "_A_*_U_" + order.unit_id);
            if (unit.limit_stock_count > 0)
            {
                if (PositionRA.GetCodeCount(order.unit_id, order.code) > unit.limit_stock_count)
                {
                    return(ApiResultEnum.Order_Unit_Limit_Count);
                }
            }

            if (unit.limit_order_price_enum == OrderPriceLimitEnum.In5LeverPrice)
            {
                decimal price_min = DataBiz.GetPriceByPriceType(order.code, OrderPriceEnum.Buy5);
                decimal price_max = DataBiz.GetPriceByPriceType(order.code, OrderPriceEnum.Sell5);
                if (order.price < price_min || order.price > price_max)
                {
                    return(ApiResultEnum.Order_Unit_Limit_Price);
                }
            }

            if (order.type_enum == OrderTypeEnum.Buy)
            {
                if (unit.capital_available < order.price * order.count)
                {
                    return(ApiResultEnum.Order_Unit_Negative_Amount);
                }

                BlockInfo block = StockInfoBiz.GetBlock(order.code);
                if (block.block_type_enum == BlockEnum.mbm)
                {
                    if (unit.limit_ratio_mbm_single > 0 && order.price * order.count > unit.capital_scale * unit.limit_ratio_mbm_single)
                    {
                        return(ApiResultEnum.Order_Unit_Limit_MBM_Single);
                    }
                }
                else if (block.block_type_enum == BlockEnum.gem)
                {
                    if (unit.limit_ratio_gem_single > 0 && order.price * order.count > unit.capital_scale * unit.limit_ratio_gem_single)
                    {
                        return(ApiResultEnum.Order_Unit_Limit_GEM_Single);
                    }
                    if (unit.limit_ratio_gem_total > 0 && order.price * order.count + unit.capital_stock_value_gem > unit.capital_scale * unit.limit_ratio_gem_total)
                    {
                        return(ApiResultEnum.Order_Unit_Limit_GEM_Total);
                    }
                }
                else if (block.block_type_enum == BlockEnum.sme)
                {
                    if (unit.limit_ratio_sme_single > 0 && order.price * order.count > unit.capital_scale * unit.limit_ratio_sme_single)
                    {
                        return(ApiResultEnum.Order_Unit_Limit_SME_Single);
                    }
                    if (unit.limit_ratio_sme_total > 0 && order.price * order.count + unit.capital_stock_value_sme > unit.capital_scale * unit.limit_ratio_sme_total)
                    {
                        return(ApiResultEnum.Order_Unit_Limit_SME_Total);
                    }
                }
                else if (block.block_type_enum == BlockEnum.star)
                {
                    if (unit.limit_ratio_star_single > 0 && order.price * order.count > unit.capital_scale * unit.limit_ratio_star_single)
                    {
                        return(ApiResultEnum.Order_Unit_Limit_STAR_Single);
                    }
                    if (unit.limit_ratio_star_total > 0 && order.price * order.count + unit.capital_stock_value_star > unit.capital_scale * unit.limit_ratio_star_total)
                    {
                        return(ApiResultEnum.Order_Unit_Limit_STAR_Total);
                    }
                }
                if (block.block_type_enum == BlockEnum.sme || block.block_type_enum == BlockEnum.gem)
                {
                    if (unit.limit_ratio_smg_total > 0 && order.price * order.count + unit.capital_stock_value_sme + unit.capital_stock_value_gem > unit.capital_scale * unit.limit_ratio_smg_total)
                    {
                        return(ApiResultEnum.Order_Unit_Limit_SMG_Total);
                    }
                }
            }
            else
            {
                if (PositionRA.GetSellable(order.unit_id, order.code) < order.count)
                {
                    return(ApiResultEnum.Order_Unit_Negative_Position);
                }
            }
            return(ApiResultEnum.Success);
        }
Esempio n. 2
0
        //获取单元最大可下单数量
        public static int GetUnitCount(Order order)
        {
            Unit unit = UnitRA.Get("U_" + order.unit_id);

            if (unit == null)
            {
                return(0);
            }

            if (order.type_enum == OrderTypeEnum.Buy && !string.IsNullOrWhiteSpace(unit.limit_no_buying) && unit.limit_no_buying.Contains(order.code))
            {
                return(0);
            }

            if (unit.status_enum == StatusEnum.Forbidden)
            {
                return(0);
            }
            if (unit.status_order_enum == StatusOrderEnum.Forbidden)
            {
                return(0);
            }
            if (order.type_enum == OrderTypeEnum.Buy && unit.status_order_enum == StatusOrderEnum.NoBuying)
            {
                return(0);
            }

            string[] keys = TradeRA.KeySearch("P_" + order.code + "_A_*_U_" + order.unit_id);
            if (unit.limit_stock_count > 0)
            {
                if (PositionRA.GetCodeCount(order.unit_id, order.code) > unit.limit_stock_count)
                {
                    return(0);
                }
            }

            if (order.type_enum == OrderTypeEnum.Buy)
            {
                decimal   count = unit.capital_available / order.price;
                BlockInfo block = StockInfoBiz.GetBlock(order.code);
                if (block.block_type_enum == BlockEnum.mbm)
                {
                    if (unit.limit_ratio_mbm_single > 0)
                    {
                        count = Math.Min(count, unit.capital_scale * unit.limit_ratio_mbm_single / order.price);
                    }
                }
                else if (block.block_type_enum == BlockEnum.gem)
                {
                    if (unit.limit_ratio_gem_single > 0)
                    {
                        count = Math.Min(count, unit.capital_scale * unit.limit_ratio_gem_single / order.price);
                    }
                    if (unit.limit_ratio_gem_total > 0)
                    {
                        count = Math.Min(count, (unit.capital_scale * unit.limit_ratio_gem_total - unit.capital_stock_value_gem) / order.price);
                    }
                }
                else if (block.block_type_enum == BlockEnum.sme)
                {
                    if (unit.limit_ratio_sme_single > 0)
                    {
                        count = Math.Min(count, unit.capital_scale * unit.limit_ratio_sme_single / order.price);
                    }
                    if (unit.limit_ratio_sme_total > 0)
                    {
                        count = Math.Min(count, (unit.capital_scale * unit.limit_ratio_sme_total - unit.capital_stock_value_sme) / order.price);
                    }
                }
                else if (block.block_type_enum == BlockEnum.star)
                {
                    if (unit.limit_ratio_star_single > 0)
                    {
                        count = Math.Min(count, unit.capital_scale * unit.limit_ratio_star_single / order.price);
                    }
                    if (unit.limit_ratio_star_total > 0)
                    {
                        count = Math.Min(count, (unit.capital_scale * unit.limit_ratio_star_total - unit.capital_stock_value_star) / order.price);
                    }
                }
                if (block.block_type_enum == BlockEnum.sme || block.block_type_enum == BlockEnum.gem)
                {
                    if (unit.limit_ratio_smg_total > 0)
                    {
                        count = Math.Min(count, (unit.capital_scale * unit.limit_ratio_smg_total - unit.capital_stock_value_sme - unit.capital_stock_value_gem) / order.price);
                    }
                }
                return((int)Math.Ceiling(count / 100) * 100);
            }
            else
            {
                return(PositionRA.GetSellable(order.unit_id, order.code));
            }
        }