9
« on: 05.07.2024, 23:49:00 »
public static string Transaq_HandleData(string data)
{
string sTime = DateTime.Now.ToString("HH:mm:ss.fff");
string info = "";
string textForWindow = data;
log.WriteLog("ServerData: " + data);
XmlReaderSettings xs = new XmlReaderSettings();
xs.IgnoreWhitespace = true;
xs.ConformanceLevel = ConformanceLevel.Fragment;
xs.ProhibitDtd = false;
XmlReader xr = XmlReader.Create(new System.IO.StringReader(data), xs);
string section = "";
string line = "";
string str = "";
string ename = "";
string[] array = { "0", "0", "0", "0" };
string sberdata = "";
string stakanID = "";
string evalue = "";
string attr = "";
string seccodeID = "0";
string seccodeID1 = "0";
string VolBuyID = "0";
string VolSellID = "0";
string buyID = "0";
string sellID = "0";
string seccodeID2 = "0";
string buyID2 = "0";
string sellID2 = "0";
string priceID2 = "0";
string transactionID2 = "0";
string dealID = "0";
string minpriceID = "0";
string maxpriceID = "0";
// обработка "узлов"
while (xr.Read())
{
switch (xr.NodeType)
{
case XmlNodeType.Element:
// ename1 = xr.Name; break;
case XmlNodeType.EndElement:
ename = xr.Name; break;
case XmlNodeType.Text:
case XmlNodeType.CDATA:
case XmlNodeType.Comment:
case XmlNodeType.XmlDeclaration:
evalue = xr.Value; break;
case XmlNodeType.DocumentType:
ename = xr.Name; evalue = xr.Value; break;
default: break;
}
if (xr.Depth == 0)
{
if (xr.NodeType == XmlNodeType.Element)
{
section = ename;
if ((section != "boards") && (section != "securities") && (section != "quotations") && (section != "pits") && (section != "sec_info") && (section != "sec_info_upd") && (textForWindow.Length > 0))
{
Form_AddText(textForWindow);
textForWindow = "";
}
line = "";
str = "";
for (int i = 0; i < xr.AttributeCount; i++)
{
str = str + xr.GetAttribute(i) + ";";
}
}
if (xr.NodeType == XmlNodeType.EndElement)
{
//line = "";
//section = "";
}
if (xr.NodeType == XmlNodeType.Text)
{
str = str + evalue + ";";
}
}
if (section == "sec_info_upd") //quotes
{
if (ename == "sec_info_upd1")
{
if (xr.NodeType == XmlNodeType.Element)
{
seccodeID1 = "0";
minpriceID = "0";
maxpriceID = "0";
}
if (xr.NodeType == XmlNodeType.EndElement)
{
// On_New_Quotation(sberdata);
// Add_Trade(order_num, trade_num, acc_code, sec_id, trade_operation, trade_time, trade_qty, trade_price);
}
}
else
{
if (xr.NodeType == XmlNodeType.Text)
{
sberdata = "";
if (ename == "seccode") seccodeID = evalue;
if (ename == "minprice")
{
minpriceID = evalue;
sberdata = "minprice;" + seccodeID + ";" + minpriceID + ";" + VolSellID;
// On_New_Quotation3(sberdata);
}
if (ename == "maxprice")
{
maxpriceID = evalue;
sberdata = "maxprice;" + seccodeID + ";" + maxpriceID + ";" + VolBuyID;
// On_New_Quotation3(sberdata);
}
}
}
}
if (section == "quotations") //quotes
{
if (ename == "quotation")
{
if (xr.NodeType == XmlNodeType.Element)
{
seccodeID = "0";
VolBuyID = "0";
VolSellID = "0";
buyID = "0";
sellID = "0";
}
if (xr.NodeType == XmlNodeType.EndElement)
{
On_New_Quotation(sberdata);
}
}
else
{
if (xr.NodeType == XmlNodeType.Text)
{
sberdata = "";
if (ename == "seccode") seccodeID = evalue;
if (ename == "biddepth")
{
VolBuyID = evalue;
sberdata = "BID;" + seccodeID + ";" + buyID + ";" + VolBuyID;
On_New_Quotation(sberdata);
}
if (ename == "offerdepth")
{
VolSellID = evalue;
sberdata = "SELL;" + seccodeID + ";" + sellID + ";" + VolSellID;
// On_New_Quotation(sberdata);
}
if (ename == "bid")
{
buyID = evalue;
sberdata = "BID;" + seccodeID + ";" + buyID + ";" + VolBuyID;
// On_New_Quotation(sberdata);
}
if (ename == "offer")
{
sellID = evalue;
sberdata = "SELL;" + seccodeID + ";" + sellID + ";" + VolSellID;
On_New_Quotation(sberdata);
}
}
}
}
if (section == "quotes") //quotes
{
if (ename == "quote")
{
if (xr.NodeType == XmlNodeType.Element)
{
seccodeID2 = "0";
priceID2 = "0";
buyID2 = "0";
sellID2 = "0";
}
if (xr.NodeType == XmlNodeType.EndElement)
{
// On_New_Quotation(sberdata);
// Add_Trade(order_num, trade_num, acc_code, sec_id, trade_operation, trade_time, trade_qty, trade_price);
}
}
else
{
if (xr.NodeType == XmlNodeType.Text)
{
stakanID = "";
if (ename == "seccode") seccodeID2 = evalue;
if (ename == "price") priceID2 = evalue;
if (ename == "buy")
{
buyID2 = evalue;
stakanID = "BUY;" + seccodeID2 + ";" + priceID2 + ";" + buyID2;
// On_New_Security(sberdata);
}
if (ename == "sell") //количество бумаг к продаже
{
sellID2 = evalue;
stakanID = "SELL;" + seccodeID2 + ";" + priceID2 + ";" + sellID2;
// On_New_Security(stakanID);
}
}
}
}
//................................................................................
// данные по свечам
if (section == "candles")
{
if (ename == "candles")
{
}
if (ename == "candle")
{
}
}
//................................................................................
// данные по клиенту
if (section == "client")
{
if (ename == "client")
{
if (xr.NodeType == XmlNodeType.Element)
{
line = "";
str = "";
for (int i = 0; i < xr.AttributeCount; i++)
{
str = str + xr.GetAttribute(i) + ";";
}
// определение параметров клиента
//string[] с_attrs = str.Split(';');
//if (с_attrs.Length > 0)
//{
// ClientCode = с_attrs[0];
//}
line = "add client: " + str;
}
}
else
{
line = "";
if (xr.NodeType == XmlNodeType.Text)
{
str = str + evalue + ";";
line = "set: " + ename + "=" + evalue;
}
}
}
//................................................................................
// данные для позиций
if (section == "positions")
{
line = "";
if (xr.NodeType == XmlNodeType.Text)
{
line = ename + ": " + evalue;
}
}
//................................................................................
if (section == "overnight")
{
if (xr.NodeType == XmlNodeType.Element)
{
line = "";
str = "";
for (int i = 0; i < xr.AttributeCount; i++)
{
str = str + "<" + xr.GetAttribute(i) + ">;";
}
line = "set overnight status: " + str;
}
}
//................................................................................
// данные о статусе соединения с сервером
if (section == "server_status")
{
if (xr.NodeType == XmlNodeType.Element)
{
line = "";
str = "";
string attr_connected = xr.GetAttribute("connected");
if (attr_connected == "true") bConnected = true;
if (attr_connected == "false") bConnected = false;
for (int i = 0; i < xr.AttributeCount; i++)
{
attr = xr.GetAttribute(i);
str = str + i.ToString() + ":<" + attr + ">;";
}
line = "set server_status: " + str;
}
}
if (section == "orders") //обрабатываем заявки
{
if (ename == "order")
{
if (xr.NodeType == XmlNodeType.Element)
{
transactionID2 = "0";
line = "";
str = "";
for (int i = 0; i < xr.AttributeCount; i++)
{
transactionID2 = xr.GetAttribute(i);
// Form_AddText2(transactionID2);
}
// On_New_Security(transactionID2);
// On_New_Security(transactionID2);
}
if (xr.NodeType == XmlNodeType.EndElement)
{
// On_New_Quotation(sberdata);
// Add_Trade(order_num, trade_num, acc_code, sec_id, trade_operation, trade_time, trade_qty, trade_price);
}
}
else
{
if (xr.NodeType == XmlNodeType.Text)
{
//Form_AddText2(BuyBest);
if (ename == "orderno")
{
transactionID2 = transactionID2 + ";" + evalue; //Код инструмента
//On_New_Security(transactionID2);
// Form_AddText2(transactionID2);
}
if (ename == "seccode")
{
transactionID2 = transactionID2 + ";" + evalue; //Код инструмента
//On_New_Security(transactionID2);
// Form_AddText2(transactionID2);
}
if (ename == "status")
{
transactionID2 = transactionID2 + ";" + evalue; //Код инструмента
// On_New_Security(transactionID2);
//Form_AddText2(transactionID2);
}
if (ename == "balance") //<balance>Неудовлетворенный остаток объема заявки влотах(контрактах) </ balance >
{
transactionID2 = transactionID2 + ";" + evalue; //Код инструмента
//On_New_Security(transactionID2);
//Form_AddText2(transactionID2);
}
if (ename == "quantity")
{
transactionID2 = transactionID2 + ";" + evalue; //Код инструмента
// On_New_Security(transactionID2);
//Form_AddText2(transactionID2);
}
}
}
}
if (section == "trades") //обрабатываем сделки
{
if (ename == "trade")
{
if (xr.NodeType == XmlNodeType.Element)
{
dealID = "0";
line = "";
str = "";
for (int i = 0; i < xr.AttributeCount; i++)
{
dealID = xr.GetAttribute(i);
}
}
if (xr.NodeType == XmlNodeType.EndElement)
{
On_New_Quotation(sberdata);
}
}
else
{
if (xr.NodeType == XmlNodeType.Text)
{
if (ename == "orderno")//Номер заявки на бирже
{
dealID = dealID + ";" + evalue;
}
if (ename == "seccode")// Код инструмента
{
dealID = dealID + ";" + evalue;
}
if (ename == "buysell") //>B - покупка, S - продажа
{
dealID = dealID + ";" + evalue;
}
if (ename == "price") //цена
{
dealID = dealID + ";" + evalue;
}
if (ename == "quantity") //количество лотов
{
dealID = dealID + ";" + evalue;
On_New_Quotation2(dealID);
}
}
}
}
if (section == "alltrades")
{
}
if (section == "ticks")
{
}
if (line.Length > 0)
{
//line = new string(' ',xr.Depth*2) + line;
if (info.Length > 0) info = info + (char)13 + (char)10;
info = info + line;
}
}
if (info.Length > 0) { } log.WriteLog(info);
return section;
}
тут нет freememory, пытался вписать ругается, он тут нужен? как правильно добавить его?