From 74fc3c57202e1d3e9be75f74ff84266cfb0b2426 Mon Sep 17 00:00:00 2001 From: Udo Bretz Date: Tue, 10 Mar 2020 01:08:10 +0100 Subject: [PATCH] Fixed fetching bitcoin price in EUR by using https://blockchain.info/ticker. --- Bitcoin.lua | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/Bitcoin.lua b/Bitcoin.lua index de49801..159ce41 100644 --- a/Bitcoin.lua +++ b/Bitcoin.lua @@ -1,9 +1,9 @@ -- Inofficial Bitcoin Extension for MoneyMoney --- Fetches Bitcoin quantity for addresses via blockexplorer API --- Fetches Bitcoin price in EUR via coinmarketcap API +-- Fetches Bitcoin quantity for addresses via blockchain.info API +-- Fetches Bitcoin price in EUR via blockchain.info API -- Returns cryptoassets as securities -- --- Username: Bitcoin Adresses comma seperated +-- Username: Bitcoin Adresses comma separated -- Password: [Whatever] -- MIT License @@ -30,14 +30,14 @@ WebBanking{ - version = 0.2, - description = "Include your Bitcoins as cryptoportfolio in MoneyMoney by providing Bitcoin addresses as usernme (comma seperated) and a random Password", + version = 0.3, + description = "Include your Bitcoins as cryptoportfolio in MoneyMoney by providing Bitcoin addresses as usernme (comma separated) and a random Password", services= { "Bitcoin" } } local bitcoinAddress local connection = Connection() -local currency = "EUR" -- fixme: make dynamik if MM enables input field +local currency = "EUR" -- fixme: make dynamic if MM enables input field function SupportsBank (protocol, bankCode) return protocol == ProtocolWebBanking and bankCode == "Bitcoin" @@ -61,7 +61,7 @@ end function RefreshAccount (account, since) local s = {} - prices = requestBitcoinPrice() + BTCinEURprice = requestBitcoinPrice() for address in string.gmatch(bitcoinAddress, '([^,]+)') do bitcoinQuantity = requestBitcoinQuantityForBitcoinAddress(address) @@ -69,9 +69,9 @@ function RefreshAccount (account, since) s[#s+1] = { name = address, currency = nil, - market = "cryptocompare", + market = "blockchain.info", quantity = bitcoinQuantity, - price = prices["price_eur"], + price = BTCinEURprice, } end @@ -82,32 +82,28 @@ function EndSession () end --- Querry Functions +-- Query Functions function requestBitcoinPrice() - response = connection:request("GET", cryptocompareRequestUrl(), {}) + response = connection:request("GET", priceRequestUrl(), {}) json = JSON(response) - - return json:dictionary()[1] + return json:dictionary()["EUR"]["last"] end function requestBitcoinQuantityForBitcoinAddress(bitcoinAddress) response = connection:request("GET", bitcoinRequestUrl(bitcoinAddress), {}) - json = JSON(response) - balance = json:dictionary()['data']['confirmed_balance'] - return balance + return convertSatoshiToBitcoin(response) end -- Helper Functions --- function convertSatoshiToBitcoin(satoshi) --- return satoshi / 100000000 --- end +function convertSatoshiToBitcoin(satoshi) + return satoshi / 100000000 +end -function cryptocompareRequestUrl() - return "https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=EUR" +function priceRequestUrl() + return "https://blockchain.info/ticker" end function bitcoinRequestUrl(bitcoinAddress) - return "https://chain.so/api/v2/get_address_balance/BTC/" .. bitcoinAddress .. "/" + return "https://blockchain.info/q/addressbalance/" .. bitcoinAddress .. "?confirmations=6" end -