Skip to content

Instantly share code, notes, and snippets.

@laurenarcher
Last active June 14, 2022 07:28
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save laurenarcher/5770792 to your computer and use it in GitHub Desktop.
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/
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")
@mikeodor
Copy link

mikeodor commented Sep 12, 2021

this is converting from btc to usd not USD to btc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment