Example #1
0
        public async static void Init()
        {
            // Runtime platform getter
            Globals.RuntimeSettings["platform"]                        = new JObject();
            Globals.RuntimeSettings["platform"]["os"]                  = GetOs();
            Globals.RuntimeSettings["platform"]["computerName"]        = Environment.MachineName;
            Globals.RuntimeSettings["platform"]["userName"]            = Environment.UserName;
            Globals.RuntimeSettings["platform"]["webInitialized"]      = false;
            Globals.RuntimeSettings["platform"]["settingsInitialized"] = false;
            Globals.RuntimeSettings["signalrClients"]                  = new JObject();

            var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true);

            Globals.GlobalConfiguration            = builder.Build();
            Globals.GlobalTradeOptions             = Globals.GlobalConfiguration.GetSection("TradeOptions").Get <TradeOptions>();
            Globals.GlobalExchangeOptions          = Globals.GlobalConfiguration.Get <ExchangeOptions>();
            Globals.GlobalMyntHostedServiceOptions = Globals.GlobalConfiguration.GetSection("Hosting").Get <MyntHostedServiceOptions>();

            LiteDBOptions databaseOptions = new LiteDBOptions();

            Globals.GlobalDataStore = new LiteDBDataStore(databaseOptions);

            var exchangeOptions = Globals.GlobalConfiguration.Get <ExchangeOptions>();

            exchangeOptions.Exchange = Exchange.Binance;

            // Global Hubs
            Globals.GlobalHubMyntTraders    = Globals.GlobalServiceScope.ServiceProvider.GetService <IHubContext <HubMyntTraders> >();
            Globals.GlobalHubMyntStatistics = Globals.GlobalServiceScope.ServiceProvider.GetService <IHubContext <HubMyntStatistics> >();

            // Creating TradeManager
            Globals.GlobalExchangeApi = new BaseExchange(exchangeOptions);
            ILogger           paperTradeLogger  = Globals.GlobalLoggerFactory.CreateLogger <PaperTradeManager>();
            PaperTradeManager paperTradeManager = new PaperTradeManager(new BaseExchange(exchangeOptions), new FreqClassic(), new SignalrNotificationManager(), paperTradeLogger, Globals.GlobalTradeOptions, Globals.GlobalDataStore);
            var runTimer = new MyntHostedService(paperTradeManager, Globals.GlobalMyntHostedServiceOptions);

            // Start task
            await runTimer.StartAsync(Globals.GlobalTimerCancellationToken);
        }
Example #2
0
        public async static void Init()
        {
            // Runtime platform getter
            Globals.RuntimeSettings["platform"]                        = new JObject();
            Globals.RuntimeSettings["platform"]["os"]                  = GetOs();
            Globals.RuntimeSettings["platform"]["computerName"]        = Environment.MachineName;
            Globals.RuntimeSettings["platform"]["userName"]            = Environment.UserName;
            Globals.RuntimeSettings["platform"]["webInitialized"]      = false;
            Globals.RuntimeSettings["platform"]["settingsInitialized"] = false;
            Globals.RuntimeSettings["signalrClients"]                  = new JObject();

            // Check if Overrides exists
            var settingsStr = "appsettings.json";

            if (File.Exists("appsettings.overrides.json"))
            {
                settingsStr = "appsettings.overrides.json";
            }

            var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(settingsStr, optional: true);

            Globals.GlobalConfiguration            = builder.Build();
            Globals.GlobalTradeOptions             = Globals.GlobalConfiguration.GetSection("TradeOptions").Get <TradeOptions>();
            Globals.GlobalExchangeOptions          = Globals.GlobalConfiguration.Get <ExchangeOptions>();
            Globals.GlobalExchangeApi              = new BaseExchange(Globals.GlobalExchangeOptions);
            Globals.GlobalMyntHostedServiceOptions = Globals.GlobalConfiguration.GetSection("Hosting").Get <MyntHostedServiceOptions>();

            // Telegram Notifications
            Globals.GlobalTelegramNotificationOptions = Globals.GlobalConfiguration.GetSection("Telegram").Get <TelegramNotificationOptions>();

            // Database options
            LiteDBOptions databaseOptions = new LiteDBOptions();

            Globals.GlobalDataStore = new LiteDBDataStore(databaseOptions);

            // Global Hubs
            Globals.GlobalHubMyntTraders    = Globals.GlobalServiceScope.ServiceProvider.GetService <IHubContext <HubMyntTraders> >();
            Globals.GlobalHubMyntStatistics = Globals.GlobalServiceScope.ServiceProvider.GetService <IHubContext <HubMyntStatistics> >();

            // Get Strategy from appsettings.overrides.json
            var type     = Type.GetType($"Mynt.Core.Strategies.{Globals.GlobalTradeOptions.DefaultStrategy}, Mynt.Core", true, true);
            var strategy = Activator.CreateInstance(type) as ITradingStrategy ?? new TheScalper();

            // Trading mode  Configuration.GetSection("Telegram").Get<TelegramNotificationOptions>())
            var notificationManagers = new List <INotificationManager>()
            {
                new SignalrNotificationManager(),
                new TelegramNotificationManager(Globals.GlobalTelegramNotificationOptions)
            };

            if (Globals.GlobalTradeOptions.PaperTrade)
            {
                // PaperTrader
                ILogger tradeLogger       = Globals.GlobalLoggerFactory.CreateLogger <PaperTradeManager>();
                var     paperTradeManager = new PaperTradeManager(Globals.GlobalExchangeApi, strategy, notificationManagers, tradeLogger, Globals.GlobalTradeOptions, Globals.GlobalDataStore);
                var     runTimer          = new MyntHostedService(paperTradeManager, Globals.GlobalMyntHostedServiceOptions);

                // Start task
                await runTimer.StartAsync(Globals.GlobalTimerCancellationToken);
            }
            else
            {
                // LiveTrader
                ILogger tradeLogger      = Globals.GlobalLoggerFactory.CreateLogger <LiveTradeManager>();
                var     liveTradeManager = new LiveTradeManager(Globals.GlobalExchangeApi, strategy, notificationManagers, tradeLogger, Globals.GlobalTradeOptions, Globals.GlobalDataStore);
                var     runTimer         = new MyntHostedService(liveTradeManager, Globals.GlobalMyntHostedServiceOptions);

                // Start task
                await runTimer.StartAsync(Globals.GlobalTimerCancellationToken);
            }
        }