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); } } }
public static async Task Run([TimerTrigger("0 * * * * *")] TimerInfo sellTimer, TraceWriter log) { var serilogger = new LoggerConfiguration().WriteTo.TraceWriter(log).CreateLogger(); var logger = new LoggerFactory().AddSerilog(serilogger).CreateLogger(nameof(SellTimer)); 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.UpdateExistingTrades(); 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); } }