コード例 #1
0
        private static void Main(string[] args)
        {
            ConfigureLogger();

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

            IConfigurationRoot configuration = builder.Build();

            Mapper.Initialize(config => config.MapEntities());

            var containerBuilder = ConfigureServices();

            // We only have one settings provider so this works for the moment
            var provider = configuration.Providers.First();

            CheckWhatIsEnabled(provider,
                               out bool coinigyEnabled,
                               out bool bittrexEnabled,
                               out bool poloniexEnabled,
                               out bool bagEnabled,
                               out bool dustEnabled);

            var busBuilder = new BusBuilder();

            busBuilder.ConfigureCore(coinigyEnabled, bittrexEnabled, poloniexEnabled, bagEnabled, dustEnabled);

            containerBuilder.RegisterMicroBus(busBuilder);
            var container = containerBuilder.Build();

            var loggerFactory = container.Resolve <ILoggerFactory>().AddSerilog();
            var log           = loggerFactory.CreateLogger <Program>();

            log.LogInformation($"Services\nCoinigy: {coinigyEnabled}\nBittrex: {bittrexEnabled}\nPoloniex: {poloniexEnabled}\nBag Management: {bagEnabled}\nDust Notifications: {dustEnabled}");
            ConfigureConfig(container, configuration, log);

            var startupService = container.Resolve <StartupCheckingService>();
            var context        = container.Resolve <CryptoGramBotDbContext>();

            DbInitializer.Initialize(context).Wait();
            log.LogInformation("Database migrated.");

            startupService.MigrateToSqlLite().Wait();

            startupService.Start(coinigyEnabled, bittrexEnabled, poloniexEnabled, bagEnabled);

            while (true)
            {
                Console.ReadKey();
            }
            ; //This wont stop app
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: tash649/CryptoGramBot
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterInstance(Configuration).As <IConfiguration>().SingleInstance();

            var serviceCollection = new ServiceCollection().AddLogging(loggingBuilder =>
                                                                       loggingBuilder.AddSerilog(dispose: true));

            serviceCollection.AddDbContextPool <CryptoGramBotDbContext>(options =>
                                                                        options.UseSqlite(StringContants.DatabaseLocation)
                                                                        );

            serviceCollection.AddBinance();

            serviceCollection.BuildServiceProvider();

            containerBuilder.Populate(serviceCollection);

            containerBuilder.Register(c => new OptionsWrapper <UserDataWebSocketClientOptions>(new UserDataWebSocketClientOptions
            {
                KeepAliveTimerPeriod = KEEP_ALIVE_PERIOD_IN_MILLISECONDS //If you set the default time(30 minutes) when the keep alive connection occurs unspecified error.
            }))
            .As <IOptions <UserDataWebSocketClientOptions> >();

            containerBuilder.RegisterType <CoinigyConfig>().SingleInstance();
            containerBuilder.RegisterType <TelegramConfig>().SingleInstance();
            containerBuilder.RegisterType <BittrexConfig>().SingleInstance();
            containerBuilder.RegisterType <BinanceConfig>().SingleInstance();
            containerBuilder.RegisterType <PoloniexConfig>().SingleInstance();
            containerBuilder.RegisterType <GeneralConfig>().SingleInstance();
            containerBuilder.RegisterType <CoinigyApiService>();
            containerBuilder.RegisterType <CryptoCompareApiService>();
            containerBuilder.RegisterType <BittrexService>();
            containerBuilder.RegisterType <PoloniexService>();
            containerBuilder.RegisterType <BinanceService>();
            containerBuilder.RegisterType <BinanceCacheService>().As <IBinanceCacheService>();
            containerBuilder.RegisterType <BinanceSubscriberService>().As <IBinanceSubscriberService>().SingleInstance();
            containerBuilder.RegisterType <BinanceWebsocketService>().As <IBinanceWebsocketService>().SingleInstance();
            containerBuilder.RegisterType <DatabaseService>();
            containerBuilder.RegisterType <TelegramMessageReceiveService>().SingleInstance();
            containerBuilder.RegisterType <TelegramMessageSendingService>();
            containerBuilder.RegisterType <StartupCheckingService>().SingleInstance();
            containerBuilder.RegisterType <CoinigyBalanceService>();
            containerBuilder.RegisterType <TelegramBot>().SingleInstance();
            containerBuilder.RegisterType <PriceService>();
            containerBuilder.RegisterType <ProfitAndLossService>();
            containerBuilder.RegisterType <TradeExportService>();
            containerBuilder.RegisterType <TelegramBittrexFileUploadService>();
            containerBuilder.RegisterType <TelegramPairProfitService>();
            containerBuilder.RegisterType <PoloniexClientFactory>().As <IPoloniexClientFactory>();

            CheckWhatIsEnabled(out bool coinigyEnabled,
                               out bool bittrexEnabled,
                               out bool poloniexEnabled,
                               out bool binanceEnabled);

            var busBuilder = new BusBuilder();

            busBuilder.ConfigureCore(coinigyEnabled, bittrexEnabled, poloniexEnabled, binanceEnabled);

            containerBuilder.RegisterMicroBus(busBuilder);
            Container = containerBuilder.Build();

            var loggerFactory = Container.Resolve <ILoggerFactory>();
            var log           = loggerFactory.CreateLogger <Program>();

            log.LogInformation($"Services\nCoinigy: {coinigyEnabled}\nBinance: {binanceEnabled}\nBittrex: {bittrexEnabled}\nPoloniex: {poloniexEnabled}");
            ConfigureConfig(Container, Configuration, log);
        }
