📄 nseutilities.cs
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -