Beispiel #1
0
 public abstract void OptionPositionQuery(QueryPara param, List <PositionBook> positionbook);
Beispiel #2
0
        public override void OptionPositionQuery(QueryPara param, List <PositionBook> positionbook)
        {
            try
            {
                if (!islogon())
                {
                    return;
                }

                #region packer
                CT2Packer packer = new CT2Packer(2);
                packer.BeginPack();
                packer.AddField("user_token", Convert.ToSByte('S'), 512, 4);
                packer.AddField("account_code", Convert.ToSByte('S'), 32, 4);
                packer.AddField("combi_no", Convert.ToSByte('S'), 8, 4);
                packer.AddField("stock_code", Convert.ToSByte('S'), 16, 4);

                packer.AddStr(this.token);
                packer.AddStr(param.fundcode);
                packer.AddStr(param.portfolio);
                packer.AddStr(param.securitycode);

                packer.EndPack();
                #endregion

                int retcode = this.sendpacker(OptionFunction.PositionQuery, packer, false);

                #region unpacker
                CT2UnPacker unpacker = getCallbackData(retcode);
                if (unpacker != null)
                {
                    //更新持仓
                    positionbook.Clear();
                    while (unpacker.IsEOF() == 0)
                    {
                        PositionBook pbook = new PositionBook();
                        pbook.code = unpacker.GetStr("stock_code");
                        int pflag = unpacker.GetInt("position_flag");
                        if (pflag == 1)
                        {
                            pbook.positiondirection = PostionDerection.LONG;
                        }
                        else
                        {
                            pbook.positiondirection = PostionDerection.SHORT;
                        }
                        pbook.volume = unpacker.GetInt("enable_amount");

                        //可能存在volume<=0的bug,所以筛选出为正的
                        if (pbook.volume > 0)
                        {
                            positionbook.Add(pbook);
                        }

                        unpacker.Next();
                    }
                }
                else
                {
                    MessageManager.GetInstance().Add(MessageType.Error, string.Format("持仓查询失败:{0}", param.securitycode));
                }
                #endregion
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #3
0
 public abstract void OptionEntrustQuery(QueryPara param, List <EntrustBook> entrustbook);
Beispiel #4
0
        public override void OptionEntrustQuery(QueryPara param, List <EntrustBook> entrustbook)
        {
            try
            {
                if (!islogon())
                {
                    return;
                }

                #region packer
                CT2Packer packer = new CT2Packer(2);
                packer.BeginPack();
                packer.AddField("user_token", Convert.ToSByte('S'), 512, 4);
                packer.AddField("account_code", Convert.ToSByte('S'), 32, 4);
                packer.AddField("combi_no", Convert.ToSByte('S'), 8, 4);
                packer.AddField("stock_code", Convert.ToSByte('S'), 16, 4);

                packer.AddStr(this.token);
                packer.AddStr(param.fundcode);
                packer.AddStr(param.portfolio);
                packer.AddStr(param.securitycode);

                packer.EndPack();
                #endregion

                int retcode = this.sendpacker(OptionFunction.EntrustQuery, packer, false);

                #region unpacker
                CT2UnPacker unpacker = getCallbackData(retcode);
                if (unpacker != null)
                {
                    //更新委托列表
                    entrustbook.Clear();
                    while (unpacker.IsEOF() == 0)
                    {
                        EntrustBook enbook = new EntrustBook();
                        enbook.code      = unpacker.GetStr("stock_code");
                        enbook.batchno   = unpacker.GetInt("batch_no");
                        enbook.entrustno = unpacker.GetInt("entrust_no");
                        enbook.price     = unpacker.GetDouble("entrust_price");
                        enbook.message   = unpacker.GetStr("withdraw_cause");

                        //委托
                        int entrustdirction = unpacker.GetInt("entrust_direction");
                        if (entrustdirction == 1)
                        {
                            enbook.tradedirection = TradeDirection.BUY;
                        }
                        else
                        {
                            enbook.tradedirection = TradeDirection.SELL;
                        }

                        //开平
                        int futuredirection = unpacker.GetInt("futures_direction");
                        if (futuredirection == 1)
                        {
                            enbook.futuredirection = FutureDirection.OPEN;
                        }
                        else
                        {
                            enbook.futuredirection = FutureDirection.COVER;
                        }

                        //剩余数量
                        int entrustvol = unpacker.GetInt("entrust_amount");
                        int dealvol    = unpacker.GetInt("deal_amount");
                        enbook.volume = entrustvol - dealvol;

                        //委托状态
                        string entruststate = unpacker.GetStr("entrust_state"); //委托状态
                        switch (entruststate)
                        {
                        case "1":        //未报
                        case "4":        //已报
                        case "6":        //部成
                            if (enbook.price > 0 && enbook.volume > 0)
                            {
                                entrustbook.Add(enbook);
                            }
                            break;

                        case "5":        //废单
                        case "7":        //已成
                        case "8":        //部撤
                        case "9":        //已撤
                        case "a":        //待撤
                        case "A":        //未撤
                        case "B":        //待撤
                        case "C":        //正撤
                        case "D":        //撤认
                        case "E":        //撤废
                        case "F":        //已撤
                            break;

                        default:
                            break;
                        }

                        unpacker.Next();
                    }
                }
                else
                {
                    MessageManager.GetInstance().Add(MessageType.Error, string.Format("委托查询失败:{0}", param.securitycode));
                }
                #endregion
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }