コード例 #1
0
        public static void LoadAccountGroupItem(AccountGroupItem item)
        {
            string key = "G_" + item.account_group_id + "_U_" + item.unit_id + "_A_" + item.account_id;

            if (TradeRA.KeyExists(key))
            {
                return;
            }

            AccountGroupRA.Add(item, key);
        }
コード例 #2
0
        public static void LoadPosition(Position position)
        {
            string key = "P_" + position.code + "_A_" + position.account_id + "_U_" + position.unit_id;

            if (TradeRA.KeyExists(key))
            {
                return;
            }

            position.count_sellable = position.count;
            PositionRA.Add(position, key);
        }
コード例 #3
0
        private void JY_NewDeal(object sender, DealItem e)
        {
            Order order   = null;
            int   unit_id = 0;

            string[] keys = TradeRA.KeySearch("O_" + e.order_no + "_*");
            if (keys.Length > 0)
            {
                order   = OrderRA.Get(keys[0]);
                unit_id = order.unit_id;
            }

            string key = "D_" + e.deal_no + "_O_" + e.order_no + "_U_" + unit_id;

            if (TradeRA.KeyExists(key))
            {
                return;
            }

            Deal deal = new Deal()
            {
                code        = e.code,
                name        = e.name,
                type        = int.Parse(e.type),
                count       = (int)decimal.Parse(e.count),
                money       = decimal.Parse(e.money),
                time_dt     = DateTime.Parse(e.date.ToDate() + " " + e.time.ToTime()),
                deal_no     = e.deal_no,
                order_no    = e.order_no,
                price       = decimal.Parse(e.price),
                unit_id     = unit_id,
                account_id  = account_id,
                transferred = unit_id > 0 ? 0 : 1,
            };

            DealRA.Add(deal, key);

            //更新成交均价
            DealAveragePrice(deal);

            //系统内成交
            if (unit_id > 0)
            {
                MessageBiz.Send(order.user_id.ToString(), MessageTypeEnum.Order_Dealt, "[" + deal.code + "]" + deal.name + "已成交,成交数量:" + deal.count);
                TradeBiz.NewDeal(deal, order.price);
                MonitorRA.Increment("account_" + account_id, "deal_count");
            }
        }
コード例 #4
0
        public static void LoadUnit(Unit unit, bool add = true)
        {
            string key = "U_" + unit.id;

            if (add && TradeRA.KeyExists(key))
            {
                return;
            }

            if (add)
            {
                UnitRA.Add(unit, key);
            }
            else
            {
                UnitRA.Update(unit, key);
            }
        }
コード例 #5
0
        public static void LoadAccount(Account account, bool add = true)
        {
            TradeBiz.LoadAccount(account);

            string key = "A_" + account.id;

            if (add && TradeRA.KeyExists(key))
            {
                return;
            }

            if (add)
            {
                AccountRA.Add(account, key);
            }
            else
            {
                AccountRA.Update(account, key);
            }
        }
コード例 #6
0
        public Result Transfer(Transfer model)
        {
            string[] keys = TradeRA.KeySearch("D_" + model.deal_no + "_*_U_0");
            if (keys.Length > 0 && TradeRA.KeyExists("U_" + model.unit_id))
            {
                Deal deal = DealRA.Get(keys[0]);
                if (deal.type_enum == OrderTypeEnum.Sell)
                {
                    int sellable_count = PositionRA.GetSellable(model.unit_id, deal.code, deal.account_id);
                    if (deal.count > sellable_count)
                    {
                        return(Result(ApiResultEnum.Order_Account_Negative_Position));
                    }
                }

                deal.unit_id = model.unit_id;
                DealRA.UpdateUnit(model.unit_id, keys[0]);
                TradeRA.KeyRename(keys[0], keys[0].Substring(0, keys[0].Length - 1) + model.unit_id);
                TradeBiz.NewDeal(deal, deal.price, 1);
                return(Result(ApiResultEnum.Success));
            }
            return(Result(ApiResultEnum.Failed));
        }