コード例 #3
0
ファイル: Startup.cs プロジェクト: tuyentranhp/CryptoGramBot
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterInstance(Configuration).As <IConfiguration>().SingleInstance();

            var serviceCollection = new ServiceCollection().AddLogging(loggingBuilder =>
                                                                       loggingBuilder.AddSerilog(dispose: true));

            var databaseLocation = Directory.GetCurrentDirectory() + "/database/cryptogrambot.sqlite";

            serviceCollection.AddDbContext <CryptoGramBotDbContext>(options =>
                                                                    options.UseSqlite("Data Source=" + databaseLocation + ";cache=shared")
                                                                    );

            containerBuilder.Populate(serviceCollection);

            containerBuilder.RegisterType <CoinigyConfig>().SingleInstance();
            containerBuilder.RegisterType <TelegramConfig>().SingleInstance();
            containerBuilder.RegisterType <BittrexConfig>().SingleInstance();
            containerBuilder.RegisterType <PoloniexConfig>().SingleInstance();
            containerBuilder.RegisterType <BagConfig>().SingleInstance();
            containerBuilder.RegisterType <DustConfig>().SingleInstance();
            containerBuilder.RegisterType <GeneralConfig>().SingleInstance();
            containerBuilder.RegisterType <LowBtcConfig>().SingleInstance();
            containerBuilder.RegisterType <CoinigyApiService>();
            containerBuilder.RegisterType <BittrexService>();
            containerBuilder.RegisterType <PoloniexService>();
            containerBuilder.RegisterType <DatabaseService>();
            containerBuilder.RegisterType <TelegramMessageRecieveService>().SingleInstance();
            containerBuilder.RegisterType <TelegramMessageSendingService>().SingleInstance();
            containerBuilder.RegisterType <StartupCheckingService>().SingleInstance();
            containerBuilder.RegisterType <CoinigyBalanceService>();
            containerBuilder.RegisterType <TelegramBot>().SingleInstance();
            containerBuilder.RegisterType <PriceService>().SingleInstance();
            containerBuilder.RegisterType <ProfitAndLossService>();
            containerBuilder.RegisterType <TradeExportService>();
            containerBuilder.RegisterType <TelegramBittrexFileUploadService>();
            containerBuilder.RegisterType <TelegramPairProfitService>();

            Mapper.Initialize(config => config.MapEntities());

            CheckWhatIsEnabled(out bool coinigyEnabled,
                               out bool bittrexEnabled,
                               out bool poloniexEnabled,
                               out bool bagEnabled,
                               out bool dustEnabled,
                               out bool lowBtcEnabled);

            var busBuilder = new BusBuilder();

            busBuilder.ConfigureCore(coinigyEnabled, bittrexEnabled, poloniexEnabled, bagEnabled, dustEnabled);

            containerBuilder.RegisterMicroBus(busBuilder);
            var container = containerBuilder.Build();

            var loggerFactory = container.Resolve <ILoggerFactory>();
            var log           = loggerFactory.CreateLogger <Program>();

            log.LogInformation($"Services\nCoinigy: {coinigyEnabled}\nBittrex: {bittrexEnabled}\nPoloniex: {poloniexEnabled}\nBag Management: {bagEnabled}\nDust Notifications: {dustEnabled}\nLow BTC Notifications: {lowBtcEnabled}");
            ConfigureConfig(container, Configuration, log);

            var startupService = container.Resolve <StartupCheckingService>();
            var context        = container.Resolve <CryptoGramBotDbContext>();

            DbInitializer.Initialize(context).Wait();

            startupService.Start().Wait();
        }
