/// <summary> /// Sets settings /// </summary> /// <param name="arg"></param> /// <returns></returns> private string telegramSetSetting(string arg) { var command = new TokenizedCommands(arg); KeyValuePair <string, string> kv = command.GetKeyVal(); var settings = _strategy.Settings; object outVal; string validKey = settings.GetKeyName(kv.Key); if (validKey != null) // Key already exists, override it { Type oldType = settings.GetSettingType(validKey); if (kv.Value == "null") { settings.Remove(kv.Key); return(string.Format("Setting removed: {0}", kv.Key)); } else if (TryParseSetting(kv.Value, oldType, out outVal)) { settings.Set(validKey, outVal); return(string.Format("Set! {0} {1} {2}", validKey, outVal, oldType)); } else { return(string.Format("Uncompatible type: {0} {1} shoud be :{2}", kv.Key, kv.Value, oldType.Name)); } } else // new key of unknown type { if (TryParseSetting(kv.Value, out outVal)) { settings.Set(kv.Key, outVal); return(string.Format("Adding new key {0} {1} as {2}", kv.Key, outVal, outVal.GetType().Name)); } else { return(string.Format("Unable to recognize value type: {0} {1} ", kv.Key, kv.Value)); } } }
/// <summary> /// Gets Positions /// </summary> /// <param name="command"></param> /// <returns></returns> private string telegramGetPositions(string arg) { StringBuilder sb = new StringBuilder(); var command = new TokenizedCommands(arg); sb.AppendFormat("*Positions {0}*\n", _strategy.GetLabel() + "-" + _strategy.Robot.Account.Number); IEnumerable <Position> positions; if (command.StartsWith("all")) { positions = _strategy.Robot.Positions.OrderBy(p => p.SymbolCode); } else { positions = _strategy.GetPositions().OrderBy(p => p.SymbolCode); } if (positions.Count() == 0) { sb.Append("No positions"); } else { foreach (var p in positions) { sb.Append("\n"); sb.AppendFormat("-{0} ", p.SymbolCode); sb.AppendFormat("{0} ", p.TradeType); sb.AppendFormat("{0:0.00} ", _strategy.Symbol.VolumeToQuantity(p.Volume)); sb.AppendFormat("Pips: {0:0.0}\n", p.Pips); sb.AppendFormat("--Net: {0:c} ", p.NetProfit); if (p.Swap > 0) { sb.AppendFormat("Swp: {0:c} ", p.Swap); } sb.AppendFormat("{0:#.#}hrs", _strategy.Robot.Server.Time.Subtract(p.EntryTime).TotalHours); } } return(sb.ToString()); }