private async Task <BotResponseModel> Calculate() { GoldValue responseGold; NasdaqValue responseNasdaq; FetchMode mode = (FetchMode)Enum.Parse(typeof(FetchMode), fetchMode); switch (mode) { case FetchMode.alphavantage: responseGold = await AlphaVantage_Gold(); responseNasdaq = await AlphaVantage_Nasdaq(); break; case FetchMode.investing: responseGold = await InvestingGold(); responseNasdaq = await InvestingNasdaq(); break; default: return(null); } decimal NasPercent = (responseNasdaq.Open * 100) / responseNasdaq.Close; decimal GoldPercent = (NasPercent * 0.4996M) / 100; decimal Pip = (responseGold.Price * GoldPercent) / 100; decimal Sl = 0; decimal A = 0; if (responseNasdaq.Open > responseNasdaq.Close) { A = responseGold.Price + Pip; Sl = responseGold.Price - Pip; } else { A = responseGold.Price - Pip; Sl = responseGold.Price + Pip; } BotResponseModel jsonResult = new BotResponseModel() { Pip = Pip, Sl = Sl, Tp = A, NasdaqPercent = NasPercent, GoldPercent = GoldPercent, Gold_Price = responseGold.Price, Nasdaq_Open = responseNasdaq.Open, Nasdaq_Close = responseNasdaq.Close }; return(jsonResult); }
public async Task <bool> Execute() { BotResponseModel jsonResult = await Calculate(); string strFormattedResult = JsonConvert.SerializeObject(jsonResult, Formatting.Indented); string botToken = _configuration.GetValue <string>("Bot:Token"); Telegram.Bot.TelegramBotClient botClient = new Telegram.Bot.TelegramBotClient(botToken); BotSettingModel setting = _bot.LoadSetting(); foreach (string receiver in setting.Receivers) { Telegram.Bot.Types.ChatId chatId = new Telegram.Bot.Types.ChatId(receiver); await botClient.SendTextMessageAsync(chatId, strFormattedResult); } return(true); }
public async Task <bool> GetResponse(long chatId) { string botToken = _configuration.GetValue <string>("Bot:Token"); Telegram.Bot.TelegramBotClient botClient = new Telegram.Bot.TelegramBotClient(botToken); try { BotResponseModel jsonResult = await Calculate(); string strFormattedResult = JsonConvert.SerializeObject(jsonResult, Formatting.Indented); await botClient.SendTextMessageAsync(chatId, strFormattedResult); return(true); } catch (Exception ex) { await botClient.SendTextMessageAsync(chatId, ex.Message); return(false); } }
public async Task <BotResponseModel> getAnswer(string say) { BotRequestModel data = new BotRequestModel() { request = new Request() { query = say, user_id = UserId }, log_id = Guid.NewGuid().ToString(), session_id = session, service_id = ServiceId }; data.dialog_state.contexts.SYS_REMEMBERED_SKILLS.Add(SkillId); var str = await client.Post(data); BotResponseModel res = JsonConvert.DeserializeObject(str, typeof(BotResponseModel)) as BotResponseModel; session = res.result.session_id; return(res); }