public void PostSignal(SignalInfo signal) { if ((SignalFlags)signal.Flags == SignalFlags.Cluster) { xtrade.PostSignalTo(signal); return; } switch ((EnumSignals)signal.Id) { case EnumSignals.SIGNAL_CHECK_HEALTH: if (xtrade.IsDebug()) { log.Info("CheckHealth: " + signal.Flags); } break; case EnumSignals.SIGNAL_DEALS_HISTORY: { List <DealInfo> deals = null; if (signal.Data != null) { deals = JsonConvert.DeserializeObject <List <DealInfo> >(signal.Data.ToString()); } else { deals = new List <DealInfo>(); } xtrade.SaveDeals(deals); } break; case EnumSignals.SIGNAL_CHECK_BALANCE: { if (signal.Data == null) { break; } JArray jarray = (JArray)signal.Data; if (jarray == null || jarray.Count == 0) { break; } decimal balance = jarray.First.Value <decimal?>("Balance") ?? 0; decimal equity = jarray.First.Value <decimal?>("Equity") ?? 0; int Account = jarray.First.Value <int?>("Account") ?? 0; xtrade.UpdateBalance(Account, balance, equity); } break; case EnumSignals.SIGNAL_UPDATE_RATES: break; case EnumSignals.SIGNAL_ACTIVE_ORDERS: { // Dictionary<string, string> signal = JsonConvert.DeserializeObject<Dictionary<string, string>>(parameters); // var jObject = JObject.Parse(parameters); // var jTokenData = jObject.GetValue("Data"); // var Value = jObject.GetValue("Value"); // if (jTokenData != null) List <PositionInfo> positions = null; if (signal.Data != null) { positions = JsonConvert.DeserializeObject <List <PositionInfo> >(signal.Data.ToString()); } else { positions = new List <PositionInfo>(); } terminals.UpdatePositions(signal.ObjectId, signal.Value, positions); } break; /* * case EnumSignals.SIGNAL_UPDATE_SLTP: * { * List<PositionInfo> positions = null; * if (signal.Data != null) * positions = JsonConvert.DeserializeObject<List<PositionInfo>>(signal.Data.ToString()); * else * positions = new List<PositionInfo>(); * terminals.UpdateSLTP(signal.ObjectId, signal.Value, positions); * } * break; */ case EnumSignals.SIGNAL_WARN_NEWS: break; case EnumSignals.SIGNAL_DEINIT_EXPERT: { ExpertInfo expert = JsonConvert.DeserializeObject <ExpertInfo>(signal.Data.ToString()); xtrade.DeInitExpert(expert); } break; case EnumSignals.SIGNAL_DEINIT_TERMINAL: { ExpertInfo expert = JsonConvert.DeserializeObject <ExpertInfo>(signal.Data.ToString()); xtrade.DeInitTerminal(expert); } break; // case EnumSignals.SIGNAL_SAVE_EXPERT: // { // deprecated //ExpertInfo expert = JsonConvert.DeserializeObject<ExpertInfo>(signal.Data.ToString()); //if (expert != null) // xtrade.SaveExpert(expert); // } // break; case EnumSignals.SIGNAL_POST_LOG: { if (signal.Data == null) { break; } Dictionary <string, string> paramsList = JsonConvert.DeserializeObject <Dictionary <string, string> >(signal.Data.ToString()); StringBuilder message = new StringBuilder(); if (paramsList.ContainsKey("Account")) { message.Append("<" + paramsList["Account"] + ">:"); } if (paramsList.ContainsKey("Magic")) { message.Append("_" + paramsList["Magic"] + "_:"); } if (paramsList.ContainsKey("order")) { message.Append("**" + paramsList["order"] + "**"); } if (paramsList.ContainsKey("message")) { message.Append(paramsList["message"]); } log.Log(message.ToString()); // log.Info(message); } break; } }
public void PostSignal(SignalInfo signal) { if ((SignalFlags)signal.Flags == SignalFlags.Cluster) { xtrade.PostSignalTo(signal); return; } switch ((EnumSignals)signal.Id) { case EnumSignals.SIGNAL_CHECK_HEALTH: if (xtrade.IsDebug()) { log.Info("CheckHealth: " + signal.Flags); } break; case EnumSignals.SIGNAL_DEALS_HISTORY: { List <DealInfo> deals = null; if (signal.Data != null) { deals = JsonConvert.DeserializeObject <List <DealInfo> >(signal.Data.ToString()); } else { deals = new List <DealInfo>(); } xtrade.SaveDeals(deals); } break; case EnumSignals.SIGNAL_CHECK_BALANCE: { if (signal.Data == null) { break; } JArray jarray = (JArray)signal.Data; if (jarray == null || jarray.Count == 0) { break; } decimal balance = jarray.First.Value <decimal?>("Balance") ?? 0; decimal equity = jarray.First.Value <decimal?>("Equity") ?? 0; int Account = jarray.First.Value <int?>("Account") ?? 0; xtrade.UpdateBalance(Account, balance, equity); } break; case EnumSignals.SIGNAL_UPDATE_RATES: { try { List <RatesInfo> rates = null; if (signal.Data != null) { rates = JsonConvert.DeserializeObject <List <RatesInfo> >(signal.Data.ToString()); } if (rates != null) { var usdbynrateTask = GetBYNRates(); double usdbynrate = usdbynrateTask.Result; if (usdbynrate > 0) { RatesInfo rate = new RatesInfo(); rate.Ask = usdbynrate; rate.Bid = usdbynrate; rate.Symbol = "USDBYN"; rates.Add(rate); } } xtrade.UpdateRates(rates); } catch (Exception e) { log.Info(String.Format($"GetBYNUSDRates Error: {0}", e.ToString())); } } break; case EnumSignals.SIGNAL_ACTIVE_ORDERS: { List <PositionInfo> positions = null; if (signal.Data != null) { positions = JsonConvert.DeserializeObject <List <PositionInfo> >(signal.Data.ToString()); } else { positions = new List <PositionInfo>(); } terminals.UpdatePositions(signal.ObjectId, signal.Value, positions); } break; /* * case EnumSignals.SIGNAL_UPDATE_SLTP: * { * List<PositionInfo> positions = null; * if (signal.Data != null) * positions = JsonConvert.DeserializeObject<List<PositionInfo>>(signal.Data.ToString()); * else * positions = new List<PositionInfo>(); * terminals.UpdateSLTP(signal.ObjectId, signal.Value, positions); * } * break; */ case EnumSignals.SIGNAL_WARN_NEWS: break; case EnumSignals.SIGNAL_DEINIT_EXPERT: { ExpertInfo expert = JsonConvert.DeserializeObject <ExpertInfo>(signal.Data.ToString()); xtrade.DeInitExpert(expert); } break; case EnumSignals.SIGNAL_DEINIT_TERMINAL: { ExpertInfo expert = JsonConvert.DeserializeObject <ExpertInfo>(signal.Data.ToString()); xtrade.DeInitTerminal(expert); } break; // case EnumSignals.SIGNAL_SAVE_EXPERT: // { // deprecated //ExpertInfo expert = JsonConvert.DeserializeObject<ExpertInfo>(signal.Data.ToString()); //if (expert != null) // xtrade.SaveExpert(expert); // } // break; case EnumSignals.SIGNAL_POST_LOG: { if (signal.Data == null) { break; } Dictionary <string, string> paramsList = JsonConvert.DeserializeObject <Dictionary <string, string> >(signal.Data.ToString()); StringBuilder message = new StringBuilder(); if (paramsList.ContainsKey("Account")) { message.Append("<" + paramsList["Account"] + ">:"); } if (paramsList.ContainsKey("Magic")) { message.Append("_" + paramsList["Magic"] + "_:"); } if (paramsList.ContainsKey("order")) { message.Append("**" + paramsList["order"] + "**"); } if (paramsList.ContainsKey("message")) { message.Append(paramsList["message"]); } log.Log(message.ToString()); // log.Info(message); } break; } }