public static void Main(string[] args) { const string connectionString = "Server=ProductiveDeveloperCode.database.windows.net;Database=TelegramDB;User Id=ProductiveDeveloper;Password=fDx-Vbt-Lvr-7Vg;"; SqlStorage sqlStorage = new SqlStorage(connectionString); InMemoryStorage inMemoryStorage = new InMemoryStorage(); TelegramReceiver reciver = new TelegramReceiver("984957183:AAECP59aHpYez0iBzmw_QBMb-sxMRgO5vpM"); TelegramSender telegramSender = new TelegramSender(reciver.botClient); Reminder reminder = new Reminder(telegramSender); BotDomain botDomain = new BotDomain(telegramSender, reciver, sqlStorage, inMemoryStorage, reminder); Console.WriteLine(reciver.GetHelloFromBot()); reciver.Run(); while (true) { Thread.Sleep(1800000); reminder.RemindersUpdate(); } }
public override async Task Publish() { var client = _marketMakerReportsClient.Client.LykkeTradesApi; var dataraw = await client.GetAsync(_lastTradeTime, DateTime.UtcNow, null, null); var data = dataraw.Entities.OrderBy(e => e.Time).ToList(); Log.Info($"Found {data.Count} trades from {_lastTradeTime:yyyy-MM-dd HH:mm:ss}. Api: {_marketMakerReportsClient.ApiUrl}"); try { foreach (var trade in data) { var message = $"{trade.AssetPairId}, {trade.Type.ToString()}, price: {trade.Price}, Volume: {trade.Volume}; {trade.Time:HH:mm:ss}"; await TelegramSender.SendTextMessageAsync(PublisherSettings.ChatId, message); } } catch (Exception ex) { Log.Info("Error at sent trade message", exception: ex); } if (data.Any()) { _lastTradeTime = data.Max(e => e.Time); } }
public static void NotifyStartUp(IServiceProvider serviceProvider) { if (notifyStarted) { return; } lock (syncRoot) { if (notifyStarted) { return; } var configuration = serviceProvider.GetService <IConfiguration>(); var cacheNotify = serviceProvider.GetService <ICacheNotify <NotifyMessage> >(); var cacheInvoke = serviceProvider.GetService <ICacheNotify <NotifyInvoke> >(); var options = serviceProvider.GetService <IOptionsMonitor <ILog> >(); var telegramHelper = serviceProvider.GetService <TelegramHelper>(); NotifyContext = new NotifyContext(serviceProvider); INotifySender jabberSender = new NotifyServiceSender(cacheNotify, cacheInvoke); INotifySender emailSender = new NotifyServiceSender(cacheNotify, cacheInvoke); INotifySender telegramSender = new TelegramSender(options, telegramHelper); var postman = configuration["core:notify:postman"]; if ("ases".Equals(postman, StringComparison.InvariantCultureIgnoreCase) || "smtp".Equals(postman, StringComparison.InvariantCultureIgnoreCase)) { jabberSender = new JabberSender(serviceProvider); var properties = new Dictionary <string, string> { ["useCoreSettings"] = "true" }; if ("ases".Equals(postman, StringComparison.InvariantCultureIgnoreCase)) { emailSender = new AWSSender(serviceProvider, options); properties["accessKey"] = configuration["ses:accessKey"]; properties["secretKey"] = configuration["ses:secretKey"]; properties["refreshTimeout"] = configuration["ses:refreshTimeout"]; } else { emailSender = new SmtpSender(serviceProvider, options); } emailSender.Init(properties); } NotifyContext.NotifyService.RegisterSender(Constants.NotifyEMailSenderSysName, new EmailSenderSink(emailSender, serviceProvider, options)); NotifyContext.NotifyService.RegisterSender(Constants.NotifyMessengerSenderSysName, new JabberSenderSink(jabberSender, serviceProvider)); NotifyContext.NotifyService.RegisterSender(Constants.NotifyTelegramSenderSysName, new TelegramSenderSink(telegramSender, serviceProvider)); NotifyContext.NotifyEngine.BeforeTransferRequest += NotifyEngine_BeforeTransferRequest; NotifyContext.NotifyEngine.AfterTransferRequest += NotifyEngine_AfterTransferRequest; notifyStarted = true; } }
public void InitializeTest() { InMemoryStorage storage = new InMemoryStorage(); TelegramSender sender = new TelegramSender("1028662742:AAFo3RAhaGwvh2zlxVEXGTFrOeufbnOZ9z4"); TelegrammReciever reciever = new TelegrammReciever("1028662742:AAFo3RAhaGwvh2zlxVEXGTFrOeufbnOZ9z4"); Domain d = new Domain(storage, sender, reciever, 50); d.Start(); d.Stop(); }
private static void RegisterMessageSenders(IServiceCollection services) { var senderDataProvider = new MongoDbSenderDataProvider(); senderDataProvider.Init(); var telegramSender = new TelegramSender(senderDataProvider); telegramSender.Init(); services.AddSingleton <IMessageSender>(telegramSender); }
private static void NotifyStartUp() { if (notifyStarted) { return; } lock (syncRoot) { if (notifyStarted) { return; } notifyContext = new NotifyContext(); INotifySender jabberSender = new NotifyServiceSender(); INotifySender emailSender = new NotifyServiceSender(); INotifySender telegramSender = new TelegramSender(); var postman = ConfigurationManagerExtension.AppSettings["core.notify.postman"]; if ("ases".Equals(postman, StringComparison.InvariantCultureIgnoreCase) || "smtp".Equals(postman, StringComparison.InvariantCultureIgnoreCase)) { jabberSender = new JabberSender(); var properties = new Dictionary <string, string>(); properties["useCoreSettings"] = "true"; if ("ases".Equals(postman, StringComparison.InvariantCultureIgnoreCase)) { emailSender = new AWSSender(); properties["accessKey"] = ConfigurationManagerExtension.AppSettings["ses.accessKey"]; properties["secretKey"] = ConfigurationManagerExtension.AppSettings["ses.secretKey"]; properties["refreshTimeout"] = ConfigurationManagerExtension.AppSettings["ses.refreshTimeout"]; } else { emailSender = new SmtpSender(); } emailSender.Init(properties); } notifyContext.NotifyService.RegisterSender(Constants.NotifyEMailSenderSysName, new EmailSenderSink(emailSender)); notifyContext.NotifyService.RegisterSender(Constants.NotifyMessengerSenderSysName, new JabberSenderSink(jabberSender)); notifyContext.NotifyService.RegisterSender(Constants.NotifyTelegramSenderSysName, new TelegramSenderSink(telegramSender)); notifyContext.NotifyEngine.BeforeTransferRequest += NotifyEngine_BeforeTransferRequest; notifyContext.NotifyEngine.AfterTransferRequest += NotifyEngine_AfterTransferRequest; notifyStarted = true; } }
static void Main(string[] args) { InMemoryStorage storage = new InMemoryStorage(); TelegramSender sender = new TelegramSender("1028662742:AAFo3RAhaGwvh2zlxVEXGTFrOeufbnOZ9z4"); TelegrammReciever reciever = new TelegrammReciever("1028662742:AAFo3RAhaGwvh2zlxVEXGTFrOeufbnOZ9z4"); Domain d = new Domain(storage, sender, reciever, 50); d.OnSuccesAdd += D_OnSuccesAdd; d.OnFailedSend += D_OnFailedSend; d.OnSuccesSend += D_OnSuccesSend; reciever.OnFailedMessageRecieved += Reciever_OnFailedMessageRecieved; d.Start(); while (true) { string msg = Console.ReadLine(); if (msg == "/stop") { d.Stop(); Console.WriteLine("Прослушивание завершено"); break; } else { switch (msg) { case "/awaiting": var awaitingItems = storage.Get(ReminderStatus.Awaiting); foreach (ReminderItem item in awaitingItems) { Console.WriteLine($"{item.Id};\ntimeToAlarm:\t{item.date.ToString("dd MMMM yyyy HH:mm:ss")};\nmessage:\t{item.Message}"); } break; default: var id = Guid.NewGuid(); var newItem = new ReminderItem { Message = msg, date = DateTimeOffset.Now.AddSeconds(1), Id = id, _status = ReminderStatus.Awaiting, contactId = 778740583 }; storage.Add(id, newItem); break; } } } Console.ReadLine(); }
private void ButtonSend_OnClick(object sender, RoutedEventArgs e) { AttachFiles(this.MediaPanel.Children); if (ToEMail.IsChecked == true) { MailSender eMailSender = new MailSender(); eMailSender.MailSend(attachments); } if (ToTelegram.IsChecked == true) { TelegramSender telegramSender = new TelegramSender(); telegramSender.TelegramSend(attachments); } }
public override async Task Publish() { try { var balancesWithIssues = await FindBalancesWithIssues(); if (balancesWithIssues.Count > 0) { await TelegramSender.SendTextMessageAsync(PublisherSettings.ChatId, await _externalBalanceWarningProvider.GetWarningMessageAsync(balancesWithIssues)); } } catch (Exception ex) { await Log.WriteErrorAsync(nameof(BalancePublisher), nameof(Publish), "", ex); } }
public override async Task Publish() { EnsureInitialized(); try { var snapshot = await GetCurrentInventorySnapshot(); await TelegramSender.SendTextMessageAsync(PublisherSettings.ChatId, await _nettingEngineStateProvider.GetStateMessageAsync(PrevSnapshot, snapshot)); PrevSnapshot = snapshot; } catch (Exception ex) { Log.Error(ex); } }
public override async Task Publish() { try { var warning = await GetWarningIfExists(); if (warning == null) { return; } await TelegramSender.SendTextMessageAsync(PublisherSettings.ChatId, await _marketMakerArbitragesWarningProvider.GetWarningMessageAsync(warning)); } catch (Exception ex) { await Log.WriteErrorAsync(nameof(MarketMakerArbitragesPublisher), nameof(Publish), "", ex); } }
private async Task CheckApi(string indexName, IWarningsApi warningsApi) { if (!_lastTimes.TryGetValue(indexName, out var lastTime)) { lastTime = DateTime.UtcNow; _lastTimes[indexName] = lastTime; } var fromDate = lastTime; var toDate = DateTime.UtcNow; Log.Info($"Started requesting warning history. Api: {indexName}. LastTime: {lastTime:yyyy-MM-dd HH:mm:ss}"); IReadOnlyCollection <Warning> warnings = new List <Warning>(); try { warnings = await warningsApi.GetHistoryAsync(fromDate, toDate); foreach (var warning in warnings) { var message = $"{indexName}: {warning.Message} {warning.Time.ToIsoDateTime()}"; await TelegramSender.SendTextMessageAsync(PublisherSettings.ChatId, message); _lastTimes[indexName] = toDate; } } catch (Exception ex) { Log.Error(ex); _lastTimes[indexName] = DateTime.UtcNow; } Log.Info($"Finished request for warning history. Found: {warnings.Count} warnings. Api: {indexName}. LastTime: {lastTime:yyyy-MM-dd HH:mm:ss}"); }
public async Task SendTest() { var telegramSender = new TelegramSender("1028662742:AAFo3RAhaGwvh2zlxVEXGTFrOeufbnOZ9z4"); await telegramSender.Send(778740583, "Hi!"); }
private async Task CheckApi(string key, IReportsApi reportsApi) { if (_lastTime == default(DateTime)) { _lastTime = DateTime.UtcNow; return; } var fromDate = _lastTime; var toDate = DateTime.UtcNow; Log.Info($"Check api Start. summary. Api: {key}. LastTime: {_lastTime:yyyy-MM-dd HH:mm:ss}"); var sb = new StringBuilder(); sb.AppendLine($"=== {fromDate:yyyy/MM/dd HH:mm:ss} ==="); sb.AppendLine($"=== {toDate:yyyy/MM/dd HH:mm:ss} ==="); sb.Append(Environment.NewLine); sb.AppendLine("Liquidity Engine Summary Statistics"); sb.Append(Environment.NewLine); var countTrade = 0; try { var report = (await reportsApi.GetPositionsReportAsync(fromDate, toDate, int.MaxValue)) .Where(x => x.IsClosed) .Where(x => x.CloseDate > fromDate) .Where(x => x.CloseDate <= toDate) .ToList(); if (report.Count == 0) { return; } var grouped = report.GroupBy(x => x.AssetPairId).OrderBy(x => x.Key); var result = new List <string>(); foreach (var assetPairTrades in grouped) { var assetPairId = assetPairTrades.Key; var count = assetPairTrades.Count(); var buyVolume = assetPairTrades.Where(x => x.Type == PositionType.Long).Sum(x => x.Volume); var sellVolume = assetPairTrades.Where(x => x.Type == PositionType.Short).Sum(x => x.Volume); var isPnLInUsd = assetPairTrades.All(x => x.PnLUsd.HasValue); var pnLInUsd = isPnLInUsd ? assetPairTrades.Sum(x => x.PnLUsd.Value) : (decimal?)null; var pnL = assetPairTrades.Sum(x => x.PnL.Value); var assetPair = await _assetsServiceWithCache.TryGetAssetPairAsync(assetPairId); var quoteAssetId = assetPair?.QuotingAssetId; var asset = await _assetsServiceWithCache.TryGetAssetAsync(quoteAssetId); var quoteAssetDisplayId = quoteAssetId == null ? null : asset.Id; var quoteAssetStr = string.IsNullOrWhiteSpace(quoteAssetDisplayId) ? "[quote asset]" : quoteAssetDisplayId; var pnLStr = pnLInUsd.HasValue ? $"{Math.Round(pnLInUsd.Value, 4)}$" : $"{Math.Round(pnL, 4)} {quoteAssetStr}"; var assetPairMessage = $"{assetPairId}; " + $"PL={pnLStr}; " + $"Count: {count}; " + $"Sell: {Math.Round(sellVolume, 6)}; " + $"Buy: {Math.Round(buyVolume, 6)}; "; result.Add(assetPairMessage); } sb.AppendLine(string.Join(Environment.NewLine, result)); _lastTime = DateTime.UtcNow; await TelegramSender.SendTextMessageAsync(PublisherSettings.ChatId, sb.ToString()); } catch (Exception ex) { Log.Error(ex); } Log.Info($"Check api complete. Found: {countTrade} asset pairs. Api: {key}. LastTime: {_lastTime:yyyy-MM-dd HH:mm:ss}"); }
public RssWorker(RssClient client, TelegramSender sender, string url) { _client = client; _sender = sender; _url = url; }
private async Task CheckApi(string key, ILiquidityEngineClient client) { var fromDate = DateTime.UtcNow.Date.AddDays(-1); var toDate = DateTime.UtcNow.Date.AddDays(+1); if (!_lastClose.TryGetValue(key, out var lastClose)) { lastClose = DateTime.UtcNow; _lastClose[key] = lastClose; } Log.Info($"Check api started. Trades. Api: {key}. LastTime: {lastClose:yyyy-MM-dd HH:mm:ss}"); var countTrade = 0; try { var data = await client.Reports.GetPositionsReportAsync(fromDate, toDate, 5000); var markups = await client.InstrumentMarkupsApi.GetAllAsync(); var positions = data.Where(e => e.CloseDate > lastClose).ToList(); foreach (var position in positions.OrderBy(e => e.CloseDate)) { var assetPair = await _assetsServiceWithCache.TryGetAssetPairAsync(position.AssetPairId); var quoteAssetId = assetPair?.QuotingAssetId; var asset = await _assetsServiceWithCache.TryGetAssetAsync(quoteAssetId); var quoteAssetDisplayId = quoteAssetId == null ? null : asset.Id; var quoteAssetStr = string.IsNullOrWhiteSpace(quoteAssetDisplayId) ? "[quote asset]" : quoteAssetDisplayId; var markupModel = markups.Single(x => x.AssetPairId == position.AssetPairId); var markupValue = position.Type == PositionType.Short ? markupModel.TotalAskMarkup : markupModel.TotalBidMarkup; var markup = markupValue == -1 ? "stopped" : (markupValue * 100).ToString("0.##") + "%"; var pnL = position.PnL ?? 0; var closePrice = position.ClosePrice ?? 0; var pnLStr = position.PnLUsd.HasValue ? $"{Math.Round(position.PnLUsd.Value, 4)}$" : $"{Math.Round(pnL, 4)} {quoteAssetStr}"; var message = $"{position.AssetPairId}; " + $"PL={pnLStr}; " + $"{(position.Type == PositionType.Short ? "Sell" : "Buy")}; " + $"Volume: {Math.Round(position.Volume, 6)}; " + $"OpenPrice: {Math.Round(position.Price, 6)}; " + $"ClosePrice: {Math.Round(closePrice, 6)}; " + $"Close: {position.CloseDate:MM-dd HH:mm:ss}; " + $"Markup: {markup}"; if (positions.Count >= 4800) { message += "; !!!max count of position in day, please add limit!!!"; } await TelegramSender.SendTextMessageAsync(PublisherSettings.ChatId, message); if (position.CloseDate.HasValue) { _lastClose[key] = position.CloseDate.Value; } countTrade++; } } catch (Exception ex) { Log.Error(ex); _lastClose[key] = DateTime.UtcNow; } Log.Info($"Check api completed. Found: {countTrade} trades. Api: {key}. LastTime: {lastClose:yyyy-MM-dd HH:mm:ss}"); }