Beispiel #1
0
        public static async Task Run([TimerTrigger("10 1 * * * *")] TimerInfo buyTimer, 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 property setters here or by providing keys in your configuration mechanism
                // matching the property names in this class.

                var options = new TradeOptions()
                {
                    MarketBlackList = new List <string> {
                        "TRX", "XVG"
                    }
                };

                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.LookForNewTrades();

                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);
                }
            }
        }
Beispiel #2
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);
            }
        }