/// <summary>
        /// 港股下单报盘
        /// </summary>
        /// <param name="model">港股下单实体</param>
        /// <returns></returns>
        public ResultDataEntity DoHKEntrustOrder(HKOrderEntity model)
        {
            //下单通道
            LogHelper.WriteDebug("[调用港股下单通道服务]");
            if (model == null)
            {
                return(null);
            }
            if (string.IsNullOrEmpty(model.SholderCode))
            {
                return(null);
            }
            //撮合中心委托单
            HKEntrustOrderInfo data = new HKEntrustOrderInfo();

            data.BranchID         = model.ChannelNo;
            data.OrderType        = (int)model.HKPriceType;
            data.HKSecuritiesCode = model.Code;
            data.OrderPrice       = model.OrderPrice;
            data.ReceiveTime      = System.DateTime.Now;
            data.OrderVolume      = model.OrderVolume;
            data.OldVolume        = model.OrderVolume;
            data.TradeType        = (int)model.TransactionDirection;
            data.SholderCode      = model.SholderCode;
            return(MatchCenterManager.Instance.DoHKStockOrder(data));
        }
        /// <summary>
        /// 港股下单
        /// </summary>
        /// <param name="model">港股委托实体</param>
        /// <returns></returns>
        public ResultDataEntity DoHKStockOrder(HKEntrustOrderInfo model)
        {
            var    result = new ResultDataEntity();
            string message;

            LogHelper.WriteDebug("撮合中心管理器港股下单方法:");
            if (model == null || string.IsNullOrEmpty((model.HKSecuritiesCode)))
            {
                message        = "CH-0010:委托单不能为空或者港股代码不能为空;";
                result.Message = message;
                LogHelper.WriteDebug(message);
                return(result);
            }
            if (matchDevices != null)
            {
                if (matchDevices.ContainsKey(model.HKSecuritiesCode.Trim()))
                {
                    return(matchDevices[model.HKSecuritiesCode.Trim()].DoHKStockOrder(model));
                }
                message = "CH-0011:管理中心撮合单元没有分配或撮合中心没有分配此品种类型撮合;";
                LogHelper.WriteDebug(message);
            }
            else
            {
                message = "CH-0012:撮合中心撮合机不存在;";
                LogHelper.WriteDebug(message);
            }
            result.Message = message;
            return(result);
        }
Пример #3
0
        /// <summary>
        ///  根据主键更新一条数据
        /// <param name="model">委托记录实体</param>
        /// </summary>
        public static void Update(HKEntrustOrderInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update HKEntrustOrder set ");
            strSql.Append("SholderCode=@SholderCode,");
            strSql.Append("BranchID=@BranchID,");
            strSql.Append("HKSecuritiesCode=@HKSecuritiesCode,");
            strSql.Append("OldVolume=@OldVolume,");
            strSql.Append("ReceiveTime=@ReceiveTime,");
            strSql.Append("OrderPrice=@OrderPrice,");
            strSql.Append("OrderVolume=@OrderVolume,");
            strSql.Append("OrderType=@OrderType,");
            strSql.Append("TradeType=@TradeType,");
            strSql.Append("OrderMessage=@OrderMessage");
            strSql.Append(" where OrderNo=@OrderNo ");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "SholderCode", DbType.AnsiString, model.SholderCode);
            db.AddInParameter(dbCommand, "OrderNo", DbType.AnsiString, model.OrderNo);
            db.AddInParameter(dbCommand, "BranchID", DbType.AnsiString, model.BranchID);
            db.AddInParameter(dbCommand, "HKSecuritiesCode", DbType.AnsiString, model.HKSecuritiesCode);
            db.AddInParameter(dbCommand, "OldVolume", DbType.Decimal, model.OldVolume);
            db.AddInParameter(dbCommand, "ReceiveTime", DbType.DateTime, model.ReceiveTime);
            db.AddInParameter(dbCommand, "OrderPrice", DbType.Decimal, model.OrderPrice);
            db.AddInParameter(dbCommand, "OrderVolume", DbType.Decimal, model.OrderVolume);
            db.AddInParameter(dbCommand, "OrderType", DbType.Int32, model.OrderType);
            db.AddInParameter(dbCommand, "TradeType", DbType.Int32, model.TradeType);
            db.AddInParameter(dbCommand, "OrderMessage", DbType.AnsiString, model.OrderMessage);
            db.ExecuteNonQuery(dbCommand);
        }
