iMonitor desktop application using dotnet 4.8
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

420 lines
12 KiB

2 weeks ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using DataAccessLayer.MySql;
using DataAccessLayer.TradingDB;
using DataAccessLayer.Utils;
using iMonitorAPI;
using iMonitorApp.Properties;
using TradingReference.DAL;
namespace iMonitorApp.Classes
{
// Token: 0x0200002B RID: 43
public class TradeAlerts
{
// Token: 0x060001B5 RID: 437 RVA: 0x0000DDB4 File Offset: 0x0000BFB4
public static string CheckNewOrders()
{
string result;
try
{
string text = "New Orders OK";
IQueryable<DataAccessLayer.TradingDB.DBTrade> source = from p in new TradingDataClassesDataContext
{
CommandTimeout = 5
}.DBTrades
where p.source == "ORDERS" && p.cdateonly == (DateTime?)DateTime.Now.AddHours(-7.0).Date
select p;
string[] array = Settings.Default.StatusKeywordsNewOrders.Split(new char[]
{
','
});
for (int i = 0; i < array.Length; i++)
{
string item = array[i];
bool flag = !TradeAlerts.dick_new_orders.ContainsKey(item);
if (flag)
{
TradeAlerts.dick_new_orders.Add(item, 0);
}
int num = (from t in source
where t.status.ToUpper().Contains(item.Trim().ToUpper()) && !t.status.Contains("NEWEDGE")
select t).Count<DataAccessLayer.TradingDB.DBTrade>();
bool flag2 = num > 0;
if (flag2)
{
bool email = false;
string phone = "FALSE";
TradeAlerts.dick_new_orders[item] = TradeAlerts.dick_new_orders[item] + 1;
bool flag3 = TradeAlerts.dick_new_orders[item] > Settings.Default.TradeEmailCounter;
if (flag3)
{
email = true;
bool flag4 = item == "PENDING";
if (flag4)
{
phone = "AUTO-h";
}
}
iMonitor.SendAlarm(num.ToString() + " " + item + " orders in i-Trade", new List<string>
{
"etrading"
}, "", "l", true, email, phone, 5, 15, "http://10.153.64.31:5001/iMonitor/Responder.aspx");
}
else
{
TradeAlerts.dick_new_orders[item] = 0;
}
}
result = text;
}
catch (Exception ex)
{
result = "Error: " + ex.Message;
}
return result;
}
// Token: 0x060001B6 RID: 438 RVA: 0x0000E190 File Offset: 0x0000C390
public static string CheckWorkingOrders()
{
return TradeAlerts.CheckWorkingOrders2();
}
// Token: 0x060001B7 RID: 439 RVA: 0x0000E1A8 File Offset: 0x0000C3A8
public static string CheckWorkingOrders2()
{
bool flag = TradeAlerts.IsWeekend();
string result;
if (flag)
{
result = "Working Orders-Weekend";
}
else
{
try
{
IQueryable<TradingReference.DAL.DBTrade> source = from p in new TradingDBDataContext
{
CommandTimeout = 10
}.DBTrades
where p.source == "ORDERS" && p.status.Contains("WORKING") && p.cdateonly == (DateTime?)DateTime.Now.AddHours(-7.0).Date
select p;
string text = "No orders Disabled.";
string[] array = Settings.Default.StatusKeywordsWorkingOrders.Split(new char[]
{
','
});
for (int i = 0; i < array.Length; i++)
{
string item = array[i];
bool flag2 = !TradeAlerts.dick_working_orders2.ContainsKey(item);
if (flag2)
{
TradeAlerts.dick_working_orders2.Add(item, 0);
}
int num = (from t in source
where t.validity.ToUpper().Contains(item.Trim().ToUpper())
select t).Count<TradingReference.DAL.DBTrade>();
bool flag3 = num > 0;
if (flag3)
{
bool email = false;
string phone = "FALSE";
string overridealarmlevel = "l";
TradeAlerts.dick_working_orders2[item] = TradeAlerts.dick_working_orders2[item] + 1;
bool flag4 = TradeAlerts.dick_working_orders2[item] >= Convert.ToInt32(Settings.Default[item + "EmailCounter"]);
if (flag4)
{
email = true;
}
bool flag5 = TradeAlerts.dick_working_orders2[item] >= Convert.ToInt32(Settings.Default[item + "PhoneCounter"]);
if (flag5)
{
phone = "TRUE";
}
bool flag6 = TradeAlerts.dick_working_orders2[item] >= Convert.ToInt32(Settings.Default[item + "EscalationCounter"]);
if (flag6)
{
overridealarmlevel = "m";
}
bool flag7 = TradeAlerts.dick_working_orders2[item] >= 2 * Convert.ToInt32(Settings.Default[item + "EscalationCounter"]);
if (flag7)
{
overridealarmlevel = "h";
}
string text2 = "";
List<string> list = new List<string>();
foreach (TradingReference.DAL.DBTrade dbtrade in from t in source
where t.validity.ToUpper().Contains(item.Trim().ToUpper())
select t)
{
text2 = string.Concat(new string[]
{
text2,
"Contract: ",
dbtrade.contract,
" Strategy: ",
dbtrade.strategy,
" Account: ",
dbtrade.account,
" Basket: ",
dbtrade.high_low_price,
"<br/>"
});
list.Add(dbtrade.high_low_price);
}
iMonitor.SendAlarm(string.Concat(new string[]
{
num.ToString(),
" Orders are ",
item,
" on ",
string.Join(",", list.Distinct<string>().ToList<string>())
}), new List<string>
{
"etrading"
}, "<![CDATA[" + text2 + "]]>", overridealarmlevel, true, email, phone, 5, 15, "http://10.153.64.31:5001/iMonitor/Responder.aspx");
text = num.ToString() + " Working Orders are " + item;
}
else
{
TradeAlerts.dick_working_orders2[item] = 0;
}
}
result = text;
}
catch (Exception ex)
{
result = "Error: " + ex.Message;
}
}
return result;
}
// Token: 0x060001B8 RID: 440 RVA: 0x0000E84C File Offset: 0x0000CA4C
public static string CheckOutbox()
{
bool flag = TradeAlerts.IsWeekend();
string result;
if (flag)
{
result = "Order Outbox-Weekend";
}
else
{
try
{
IQueryable<Outbox> source = from p in new TradingDataClassesDataContext
{
CommandTimeout = 10
}.Outboxes
where p.createdOn >= (DateTime?)DateTime.Now.AddHours(-7.0).Date && (!p.isSent.HasValue || !p.isSent.Value)
select p;
bool flag2 = source.Count<Outbox>() > 0;
if (flag2)
{
iMonitor.SendAlarm(source.Count<Outbox>().ToString() + " Unsent emails in the outbox.", new List<string>
{
"etrading"
}, "", "NULL", true, true, "AUTO-m", 5, 15, "http://10.153.64.31:5001/iMonitor/Responder.aspx");
}
result = "No Emails in Outbox";
}
catch (Exception ex)
{
result = "Error: " + ex.Message;
}
}
return result;
}
// Token: 0x060001B9 RID: 441 RVA: 0x0000EA58 File Offset: 0x0000CC58
public static string CheckDataRecorders()
{
bool flag = TradeAlerts.IsWeekend();
string result;
if (flag)
{
result = "Data Recorders-Weekend";
}
else
{
string text = "";
bool flag2 = false;
try
{
ConnectionHandler connectionHandler = new ConnectionHandler(Settings.Default.IntradayDatabaseName, Settings.Default.IntradayDatabase);
connectionHandler.Open();
bool flag3 = !DataLogger.IsAlive(connectionHandler, TimeSpan.FromMinutes(Settings.Default.DataRecorderLatencyMinutes), Settings.Default.PrimaryDataRecorder);
if (flag3)
{
string alarmXML = ParseStackAlarms.GetAlarmXML("Primary Data Recorder not working", new List<string>
{
"mktdata"
}, "", "NULL", true, true, "AUTO-h", 20, 60, "http://4ecappcsg11:5001/Convertor.aspx");
ParseStackAlarms parseStackAlarms = new ParseStackAlarms(alarmXML);
parseStackAlarms.Process();
text = " Primary ";
flag2 = true;
}
bool flag4 = !DataLogger.IsAlive(connectionHandler, TimeSpan.FromMinutes(Settings.Default.DataRecorderLatencyMinutes), Settings.Default.SecondaryDataRecorder);
if (flag4)
{
string alarmXML2 = ParseStackAlarms.GetAlarmXML("Secondary Data Recorder not working", new List<string>
{
"mktdata"
}, "", "NULL", true, true, "FALSE", 20, 60, "http://4ecappcsg11:5001/Convertor.aspx");
ParseStackAlarms parseStackAlarms2 = new ParseStackAlarms(alarmXML2);
parseStackAlarms2.Process();
text += " Secondary ";
flag2 = true;
}
connectionHandler.Close();
bool flag5 = flag2;
if (flag5)
{
result = text.Trim() + " Data Recorders not working";
}
else
{
result = "Data Recorders OK";
}
}
catch (Exception ex)
{
result = "Error Checking DataRecorder Activity:" + ex.Message;
}
}
return result;
}
// Token: 0x060001BA RID: 442 RVA: 0x0000EC00 File Offset: 0x0000CE00
public static string CheckBaskets()
{
bool flag = TradeAlerts.IsWeekend();
string result;
if (flag)
{
result = "Basket Check-Weekend";
}
else
{
try
{
Dictionary<BasketConfig, int> basketListComplete = Baskets.GetBasketListComplete();
List<string> list = new List<string>();
double num = 0.0;
foreach (BasketConfig basketConfig in basketListComplete.Keys)
{
bool flag2 = basketConfig.enabled != null;
if (flag2)
{
bool value = basketConfig.enabled.Value;
if (value)
{
TimeSpan timeSpan = DateTime.Now - basketConfig.heartbeat.Value;
bool flag3 = timeSpan.TotalMinutes > Settings.Default.BasketSyncThresholdMinutes;
if (flag3)
{
list.Add(basketConfig.name);
bool flag4 = num < timeSpan.TotalMinutes;
if (flag4)
{
num = timeSpan.TotalMinutes;
}
}
}
}
}
bool flag5 = list.Count > 0;
if (flag5)
{
iMonitor.SendAlarm(string.Concat(new string[]
{
"Baskets ",
string.Join(",", list),
" is not enabled for the last ",
Settings.Default.BasketSyncThresholdMinutes.ToString(),
" minutes"
}), new List<string>
{
"etrading"
}, "Not enabled for the last " + num.ToString() + " minutes", "NULL", true, true, "AUTO-h", 10, 20, "http://10.153.64.31:5001/iMonitor/Responder.aspx");
result = string.Join(",", list);
}
else
{
result = "Baskets OK.";
}
}
catch (Exception ex)
{
result = "Error: " + ex.Message;
}
}
return result;
}
// Token: 0x060001BB RID: 443 RVA: 0x0000EE04 File Offset: 0x0000D004
public static string CheckGun()
{
string result;
try
{
IQueryable<DataAccessLayer.TradingDB.DBTrade> queryable = from p in new TradingDataClassesDataContext
{
CommandTimeout = 5
}.DBTrades
where p.source == "ORDERS" && p.cdateonly == (DateTime?)DateTime.Now.AddHours(-7.0).Date && (p.status.ToLower().Contains("w automate") || p.status.ToLower().Contains("working fidessa")) && Math.Abs(p.qty) <= 1m
select p;
List<string> list = (from t in Settings.Default.EmptyGunStrategues.Split(new char[]
{
','
})
select t.Trim()).ToList<string>();
foreach (DataAccessLayer.TradingDB.DBTrade dbtrade in queryable)
{
bool flag = list.Contains(dbtrade.tblAllOrders.order1);
if (flag)
{
string subject = string.Concat(new string[]
{
"Attention! Please fill the gun for ",
dbtrade.contract,
" strategy ",
dbtrade.tblAllOrders.order1,
" account ",
dbtrade.account
});
iMonitor.SendAlarm(subject, new List<string>
{
"etrading"
}, "", "l", true, true, "TRUE", 10, 20, "http://10.153.64.31:5001/iMonitor/Responder.aspx");
}
}
result = "Check Gun OK.";
}
catch (Exception ex)
{
result = "Error: " + ex.Message;
}
return result;
}
// Token: 0x060001BC RID: 444 RVA: 0x0000F1A8 File Offset: 0x0000D3A8
public static bool IsWeekend()
{
return DateTime.Now.AddHours(-7.0).DayOfWeek == DayOfWeek.Saturday || DateTime.Now.AddHours(-7.0).DayOfWeek == DayOfWeek.Sunday;
}
// Token: 0x040000E8 RID: 232
private static Dictionary<string, int> dick_new_orders = new Dictionary<string, int>();
// Token: 0x040000E9 RID: 233
private static Dictionary<string, int> dick_working_orders2 = new Dictionary<string, int>();
}
}