示例#1
0
        private async void SendArbitrageAlarmNotifications(IEnumerable <Dto.TeamNotification> arbitrageAlarmNotifications)
        {
            //:bell: slack alarm emoji

            /*
             * BtcTurk/BitStamp Eth Diff
             * 1420.30 - 1397.87 = 22.43 Usd
             * BtcTurk/BitStamp Btc Diff
             * 14411.95 - 14180.73 = 231.22 Usd
             * Eth profit = 1.58
             * Btc profit = 1.60
             */

            //get all crypto currencies
            var cryptoCurrencies = GetCryptoCurrencies();

            foreach (var teamNotification in arbitrageAlarmNotifications)
            {
                var keyArray          = teamNotification.Key.Split(':');
                var currency          = Statics.GetCurrency(int.Parse(keyArray[1]));
                var profitLimitAmount = keyArray[2].ToMoneyMarketDecimalFormat();

                var successMessage = SlackMessageGenerator.GetArbitrageAlarmMessage(cryptoCurrencies, currency, profitLimitAmount);

                if (!string.IsNullOrEmpty(successMessage))
                {
                    await PostMessage(GetSlackExecutionSuccessMessage(successMessage, teamNotification.Team));

                    Delete(teamNotification.Id);
                }
            }
        }
示例#2
0
        private async void SendAssetReminderNotifications(IEnumerable <Dto.TeamNotification> assetReminderNotifications)
        {
            //:pushpin: slack pin emoji
            //mute: 100.00 Btc
            //Assets total: 1,718,393.08 Usd

            var command = new CommandBusiness().Get(DatabaseKey.Command.GetBalance);

            var utcNow = DateTime.UtcNow;

            //get notifications needs to be pushed by time interval in minutes.
            var filteredNotifications = assetReminderNotifications
                                        .Where(p => p.LastExecutedAt.AddMinutes(p.TimeInterval) < utcNow);

            foreach (var teamNotification in filteredNotifications)
            {
                var currency = Statics.GetCurrency(int.Parse(teamNotification.Key));

                var balances = GetTeamCryptoCurrencyBalances(currency, teamNotification.TeamId);

                if (!balances.Any())
                {
                    //do nothing
                    continue;
                }

                //get crypto currencies by team.provider
                var cryptoCurrencies = GetCryptoCurrencies(teamNotification.Team.Provider);

                var successText = command.Responses.First(p => p.Language == teamNotification.Team.Language && p.Depth == 0).SuccessText;

                var successMessage = SlackMessageGenerator.GetCryptoCurrencyBalanceMessage(balances, teamNotification.Team.MainCurrency, cryptoCurrencies, successText);

                var pushpinEmoji = ":pushpin:{lf}";

                successMessage = pushpinEmoji + successMessage;

                await PostMessage(GetSlackExecutionSuccessMessage(successMessage, teamNotification.Team));

                teamNotification.LastExecutedAt = DateTime.UtcNow;

                Edit(teamNotification);
            }
        }
示例#3
0
        private async void SendPriceTrackerAlarmNotifications(IEnumerable <Dto.TeamNotification> priceTrackerAlarmNotifications)
        {
            //:bell: slack alarm emoji
            //BtcTurk Btc: 17,022.33323 Usd

            var usdSellRate = new SettingBusiness().GetUsdValue();

            //get all crypto currencies
            var cryptoCurrencies = GetCryptoCurrencies();

            foreach (var teamNotification in priceTrackerAlarmNotifications)
            {
                var keyArray     = teamNotification.Key.Split(':');
                var provider     = Statics.GetProvider(int.Parse(keyArray[0]));
                var currency     = Statics.GetCurrency(int.Parse(keyArray[1]));
                var limitAmount  = keyArray[2].ToMoneyMarketDecimalFormat();
                var mainCurrency = Statics.GetMainCurrency(int.Parse(keyArray[3]));
                var alarmType    = Statics.GetAlarmType(int.Parse(keyArray[4]));

                IEnumerable <Dto.CryptoCurrency> alarms;

                if (mainCurrency == MainCurrency.Try)
                {
                    switch (alarmType)
                    {
                    case AlarmType.Sell:
                        alarms = cryptoCurrencies.Where(p => (p.UsdValue * usdSellRate) >= limitAmount &&
                                                        p.Currency == currency);
                        break;

                    case AlarmType.Purchase:
                        alarms = cryptoCurrencies.Where(p => (p.UsdValue * usdSellRate) < limitAmount &&
                                                        p.Currency == currency);
                        break;

                    default:
                        continue;
                    }
                }
                else
                {
                    switch (alarmType)
                    {
                    case AlarmType.Sell:
                        alarms = cryptoCurrencies.Where(p => p.UsdValue >= limitAmount && p.Currency == currency);
                        break;

                    case AlarmType.Purchase:
                        alarms = cryptoCurrencies.Where(p => p.UsdValue < limitAmount && p.Currency == currency);
                        break;

                    default:
                        continue;
                    }
                }

                if (provider != Provider.Unknown)
                {
                    alarms = alarms.Where(p => p.Provider == provider);
                }

                if (!alarms.Any())
                {
                    //do nothing
                    continue;
                }

                var successMessage = SlackMessageGenerator.GetCryptoCurrencyAlarmMessage(alarms, mainCurrency, usdSellRate);

                await PostMessage(GetSlackExecutionSuccessMessage(successMessage, teamNotification.Team));

                Delete(teamNotification.Id);
            }
        }