Last active
June 14, 2022 07:28
-
-
Save laurenarcher/5770792 to your computer and use it in GitHub Desktop.
Simple python bitcoin currency converter using the Bitcoin Charts API. Documentation here: http://bitcoincharts.com/about/markets-api/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import json | |
data = urllib2.urlopen("http://api.bitcoincharts.com/v1/weighted_prices.json") | |
def convert_to_bitcoin(amount, currency): | |
bitcoins = json.loads(data.read()) | |
converted = float(bitcoins[currency]["24h"]) * amount | |
print converted | |
convert_to_bitcoin(1, "USD") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is converting from btc to usd not USD to btc