Beispiel #1
0
        //获取主账户最大可下单数量
        public static int GetAccountCount(Order order)
        {
            Account account = AccountRA.Get("A_" + order.account_id);

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

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

            if (order.type_enum == OrderTypeEnum.Buy)
            {
                decimal count = account.capital_initial / order.price;
                if (account.limit_ratio_single > 0)
                {
                    count = Math.Min(count, account.capital_initial * account.limit_ratio_single / order.price);
                }

                BlockInfo block = StockInfoBiz.GetBlock(order.code);
                if (block.block_type_enum == BlockEnum.gem)
                {
                    if (account.limit_ratio_gem_single > 0)
                    {
                        count = Math.Min(count, account.capital_initial * account.limit_ratio_gem_single / order.price);
                    }
                    if (account.limit_ratio_gem_total > 0)
                    {
                        count = Math.Min(count, (account.capital_initial * account.limit_ratio_gem_total - account.capital_stock_value_gem) / order.price);
                    }
                }

                string[]         keys = TradeRA.KeySearch("G_*_U_" + order.unit_id + "_A_" + order.account_id);
                AccountGroupItem item = AccountGroupRA.Get(keys[0]);
                if (item.capital_available > 0)
                {
                    count = Math.Min(count, (item.capital_available - item.capital_stock_value) / order.price);
                }
                return((int)Math.Ceiling(count / 100) * 100);
            }
            else
            {
                return(PositionRA.GetSellable(order.unit_id, order.code, order.account_id));
            }
        }
Beispiel #2
0
        //检查主账户是否满足下单条件
        public static ApiResultEnum CheckAccount(Order order)
        {
            Account account = AccountRA.Get("A_" + order.account_id);

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

            if (account.status_enum == StatusEnum.Forbidden)
            {
                return(ApiResultEnum.Order_Account_Forbidden);
            }
            if (account.status_order_enum == StatusOrderEnum.Forbidden)
            {
                return(ApiResultEnum.Order_Account_Forbidden_Order);
            }
            if (order.type_enum == OrderTypeEnum.Buy && account.status_order_enum == StatusOrderEnum.NoBuying)
            {
                return(ApiResultEnum.Order_Account_NoBuying_Order);
            }

            if (order.type_enum == OrderTypeEnum.Buy)
            {
                if (account.limit_ratio_single > 0 && order.price * order.count > account.capital_initial * account.limit_ratio_single)
                {
                    return(ApiResultEnum.Order_Account_Limit_Single);
                }

                BlockInfo block = StockInfoBiz.GetBlock(order.code);
                if (block.block_type_enum == BlockEnum.gem)
                {
                    if (account.limit_ratio_gem_single > 0 && order.price * order.count > account.capital_initial * account.limit_ratio_gem_single)
                    {
                        return(ApiResultEnum.Order_Account_Limit_GEM_Single);
                    }
                    if (account.limit_ratio_gem_total > 0 && order.price * order.count + account.capital_stock_value_gem > account.capital_initial * account.limit_ratio_gem_total)
                    {
                        return(ApiResultEnum.Order_Account_Limit_GEM_Total);
                    }
                }

                string[]         keys = TradeRA.KeySearch("G_*_U_" + order.unit_id + "_A_" + order.account_id);
                AccountGroupItem item = AccountGroupRA.Get(keys[0]);
                if (item.capital_available > 0 && item.capital_available < order.price * order.count + item.capital_stock_value)
                {
                    return(ApiResultEnum.Order_Account_Negative_Amount);
                }
            }
            else
            {
                if (PositionRA.GetSellable(order.unit_id, order.code, order.account_id) < order.count)
                {
                    return(ApiResultEnum.Order_Account_Negative_Position);
                }
            }

            //风控通过进行冻结
            if (order.type_enum == OrderTypeEnum.Buy)
            {
                string key_unit = "U_" + order.unit_id;
                UnitRA.UpdateCapitalOrderBuy(order.price * order.count, key_unit);
            }
            else if (order.type_enum == OrderTypeEnum.Sell)
            {
                string key_position = "P_" + order.code + "_A_" + order.account_id + "_U_" + order.unit_id;
                PositionRA.UpdateSellableOrderSell(-order.count, key_position);
            }
            return(ApiResultEnum.Success);
        }