コード例 #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterInstance(Configuration).As <IConfiguration>().SingleInstance();

            var serviceCollection = new ServiceCollection().AddLogging(loggingBuilder =>
                                                                       loggingBuilder.AddSerilog(dispose: true));

            serviceCollection.AddDbContext <CryptoGramBotDbContext>(options =>
                                                                    options.UseSqlite(StringContants.DatabaseLocation)
                                                                    );

            serviceCollection.AddBinance();

            serviceCollection.BuildServiceProvider();

            containerBuilder.Populate(serviceCollection);

            containerBuilder.RegisterType <CoinigyConfig>().SingleInstance();
            containerBuilder.RegisterType <TelegramConfig>().SingleInstance();
            containerBuilder.RegisterType <BittrexConfig>().SingleInstance();
            containerBuilder.RegisterType <BinanceConfig>().SingleInstance();
            containerBuilder.RegisterType <PoloniexConfig>().SingleInstance();
            containerBuilder.RegisterType <GeneralConfig>().SingleInstance();
            containerBuilder.RegisterType <CoinigyApiService>();
            containerBuilder.RegisterType <BittrexService>();
            containerBuilder.RegisterType <PoloniexService>();
            containerBuilder.RegisterType <BinanceService>().SingleInstance(); // because symbols is saved in it. //todo move this out into a cache
            containerBuilder.RegisterType <DatabaseService>();
            containerBuilder.RegisterType <TelegramMessageRecieveService>().SingleInstance();
            containerBuilder.RegisterType <TelegramMessageSendingService>();
            containerBuilder.RegisterType <StartupCheckingService>().SingleInstance();
            containerBuilder.RegisterType <CoinigyBalanceService>();
            containerBuilder.RegisterType <TelegramBot>().SingleInstance();
            containerBuilder.RegisterType <PriceService>();
            containerBuilder.RegisterType <ProfitAndLossService>();
            containerBuilder.RegisterType <TradeExportService>();
            containerBuilder.RegisterType <TelegramBittrexFileUploadService>();
            containerBuilder.RegisterType <TelegramPairProfitService>();
            containerBuilder.RegisterType <PoloniexClientFactory>().As <IPoloniexClientFactory>();

            CheckWhatIsEnabled(out bool coinigyEnabled,
                               out bool bittrexEnabled,
                               out bool poloniexEnabled,
                               out bool binanceEnabled,
                               out bool bagEnabled,
                               out bool dustEnabled,
                               out bool lowBtcEnabled);

            var busBuilder = new BusBuilder();

            busBuilder.ConfigureCore(coinigyEnabled, bittrexEnabled, poloniexEnabled, binanceEnabled, bagEnabled, dustEnabled);

            containerBuilder.RegisterMicroBus(busBuilder);
            Container = containerBuilder.Build();

            var loggerFactory = Container.Resolve <ILoggerFactory>();
            var log           = loggerFactory.CreateLogger <Program>();

            log.LogInformation($"Services\nCoinigy: {coinigyEnabled}\nBittrex: {bittrexEnabled}\nBinance: {binanceEnabled}\nPoloniex: {poloniexEnabled}\nBag Management: {bagEnabled}\nDust Notifications: {dustEnabled}\nLow BTC Notifications: {lowBtcEnabled}");
            ConfigureConfig(Container, Configuration, log);
        }