Skip to content

Commit

Permalink
Fixed fetching bitcoin price in EUR by using https://blockchain.info/…
Browse files Browse the repository at this point in the history
  • Loading branch information
UdoBretz committed Mar 10, 2020
1 parent 3115830 commit 74fc3c5
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions Bitcoin.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand All @@ -61,17 +61,17 @@ end

function RefreshAccount (account, since)
local s = {}
prices = requestBitcoinPrice()
BTCinEURprice = requestBitcoinPrice()

for address in string.gmatch(bitcoinAddress, '([^,]+)') do
bitcoinQuantity = requestBitcoinQuantityForBitcoinAddress(address)

s[#s+1] = {
name = address,
currency = nil,
market = "cryptocompare",
market = "blockchain.info",
quantity = bitcoinQuantity,
price = prices["price_eur"],
price = BTCinEURprice,
}
end

Expand All @@ -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

0 comments on commit 74fc3c5

Please sign in to comment.