public async Task <IActionResult> Edit(int id, [Bind("id,disclaimer,license,timestamp,baseData")] BaseCurrency baseCurrency) { if (id != baseCurrency.id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(baseCurrency); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BaseCurrencyExists(baseCurrency.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(baseCurrency)); }
public async Task SaveSettingsAsync() { await SecureStorage.SetAsync(_wrapper.BaseCurrencySettingLocation, BaseCurrency.ToString()); var symbolsJson = JsonConvert.SerializeObject(SymbolsList); await SecureStorage.SetAsync(_wrapper.SymbolsListSettingLocation, symbolsJson); }
private decimal ConvertFromUS(BaseCurrency type, decimal USAmount) { decimal converted = 0; converted = USAmount * type.InUS; return(converted); }
public decimal ConvertTo(BaseCurrency type) { decimal converted = ConvertToUS(); converted = ConvertFromUS(type, converted); return(converted); }
/// <summary>Returns the hash code for this instance.</summary> /// <returns>A 32-bit signed integer that is the hash code for this instance.</returns> public override int GetHashCode() { unchecked { return(Value.GetHashCode() + (397 * BaseCurrency.GetHashCode()) + (397 * QuoteCurrency.GetHashCode())); } }
public override int GetHashCode() { unchecked { return(((BaseCurrency?.GetHashCode() ?? 0) * 397) ^ (QuoteCurrency?.GetHashCode() ?? 0)); } }
public override int GetHashCode() { unchecked { return((BaseCurrency.GetHashCode() * 397) ^ ContraCurrency.GetHashCode()); } }
public async Task <IActionResult> Create([Bind("id,disclaimer,license,timestamp,baseData")] BaseCurrency baseCurrency) { if (ModelState.IsValid) { _context.Add(baseCurrency); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(baseCurrency)); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) hashCode = hashCode * 59 + QuoteCurrency.GetHashCode(); hashCode = hashCode * 59 + Kind.GetHashCode(); if (TickSize != null) { hashCode = hashCode * 59 + TickSize.GetHashCode(); } if (ContractSize != null) { hashCode = hashCode * 59 + ContractSize.GetHashCode(); } if (IsActive != null) { hashCode = hashCode * 59 + IsActive.GetHashCode(); } hashCode = hashCode * 59 + OptionType.GetHashCode(); if (MinTradeAmount != null) { hashCode = hashCode * 59 + MinTradeAmount.GetHashCode(); } if (InstrumentName != null) { hashCode = hashCode * 59 + InstrumentName.GetHashCode(); } hashCode = hashCode * 59 + SettlementPeriod.GetHashCode(); if (Strike != null) { hashCode = hashCode * 59 + Strike.GetHashCode(); } hashCode = hashCode * 59 + BaseCurrency.GetHashCode(); if (CreationTimestamp != null) { hashCode = hashCode * 59 + CreationTimestamp.GetHashCode(); } if (ExpirationTimestamp != null) { hashCode = hashCode * 59 + ExpirationTimestamp.GetHashCode(); } return(hashCode); } }
/// <summary> /// Creates a Base Currency /// </summary> /// <param name="givenBaseCurrency">The given base currency</param> private void CreateBaseCurrency(string givenBaseCurrency) { var baseCurrencyInfo = this.ecbEnvelope.CubeRootEl[0].CubeItems.Find(c => c.Currency == givenBaseCurrency); if (!this.CheckIfEuro(givenBaseCurrency)) { if (baseCurrencyInfo == null) { throw new CustomArgumentException(string.Format(GlobalConstants.ERROR_BaseCurrencyDoesNotExists, givenBaseCurrency)); } } this.baseCurrency = new BaseCurrency(); this.baseCurrency.Name = this.CheckIfEuro(givenBaseCurrency) ? GlobalConstants.EURO_NAME : baseCurrencyInfo.Currency; this.baseCurrency.Rate = this.CheckIfEuro(givenBaseCurrency) ? GlobalConstants.EURO_RATE : baseCurrencyInfo.Rate; }
public async Task <ServiceResponce <GetBaseCurrencyDto> > GetBaseCurrency(int ID) { ServiceResponce <GetBaseCurrencyDto> serviceResponce = new ServiceResponce <GetBaseCurrencyDto>(); BaseCurrency basecurrency = await _dataContext.BaseCurrencys.FirstOrDefaultAsync(c => c.BaseCurrencyId == ID && c.IsActive == true); if (basecurrency != null) { serviceResponce.Data = _mapper.Map <GetBaseCurrencyDto>(basecurrency); } else { serviceResponce.Success = false; serviceResponce.Message = "No Record Found"; } return(serviceResponce); }
public bool Equals(ExchangeRatesResponse other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } var equals = BaseCurrency.Equals(other.BaseCurrency) && Date.Equals(other.Date); return(equals); }
public async Task <ServiceResponce <List <GetBaseCurrencyDto> > > AddBaseCurrency(AddBaseCurrencyDto newbasecurrency) { ServiceResponce <List <GetBaseCurrencyDto> > serviceResponse = new ServiceResponce <List <GetBaseCurrencyDto> >(); BaseCurrency basecurrency = _mapper.Map <BaseCurrency>(newbasecurrency); basecurrency.IsActive = true; basecurrency.CreatedOn = DateTime.Now; await _dataContext.BaseCurrencys.AddAsync(basecurrency); await _dataContext.SaveChangesAsync(); serviceResponse.Data = await _dataContext.BaseCurrencys.Where(x => x.IsActive == true).Select(c => _mapper.Map <GetBaseCurrencyDto>(c)).ToListAsync(); return(serviceResponse); }
// GET: BaseCurrencies/Create public async Task <IActionResult> Create() { //Initialize HTTP Client for calling the service HttpClient client = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "https://openexchangerates.org/api/latest.json?app_id=65368373a86d467481480393f8180482&base=usd"); HttpResponseMessage response = await client.SendAsync(request); if (response.IsSuccessStatusCode) { ServiceData.RootObject responseElement = new ServiceData.RootObject(); JsonSerializerSettings settings = new JsonSerializerSettings(); String responseString = await response.Content.ReadAsStringAsync(); //Call Service responseElement = JsonConvert.DeserializeObject <ServiceData.RootObject>(responseString, settings); //Deserialize JSON to C# Object // Convert Service Data Transfer Object (DTO) to Database Object to persist in database BaseCurrency newItem = new BaseCurrency(); newItem.baseData = responseElement.@base; newItem.disclaimer = responseElement.disclaimer; newItem.license = responseElement.license; newItem.timestamp = responseElement.timestamp; Rates newRate = new Rates(); newRate.AED = responseElement.rates.AED; newRate.AFN = responseElement.rates.AFN; newRate.ALL = responseElement.rates.ALL; newRate.AMD = responseElement.rates.AMD; newRate.ANG = responseElement.rates.ANG; newRate.CAD = responseElement.rates.CAD; newItem.rates = new List <Rates>(); newItem.rates.Add(newRate); //Persist DTO in Database _context.Add(newItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(await _context.BaseCurrency.ToListAsync())); }
public CurrencyConvertResponse FindRate(BaseCurrency crr) { var response = new CurrencyConvertResponse { IsSuccess = false, Message = "Unknows", Rate = 0m, Status = Enum.Status.Unknown }; var line = crr is Dollar ? "USD" : crr is Euro ? "EUR" : "ERROR"; StringBuilder sb = new StringBuilder("http://api.fixer.io/latest?base="); sb.Append(line); // currency try { using (var client = new WebClient()) { var json = client.DownloadString(sb.ToString()); var rate = JsonConvert.DeserializeObject <FixerModel>(json); response.IsSuccess = true; response.Message = "Well done kereta"; response.Rate = rate.Rates.Try; response.Status = Enum.Status.Success; } } catch (Exception ex) { Logger.Error($"Error while calculation rate. ex : {ex.StackTrace} ex.Message = {ex.Message}"); response.Status = Enum.Status.Error; response.Message = "Error while calculation rate."; } Logger.Debug($"Response : {JsonConvert.SerializeObject(response)}"); return(response); }
public async Task <ServiceResponce <GetBaseCurrencyDto> > UpdateBaseCurrency(UpdatedBaseCurrencyDto updatedBaseCurrency) { ServiceResponce <GetBaseCurrencyDto> serviceResponce = new ServiceResponce <GetBaseCurrencyDto>(); try { BaseCurrency basecurrency = await _dataContext.BaseCurrencys.FirstOrDefaultAsync(c => c.BaseCurrencyId == updatedBaseCurrency.BaseCurrencyId && c.IsActive == true); basecurrency.BaseCurrencyCode = updatedBaseCurrency.BaseCurrencyCode; basecurrency.LastModifiedBy = updatedBaseCurrency.LastModifiedBy; basecurrency.LastModifiedon = DateTime.Now; _dataContext.BaseCurrencys.Update(basecurrency); await _dataContext.SaveChangesAsync(); serviceResponce.Data = _mapper.Map <GetBaseCurrencyDto>(basecurrency); } catch (Exception e) { serviceResponce.Success = false; serviceResponce.Message = e.Message; } return(serviceResponce); }
public async Task <ServiceResponce <List <GetBaseCurrencyDto> > > DeleteBaseCurrency(int ID) { ServiceResponce <List <GetBaseCurrencyDto> > serviceResponce = new ServiceResponce <List <GetBaseCurrencyDto> >(); try { BaseCurrency basecurrency = await _dataContext.BaseCurrencys.FirstAsync(c => c.BaseCurrencyId == ID); basecurrency.IsActive = false; basecurrency.LastModifiedon = DateTime.Now; _dataContext.BaseCurrencys.Update(basecurrency); await _dataContext.SaveChangesAsync(); serviceResponce.Data = await(_dataContext.BaseCurrencys.Where(x => x.IsActive == true).Select(c => _mapper.Map <GetBaseCurrencyDto>(c))).ToListAsync(); } catch (Exception e) { serviceResponce.Success = false; serviceResponce.Message = e.Message; } return(serviceResponce); }
public async Task <ActionResult> Get() { try { var model = new BaseCurrency { currency = "test1", name = "test2", can_deposit = "1", can_withdraw = "0", min_withdrawal = "100" }; await _baseCurrencyRepository.InsertAsync(model); return(Ok(JsonHelper.ToJson(model))); } catch (Exception ex) { _logger.LogError(ex, "失败!"); return(StatusCode(500)); } }
/// <inheritdoc /> public override string ToString() { return($"{BaseCurrency.ToString().ToUpper()}_{QuoteCurrency.ToString().ToUpper()}"); }
public override int GetHashCode() { return(BaseCurrency.GetHashCode() ^ CounterCurrency.GetHashCode()); }
public override int GetHashCode() { var hashCode = BaseCurrency.GetHashCode() ^ Date.GetHashCode(); return(hashCode); }
public static decimal CurrencyConvert(decimal amount, BaseCurrency fromCur, BaseCurrency toCur) { return(new ConvertibleCurrency(fromCur, amount).ConvertTo(toCur)); }
public bool HasCurrency(Currency currency) { return(BaseCurrency.Equals(currency) || QuoteCurrency.Equals(currency)); }
/// <summary> /// Returns true if BookSummary instances are equal /// </summary> /// <param name="other">Instance of BookSummary to be compared</param> /// <returns>Boolean</returns> public bool Equals(BookSummary other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( UnderlyingIndex == other.UnderlyingIndex || UnderlyingIndex != null && UnderlyingIndex.Equals(other.UnderlyingIndex) ) && ( Volume == other.Volume || Volume != null && Volume.Equals(other.Volume) ) && ( VolumeUsd == other.VolumeUsd || VolumeUsd != null && VolumeUsd.Equals(other.VolumeUsd) ) && ( UnderlyingPrice == other.UnderlyingPrice || UnderlyingPrice != null && UnderlyingPrice.Equals(other.UnderlyingPrice) ) && ( BidPrice == other.BidPrice || BidPrice != null && BidPrice.Equals(other.BidPrice) ) && ( OpenInterest == other.OpenInterest || OpenInterest != null && OpenInterest.Equals(other.OpenInterest) ) && ( QuoteCurrency == other.QuoteCurrency || QuoteCurrency != null && QuoteCurrency.Equals(other.QuoteCurrency) ) && ( High == other.High || High != null && High.Equals(other.High) ) && ( EstimatedDeliveryPrice == other.EstimatedDeliveryPrice || EstimatedDeliveryPrice != null && EstimatedDeliveryPrice.Equals(other.EstimatedDeliveryPrice) ) && ( Last == other.Last || Last != null && Last.Equals(other.Last) ) && ( MidPrice == other.MidPrice || MidPrice != null && MidPrice.Equals(other.MidPrice) ) && ( InterestRate == other.InterestRate || InterestRate != null && InterestRate.Equals(other.InterestRate) ) && ( Funding8h == other.Funding8h || Funding8h != null && Funding8h.Equals(other.Funding8h) ) && ( MarkPrice == other.MarkPrice || MarkPrice != null && MarkPrice.Equals(other.MarkPrice) ) && ( AskPrice == other.AskPrice || AskPrice != null && AskPrice.Equals(other.AskPrice) ) && ( InstrumentName == other.InstrumentName || InstrumentName != null && InstrumentName.Equals(other.InstrumentName) ) && ( Low == other.Low || Low != null && Low.Equals(other.Low) ) && ( BaseCurrency == other.BaseCurrency || BaseCurrency != null && BaseCurrency.Equals(other.BaseCurrency) ) && ( CreationTimestamp == other.CreationTimestamp || CreationTimestamp != null && CreationTimestamp.Equals(other.CreationTimestamp) ) && ( CurrentFunding == other.CurrentFunding || CurrentFunding != null && CurrentFunding.Equals(other.CurrentFunding) )); }
public override string ToString() { return($"{Id} - [Base Currency : {BaseCurrency?.ToString()}] - [Quote Currency : {QuoteCurrency?.ToString()}] | {Value}"); }
public ConvertibleCurrency(BaseCurrency type, decimal val) { currency = type; amount = val; }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (UnderlyingIndex != null) { hashCode = hashCode * 59 + UnderlyingIndex.GetHashCode(); } if (Volume != null) { hashCode = hashCode * 59 + Volume.GetHashCode(); } if (VolumeUsd != null) { hashCode = hashCode * 59 + VolumeUsd.GetHashCode(); } if (UnderlyingPrice != null) { hashCode = hashCode * 59 + UnderlyingPrice.GetHashCode(); } if (BidPrice != null) { hashCode = hashCode * 59 + BidPrice.GetHashCode(); } if (OpenInterest != null) { hashCode = hashCode * 59 + OpenInterest.GetHashCode(); } if (QuoteCurrency != null) { hashCode = hashCode * 59 + QuoteCurrency.GetHashCode(); } if (High != null) { hashCode = hashCode * 59 + High.GetHashCode(); } if (EstimatedDeliveryPrice != null) { hashCode = hashCode * 59 + EstimatedDeliveryPrice.GetHashCode(); } if (Last != null) { hashCode = hashCode * 59 + Last.GetHashCode(); } if (MidPrice != null) { hashCode = hashCode * 59 + MidPrice.GetHashCode(); } if (InterestRate != null) { hashCode = hashCode * 59 + InterestRate.GetHashCode(); } if (Funding8h != null) { hashCode = hashCode * 59 + Funding8h.GetHashCode(); } if (MarkPrice != null) { hashCode = hashCode * 59 + MarkPrice.GetHashCode(); } if (AskPrice != null) { hashCode = hashCode * 59 + AskPrice.GetHashCode(); } if (InstrumentName != null) { hashCode = hashCode * 59 + InstrumentName.GetHashCode(); } if (Low != null) { hashCode = hashCode * 59 + Low.GetHashCode(); } if (BaseCurrency != null) { hashCode = hashCode * 59 + BaseCurrency.GetHashCode(); } if (CreationTimestamp != null) { hashCode = hashCode * 59 + CreationTimestamp.GetHashCode(); } if (CurrentFunding != null) { hashCode = hashCode * 59 + CurrentFunding.GetHashCode(); } return(hashCode); } }
/// <summary> /// Returns true if Instrument instances are equal /// </summary> /// <param name="other">Instance of Instrument to be compared</param> /// <returns>Boolean</returns> public bool Equals(Instrument other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( QuoteCurrency == other.QuoteCurrency || QuoteCurrency.Equals(other.QuoteCurrency) ) && ( Kind == other.Kind || Kind.Equals(other.Kind) ) && ( TickSize == other.TickSize || TickSize != null && TickSize.Equals(other.TickSize) ) && ( ContractSize == other.ContractSize || ContractSize != null && ContractSize.Equals(other.ContractSize) ) && ( IsActive == other.IsActive || IsActive != null && IsActive.Equals(other.IsActive) ) && ( OptionType == other.OptionType || OptionType.Equals(other.OptionType) ) && ( MinTradeAmount == other.MinTradeAmount || MinTradeAmount != null && MinTradeAmount.Equals(other.MinTradeAmount) ) && ( InstrumentName == other.InstrumentName || InstrumentName != null && InstrumentName.Equals(other.InstrumentName) ) && ( SettlementPeriod == other.SettlementPeriod || SettlementPeriod.Equals(other.SettlementPeriod) ) && ( Strike == other.Strike || Strike != null && Strike.Equals(other.Strike) ) && ( BaseCurrency == other.BaseCurrency || BaseCurrency.Equals(other.BaseCurrency) ) && ( CreationTimestamp == other.CreationTimestamp || CreationTimestamp != null && CreationTimestamp.Equals(other.CreationTimestamp) ) && ( ExpirationTimestamp == other.ExpirationTimestamp || ExpirationTimestamp != null && ExpirationTimestamp.Equals(other.ExpirationTimestamp) )); }
public bool Equals(Pair other) { return(other != null && BaseCurrency.Equals(other.BaseCurrency) && QuoteCurrency.Equals(other.QuoteCurrency)); }
public CurrencyConvertResponse FindRate(BaseCurrency crr) { var response = new CurrencyConvertResponse { IsSuccess = false, Message = "Unknows", Rate = 0m, Status = Enum.Status.Unknown }; var line = crr is Dollar ? "USD/TRY" : crr is Euro ? "EUR/TRY" : "ERROR"; var web = new HtmlWeb(); var doc = web.Load("http://www.bloomberght.com/"); var currencyRate = doc.DocumentNode.SelectNodes("//div[@class='line2']").FirstOrDefault(c => c.ParentNode.InnerHtml.Contains(line)); if (currencyRate == null) { // log error Logger.Error($"CurrencyRate is null"); return(response); } var rateContent = Regex.Replace(currencyRate.InnerText.ToLower(), @"\s+", string.Empty); rateContent = rateContent.Replace(",", "."); var rate = 0m; #region Exception Handling try { rate = Convert.ToDecimal(rateContent); Console.WriteLine("The string as a decimal is {0}.", rate); } catch (OverflowException ex) { Logger.Error($"Error while calculation rate, OverflowException", ex); response.Status = Enum.Status.Error; response.Message = "The conversion from string to decimal overflowed."; } catch (FormatException ex) { Logger.Error($"Error while calculation rate, FormatException", ex); response.Status = Enum.Status.Error; response.Message = "The string is not formatted as a decimal."; } catch (ArgumentNullException ex) { Logger.Error($"Error while calculation rate, ArgumentNullException", ex); response.Status = Enum.Status.Error; response.Message = "The string is null."; } #endregion response.IsSuccess = true; response.Message = "Well done kereta"; response.Rate = rate; response.Status = Enum.Status.Success; Logger.Debug($"Response : {JsonConvert.SerializeObject(response)}"); return(response); }