Пример #4
0
        /// <summary>
        /// 增加一条数据
        /// <param name="model">委托记录实体</param>
        /// </summary>
        public static void Add(HKEntrustOrderInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into HKEntrustOrder(");
            strSql.Append("SholderCode,OrderNo,BranchID,HKSecuritiesCode,OldVolume,ReceiveTime,OrderPrice,OrderVolume,OrderType,TradeType,OrderMessage)");

            strSql.Append(" values (");
            strSql.Append("@SholderCode,@OrderNo,@BranchID,@HKSecuritiesCode,@OldVolume,@ReceiveTime,@OrderPrice,@OrderVolume,@OrderType,@TradeType,@OrderMessage)");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "SholderCode", DbType.AnsiString, model.SholderCode);
            db.AddInParameter(dbCommand, "OrderNo", DbType.AnsiString, model.OrderNo);
            db.AddInParameter(dbCommand, "BranchID", DbType.AnsiString, model.BranchID);
            db.AddInParameter(dbCommand, "HKSecuritiesCode", DbType.AnsiString, model.HKSecuritiesCode);
            db.AddInParameter(dbCommand, "OldVolume", DbType.Decimal, model.OldVolume);
            db.AddInParameter(dbCommand, "ReceiveTime", DbType.DateTime, model.ReceiveTime);
            db.AddInParameter(dbCommand, "OrderPrice", DbType.Decimal, model.OrderPrice);
            db.AddInParameter(dbCommand, "OrderVolume", DbType.Decimal, model.OrderVolume);
            db.AddInParameter(dbCommand, "OrderType", DbType.Int32, model.OrderType);
            db.AddInParameter(dbCommand, "TradeType", DbType.Int32, model.TradeType);
            db.AddInParameter(dbCommand, "OrderMessage", DbType.AnsiString, model.OrderMessage);
            db.ExecuteNonQuery(dbCommand);
        }
Пример #5
0
        /// <summary>
        /// 根据主键得到一个实体(记录)
        /// <param name="orderNo">委托编号(主键)</param>
        /// </summary>
        public static HKEntrustOrderInfo GetModel(string orderNo)
        {
            HKEntrustOrderInfo model = null;

            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("select SholderCode,OrderNo,BranchID,HKSecuritiesCode,OldVolume,ReceiveTime,OrderPrice,OrderVolume,OrderType,TradeType,OrderMessage,MatchState,MarketVolumeNo,MarkVolume from HKEntrustOrder ");
                strSql.Append(" where OrderNo=@OrderNo ");
                Database  db        = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
                db.AddInParameter(dbCommand, "OrderNo", DbType.AnsiString, orderNo);

                using (IDataReader dataReader = db.ExecuteReader(dbCommand))
                {
                    if (dataReader.Read())
                    {
                        model = ReaderBind(dataReader);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteError("CH-111:数据库操作异常", ex);
            }
            return(model);
        }
Пример #6
0
        /// <summary>
        /// 对象实体绑定数据
        /// <param name="dataReader">IDataReader对象</param>
        /// </summary>
        public static HKEntrustOrderInfo ReaderBind(IDataReader dataReader)
        {
            HKEntrustOrderInfo model = new HKEntrustOrderInfo();
            object             ojb;

            model.SholderCode      = dataReader["SholderCode"].ToString();
            model.OrderNo          = dataReader["OrderNo"].ToString();
            model.BranchID         = dataReader["BranchID"].ToString();
            model.HKSecuritiesCode = dataReader["HKSecuritiesCode"].ToString();
            ojb = dataReader["OldVolume"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.OldVolume = (decimal)ojb;
            }
            ojb = dataReader["ReceiveTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ReceiveTime = (DateTime)ojb;
            }
            ojb = dataReader["OrderPrice"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.OrderPrice = (decimal)ojb;
            }
            ojb = dataReader["OrderVolume"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.OrderVolume = (decimal)ojb;
            }
            ojb = dataReader["OrderType"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.OrderType = (int)ojb;
            }
            ojb = dataReader["OrderType"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.TradeType = (int)ojb;
            }
            model.OrderMessage = dataReader["OrderMessage"].ToString();

            ojb = dataReader["MatchState"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.MatchState = (Types.MatchCenterState)ojb;
            }
            if (dataReader["MarketVolumeNo"] != null)
            {
                model.MarketVolumeNo = dataReader["MarketVolumeNo"].ToString();
            }
            ojb = dataReader["MarkVolume"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.MarkLeft = (decimal)ojb;
            }
            return(model);
        }
Пример #7
0
        /// <summary>
        /// 删除撮合委托实体
        /// </summary>
        /// <param name="dataX">委托</param>
        public bool Remove(T dataX)
        {
            if (entrustOrderList == null)
            {
                return(false);
            }
            rwLock.EnterWriteLock();
            try
            {
                string sholderCode = "";
                if (typeof(T) == typeof(FutureDataOrderEntity))
                {
                    #region  股指期货添加
                    FutureDataOrderEntity qhitem = dataX as FutureDataOrderEntity;
                    sholderCode = qhitem.SholderCode.Trim();
                    #endregion
                }
                else if (typeof(T) == typeof(StockDataOrderEntity))
                {
                    #region  现货添加
                    StockDataOrderEntity xhitem = dataX as StockDataOrderEntity;
                    sholderCode = xhitem.SholderCode.Trim();
                    #endregion
                }
                else if (typeof(T) == typeof(HKEntrustOrderInfo))
                {
                    #region  港股添加
                    HKEntrustOrderInfo hkitem = dataX as HKEntrustOrderInfo;
                    sholderCode = hkitem.SholderCode.Trim();
                    #endregion
                }
                else if (typeof(T) == typeof(CommoditiesDataOrderEntity))
                {
                    #region  商品期货添加 add by 董鹏 2010-01-22
                    CommoditiesDataOrderEntity qhitem = dataX as CommoditiesDataOrderEntity;
                    sholderCode = qhitem.SholderCode.Trim();
                    #endregion
                }

                if (entrustOrderList.ContainsKey(sholderCode))
                {
                    bool remove = entrustOrderList[sholderCode].Remove(dataX);
                    if (entrustOrderList[sholderCode].Count <= 0)
                    {
                        entrustOrderList.Remove(sholderCode);
                    }
                    return(remove);
                }

                return(false);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }
Пример #8
0
        /// <summary>
        /// 修改委托单中委托数量(撮合中只处理减量委托)
        /// 返回0表示改单失败包含实体为空和查询不到委托单等--不回报
        /// 返回1表示查询到委托单,但不附合减量改单规则 --回报
        /// 返回2表示查改单成功--回报
        /// </summary>
        /// <param name="orderNo">要改单的原委托单编号</param>
        /// <param name="sholderCode">股东代码</param>
        /// <param name="modifynumer">改单委托量</param>
        /// <param name="nowOrderVolue">改单后当前委托量</param>
        /// <param name="canleCount">撤单量</param>
        /// <param name="errMsg">异常信息</param>
        /// <returns>返回0,1,2中其一</returns>
        public int Modify(string orderNo, string sholderCode, decimal modifynumer, ref decimal nowOrderVolue, ref decimal canleCount, ref string errMsg)
        {
            if (entrustOrderList == null)
            {
                return(0);
            }
            rwLock.EnterWriteLock();

            errMsg        = "";
            canleCount    = 0;
            nowOrderVolue = 0;
            try
            {
                if (typeof(T) != typeof(HKEntrustOrderInfo))
                {
                    return(0);
                }
                if (!entrustOrderList.ContainsKey(sholderCode))
                {
                    return(0);
                }
                List <T> list = entrustOrderList[sholderCode];
                foreach (T entity in list)
                {
                    HKEntrustOrderInfo item = entity as HKEntrustOrderInfo;
                    if (item.OrderNo == orderNo)
                    {
                        if (modifynumer >= item.OldVolume)
                        {
                            errMsg     = "CH-0001:减量委托改单失败,改单量不可以大于或者等于原委托量";
                            canleCount = 0;
                            return(1);
                        }
                        //计算当前已经成交量=原委托量-当前剩余量;
                        decimal tradeVolume = item.OldVolume - item.OrderVolume;
                        //计算当前还可以委托量多少=当前改单委托量-当前已经成交量
                        decimal nowEntrusVolume = modifynumer - tradeVolume;
                        if (nowEntrusVolume <= 0)
                        {
                            errMsg     = "CH-0001:减量委托改单失败,当前委托单的成交量已经大于或者等于改单委托量";
                            canleCount = 0;
                            return(1);
                        }
                        //当前撤单量=当前剩余量-当前还可以委托量
                        canleCount       = item.OrderVolume - nowEntrusVolume;
                        nowOrderVolue    = nowEntrusVolume;
                        item.OldVolume   = modifynumer;
                        item.OrderVolume = nowEntrusVolume;
                        errMsg           = "改单成功";
                        return(2);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteError("港股改单队列修改实体异常", ex);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
            return(0);
        }
Пример #9
0
        /// <summary>
        /// 删除撮合实体
        /// </summary>
        /// <param name="orderNo">委托编号</param>
        /// <param name="sholderCode">股东代码</param>
        /// <param name="cancount"></param>
        /// <returns></returns>
        public bool Remove(string orderNo, string sholderCode, ref decimal cancount)
        {
            if (entrustOrderList == null)
            {
                return(false);
            }

            rwLock.EnterWriteLock();
            try
            {
                if (!entrustOrderList.ContainsKey(sholderCode))
                {
                    return(false);
                }
                List <T> list = entrustOrderList[sholderCode];
                if (typeof(T) == typeof(FutureDataOrderEntity))
                {
                    #region  股指期货删除
                    foreach (T entity in list)
                    {
                        FutureDataOrderEntity item = entity as FutureDataOrderEntity;
                        if (item.OrderNo == orderNo)
                        {
                            cancount = item.OrderVolume;
                            return(list.Remove(entity));
                        }
                    }
                    #endregion
                }
                else if (typeof(T) == typeof(StockDataOrderEntity))
                {
                    #region  现货删除
                    foreach (T entity in list)
                    {
                        StockDataOrderEntity item = entity as StockDataOrderEntity;
                        if (item.OrderNo == orderNo)
                        {
                            cancount = item.OrderVolume;
                            return(list.Remove(entity));
                        }
                    }
                    #endregion
                }
                else if (typeof(T) == typeof(HKEntrustOrderInfo))
                {
                    #region  港股股删除
                    foreach (T entity in list)
                    {
                        HKEntrustOrderInfo item = entity as HKEntrustOrderInfo;
                        if (item.OrderNo == orderNo)
                        {
                            cancount = item.OrderVolume;
                            return(list.Remove(entity));
                        }
                    }
                    #endregion
                }
                else if (typeof(T) == typeof(CommoditiesDataOrderEntity))
                {
                    #region  商品期货删除  add by 董鹏 2010-01-22
                    foreach (T entity in list)
                    {
                        CommoditiesDataOrderEntity item = entity as CommoditiesDataOrderEntity;
                        if (item.OrderNo == orderNo)
                        {
                            cancount = item.OrderVolume;
                            return(list.Remove(entity));
                        }
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteError("撮合撤单删除撮合实体异常", ex);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }

            return(false);
        }
Пример #10
0
        /// <summary>
        /// 添加委托到数据存储区
        /// </summary>
        /// <param name="dataX">委托单</param>
        public void Add(T dataX)
        {
            if (entrustOrderList == null)
            {
                return;
            }
            rwLock.EnterWriteLock();
            try
            {
                string sholderCode = "";
                if (typeof(T) == typeof(FutureDataOrderEntity))
                {
                    #region  股指期货添加
                    FutureDataOrderEntity qhitem = dataX as FutureDataOrderEntity;
                    sholderCode = qhitem.SholderCode.Trim();
                    #endregion
                }
                else if (typeof(T) == typeof(StockDataOrderEntity))
                {
                    #region  现货添加
                    StockDataOrderEntity xhitem = dataX as StockDataOrderEntity;
                    sholderCode = xhitem.SholderCode.Trim();
                    #endregion
                }
                else if (typeof(T) == typeof(HKEntrustOrderInfo))
                {
                    #region  港股添加
                    HKEntrustOrderInfo hkitem = dataX as HKEntrustOrderInfo;
                    sholderCode = hkitem.SholderCode.Trim();
                    #endregion
                }
                else if (typeof(T) == typeof(CommoditiesDataOrderEntity))
                {
                    #region  商品期货添加 add by 董鹏 2010-01-22
                    CommoditiesDataOrderEntity qhitem = dataX as CommoditiesDataOrderEntity;
                    sholderCode = qhitem.SholderCode.Trim();
                    #endregion
                }

                #region 添加保存队列处理
                if (entrustOrderList.ContainsKey(sholderCode.Trim()))
                {
                    List <T> queryList = entrustOrderList[sholderCode.Trim()];
                    if (queryList != null)
                    {
                        queryList.Add(dataX);
                        if (transactionDirection == Types.TransactionDirection.Buying)
                        {
                            queryList.Sort(sortList.CompareSortBuy);
                        }
                        else if (transactionDirection == Types.TransactionDirection.Selling)
                        {
                            queryList.Sort(sortList.CompareSortSell);
                        }
                    }
                    else
                    {
                        queryList = new List <T>();
                        queryList.Add(dataX);
                    }
                }
                else
                {
                    List <T> futureList = new List <T>();
                    futureList.Add(dataX);
                    entrustOrderList.Add(sholderCode.Trim(), futureList);
                }
                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.WriteError("添加委托数据存储区时异常", ex);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }
        /// <summary>
        /// 期货买比较排序器,比较排序规则:高价在先,同等价时间先到在前。
        /// </summary>
        /// <param name="dataX">期货委托单</param>
        /// <param name="dataY">期货委托单</param>
        /// <returns></returns>
        public int CompareSortBuy(T dataX, T dataY)
        {
            // FutureDataOrderEntity

            if (typeof(T) == typeof(FutureDataOrderEntity))
            {
                #region 股指期货比较排序
                FutureDataOrderEntity itemX = dataX as FutureDataOrderEntity;
                FutureDataOrderEntity itemY = dataY as FutureDataOrderEntity;
                if (itemX.OrderPrice > itemY.OrderPrice)
                {
                    return(1);
                }
                else if (itemX.OrderPrice == itemY.OrderPrice)
                {
                    if (itemX.ReachTime >= itemY.ReachTime)
                    {
                        return(1);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(-1);
                }
                #endregion
            }
            else if (typeof(T) == typeof(StockDataOrderEntity))
            {
                #region 现货比较排序
                StockDataOrderEntity itemX = dataX as StockDataOrderEntity;
                StockDataOrderEntity itemY = dataY as StockDataOrderEntity;
                if (itemX.OrderPrice > itemY.OrderPrice)
                {
                    return(1);
                }
                else if (itemX.OrderPrice == itemY.OrderPrice)
                {
                    if (itemX.ReachTime >= itemY.ReachTime)
                    {
                        return(1);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(-1);
                }
                #endregion
            }
            else if (typeof(T) == typeof(HKEntrustOrderInfo))
            {
                #region 港股比较排序
                HKEntrustOrderInfo itemX = dataX as HKEntrustOrderInfo;
                HKEntrustOrderInfo itemY = dataY as HKEntrustOrderInfo;
                if (itemX.OrderPrice > itemY.OrderPrice)
                {
                    return(1);
                }
                else if (itemX.OrderPrice == itemY.OrderPrice)
                {
                    if (itemX.ReceiveTime >= itemY.ReceiveTime)
                    {
                        return(1);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(-1);
                }
                #endregion
            }
            else if (typeof(T) == typeof(CommoditiesDataOrderEntity))
            {
                #region 商品期货比较排序
                CommoditiesDataOrderEntity itemX = dataX as CommoditiesDataOrderEntity;
                CommoditiesDataOrderEntity itemY = dataY as CommoditiesDataOrderEntity;
                if (itemX.OrderPrice > itemY.OrderPrice)
                {
                    return(1);
                }
                else if (itemX.OrderPrice == itemY.OrderPrice)
                {
                    if (itemX.ReachTime >= itemY.ReachTime)
                    {
                        return(1);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(-1);
                }
                #endregion
            }
            else
            {
                return(-1);
            }
        }