public void PostSignal(SignalInfo signal, IMessagingServer server) { if ((SignalFlags)signal.Flags == SignalFlags.Cluster) { xtrade.PostSignalTo(signal); return; } switch ((EnumSignals)signal.Id) { case EnumSignals.SIGNAL_POST_LOG: { if (signal.Data == null) { break; } MainService.thisGlobal.DoLog(signal); } break; 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>(); } var terminals = MainService.thisGlobal.Container.Resolve <ITerminalEvents>(); 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_LEVELS4SYMBOL: { string symbol = signal.Sym; string levelsString = xtrade.Levels4Symbol(symbol); var result = xtrade.CreateSignal(SignalFlags.Expert, signal.ObjectId, (EnumSignals)signal.Id, signal.ChartId); result.Sym = symbol; result.Data = levelsString; var send = JsonConvert.SerializeObject(result); if (server != null) { server.MulticastText(send); } } break; default: if (server != null) { var result = xtrade.SendSignal(signal); if (result != null) { var send = JsonConvert.SerializeObject(result); server.MulticastText(send); } } break; } }
public void PostSignal(SignalInfo signal, IMessagingServer server) { if ((SignalFlags)signal.Flags == SignalFlags.Cluster) { xtrade.PostSignalTo(signal); return; } switch ((EnumSignals)signal.Id) { case EnumSignals.SIGNAL_POST_LOG: { if (string.IsNullOrEmpty(signal.Data)) { break; } MainService.thisGlobal.DoLog(signal); } break; case EnumSignals.SIGNAL_CHECK_HEALTH: if (Utils.IsDebug()) { log.Info("CheckHealth: " + signal.Flags); } break; case EnumSignals.SIGNAL_DEALS_HISTORY: { List <DealInfo> deals = Utils.ExtractList <DealInfo>(signal.Data); xtrade.SaveDeals(deals); } break; case EnumSignals.SIGNAL_CHECK_BALANCE: { if (signal.Data == null) { break; } var jList = Utils.ExtractList <BalanceInfo>(signal.Data); if (Utils.HasAny(jList)) { BalanceInfo info = jList.FirstOrDefault(); xtrade.UpdateBalance((int)info.Account, info.Balance, info.Equity); } } break; case EnumSignals.SIGNAL_UPDATE_RATES: { try { var jRates = Utils.ExtractList <RatesInfo>(signal.Data); if (Utils.HasAny(jRates)) { var usdbynrateTask = GetBYNRates(); var usdbynrate = usdbynrateTask.Result; if (usdbynrate > 0) { var rate = new RatesInfo(); rate.Ask = usdbynrate; rate.Bid = usdbynrate; rate.Symbol = "USDBYN"; jRates.Add(rate); } } xtrade.UpdateRates(jRates); } catch (Exception e) { log.Info(string.Format($"GetBYNUSDRates Error: {0}", e)); } } break; case EnumSignals.SIGNAL_ACTIVE_ORDERS: { List <PositionInfo> positions = Utils.ExtractList <PositionInfo>(signal.Data); var terminals = MainService.thisGlobal.Container.Resolve <ITerminalEvents>(); terminals.UpdatePositions(signal.ObjectId, signal.Value, positions); } break; case EnumSignals.SIGNAL_ADD_ORDERS: { List <PositionInfo> orders = Utils.ExtractList <PositionInfo>(signal.Data); if (Utils.HasAny(orders)) { var terminals = MainService.thisGlobal.Container.Resolve <ITerminalEvents>(); terminals.AddOrders(signal.ObjectId, signal.Value, orders); } } break; case EnumSignals.SIGNAL_DELETE_ORDERS: { List <PositionInfo> orders = Utils.ExtractList <PositionInfo>(signal.Data); if (Utils.HasAny(orders)) { var terminals = MainService.thisGlobal.Container.Resolve <ITerminalEvents>(); terminals.DeleteOrders(signal.ObjectId, signal.Value, orders); } } break; case EnumSignals.SIGNAL_UPDATE_ORDERS: { List <PositionInfo> orders = Utils.ExtractList <PositionInfo>(signal.Data); if (Utils.HasAny(orders)) { var terminals = MainService.thisGlobal.Container.Resolve <ITerminalEvents>(); terminals.UpdateOrders(signal.ObjectId, signal.Value, orders); } } break; case EnumSignals.SIGNAL_WARN_NEWS: break; case EnumSignals.SIGNAL_DEINIT_EXPERT: { var expert = JsonConvert.DeserializeObject <ExpertInfo>(signal.Data); xtrade.DeInitExpert(expert); } break; case EnumSignals.SIGNAL_DEINIT_TERMINAL: { var expert = JsonConvert.DeserializeObject <ExpertInfo>(signal.Data); xtrade.DeInitTerminal(expert); } break; case EnumSignals.SIGNAL_LEVELS4SYMBOL: { var symbol = signal.Sym; var levelsString = xtrade.Levels4Symbol(symbol); var result = xtrade.CreateSignal(SignalFlags.Expert, signal.ObjectId, (EnumSignals)signal.Id, signal.ChartId); result.Sym = symbol; result.SetData(levelsString); var send = JsonConvert.SerializeObject(result); if (server != null) { server.MulticastText(send); } } break; case EnumSignals.SIGNAL_SAVELEVELS4SYMBOL: { var levels = signal.Data; xtrade.SaveLevels4Symbol(signal.Sym, levels); log.Info($"Levels Saved For Symbol {signal.Sym}: {levels}"); } break; default: if (server != null) { var result = xtrade.SendSignal(signal); if (result != null) { var send = JsonConvert.SerializeObject(result); server.MulticastText(send); } } 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; } }