Пример #1
0
        // 请求查询交易员持仓
        public override bool GetPositions(QryPosition qry, ref List <PositionInfo> refPositions)
        {
            bool result = false;

            lock (this)
            {
                string   szHashId  = "p:" + RunSingleStrategy.StrategyInfo.TraderName;
                string   szInst    = qry.InstrumentID;
                string   szValue   = null;
                byte[]   bKey      = null;
                byte[]   bValue    = null;
                byte[][] bValueAll = null;

                bValueAll = Redis.HKeys(szHashId);
                List <string> keyList = new List <string>();

                foreach (byte[] elem in bValueAll)
                {
                    szValue = Tool.GetString(elem);
                    keyList.Add(szValue);
                }

                if (qry.PosiDirection.Equals('-'))
                {
                    //双向
                    if (szInst.Length == 0)
                    {
                        //全部合约
                        foreach (string key in keyList)
                        {
                            bKey   = Tool.GetBytes(key);
                            bValue = Redis.HGet(szHashId, bKey);
                            if (bValue != null)
                            {
                                PositionInfo position = new PositionInfo();
                                szValue = Tool.GetString(bValue);
                                xmlOpr.Transfer(szValue, ref position);
                                refPositions.Add(position);
                                result = true;
                            }
                        }
                    }
                    else
                    {
                        //特定合约
                        foreach (string key in keyList)
                        {
                            if (key.Contains(szInst))
                            {
                                bKey   = Tool.GetBytes(key);
                                bValue = Redis.HGet(szHashId, bKey);
                                if (bValue != null)
                                {
                                    PositionInfo position = new PositionInfo();
                                    szValue = Tool.GetString(bValue);
                                    xmlOpr.Transfer(szValue, ref position);
                                    refPositions.Add(position);
                                    result = true;
                                }
                            }
                        }
                    }
                }
                else
                {
                    //单向
                    string szDirect = "Direct" + Convert.ToInt32(qry.PosiDirection).ToString();
                    if (szInst.Length == 0)
                    {
                        //全部合约
                        foreach (string key in keyList)
                        {
                            if (key.Contains(szDirect))
                            {
                                bKey   = Tool.GetBytes(key);
                                bValue = Redis.HGet(szHashId, bKey);
                                if (bValue != null)
                                {
                                    PositionInfo position = new PositionInfo();
                                    szValue = Tool.GetString(bValue);
                                    xmlOpr.Transfer(szValue, ref position);
                                    refPositions.Add(position);
                                    result = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        //特定合约
                        foreach (string key in keyList)
                        {
                            if (key.Contains(szInst) && key.Contains(szDirect))
                            {
                                bKey   = Tool.GetBytes(key);
                                bValue = Redis.HGet(szHashId, bKey);
                                if (bValue != null)
                                {
                                    PositionInfo position = new PositionInfo();
                                    szValue = Tool.GetString(bValue);
                                    xmlOpr.Transfer(szValue, ref position);
                                    refPositions.Add(position);
                                    result = true;
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Пример #2
0
 // 请求查询交易员持仓
 public abstract bool GetPositions(QryPosition qry, ref List <PositionInfo> retPositions);