Exemplo n.º 1
0
        public override void SubscribeBidAskBook(ASecurity s, int level)
        {
            try
            {
                string fields = "rt_time,rt_pre_settle,rt_pre_close,rt_open,rt_high,rt_low,rt_last";
                for (int i = 1; i <= Math.Min(level, 5); i++)
                {
                    fields += ",rt_bid?,rt_ask?,rt_bsize?,rt_asize?".Replace("?", i.ToString());
                }

                //注意:snaponly参数,false=持续更新
                long reqid = this._windapi.WSQ(s.GetWindCode(), fields, false, this.callBackOnSubscribeBidAskBook);
                if (reqid < 0)
                {
                    string msg = this._windapi.WErr((eWQErr)reqid, eLang.eCHN);
                    MessageManager.GetInstance().Add(MessageType.Error, msg);
                    throw new Exception(msg);
                }

                //异步执行时,将s对象临时保存于htAsyncObject
                this.htSubscribe.Add(reqid, s.bidaskbook);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public override List <Option> GetOptionSet(ASecurity underlying)
        {
            try
            {
                long reqid = this._windapi.WSET("OptionChain", "date=" + DateTime.Today.ToString("yyyyMMdd") + ";us_code=" + underlying.GetWindCode() + ";option_var=;month=全部;call_put=全部", this.callBackOnGetOptionSet);
                if (reqid < 0)
                {
                    string msg = this._windapi.WErr((eWQErr)reqid, eLang.eCHN);
                    MessageManager.GetInstance().Add(MessageType.Error, msg);
                    throw new Exception(msg);
                }

                //等待回报数据
                this.waitCallBackData(reqid);

                //读取数据
                if (this.htOptionSets.Contains(underlying.code))
                {
                    return((List <Option>) this.htOptionSets[underlying.code]);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        static void testMM2()
        {
            AMarket   mkt = AMarket.GetInstance(MarketVendor.Exchange);
            ASecurity s   = mkt.GetOption("90000229", new ETF("510050", Exchange.SHE));

            AOptionMakeMarket mm = new OptionMakeMarket1();

            mm.AddOptions(s);
            mm.Run();
        }
Exemplo n.º 4
0
 public void GetBidAskBook(ASecurity s)
 {
     try
     {
         //注意:snaponly参数,false=持续更新
         long reqid = this._windapi.WSQ(s.windcode, "rt_time,rt_pre_settle,rt_open,rt_last,rt_ask1,rt_bid1,rt_bsize1,rt_asize1", false, s.QuantCallbackRealtime);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 5
0
        public Option GetOption(string code, ASecurity underlying)
        {
            Option o = null;

            if (!htUnderlyingSets.Contains(underlying.code))
            {
                this.GetOptionSet(underlying);
            }

            if (htOptionSets.Contains(underlying.code))
            {
                List <Option> oplist = (List <Option>)htOptionSets[underlying.code];
                o = oplist.Find(delegate(Option of) { return(of.code == code); });
            }

            return(o);
        }
Exemplo n.º 6
0
 public override List <Option> GetOptionSet(ASecurity underlying)
 {
     try
     {
         this.readOptionContractFile();
         if (this.htOptionSets.Contains(underlying.code))
         {
             return((List <Option>)htOptionSets[underlying.code]);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 7
0
 public virtual void AddOptions(ASecurity underlying)
 {
     try
     {
         if (underlying.category == SecurityCategory.OPTION)
         {
             //添加期权合约本身
             this.AddOptions((Option)underlying);
         }
         else
         {
             //添加标的对应的期权合约
             List <Option> optionlist = _optionengine.GetOptionSet(underlying);
             this.AddOptions(optionlist);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 8
0
        public override void SubscribeBidAskBook(ASecurity s, int level)
        {
            //异步执行前,保存记录
            long reqId = _requestId++;

            this.htSubscribe.Add(reqId, true);

            //异步调用
            AsyncDelegate dlg;

            switch (s.category)
            {
            case SecurityCategory.STOCK:
            case SecurityCategory.ETF:
                this.htSubscribedStocks.Add(s.code, s.bidaskbook);
                this.addSubscribedStocks(s.code);
                if (!isLoopingDbfFile)
                {
                    isLoopingDbfFile = true;
                    dlg = new AsyncDelegate(updateStockBidAskBook);
                    dlg.BeginInvoke(reqId, null, null);
                }
                break;

            case SecurityCategory.OPTION:
                this.htSubscribedOptions.Add(s.code, s.bidaskbook);
                if (!isLoopingMktFile)
                {
                    isLoopingMktFile = true;
                    dlg = new AsyncDelegate(updateOptionBidAskBook);
                    dlg.BeginInvoke(reqId, null, null);
                }
                break;

            default:
                string msg = string.Format("无法读取该类证券行情:{0}", s.category);
                MessageManager.GetInstance().Add(MessageType.Error, msg);
                throw new Exception(msg);
            }
        }
Exemplo n.º 9
0
        private void btnRunMM_Click(object sender, EventArgs e)
        {
            foreach (string code in checkedListBoxUnderlying.CheckedItems)
            {
                ASecurity s = null;
                if (htUnderlyings.Contains(code))
                {
                    s = (ASecurity)htUnderlyings[code];
                }

                AOptionMakeMarket omm = new OptionMakeMarket1();
                omm.AddOptions(s);
                MMRunDelegate dlg = new MMRunDelegate(omm.Run);
                dlg.BeginInvoke(null, null);
                htmarketmakers.Add(s.code, omm);
            }

            //消息列表
            isMMruning = true;
            Thread thread = new Thread(readMsg);

            thread.IsBackground = true;
            thread.Start();
        }
Exemplo n.º 10
0
 public abstract List <Option> GetOptionSet(ASecurity underlying);
Exemplo n.º 11
0
 public abstract void SubscribeBidAskBook(ASecurity s, int level);
Exemplo n.º 12
0
        private void readOptionContractFile()
        {
            try
            {
                if (this.htOptionSets.Count == 0)
                {
                    #region 读取文件
                    //复制到本地
                    File.Copy(filepath_option_contract_source, filepath_option_contract_target, true);

                    //读取该文件
                    string filecontent = "";
                    using (StreamReader sReader = new StreamReader(filepath_option_contract_target, Encoding.Default))
                    {
                        filecontent = sReader.ReadToEnd();
                        sReader.Close();
                    }
                    #endregion

                    #region 解析合约
                    string[] lines = filecontent.Split("\n".ToCharArray());
                    if (lines == null || lines.Length == 0)
                    {
                        MessageManager.GetInstance().Add(MessageType.Error, string.Format("期权合约文件为空"));
                        return;
                    }

                    List <Option> optionlist;
                    foreach (string line in lines)
                    {
                        if (line != null && line.Trim().Length > 0)
                        {
                            string[] fields = line.Split("|".ToCharArray());

                            if (fields.Length >= 34)
                            {
                                //代码
                                Option o = new Option(fields[1].Trim(), Exchange.SHE);
                                o.contractcode    = fields[2].Trim();
                                o.name            = fields[3].Trim();
                                o.underlyingunits = Convert.ToInt16(fields[9].Trim());
                                o.strike          = Convert.ToDouble(fields[10].Trim());
                                o.exercisedate    = Utility.ConvertToDateTime(fields[13].Trim(), "yyyyMMdd");
                                o.priceuplimit    = Convert.ToDouble(fields[22].Trim());
                                o.pricedownlimit  = Convert.ToDouble(fields[23].Trim());
                                o.marginunit      = Convert.ToDouble(fields[24].Trim());
                                o.lmtordmaxfloor  = Convert.ToInt16(fields[29].Trim());
                                o.ticksize        = Convert.ToDouble(fields[32].Trim());
                                o.daystoexercise  = (o.exercisedate - DateTime.Today).Days;
                                o.exercisemonth   = o.exercisedate.Month;

                                #region 标的
                                string underlyingtype = fields[6].Trim().ToUpper();
                                string underlyingcode = fields[4].Trim();
                                if (this.htUnderlyingSets.Contains(underlyingcode))
                                {
                                    //标的已存在
                                    o.underlying = (ASecurity)htUnderlyingSets[underlyingcode];
                                }
                                else
                                {
                                    //新建标的
                                    ASecurity s = null;
                                    switch (underlyingtype)
                                    {
                                    case "ASH":     //股票
                                        s = new Stock(underlyingcode, Exchange.SHE);
                                        break;

                                    case "EBS":     //ETF
                                        s = new ETF(underlyingcode, Exchange.SHE);
                                        break;

                                    default:
                                        break;
                                    }

                                    if (s != null)
                                    {
                                        s.name = fields[5].Trim();
                                        htUnderlyingSets.Add(underlyingcode, s);
                                        o.underlying = s;
                                    }
                                }
                                #endregion

                                //类型:call or put
                                string type = fields[8].Trim().ToUpper();
                                if (type == "C")
                                {
                                    o.type = OptionType.CALL;
                                }
                                else
                                {
                                    o.type = OptionType.PUT;
                                }

                                //交易标志
                                char[] flag = fields[33].Trim().ToUpper().ToCharArray();
                                o.islimitopening = (flag[0] == '0') ? false : true;     //第1位:‘0’表示可开仓,‘1’表示限制卖出开仓(不.包括备兑开仓)和买入开仓。
                                o.istrading      = (flag[1] == '0') ? true : false;     //第2位:‘0’表示未连续停牌,‘1’表示连续停牌。
                                o.isnew          = (flag[4] == 'A') ? true : false;     //第5位:‘A’表示当日新挂牌的合约,‘E’表示存续的合约

                                //加入列表
                                if (this.htOptionSets.Contains(o.underlying.code))
                                {
                                    optionlist = (List <Option>) this.htOptionSets[o.underlying.code];
                                    optionlist.Add(o);
                                }
                                else
                                {
                                    optionlist = new List <Option>();
                                    optionlist.Add(o);
                                    this.htOptionSets.Add(o.underlying.code, optionlist);
                                }
                            }
                        }
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 13
0
        private int callBackOnGetOptionSet(QuantEvent quantEvent)
        {
            //////////////////////////////////
            //同步调用:htSyncWaiting
            //////////////////////////////////

            //检查等待列表,首次未找到则等待一会儿
            if (!this.htSyncWaiting.Contains(quantEvent.RequestID))
            {
                Thread.Sleep(100);
            }
            if (!this.htSyncWaiting.Contains(quantEvent.RequestID))
            {
                return(-1);
            }

            if (!isCallBackDataValid(quantEvent))
            {
                //解除主进程等待
                this.htSyncWaiting[quantEvent.RequestID] = quantEvent.ErrCode;

                //退出
                return(-1);
            }

            object[] data;
            data = (object[])quantEvent.quantData.MatrixData;

            List <Option> optionlist = new List <Option>();

            for (int i = 0; i < data.Length / 13; i++)
            {
                string underlyingwindcode = data[0 + i * 13].ToString();
                string underlyingname     = data[1 + i * 13].ToString();
                string optionwindcode     = data[3 + i * 13].ToString();
                //转换Wind代码和交易代码
                string   optioncode     = optionwindcode;
                Exchange exchange       = ASecurity.GetExchange(optionwindcode, ref optioncode);
                string   underlyingcode = underlyingwindcode;
                ASecurity.GetExchange(underlyingwindcode, ref underlyingcode);

                //读取期权信息
                Option o = new Option(optioncode, exchange);
                #region 期权信息
                o.name            = data[4 + i * 13].ToString();
                o.strike          = Convert.ToDouble(data[6 + i * 13]);
                o.exercisedate    = Utility.ConvertToDateTime(data[10 + i * 13].ToString(), "");
                o.daystoexercise  = (o.exercisedate - DateTime.Today).Days;
                o.yearstoexercise = o.daystoexercise / 365.0;
                string typename = data[8 + i * 13].ToString();
                if (typename == "认购")
                {
                    o.type = OptionType.CALL;
                }
                else
                {
                    o.type = OptionType.PUT;
                }
                #endregion

                #region 标的信息
                SecurityCategory category = ASecurity.GetSecurityCategory(underlyingcode, exchange);
                o.underlying      = ASecurity.GetSecurity(category, underlyingcode, exchange);
                o.underlying.name = underlyingname;
                #endregion

                optionlist.Add(o);
            }

            if (!htOptionSets.Contains(optionlist[0].underlying.code))
            {
                htOptionSets.Add(optionlist[0].underlying.code, optionlist);
            }
            else
            {
                htOptionSets[optionlist[0].underlying.code] = optionlist;
            }

            //解除主进程等待
            this.htSyncWaiting[quantEvent.RequestID] = quantEvent.ErrCode;
            return((int)quantEvent.ErrCode);
        }