Esempio n. 1
0
        private void Test02()
        {
            const int CYCLE_SEC = 20;
            long      next_t    = (TimeData.Now.T / CYCLE_SEC + 1) * CYCLE_SEC;

            for (; ;)
            {
                WrLine("----");
                WrLine("日時: " + TimeData.Now);

                // TEST_日本円/USドル
                try
                {
                    byte[] resBody = new HttpClient(
                        //////////////////////////////////////////////////////////////// $_git:secret
                        ).Perform();
                    WrLine("resBody_length: " + resBody.Length);
                    string strResBody = Encoding.UTF8.GetString(resBody);
                    WrLine("strResBody_length: " + strResBody.Length);

                    {
                        int bgn = StringTools.ExTailIndexOf(strResBody, "<td class=\"newest\">");
                        int end = StringTools.ExIndexOf(strResBody, "<span>", bgn);

                        string part = strResBody.Substring(bgn, end - bgn);

                        WrLine("$TEST_JPYUSD:" + TimeData.Now.GetCompactString() + ":" + part);
                    }
                }
                catch (Exception e)
                {
                    WrLine("" + e);
                }

                // 日本円/USドル
                try
                {
                    byte[] resBody = new HttpClient(
                        /////////////////////////////////////////////////////////////////// $_git:secret
                        ).Perform();
                    WrLine("resBody_length: " + resBody.Length);
                    string strResBody = Encoding.UTF8.GetString(resBody);
                    WrLine("strResBody_length: " + strResBody.Length);

                    {
                        string part = TagData.GetTagData(strResBody, "<td class=\"stoksPrice\">", "</td>").GetInnerString();

                        WrLine("$JPYUSD:" + TimeData.Now.GetCompactString() + ":" + part);
                    }
                }
                catch (Exception e)
                {
                    WrLine("" + e);
                }

                // 日本円/ユーロ
                try
                {
                    byte[] resBody = new HttpClient(
                        /////////////////////////////////////////////////////////////////// $_git:secret
                        ).Perform();
                    WrLine("resBody_length: " + resBody.Length);
                    string strResBody = Encoding.UTF8.GetString(resBody);
                    WrLine("strResBody_length: " + strResBody.Length);

                    {
                        string part = TagData.GetTagData(strResBody, "<td class=\"stoksPrice\">", "</td>").GetInnerString();

                        WrLine("$JPYEUR:" + TimeData.Now.GetCompactString() + ":" + part);
                    }
                }
                catch (Exception e)
                {
                    WrLine("" + e);
                }

                FxDetail("USDJPY");
                FxDetail("EURJPY");

                while (TimeData.Now.T < next_t)
                {
                    while (Console.KeyAvailable)
                    {
                        if (Console.ReadKey().KeyChar == 0x1b)                         // ? esc
                        {
                            throw new Exception("プロセス停止");
                        }
                    }
                    Thread.Sleep(2000);
                }
                next_t += CYCLE_SEC;
            }
        }
Esempio n. 2
0
        private static void FxDetail(string code)         // code: "USDJPY" etc.
        {
            try
            {
                byte[] resBody = new HttpClient(
                    //////////////////////////////////////////////////////////////////// $_git:secret
                    ).Perform();
                WrLine("resBody_length: " + resBody.Length);
                string strResBody = Encoding.UTF8.GetString(resBody);
                WrLine("strResBody_length: " + strResBody.Length);

                string stamp = TimeData.Now.GetCompactString();

                {
                    string part = TagData.GetTagData(strResBody, "<dd id=\"" + code + "_detail_bid\">", "</dd>").GetInnerString();
                    part = RemoveTag(part);

                    WrLine("$" + code + "_BID:" + stamp + ":" + part);
                }

                {
                    string part = TagData.GetTagData(strResBody, "<dd id=\"" + code + "_detail_ask\">", "</dd>").GetInnerString();
                    part = RemoveTag(part);

                    WrLine("$" + code + "_ASK:" + stamp + ":" + part);
                }

                {
                    string part = TagData.GetTagData(strResBody, "<dd id=\"" + code + "_detail_change\">", "</dd>").GetInnerString();

                    WrLine("$" + code + "_CHANGE:" + stamp + ":" + part);
                }

                {
                    string part = TagData.GetTagData(strResBody, "<dd id=\"" + code + "_detail_open\">", "</dd>").GetInnerString();
                    part = RemoveTag(part);

                    WrLine("$" + code + "_OPEN:" + stamp + ":" + part);
                }

                {
                    string part = TagData.GetTagData(strResBody, "<dd id=\"" + code + "_detail_high\">", "</dd>").GetInnerString();
                    part = RemoveTag(part);

                    WrLine("$" + code + "_HIGH:" + stamp + ":" + part);
                }

                {
                    string part = TagData.GetTagData(strResBody, "<dd id=\"" + code + "_detail_low\">", "</dd>").GetInnerString();
                    part = RemoveTag(part);

                    WrLine("$" + code + "_LOW:" + stamp + ":" + part);
                }

                {
                    string part = TagData.GetTagData(strResBody, "<div class=\"buyBox clearFix\">", "</div>").GetInnerString();
                    part = TagData.GetTagData(part, "<strong>", "</strong>").GetInnerString();

                    WrLine("$" + code + "_BUYPCT:" + stamp + ":" + part);
                }

                {
                    string part = TagData.GetTagData(strResBody, "<div class=\"sellBox clearFix\">", "</div>").GetInnerString();
                    part = TagData.GetTagData(part, "<strong>", "</strong>").GetInnerString();

                    WrLine("$" + code + "_SELLPCT:" + stamp + ":" + part);
                }

                {
                    string part = TagData.GetTagData(strResBody, "<div class=\"box\">", "</div>").GetInnerString();
                    part = TagData.GetTagData(part, "<span>", "</span>").GetInnerString();

                    WrLine("$" + code + "_BUYNUM:" + stamp + ":" + part);
                }

                {
                    string part = TagData.GetTagData(strResBody, "<div class=\"box right\">", "</div>").GetInnerString();
                    part = TagData.GetTagData(part, "<span>", "</span>").GetInnerString();

                    WrLine("$" + code + "_SELLNUM:" + stamp + ":" + part);
                }
            }
            catch (Exception e)
            {
                WrLine("" + e);
            }
        }