コード例 #1
0
ファイル: Trade.svc.cs プロジェクト: wshPrt/trading
        public Result OrderAutoUpdate(OrderAutoUpdate model)
        {
            if (model.count_min > model.count_max || model.price_min > model.price_max || model.time_min > model.time_max)
            {
                return(Result(ApiResultEnum.Parameter_Error));
            }

            bool result = OrderAutoRA.Update(model);

            return(Result(result ? ApiResultEnum.Success : ApiResultEnum.NO_Action));
        }
コード例 #2
0
ファイル: Trade.svc.cs プロジェクト: wshPrt/trading
        public Result <long> OrderAutoAdd(OrderAutoAdd model)
        {
            if (model.count_min > model.count_max || model.price_min > model.price_max || model.time_min > model.time_max)
            {
                return(Result(ApiResultEnum.Parameter_Error, 0L));
            }

            HQItem hq    = HQService.Get(model.code);
            Order  order = new Order()
            {
                user_id  = user_id,
                unit_id  = model.unit_id,
                code     = model.code,
                price    = hq.Last,
                count    = model.count_total,
                type     = model.type,
                platform = platform
            };

            ApiResultEnum result = LimitBiz.CheckStatus(order);

            if (result != ApiResultEnum.Success)
            {
                return(Result(result, 0L));
            }
            result = LimitBiz.CheckUnit(order);
            if (result != ApiResultEnum.Success)
            {
                return(Result(result, 0L));
            }

            model.name     = StockInfoBiz.GetStock(model.code).name;
            model.id       = FuncHelper.GetUniqueID();
            model.user_id  = user_id;
            model.platform = platform;
            if (model.account_id > 0)
            {
                model.account_name = AccountRA.GetName(model.account_id);
            }
            else
            {
                model.account_name = "";
            }
            string key = "S_" + model.id + "_U_" + model.unit_id + "_D_0";

            OrderAutoRA.Add(model, key);
            return(Result(ApiResultEnum.Success, model.id));
        }
コード例 #3
0
ファイル: Trade.svc.cs プロジェクト: wshPrt/trading
        public Result OrderAutoUpdateStatus(StatusAutoOrder model)
        {
            if (model.status != StatusAutoOrderEnum.Run && model.status != StatusAutoOrderEnum.Pause)
            {
                return(Result(ApiResultEnum.Parameter_Error));
            }

            string[] keys = TradeRA.KeySearch("S_" + model.id + "_*_D_0");
            if (keys.Length == 0)
            {
                return(Result(ApiResultEnum.NO_Action));
            }

            OrderAutoRA.UpdateStatus(model.status, user_id, keys[0]);
            return(Result(ApiResultEnum.Success));
        }
コード例 #4
0
        public static void RunOrderAuto()
        {
            List <OrderAuto> orders = OrderAutoRA.List4Undone();

            foreach (OrderAuto orderAuto in orders)
            {
                if (orderAuto.status_enum != StatusAutoOrderEnum.Run)
                {
                    continue;
                }
                if (orderAuto.time_next_dt > DateTime.Now)
                {
                    continue;
                }

                string key    = "S_" + orderAuto.id + "_U_" + orderAuto.unit_id + "_D_0";
                Random random = new Random();
                Order  order  = new Order()
                {
                    code       = orderAuto.code,
                    type       = orderAuto.type,
                    unit_id    = orderAuto.unit_id,
                    account_id = orderAuto.account_id,
                    user_id    = orderAuto.user_id,
                    platform   = orderAuto.platform
                };
                order.count            = orderAuto.count_total - orderAuto.order_count;
                orderAuto.time_next_dt = DateTime.MinValue;
                if (order.count > orderAuto.count_max)
                {
                    order.count            = random.Next(orderAuto.count_min / 100, orderAuto.count_max / 100) * 100;
                    orderAuto.time_next_dt = DateTime.Now.AddSeconds(random.Next(orderAuto.time_min, orderAuto.time_max));
                }
                if (orderAuto.time_next_dt >= time_pause && orderAuto.time_next_dt <= time_recovery)
                {
                    orderAuto.time_next_dt = orderAuto.time_next_dt.AddMinutes(90);
                }
                if (orderAuto.time_next_dt >= time_close)
                {
                    OrderAutoRA.UpdateStatus(StatusAutoOrderEnum.Stop, 1, key);
                    continue;
                }
                order.price = DataBiz.GetPriceByPriceType(orderAuto.code, orderAuto.price_type_enum);
                if (order.price < orderAuto.price_min)
                {
                    order.price = orderAuto.price_min;
                }
                else if (order.price > orderAuto.price_max)
                {
                    order.price = orderAuto.price_max;
                }

                ApiResultEnum result = Order(order.Clone() as Order);

                orderAuto.result_prev = new Model.Return.Return(result).Message;
                orderAuto.order_times++;
                orderAuto.order_count += order.count;
                orderAuto.time_prev_dt = DateTime.Now;
                OrderAutoRA.UpdateExecuted(orderAuto, order, key);
            }
        }
コード例 #5
0
ファイル: Trade.svc.cs プロジェクト: wshPrt/trading
        public Result OrderAutoDelete(OrderAutoUpdate model)
        {
            bool result = OrderAutoRA.Delete(model);

            return(Result(result ? ApiResultEnum.Success : ApiResultEnum.Failed));
        }
コード例 #6
0
ファイル: Trade.svc.cs プロジェクト: wshPrt/trading
        public Result <List <OrderAuto> > ListOrderAuto(int unit_id)
        {
            List <OrderAuto> orderAutos = OrderAutoRA.List4Unit(unit_id);

            return(Result(orderAutos));
        }