Пример #1
0
        public void Init()
        {
            var serilogger = new Serilog.LoggerConfiguration().CreateLogger();
            var logger     = new LoggerFactory().AddSerilog(serilogger).CreateLogger <PaperTradeManagerTests>();

            _tradeManager = new PaperTradeManager(new BaseExchange(new ExchangeOptions()), new TheScalper(), null, logger, new TradeOptions(), new InMemoryDataStore());
        }
Пример #2
0
        public static async Task Run([TimerTrigger("0 * * * * *")] TimerInfo sellTimer, TraceWriter log, ExecutionContext context)
        {
            var config = new ConfigurationBuilder()
                         .SetBasePath(context.FunctionAppDirectory)
                         .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                         .AddEnvironmentVariables()
                         .Build();

            var logger = new LoggerConfiguration().WriteTo.TraceWriter(log).CreateLogger();

            try
            {
                logger.Information("Starting processing...");

                // Either use the default options as defined in TradeOptions or override them.
                // You can override them using the properties in the TradeOptions class below.
                var options = new TradeOptions()
                {
                    MarketBlackList = new List <string> {
                        "TRX", "XVG"
                    }
                };

                // Spin up something from Newtonsoft.Json...
                var obj = new Newtonsoft.Json.Linq.JObject();

                var exchangeOptions             = config.Get <ExchangeOptions>();
                var azureTableStorageOptions    = config.Get <AzureTableStorageOptions>();
                var telegramNotificationOptions = config.Get <TelegramNotificationOptions>();

                // Initialize a Trade Manager instance that will run using the settings provided below.
                // Once again, you can use the default values for the settings defined in te Options classes below.
                // You can also override them here or using the configuration mechanism of your choosing.
                var tradeManager = new PaperTradeManager(
                    api: new BaseExchange(exchangeOptions),
                    dataStore: new AzureTableStorageDataStore(azureTableStorageOptions),
                    logger: null,
                    notificationManager: new TelegramNotificationManager(telegramNotificationOptions),
                    settings: options,
                    strategy: new TheScalper());

                // Start running this thing!
                await tradeManager.UpdateExistingTrades();

                logger.Information("Done...");
            }
            catch (Exception ex)
            {
                // If anything goes wrong log an error to Azure.
                logger.Error(ex.Message + ex.StackTrace);

                if (ex.InnerException != null)
                {
                    logger.Error(ex.InnerException.Message + ex.InnerException.StackTrace);
                }
            }
        }
Пример #3
0
        public static async Task Run([TimerTrigger("0 * * * * *")] TimerInfo buyTimer, TraceWriter log)
        {
            var serilogger = new LoggerConfiguration().WriteTo.TraceWriter(log).CreateLogger();
            var logger     = new LoggerFactory().AddSerilog(serilogger).CreateLogger(nameof(BuyTimer));

            try
            {
                logger.LogInformation("Starting processing...");

                // Either use the default options as defined in TradeOptions or override them.
                // You can override them using the property setters here or by providing keys in your configuration mechanism
                // matching the property names in this class.

                var tradeOptions = AppSettings.Get <TradeOptions>();

                var exchangeOptions             = AppSettings.Get <ExchangeOptions>();
                var azureTableStorageOptions    = AppSettings.Get <AzureTableStorageOptions>();
                var telegramNotificationOptions = AppSettings.Get <TelegramNotificationOptions>();

                // logger.Information("Using trade options {@Options}", tradeOptions);

                // Initialize a Trade Manager instance that will run using the settings provided below.
                // Once again, you can use the default values for the settings defined in te Options classes below.
                // You can also override them here or using the configuration mechanism of your choosing.
                var tradeManager = new PaperTradeManager(
                    api: new BaseExchange(exchangeOptions),
                    dataStore: new AzureTableStorageDataStore(azureTableStorageOptions),
                    logger: logger,
                    notificationManager: new TelegramNotificationManager(telegramNotificationOptions),
                    settings: tradeOptions,
                    strategy: ApplicationHelper.TryCreateTradingStrategy(tradeOptions.DefaultStrategy) ?? new TheScalper());

                // Start running this thing!
                await tradeManager.LookForNewTrades();

                logger.LogInformation("Done...");
            }
            catch (Exception ex)
            {
                // If anything goes wrong log an error to Azure.
                logger.LogError(ex, "Error on BuyTimer");

                // TODO necessary?
//                if (ex.InnerException != null)
//                    logger.Error(ex.InnerException.Message + ex.InnerException.StackTrace);
            }
        }
Пример #4
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);
        }
Пример #5
0
 public void CreatePaperTradeManagerWithoutDataStoreShouldThrowException()
 {
     // Arrange
     var target = new PaperTradeManager(new BaseExchange(new ExchangeOptions()), new TheScalper(), null, null, new TradeOptions(), null);
 }
Пример #6
0
 public void CreatePaperTradeManagerWithoutStrategyShouldThrowException()
 {
     // Arrange
     var target = new PaperTradeManager(new BaseExchange(new ExchangeOptions()), null, null, null, new TradeOptions(), new InMemoryDataStore());
 }
Пример #7
0
 public void CreatePaperTradeManagerWithoutExchangeShouldThrowException()
 {
     // Arrange
     var target = new PaperTradeManager(null, new TheScalper(), null, null, new TradeOptions(), new InMemoryDataStore());
 }
Пример #8
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);
            }
        }