Beispiel #1
0
        /// <summary>
        /// 更新失败记录
        /// </summary>
        /// <param name="key"></param>
        /// <param name="Err"></param>
        public void MarkFailure(int OrderRef, String Err)
        {
            RecordItem _record = new RecordItem();


            _record        = this.GetOrAdd(OrderRef, _record);
            _record.ErrMsg = Err;
            _record.Status = TradeDealStatus.ORDERFAILURE;

            _record.OrderStatus = 77; //委托失败特定返回码

            this.AddOrUpdate(OrderRef, _record, (key, oldValue) =>
                             oldValue = _record
                             );

            CompletedTradeRecord.GetInstance().Update(_record.OrderRef, _record);
        }
Beispiel #2
0
        /// <summary>
        /// 更新成交信息
        /// </summary>
        /// <param name="OrderRef">交易委托本地索引</param>
        /// <param name="Volume">成交量</param>
        /// <param name="Price">成交价格</param>
        /// <param name="TradeId">成交编号</param>
        public void UpdateTrade(int OrderRef, int Volume, decimal Price, String TradeId)
        {
            RecordItem _record = new RecordItem();

            _record = this.GetOrAdd(OrderRef, _record);

            if (_record.Trades == null)
            {
                _record.Trades = new List <TradeItem>();
            }

            _record.Trades.Add(new TradeItem()
            {
                TradeID = TradeId,
                Price   = Price,
                Volume  = Volume
            });

            decimal totalVolume = 0;
            decimal totalCost   = 0;

            foreach (TradeItem item in _record.Trades)
            {
                totalVolume += item.Volume;
                totalCost   += (item.Volume * item.Price);
            }

            _record.AveragePrice = (totalCost / totalVolume);

            String        UserName = UserRequestMap.GetInstance()[OrderRef];
            TradeViewItem trade    = new TradeViewItem(OrderRef.ToString(), TradeId, _record.Code, _record.Orientation, _record.CombOffsetFlag.ToString(), Price.ToString(), Volume.ToString(), _record.OrderSysID);

            String JsonString = JsonConvert.SerializeObject(trade);

            //TradeMonitor.Instance.updateTradeList(UserName, JsonString); 不从这里收集成交信息,直接从数据库中同步

            this.AddOrUpdate(OrderRef, _record, (key, oldValue) =>
                             oldValue = _record
                             );

            if (_record.Status == TradeDealStatus.ORDERCOMPLETED || _record.VolumeTotalOriginal == totalVolume)
            {
                CompletedTradeRecord.GetInstance().Update(_record.OrderRef, _record);
                CompletedTradeRecord.GetInstance().Delete(_record.OrderRef, _record);

                managedBargainreturnstruct bargin = new managedBargainreturnstruct()
                {
                    Security_code = _record.Code,
                    OrderType     = Convert.ToSByte(_record.Type),
                    stock_amount  = _record.VolumeTraded,
                    bargain_price = Convert.ToDouble(Price),
                    User          = _record.User,
                    offsetflag    = _record.CombOffsetFlag,
                    direction     = (_record.Orientation == "0") ? 48 : 49
                };

                //更新持仓列表
                ThreadPool.QueueUserWorkItem(new WaitCallback(DBAccessLayer.UpdateCCRecords), (object)bargin);

                //删除委托信息
                ThreadPool.QueueUserWorkItem(new WaitCallback(DBAccessLayer.DeleteERRecord), (object)OrderRef);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 更新委托信息
        /// </summary>
        /// <param name="volumeTraded"></param>
        /// <param name="OrderRef"></param>
        /// <param name="OrderSysID"></param>
        /// <param name="StatusMsg"></param>
        /// <param name="OrderStatus"></param>
        /// <param name="VolumeTotal"></param>
        /// <param name="ExchangeID">退货使用</param>
        public void UpdateOrder(int volumeTraded, int OrderRef, String OrderSysID, String StatusMsg, int OrderStatus, int VolumeTotal, String ExchangeID)
        {
            RecordItem _record = new RecordItem();

            _record = this.GetOrAdd(OrderRef, _record);

            _record.VolumeTraded = volumeTraded;
            _record.VolumeTotal  = VolumeTotal;
            _record.ErrMsg       = StatusMsg;
            _record.OrderStatus  = OrderStatus;
            _record.OrderSysID   = OrderSysID;
            _record.ExchangeID   = ExchangeID;
            _record.Status       = TradeDealStatus.ORDERING;
            if (_record.OrderSysID.Trim() == "0" && _record.OrderSysID != String.Empty)
            {
                QueryEntrustOrderStruct_M record = new QueryEntrustOrderStruct_M()
                {
                    Code         = _record.Code,
                    User         = _record.User,
                    OrderRef     = _record.OrderRef,
                    Direction    = Convert.ToInt32(_record.Orientation),
                    ExchangeID   = ExchangeID,
                    OrderPrice   = Convert.ToDouble(_record.Price),
                    OrderSysID   = _record.OrderSysID.Trim(),
                    SecurityType = Convert.ToSByte(_record.Type),
                    StrategyId   = _record.StrategyId,
                    OffsetFlag   = _record.CombOffsetFlag,
                    Amount       = _record.VolumeTotalOriginal
                };

                ThreadPool.QueueUserWorkItem(new WaitCallback(DBAccessLayer.CreateFutureERRecord), ((object)record));
            }

            //若交易已撤单 或者 全部成交则标记该委托完成
            if (OrderStatus == 53 || _record.VolumeTotalOriginal == _record.VolumeTraded)
            {
                _record.OrderTime_Completed = DateTime.Now;
                _record.Status = TradeDealStatus.ORDERCOMPLETED;
            }



            this.AddOrUpdate(OrderRef, _record, (key, oldValue) =>
                             oldValue = _record
                             );


            if (UserRequestMap.GetInstance().Count == 0)
            {
                return;
            }

            String USERNAME = string.Empty;

            try
            {
                USERNAME = UserRequestMap.GetInstance()[OrderRef];
            }
            catch (Exception ex)
            {
                DBAccessLayer.LogSysInfo("TradeAdditionalClass->UpdateOrder", ex.ToString());
            }
            OrderViewItem order = new OrderViewItem(_record.OrderRef.ToString(), _record.OrderSysID, _record.Code, _record.Orientation, _record.CombOffsetFlag.ToString(), _record.VolumeTotalOriginal.ToString(), _record.VolumeTotal.ToString(), _record.Price.ToString(), _record.ErrMsg, _record.OrderTime_Start.ToString());

            TradeMonitor.Instance.updateOrderList(USERNAME, order);

            if (_record.Status == TradeDealStatus.ORDERCOMPLETED)
            {
                CompletedTradeRecord.GetInstance().Update(_record.OrderRef, _record);
            }
        }