// private decimal _targetProfitLossRatio; /// <summary> /// Initializes each Trading Asset /// </summary> /// <param name="security"></param> /// <param name="enterSignal"></param> /// <param name="exitSignal"></param> /// <param name="risk"></param> /// <param name="maximumTradeSize"></param> /// <param name="orderMethods"></param> public TradingAsset(Security security, ISignal enterSignal, IExitSignal exitSignal, decimal risk, decimal maximumTradeSize, IRequiredOrderMethods orderMethods) { _security = security; _symbol = _security.Symbol; EnterSignal = enterSignal; ExitSignal = exitSignal; _risk = risk; _maximumTradeSize = maximumTradeSize; _orderMethods = orderMethods; _tradeProfiles = new List <TradeProfile>(); }
public static void Main() { if (MultiAdminConfig.GlobalConfig.SafeServerShutdown.Value) { AppDomain.CurrentDomain.ProcessExit += OnExit; if (Utils.IsUnix) { exitSignalListener = new UnixExitSignal(); } else if (Utils.IsWindows) { exitSignalListener = new WinExitSignal(); } if (exitSignalListener != null) { exitSignalListener.Exit += OnExit; } } // Remove executable path if (Args.Length > 0) { Args[0] = null; } Headless = GetFlagFromArgs(Args, "headless", "h"); if (!Headless) { CheckMonoVersion(); } string serverIdArg = GetParamFromArgs(Args, "server-id", "id"); string configArg = GetParamFromArgs(Args, "config", "c"); portArg = uint.TryParse(GetParamFromArgs(Args, "port", "p"), out uint port) ? (uint?)port : null; Server server = null; if (!string.IsNullOrEmpty(serverIdArg) || !string.IsNullOrEmpty(configArg)) { server = new Server(serverIdArg, configArg, portArg, Args); InstantiatedServers.Add(server); } else { if (Servers.IsEmpty()) { server = new Server(port: portArg, args: Args); InstantiatedServers.Add(server); } else { Server[] autoStartServers = AutoStartServers; if (autoStartServers.IsEmpty()) { Write("No servers are set to automatically start, please enter a Server ID to start:"); InputHandler.InputPrefix?.Write(); server = new Server(Console.ReadLine(), port: portArg, args: Args); InstantiatedServers.Add(server); } else { Write("Starting this instance in multi server mode..."); for (int i = 0; i < autoStartServers.Length; i++) { if (i == 0) { server = autoStartServers[i]; InstantiatedServers.Add(server); } else { StartServer(autoStartServers[i]); } } } } } if (server != null) { if (!string.IsNullOrEmpty(server.serverId) && !string.IsNullOrEmpty(server.configLocation)) { Write( $"Starting this instance with Server ID: \"{server.serverId}\" and config directory: \"{server.configLocation}\"..."); } else if (!string.IsNullOrEmpty(server.serverId)) { Write($"Starting this instance with Server ID: \"{server.serverId}\"..."); } else if (!string.IsNullOrEmpty(server.configLocation)) { Write($"Starting this instance with config directory: \"{server.configLocation}\"..."); } else { Write("Starting this instance in single server mode..."); } server.StartServer(); } }
static Program() { OnExit = new WinExitSignal(); OnExit.Exit += OnExit_Exit; }
public static void Main(string[] args) { // F**k that, it's impossible to make Mono accept certificates from OGame, at least I'm too stupid to do it apparently. if (IsRunningOnMono()) { System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); }; } if (!File.Exists("config.json")) { Console.WriteLine("Please copy config.template.json to config.json and fill it out"); return; } IExitSignal onExitSignal = null; if (IsRunningOnMono()) { onExitSignal = new UnixExitSignal(); } else { onExitSignal = new WindowsExitSignal(); } Config config = JsonConvert.DeserializeObject <Config>(File.ReadAllText("config.json")); Logger.Instance.MinimumLogLevel = config.LogLevel; Logger.Instance.IncludeTimestamp = config.LogIncludeTimestamp; Logger.Instance.Log(LogLevel.Info, $"Loaded settings, user: {config.Username}, server: {config.Server}"); // Setup OGameStringProvider stringProvider = OGameStringProvider.Load(@"Resources/strings-en.json"); CultureInfo clientServerCulture = CultureInfo.GetCultureInfo("da-DK"); var commander = new CommandBase.Commander(); // Processing OGameClient client = new OGameClient(config.Server, stringProvider, config.Username, config.Password, commander); client.Settings.ServerUtcOffset = TimeSpan.FromHours(1); client.Settings.Galaxies = 8; client.Settings.Systems = 499; client.ServerCulture = clientServerCulture; Logger.Instance.Log(LogLevel.Debug, "Prepared OGameClient"); // Savers client.RegisterSaver(new GalaxyPageSaver()); client.RegisterSaver(new EspionageReportSaver()); client.RegisterSaver(new GalaxyPageDebrisSaver()); client.RegisterSaver(new MessageSaver()); client.RegisterSaver(new PlayerPlanetSaver()); client.RegisterSaver(new GalaxyActivitySaver()); client.RegisterSaver(new HostileAttackEmailSender(config.HostileWarning.From, config.HostileWarning.To, config.HostileWarning.Server, config.HostileWarning.Login, config.HostileWarning.Password)); // Injects client.RegisterInject(new CommandsInject()); client.RegisterInject(new CargosForTransportInject()); client.RegisterInject(new PlanetExclusiveInject(client)); client.RegisterInject(new CommonInject()); client.RegisterInject(new BuildQueueInject()); client.RegisterInject(new CustomPlanetOrderInject(config.CustomOrder)); client.RegisterInject(new EventListTotalsInject()); // UA stuff client.RegisterDefaultHeader("Accept-Language", "en-GB,en;q=0.8,da;q=0.6"); client.RegisterDefaultHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); client.RegisterDefaultHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"); Logger.Instance.Log(LogLevel.Debug, "Prepared user agent"); // Show details foreach (IInterventionHandler item in client.GetIntervention()) { Logger.Instance.Log(LogLevel.Info, $"Loaded Intervention Handler: {item.GetType().FullName}"); } foreach (BaseParser item in client.GetParsers()) { Logger.Instance.Log(LogLevel.Info, $"Loaded Parser: {item.GetType().FullName}"); } foreach (SaverBase item in client.GetSavers()) { Logger.Instance.Log(LogLevel.Info, $"Loaded Saver: {item.GetType().FullName}"); } // Start proxy OgameClientProxy proxy = new OgameClientProxy(config.ListenAddress, config.ListenPort, client); proxy.SubstituteRoot = new Uri($"https://{config.Server}"); proxy.Start(); Logger.Instance.Log(LogLevel.Success, $"Prepared reverse proxy, visit: {proxy.ListenPrefix}"); // Kick-off client.IssueRequest(client.RequestBuilder.GetPage(Objects.Types.PageType.Overview)); // Example job ApiImporterJob job1 = new ApiImporterJob(client, new DirectoryInfo("temp")); job1.Start(); AuctionMonitor monitor = new AuctionMonitor(client); client.RegisterInject(new AuctionStatusInject(monitor)); monitor.Start(); SessionKeepAliveJob job3 = new SessionKeepAliveJob(client, config.SessionKeepaliveMode); if (config.SessionKeepaliveMode == SessionKeepAliveMode.Single) { job3.PlanetId = config.SessionKeepalivePlanet; } job3.Start(); commander.Start(); Action <int> recallAction = (fleet) => { RecallFleetCommand recall = new RecallFleetCommand() { FleetId = fleet }; recall.Run(); }; if (config.FleetToRecall > 0) { recallAction(config.FleetToRecall); Thread.Sleep(5000); return; } if (config.SystemsToScan?.Count > 0) { SystemScanner sysScanner = new SystemScanner(config.SystemsToScan.Select(z => SystemCoordinate.Parse(z))); sysScanner.Start(); } SetupProxyCommands(client, config, proxy); onExitSignal.Exit += (sender, eventArgs) => { client.SaveCookies(); }; Console.TreatControlCAsInput = true; Console.ReadKey(true); client.SaveCookies(); }