Пример #1
0
        /// <summary>
        /// Parses plain txt update to CryptoCurrencyUpdate
        /// sample input: 42["m","0~Bitfinex~BTC~USD~1~159021061~1515488499~0.119~15091.30724464~1795.86556211216~1f"]
        /// </summary>
        /// <param name="str"></param>
        /// <returns>Return null if parsing was not possible</returns>
        private CryptoCurrencyUpdate Parse(String str)
        {
            if (str.Length < 3 || !str.Substring(0, 2).Equals("42"))
            {
                return(null);
            }

            CryptoCurrencyUpdate retVal = new CryptoCurrencyUpdate();
            var strValues = str.Substring(2).Split(',')[1].Split('~');

            if (strValues[0].Substring(1) != "0")
            {
                return(null);
            }

            retVal.ExchangeName       = strValues[1];
            retVal.CryptoCurrencyName = strValues[2];
            retVal.FiatCurrencyName   = strValues[3];

            decimal decVal;

            if (decimal.TryParse(strValues[7], NumberStyles.Number, CultureInfo.InvariantCulture, out decVal))
            {
                retVal.Quantity = decVal;
            }

            if (decimal.TryParse(strValues[8], NumberStyles.Number, CultureInfo.InvariantCulture, out decVal))
            {
                retVal.LastPrice = decVal;
            }

            return(retVal);
        }
Пример #2
0
        public static async void CheckAlerts(List <AlertSetting> alertSettings, string sData)
        {
            //parse data to get current prices
            CryptoCurrencyUpdate cUpdate = Parse(sData);

            if (cUpdate != null)
            {
                string sExchange     = cUpdate.ExchangeName;
                string sCurrencyPair = cUpdate.CryptoCurrencyName + "/" + cUpdate.FiatCurrencyName;

                if (alertSettings != null)
                {
                    //loop through settings to see if we need to send any
                    foreach (AlertSetting aSetting in alertSettings)
                    {
                        //check for match
                        if (aSetting.Exchanx.SName == cUpdate.ExchangeName &&
                            aSetting.CurrencyPair.SName == (cUpdate.CryptoCurrencyName + "/" + cUpdate.FiatCurrencyName))
                        {
                            //check for setting conditions
                            if (cUpdate.LastPrice > aSetting.PriceHigh)
                            {
                                await CreateAlert(aSetting.IAlertSettingId, aSetting.IUserId.Value, "Price Up", "");
                            }

                            else if (cUpdate.LastPrice < aSetting.PriceLow)
                            {
                                await CreateAlert(aSetting.IAlertSettingId, aSetting.IUserId.Value, "Price Down", "");
                            }
                        }
                    }
                }
            }
        }