public void Execute() { _logger.LogInformation("Execute task await to sell - {time}", DateTimeOffset.Now); var ShoulSell = _decisionMakerService.DecideIfShouldSell(); if (ShoulSell) { _logger.LogInformation("Bot Decide to Sell - {time}", DateTimeOffset.Now); _taskSell.Execute(); } else { _logger.LogInformation("Bot Decide to NOT sell - {time}", DateTimeOffset.Now); } }
public void Execute(dynamic objData) { try { // *************************************** Init services *************************************** //new Task _logger.LogInformation("******************** NEW TASK *********************"); //Starting task _logger.LogInformation("Starting main task - {time}", DateTimeOffset.Now); // set the private Key of the service BITCOIN TRADE _bitCoinTradeService.SetKey((string)_genericService.getObjectFromDynamic("TradeKey", objData)); // set the Percent Buy Order Limit _bitCoinTradeService.SetPercentBuyOrderLimit((decimal)_genericService.getObjectFromDynamic("SetPercentBuyOrderLimit", objData)); // set the Percent sell Order Limit _bitCoinTradeService.SetPercentSellOrderLimit((decimal)_genericService.getObjectFromDynamic("SetPercentSellOrderLimit", objData)); // set the private key of notification service _notificationService.SetKey((string)_genericService.getObjectFromDynamic("NotificationKey", objData)); //set the buy value order _bitCoinTradeService.SetOrderValue((decimal)_genericService.getObjectFromDynamic("BuyValueOrder", objData)); //Notificate bot is alive if (_notificateBotIsAlive) { _notificationService.BotIsAliveNotification(); _notificateBotIsAlive = false; } //Retrive the crypto currency type enum EnumCryptoCurrencyType enumType; var canConvert = Enum.TryParse <EnumCryptoCurrencyType>((string)_genericService.getObjectFromDynamic("EnumCryptoCurrencyType", objData), out enumType); if (!canConvert) { throw new CoreException("crypto currency not defined on enum: " + (string)_genericService.getObjectFromDynamic("EnumCryptoCurrencyType", objData)); } // set the crypto Currency type _decisionMakerService.SetCryptoCurrencyTypeEnum(enumType); // set the crypto Currency URL decision maker _decisionMakerService.SetURLdecisonMaker((string)_genericService.getObjectFromDynamic("URLdecisonMaker", objData)); // set the values to sell _decisionMakerService.SetPercentToSell((decimal)_genericService.getObjectFromDynamic("lowToSell", objData), (decimal)_genericService.getObjectFromDynamic("highToSell", objData)); // set the crypto Currency type _bitCoinTradeService.SetCryptoCurrencyTypeEnum(enumType); //set the crypto Currency type _cryptoCurrencyService.SetCryptoCurrencyType(enumType); // *************************************** Decide which State to Go ****************************** var state = _decisionMakerService.DecideWhichStateToGo(); if (state == EnumBotState.EnumBotStateType.awaitToBuy) { _awaitToBuyTask.Execute(); } else if (state == EnumBotState.EnumBotStateType.tryToBuy) { _buyTask.Execute(); } else if (state == EnumBotState.EnumBotStateType.awaitToSell) { _awaiToSellTask.Execute(); } else if (state == EnumBotState.EnumBotStateType.tryToSell) { _sellTask.Execute(); } // ************************************************ End TASK *************************************** _logger.LogInformation("Ending main task - {time}", DateTimeOffset.Now); } catch (CoreException cex) { _logger.LogError("CoreException - " + cex.Message + " - {time}", DateTimeOffset.Now); _notificationService.ErrorNotification(cex.Message); } catch (Exception ex) { _logger.LogError("Exeception - " + ex.Message + " - {time}", DateTimeOffset.Now); _notificationService.ErrorNotification(ex.Message); } }