From 191938f1c0645943c77ced0d00a22549e3debdda Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sun, 29 Dec 2019 10:16:45 +0100 Subject: [PATCH] Shapeshift doesn't provide rates anymore --- Backend/BackendLoop.cs | 15 +++++++++++-- Logic/Financial/ExchangeRateSnapshot.cs | 28 +++++++++++++++++++------ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Backend/BackendLoop.cs b/Backend/BackendLoop.cs index ff68c998..799435dc 100644 --- a/Backend/BackendLoop.cs +++ b/Backend/BackendLoop.cs @@ -148,13 +148,24 @@ namespace Swarmops.Backend if (args[0].ToLower() == "console") { - Console.WriteLine ("\r\nRunning Swarmops-Backend in CONSOLE mode.\r\n"); + Console.WriteLine ("\r\nRunning Swarmops-Backend in ONE OFF CONSOLE mode.\r\n"); - // ------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------- + ExchangeRateSnapshot.Create(); + + Organizations allOrganizations = Organizations.GetAll(); + foreach (Organization organization in allOrganizations) + { + // this actually checks hot storage too, but that's supposed + // to be up to date since we're the ones handling it + BitcoinUtility.CheckColdStorageForOrganization(organization); + } + + // ------------------------------------------------------------------------------------- // ----------------------- INSERT ANY ONE-OFF ACTIONS HERE ------------------------- + // ------------------------------------------------------------------------------------- Console.Write ("\r\nWaiting for mail queue to flush... "); diff --git a/Logic/Financial/ExchangeRateSnapshot.cs b/Logic/Financial/ExchangeRateSnapshot.cs index 6b4fc859..7959c006 100644 --- a/Logic/Financial/ExchangeRateSnapshot.cs +++ b/Logic/Financial/ExchangeRateSnapshot.cs @@ -48,10 +48,15 @@ namespace Swarmops.Logic.Financial client.Encoding = Encoding.UTF8; JavaScriptSerializer serializer = new JavaScriptSerializer(); int bitcoinId = GetOrCreateCryptocurrency("BTC"); + GetOrCreateCryptocurrency("BCH"); // ensure exists + GetOrCreateCryptocurrency("ETH"); // ensure exists + int exchangeRateSnapshotId = SwarmDb.GetDatabaseForWriting().CreateExchangeRateSnapshot(); // Download Shapeshift data + /* This entire section is disabled -- ShapeShift disabled their rate API in August 2019. Bitpay still provides theirs, below. + string cryptoRateDataRaw = client.DownloadString("https://shapeshift.io/marketinfo"); ShapeshiftRateDatapoint[] cryptoRates = @@ -98,7 +103,7 @@ namespace Swarmops.Logic.Financial } } } - } + } */ // Download BitPay data @@ -118,18 +123,29 @@ namespace Swarmops.Logic.Financial double btcRate = Double.Parse (match.Groups[3].Value, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture); // rounding errors and loss of precision ok, don't use Formatting fn - btcRate /= 1000000.0; // We're operating in microbitcoin, so adjust the stored exchange rate accordingly (right-shift six decimal places) + if (currencyCode != "BCH") + { + btcRate /= 1000000.0; + // We're operating in microbitcoin, so adjust the stored exchange rate right six decimal places + // EXCEPT for Bitcoin Cash which ALSO operates in microbitcoin + } - int currencyId = GetOrCreateFiatCurrency (currencyCode, currencyName); + int currencyId = GetOrCreateFiatCurrency (currencyCode, currencyName); // ETH, BTC, and BCH aren't fiat currencies, but still provided by BitPay Currency currency = Currency.FromIdentityAggressive(currencyId); // Only store if it's not a cryptocurrency provided by Shapeshift - + /* + * CONDITION DISABLED since Shapeshift doesn't provide anything anymore + * if (!currency.IsCrypto) - { + {*/ + + SwarmDb.GetDatabaseForWriting() .CreateExchangeRateDatapoint(exchangeRateSnapshotId, currencyId, bitcoinId, btcRate); - } + + /* + }*/ match = match.NextMatch(); }