Пример #1
0
        /// <summary>
        /// Get quote from exchange.  Make this own class
        /// </summary>
        private void GetQuote()
        {
            try
            {
                Int32        fiatAmount   = Convert.ToInt32(txtFiat.Text);
                Models.Quote currentQuote = GetQuote(fiatAmount);

                //bind to view
                txtBitcoins.Text = currentQuote.Amount.ToString("0.000000");
                txtRate.Text     = currentQuote.Rate.ToString("0.000000");
            }
            catch (Exception ex)
            {
                GeneralExceptions("GetQuote", System.Diagnostics.TraceEventType.Critical, ex);
                ReturnToMainMenu();
            }
        }
Пример #2
0
        /// <summary>
        /// Get quote off our exchange.  Note the exchange adds margin based on terminal id.
        /// </summary>
        /// <param name="fiatAmount"></param>
        /// <returns></returns>
        public Models.Quote GetQuote(Int32 fiatAmount)
        {
            if (fiatAmount > 0)
            {
                // CryptoCurrency.Amount = Convert.ToDecimal(txtFiat.Text);
                using (DCExchange.ExchangeClient ExchangeClient = new DCExchange.ExchangeClient())
                {
                    //This method gets the buy and sell prices off 1.0 unit.
                    DCExchange.Margin margin = ExchangeClient.GetMargin(this.Settings.DefaultFiatCurrency, TerminalId);

                    Decimal rate = 0.0M;

                    if (Operation == Enums.State.Buy)
                    {
                        rate = margin.Buy;
                        CryptoCurrency.Amount = Convert.ToDecimal(fiatAmount) * margin.Buy;
                        CryptoCurrency.Fiat   = Convert.ToDecimal(fiatAmount);
                    }
                    else if (Operation == Enums.State.Sell)
                    {
                        rate = margin.Sell;
                        CryptoCurrency.Amount = Convert.ToDecimal(fiatAmount) * margin.Sell;
                        CryptoCurrency.Fiat   = Convert.ToDecimal(fiatAmount);
                    }

                    Models.Quote currentQuote = new Models.Quote()
                    {
                        Amount = CryptoCurrency.Amount,
                        Rate   = rate
                    };

                    return(currentQuote);
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException();
            }
        }