nseutilities.cs

来自「NSEGrabber is application to take live f」· CS 代码 · 共 82 行

CS
82
字号
using System;
using System.Collections.Generic;
using System.Text;

namespace NSEGrabber {
    class NSEUtilities {
        public static float getLastTradePrice(string str) {
            float lastTradePrice = 0;
            int index = str.IndexOf("Last Price");
            if (index != -1) {
                string tempStr = str.Substring(index);
                tempStr = tempStr.Substring(tempStr.IndexOf("t1>") + 3);
                int endIndex = tempStr.IndexOf("</td>");
                string ltp = tempStr.Substring(0, endIndex);
                lastTradePrice = float.Parse(ltp);
            }
            return lastTradePrice;
        }
        public static float getPreviousDayClose(string str) {
            float previousDayClose = 0;
            int index = str.IndexOf("Prev. Close");
            if (index != -1) {
                string tempStr = str.Substring(index);
                tempStr = tempStr.Substring(tempStr.IndexOf("t1>") + 3);
                int endIndex = tempStr.IndexOf("</td>");
                string ltp = tempStr.Substring(0, endIndex);
                previousDayClose = float.Parse(ltp);
            }
            return previousDayClose;
        }

        public static int getTradeQuantity(string str) {
            int tradeQuantity = 0;
            int index = str.IndexOf("Total traded quantity");
            if (index != -1) {
                string tempStr = str.Substring(index);
                tempStr = tempStr.Substring(tempStr.IndexOf("t1>") + 3);
                tempStr = tempStr.Substring(tempStr.IndexOf("t1>") + 3);
                tempStr = tempStr.Substring(tempStr.IndexOf("t1>") + 3);
                tempStr = tempStr.Substring(tempStr.IndexOf("t1>") + 3);
                int endIndex = tempStr.IndexOf("</td>");
                string ltp = tempStr.Substring(0, endIndex);
                tradeQuantity = int.Parse(ltp);
            }
            return tradeQuantity;
        }
        public static float calculatePercentage(float yest, float today) {
            return ((today - yest) / yest) * 100;
        }
        public static float getTodaysHigh(string str) {
            float todayHigh = 0;
            int index = str.IndexOf("High", StringComparison.Ordinal);
            if (index != -1) {
                string tempStr = str.Substring(index);
                tempStr = tempStr.Substring(tempStr.IndexOf("t1>") + 3);
                tempStr = tempStr.Substring(tempStr.IndexOf("t1>") + 3);
                tempStr = tempStr.Substring(tempStr.IndexOf("t1>") + 3);
                int endIndex = tempStr.IndexOf("</td>");
                string th = tempStr.Substring(0, endIndex);
                todayHigh = float.Parse(th);
            }
            return todayHigh;
        }
        public static float getTodaysLow(string str) {
            float todayLow = 0;
            //Some problem in search the "Low". So instead use Average Price
            int index = str.IndexOf("Average Price", StringComparison.Ordinal);
            if (index != -1) {
                string tempStr = str.Substring(index);
                tempStr = tempStr.Substring(tempStr.IndexOf("t1>") + 3);
                tempStr = tempStr.Substring(tempStr.IndexOf("t1>") + 3);
                tempStr = tempStr.Substring(tempStr.IndexOf("t1>") + 3);
                tempStr = tempStr.Substring(tempStr.IndexOf("t1>") + 3);
                int endIndex = tempStr.IndexOf("</td>");
                string tl = tempStr.Substring(0, endIndex);
                todayLow = float.Parse(tl);
            }
            return todayLow;
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?