public void Exchange_KwhPrice_ShouldMatch() { var kwhPriceInUsd = KwhPrice / FiatExchanges[Currency]; var kwhPriceInBtc = kwhPriceInUsd / UsdBtcRate; Assert.AreEqual(kwhPriceInBtc, ExchangeRateApi.GetKwhPriceInBtc(), DoubleAccuracy); }
// full of state private static bool CheckIfProfitable(double currentProfit, bool log = true) { if (ConfigManager.IsMiningRegardlesOfProfit) { if (log) { Logger.Info(Tag, $"Mine always regardless of profit"); } return(true); } // TODO FOR NOW USD ONLY var currentProfitUsd = (currentProfit * ExchangeRateApi.GetUsdExchangeRate()); var minProfit = ConfigManager.GeneralConfig.MinimumProfit; _isProfitable = currentProfitUsd >= minProfit; if (log) { Logger.Info(Tag, $"Current global profit = {currentProfitUsd.ToString("F8")} USD/Day"); if (!_isProfitable) { Logger.Info(Tag, $"Current global profit = NOT PROFITABLE, MinProfit: {minProfit.ToString("F8")} USD/Day"); } else { var profitabilityInfo = minProfit.ToString("F8") + " USD/Day"; Logger.Info(Tag, $"Current global profit = IS PROFITABLE, MinProfit: {profitabilityInfo}"); } } return(_isProfitable); }
public static async Task MinerStatsCheck() { await _semaphore.WaitAsync(); try { foreach (var m in _runningMiners.Values) { // skip if not running or if await already in progress if (!m.IsRunning || m.IsUpdatingApi) { continue; } var ad = m.GetSummaryAsync(); } // Update GUI ApplicationStateManager.RefreshRates(); // now we shoud have new global/total rate display it var kwhPriceInBtc = ExchangeRateApi.GetKwhPriceInBtc(); var profitInBTC = MiningStats.GetProfit(kwhPriceInBtc); ApplicationStateManager.DisplayTotalRate(profitInBTC); } catch (Exception e) { Logger.Error(Tag, $"Error occured while getting mining stats: {e.Message}"); } finally { _semaphore.Release(); } // TODO put this somewhere else maybe await RestartStagnatedMiners(); }
// full of state private bool CheckIfProfitable(double currentProfit, bool log = true) { // TODO FOR NOW USD ONLY var currentProfitUsd = (currentProfit * ExchangeRateApi.GetUsdExchangeRate()); _isProfitable = _isMiningRegardlesOfProfit || !_isMiningRegardlesOfProfit && currentProfitUsd >= ConfigManager.GeneralConfig.MinimumProfit; if (log) { Helpers.ConsolePrint(Tag, "Current Global profit: " + currentProfitUsd.ToString("F8") + " USD/Day"); if (!_isProfitable) { Helpers.ConsolePrint(Tag, "Current Global profit: NOT PROFITABLE MinProfit " + ConfigManager.GeneralConfig.MinimumProfit.ToString("F8") + " USD/Day"); } else { var profitabilityInfo = _isMiningRegardlesOfProfit ? "mine always regardless of profit" : ConfigManager.GeneralConfig.MinimumProfit.ToString("F8") + " USD/Day"; Helpers.ConsolePrint(Tag, "Current Global profit: IS PROFITABLE MinProfit " + profitabilityInfo); } } return(_isProfitable); }
private static (double fiatBalance, string fiatSymbol) getFiatFromBtcBalance(double btcBalance) { var usdAmount = (BtcBalance * ExchangeRateApi.GetUsdExchangeRate()); var fiatBalance = ExchangeRateApi.ConvertToActiveCurrency(usdAmount); var fiatSymbol = ExchangeRateApi.ActiveDisplayCurrency; return(fiatBalance, fiatSymbol); }
public void Exchange_ShouldMatchInitialized() { Assert.AreEqual(UsdBtcRate, ExchangeRateApi.GetUsdExchangeRate()); const double testAmountInUsd = 3256.85; var testInCur = testAmountInUsd * FiatExchanges[Currency]; Assert.AreEqual(testInCur, ExchangeRateApi.ConvertToActiveCurrency(testAmountInUsd)); }
public void Exchange_KwhPrice_ShouldBe0For0Exchange() { ExchangeRateApi.UpdateExchangesFiat(new Dictionary <string, double> { { "HMB", 0 } }); ExchangeRateApi.ActiveDisplayCurrency = "HMB"; Assert.AreEqual(0, ExchangeRateApi.GetKwhPriceInBtc()); }
public async Task MinerStatsCheck() { var currentProfit = 0.0d; _mainFormRatesComunication.ClearRates(_runningGroupMiners.Count); var checks = new List <GroupMiner>(_runningGroupMiners.Values); try { foreach (var groupMiners in checks) { var m = groupMiners.Miner; // skip if not running or if await already in progress if (!m.IsRunning || m.IsUpdatingApi) { continue; } m.IsUpdatingApi = true; var ad = await m.GetSummaryAsync(); m.IsUpdatingApi = false; if (ad == null) { Helpers.ConsolePrint(m.MinerTag(), "GetSummary returned null.."); } // set rates if (ad != null && NHSmaData.TryGetPaying(ad.AlgorithmID, out var paying)) { groupMiners.CurrentRate = paying * ad.Speed * 0.000000001; if (NHSmaData.TryGetPaying(ad.SecondaryAlgorithmID, out var secPaying)) { groupMiners.CurrentRate += secPaying * ad.SecondarySpeed * 0.000000001; } // Deduct power costs var powerUsage = ad.PowerUsage > 0 ? ad.PowerUsage : groupMiners.TotalPower; groupMiners.CurrentRate -= ExchangeRateApi.GetKwhPriceInBtc() * powerUsage * 24 / 1000; groupMiners.PowerRate = ExchangeRateApi.GetKwhPriceInBtc() * powerUsage * 24 / 1000; } else { groupMiners.CurrentRate = 0; // set empty ad = new ApiData(groupMiners.AlgorithmType); } currentProfit += groupMiners.CurrentRate; // Update GUI _mainFormRatesComunication.AddRateInfo(m.MinerTag(), groupMiners.DevicesInfoString, ad, groupMiners.CurrentRate, groupMiners.PowerRate, m.IsApiReadException); } } catch (Exception e) { Helpers.ConsolePrint(Tag, e.Message); } }
public void ExportTest() { string pathExport = "ExchangeRate4.xlsx"; ExchangeRateApi api = new ExchangeRateApi(); string path = AppDomain.CurrentDomain.BaseDirectory + pathExport; var list = api.SortByAndExport(path, false, true).GetAwaiter().GetResult(); Assert.True(list); }
public static void Initialize(TestContext context) { ConfigManager.GeneralConfig.DisplayCurrency = Currency; ConfigManager.GeneralConfig.KwhPrice = KwhPrice; // Add exchange info ExchangeRateApi.UsdBtcRate = UsdBtcRate; ExchangeRateApi.UpdateExchangesFiat(FiatExchanges); ExchangeRateApi.ActiveDisplayCurrency = Currency; }
protected void SubtractPowerFromProfit() { // This is power usage in BTC/hr var power = PowerUsage / 1000 * ExchangeRateApi.GetKwhPriceInBtc(); // Now it is power usage in BTC/day power *= 24; // Now we subtract from profit, which may make profit negative CurrentProfit -= power; }
public void Exchange_ShouldFallOnUsdWhenUnknown() { // Set to unknown currency ExchangeRateApi.ActiveDisplayCurrency = "ETH"; var testAmount = R.NextDouble() * 20000; Assert.AreEqual(testAmount, ExchangeRateApi.ConvertToActiveCurrency(testAmount), DoubleAccuracy); Assert.AreEqual("USD", ExchangeRateApi.ActiveDisplayCurrency); Assert.AreEqual(testAmount, ExchangeRateApi.ConvertToActiveCurrency(testAmount), DoubleAccuracy); }
public async Task GetRateAsync_ArgumentsNullOrEmpty(string from, string to) { var logger = TestHelper.CreateDefaultLogger(); var httpMessageHandler = new Mock <HttpMessageHandler>(); var httpClient = new HttpClient(httpMessageHandler.Object); var exchageRateApi = new ExchangeRateApi(httpClient, logger.Object); var rate = await exchageRateApi.GetRateAsync(from, to); Assert.IsNull(rate); }
public static void Initialize(TestContext context) { // Use this to init exchange rates ExchangeRateApiTest.Initialize(context); // Assume this is returning correct value because it's tested elsewhere _kwhInBtc = ExchangeRateApi.GetKwhPriceInBtc(); _algorithm = new Algorithm(Miner, Algo, "") { AvaragedSpeed = Speed, PowerUsage = PowerUsage }; }
public async Task GetRateAsync_ArgumentsEquals() { var logger = TestHelper.CreateDefaultLogger(); var httpMessageHandler = new Mock <HttpMessageHandler>(); var httpClient = new HttpClient(httpMessageHandler.Object); var exchageRateApi = new ExchangeRateApi(httpClient, logger.Object); var currency = EurCurrency; var rate = await exchageRateApi.GetRateAsync(currency, currency); Assert.AreEqual(1m, rate); }
public async Task Get() { var repository = new ExchangeRateApi( this.configuration, this.httpClientFactory, this.policyFactory, this.logger); var response = await repository .GetAsync( new DateTime(2017, 09, 25), new DateTime(2017, 09, 29)); Assert.IsNotNull(response); Assert.IsNotEmpty(response); }
public async Task GetRateAsync_ResponseSuccessJsonWithoutRate() { var logger = TestHelper.CreateDefaultLogger(); var response = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(@"{""result"": ""success""}"), }; var httpMessageHandler = new Mock <HttpMessageHandler>(); var httpClient = new HttpClient(httpMessageHandler.Object); httpMessageHandler.Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(response); var exchageRateApi = new ExchangeRateApi(httpClient, logger.Object); var rate = await exchageRateApi.GetRateAsync(EurCurrency, UsdCurrency); Assert.IsNull(rate); }
public async Task WeightedExchangeRate_Returns_ExpectedResult() { var clientFactory = new HttpClientFactory(new NullLogger <HttpClientFactory>()); var repo = new ExchangeRateApi(this._configuration, clientFactory, this._policyFactory, this._logger); var repoDecorator = new ExchangeRateApiCachingDecorator(repo); var exchangeRates = new ExchangeRatesService(repoDecorator, this._loggerExchRate); var calculator = new TradePositionWeightedAverageExchangeRateService(exchangeRates, this._calculatorLogger); var tradeOne = new Order().Random(); var tradeTwo = new Order().Random(); var tradeThree = new Order().Random(); tradeOne.FilledDate = new DateTime(2017, 01, 01); tradeTwo.FilledDate = new DateTime(2017, 10, 25); tradeThree.FilledDate = new DateTime(2017, 10, 25); var position = new TradePosition(new List <Order> { tradeOne, tradeTwo, tradeThree }); var usd = new Currency("usd"); var wer = await calculator.WeightedExchangeRate(position, usd, this._ruleCtx); }
//constructors public MainViewModel() { mExchangeRateApi = new ExchangeRateApi(); mExchangeRateDb = new ExchangeRateDb(); Rates = new ObservableCollection <RateViewObject>(); }
private void Display_PricingTab() { List<CurrencyData> activeCurrencyList = m_refCurrency.GetActiveCurrencyList(); List<ExchangeRateData> exchangeRateList = new List<ExchangeRateData>(); if (activeCurrencyList.Count > 1) { ExchangeRateApi exchangeRateApi = new ExchangeRateApi(); Criteria<ExchangeRateProperty> exchangeRateCriteria = new Criteria<ExchangeRateProperty>(); List<long> currencyIDList = new List<long>(); for (int i = 0; i <= (activeCurrencyList.Count - 1); i++) { currencyIDList.Add(activeCurrencyList[i].Id); } exchangeRateCriteria.AddFilter(ExchangeRateProperty.BaseCurrencyId, CriteriaFilterOperator.EqualTo, m_refContentApi.RequestInformationRef.CommerceSettings.DefaultCurrencyId); exchangeRateCriteria.AddFilter(ExchangeRateProperty.ExchangeCurrencyId, CriteriaFilterOperator.In, currencyIDList.ToArray()); exchangeRateList = exchangeRateApi.GetCurrentList(exchangeRateCriteria); } bool showPricingTier = this.ShowPricingTier(); ltr_pricing.Text = this.CommerceLibrary.GetPricingMarkup(entry_edit_data.Pricing, activeCurrencyList, exchangeRateList, entry_edit_data.EntryType, showPricingTier, Util_GetMode()); }
private void Display_PricingTab(EntryData versionData) { Currency m_refCurrency = new Currency(m_refContentApi.RequestInformationRef); Ektron.Cms.Workarea.workareabase workarearef = new Ektron.Cms.Workarea.workareabase(); List<CurrencyData> activeCurrencyList = m_refCurrency.GetActiveCurrencyList(); List<ExchangeRateData> exchangeRateList = new List<ExchangeRateData>(); if (activeCurrencyList.Count > 1) { ExchangeRateApi exchangeRateApi = new ExchangeRateApi(); Criteria<ExchangeRateProperty> exchangeRateCriteria = new Criteria<ExchangeRateProperty>(); List<long> currencyIDList = new List<long>(); for (int i = 0; i <= (activeCurrencyList.Count - 1); i++) { currencyIDList.Add(activeCurrencyList[i].Id); } exchangeRateCriteria.AddFilter(ExchangeRateProperty.BaseCurrencyId, CriteriaFilterOperator.EqualTo, m_refContentApi.RequestInformationRef.CommerceSettings.DefaultCurrencyId); exchangeRateCriteria.AddFilter(ExchangeRateProperty.ExchangeCurrencyId, CriteriaFilterOperator.In, currencyIDList.ToArray()); exchangeRateList = exchangeRateApi.GetCurrentList(exchangeRateCriteria); } ltr_pricing.Text = workarearef.CommerceLibrary.GetPricingMarkup(versionData.Pricing, activeCurrencyList, exchangeRateList, entry_data.EntryType, false, workareaCommerce.ModeType.View); }
protected void Util_PopulateData(CurrencyData currency) { ExchangeRateData exchangeRateData = new ExchangeRateData(); decimal rate = (decimal) 0.0; ExchangeRateApi exchangeRateApi = new ExchangeRateApi(); exchangeRateData = exchangeRateApi.GetCurrentExchangeRate(currency.Id); if (exchangeRateData != null) { rate = exchangeRateData.Rate; } txt_name.Text = currency.Name; txt_numericisocode.Text = currency.Id.ToString(); txt_alphaisocode.Text = currency.AlphaIsoCode; chk_enabled.Checked = currency.Enabled; txt_exchangerate.Text = rate.ToString(); //txt_exchangerate.Text = txt_exchangerate.Text.Substring(0, txt_exchangerate.Text.LastIndexOf(".") + 3) }
private void Display_ExchangeRate() { Ektron.Cms.Common.Criteria<CurrencyProperty> criteria = new Ektron.Cms.Common.Criteria<CurrencyProperty>(sortCriteria, Ektron.Cms.Common.EkEnumeration.OrderByDirection.Ascending); System.Collections.Generic.List<CurrencyData> currencyList; criteria.PagingInfo = new PagingInfo(1000); criteria.PagingInfo.CurrentPage = _currentPageNumber; criteria.AddFilter(CurrencyProperty.Enabled, Ektron.Cms.Common.CriteriaFilterOperator.EqualTo, true); criteria.AddFilter(CurrencyProperty.Id, Ektron.Cms.Common.CriteriaFilterOperator.NotEqualTo, m_refCurrency.RequestInformation.CommerceSettings.DefaultCurrencyId); currencyList = m_refCurrency.GetList(criteria); ExchangeRateApi exchangeRateApi = new ExchangeRateApi(); Ektron.Cms.Common.Criteria<Ektron.Cms.Commerce.ExchangeRateProperty> exchangeRateCriteria = new Ektron.Cms.Common.Criteria<Ektron.Cms.Commerce.ExchangeRateProperty>(); System.Collections.Generic.List<long> currencyIDList = new System.Collections.Generic.List<long>(); for (int i = 0; i <= (currencyList.Count - 1); i++) { currencyIDList.Add(currencyList[i].Id); } if (currencyIDList.Count > 0) { exchangeRateCriteria.AddFilter(ExchangeRateProperty.BaseCurrencyId, Ektron.Cms.Common.CriteriaFilterOperator.EqualTo, m_refContentApi.RequestInformationRef.CommerceSettings.DefaultCurrencyId); exchangeRateCriteria.AddFilter(ExchangeRateProperty.ExchangeCurrencyId, Ektron.Cms.Common.CriteriaFilterOperator.In, currencyIDList.ToArray()); exchangeRateList = exchangeRateApi.GetCurrentList(exchangeRateCriteria); dg_xc.DataSource = currencyList; dg_xc.DataBind(); } else { ltr_ExchangeRateMsg.Text = GetMessage("ecomm no enabled currencies"); } Util_SetJs(); paginglinks.Visible = false; Util_SetLabels(); }
private void Process_ExchangeRate() { ExchangeRateApi exchangeRateApi = new ExchangeRateApi(); for (int i = 0; i <= (dg_xc.Items.Count - 1); i++) { CheckBox chkUpdate = (CheckBox)dg_xc.Items[i].FindControl("chk_email"); HiddenField hdnCurrency = (HiddenField)dg_xc.Items[i].FindControl("hdn_currencyId"); long currentCurrencyId = Convert.ToInt64(hdnCurrency.Value); if (chkUpdate.Checked && Util_IsActiveExchangeCurrency(currentCurrencyId)) { // If Request.Form("chk_email_" & currencyList(i).Id) <> "" Then if (dg_xc.Items[i].FindControl("txt_exchange") != null) { TextBox txtXCRate = (TextBox)dg_xc.Items[i].FindControl("txt_exchange"); decimal newRate = decimal.Parse(txtXCRate.Text); ExchangeRateData exchangeRateData = new ExchangeRateData(exchangeRateApi.RequestInformationRef.CommerceSettings.DefaultCurrencyId, Convert.ToInt32(currentCurrencyId), newRate, DateTime.Now); exchangeRateApi.Add(exchangeRateData); } } } ltr_js.Text = "self.parent.location.reload(); self.parent.ektb_remove();"; }
private void Process_Edit() { CurrencyData currency = null; currency = m_refCurrency.GetItem(Convert.ToInt32(m_iID)); ExchangeRateApi exchangeRateApi = new ExchangeRateApi(); ExchangeRateData exchangeRateData = new ExchangeRateData(exchangeRateApi.RequestInformationRef.CommerceSettings.DefaultCurrencyId, currency.Id, Convert.ToDecimal(txt_exchangerate.Text), DateTime.Now); exchangeRateApi.Add(exchangeRateData); currency.Name = (string) txt_name.Text; currency.Id = System.Convert.ToInt32(txt_numericisocode.Text); currency.AlphaIsoCode = (string) txt_alphaisocode.Text; currency.Enabled = System.Convert.ToBoolean(chk_enabled.Checked); m_refCurrency.Update(currency); ltr_js.Text = "self.parent.location.reload(); self.parent.ektb_remove();"; }