Exemplo n.º 1
0
 protected void start()
 {
     RealtimeDataCenter.getInstance().registry(getCodes(), this);
     this.th = new Thread(this.worker)
     {
         IsBackground = true
     };
     this.th.Start();
 }
Exemplo n.º 2
0
        public ThreadGetDataFromTradeX(string[] arrCode, RealtimeDataCenter rdc)
        {
            foreach (var item in arrCode)
            {
                addObj(item);
            }

            this.rdc = rdc;
        }
Exemplo n.º 3
0
        //private List<KeyValuePair<RealtimeData, RecvRealtimeData>> ltRddRd = new List<KeyValuePair<RealtimeData, RecvRealtimeData>>();

        /*
         * 两种创建方式:唯一实例,这也是推荐的使用方式;也可以在某些特殊情况下使用普通new(即手动调用构造函数)
         */
        static public RealtimeDataCenter getInstance(int thCount = 8, string codes = null, EDataSource ds = EDataSource.sinajs)
        {
            if (null == s_instance)
            {
                s_instance = new RealtimeDataCenter(thCount, codes, ds);
            }

            return(s_instance);
        }
Exemplo n.º 4
0
        protected void unregistry(string code)
        {
            if (this.ssCode.Contains(code))
            {
                this.ssCode.Remove(code);
            }

            if (this.th != null)
            {
                RealtimeDataCenter.getInstance().unregistry(code, this);
            }
        }
Exemplo n.º 5
0
        public ThreadGetDataFromHttp2(string[] arrCode, RealtimeDataCenter rdc)
        {
            this.codes   = "";
            this.codes_i = "";
            foreach (var item in arrCode)
            {
                this.codes   += (getPlusPrefixCode(item) + ",");
                this.codes_i += (getPlusPrefixCode(item) + "_i,");
            }

            this.rdc      = rdc;
            this.dcCodeFD = new Dictionary <string, RealtimeDataCenter.FinancialData>();
        }
Exemplo n.º 6
0
        private void worker()
        {
            List <RealtimeDataCenter.RealtimeData> ltRd = new List <RealtimeDataCenter.RealtimeData>();

            bool bHasData = true;

            while (true)
            {
                if (!bHasData)
                {
                    System.Threading.Thread.Sleep(1);
                }

                RealtimeDataCenter.getInstance().getData(this, ref ltRd);
                if (ltRd.Count <= 0)
                {
                    bHasData = false;
                }
                else
                {
                    bHasData = true;

                    this.bNeedSort = false;
                    foreach (var rd in ltRd)
                    {
                        recv(rd); //this.bNeedSort' value may be changed in here
                    }

                    if (bNeedSort)
                    {
                        sort();
                        this.bNeedSort = false;
                    }

                    ltRd.Clear();
                }

                if (this.iTimerMS >= 0)
                {
                    TimeSpan tsNow  = new TimeSpan(DateTime.Now.Ticks);
                    TimeSpan tsLast = new TimeSpan(this.dtTimerLast.Ticks);
                    if (tsNow.Subtract(tsLast).TotalMilliseconds >= this.iTimerMS)
                    {
                        timer();
                        this.dtTimerLast = DateTime.Now;
                    }
                }
            }
        }
Exemplo n.º 7
0
        protected bool registry(string code)
        {
            if (this.ssCode.Contains(code))
            {
                return(false);
            }

            this.ssCode.Add(code);
            if (this.th != null)
            {
                RealtimeDataCenter.getInstance().registry(code, this);
            }

            return(true);
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            /*
             * string szTime = DateTime.Now.ToString("HHmmss");
             * while (string.Compare(szTime, "091500") < 0
             || string.Compare(szTime, "150000") > 0)
             ||{
             || Console.WriteLine(szTime);
             || System.Threading.Thread.Sleep(1000);
             || szTime = DateTime.Now.ToString("HHmmss");
             ||}
             */

            StringBuilder sErrInfo = new StringBuilder(256);
            int           ret      = TradeXB.OpenTdx(sErrInfo);

            if (ret < 0)
            {
                Console.WriteLine("TradeXB.OpenTdx error: " + sErrInfo);
                Console.ReadLine();
                return;
            }

            RealtimeDataCenter.getInstance(5, "999999,399001,399006", RealtimeDataCenter.EDataSource.tradeX);
            Limit.getInstance();
            Reactor.getInstance();

            TN   tn   = new TN();
            MAID maid = new MAID();
            RI   ri   = new RI();
            RT   rt   = new RT();

            while (true)
            {
                Console.ReadLine();
            }
        }
Exemplo n.º 9
0
 protected void stop()
 {
     RealtimeDataCenter.getInstance().unregistry(getCodes(), this);
     this.th.Abort();
 }