Skip to content

Instantly share code, notes, and snippets.

@angeloped
Forked from laurenarcher/bitconvert.py
Created January 12, 2021 04:50
Show Gist options
  • Save angeloped/c6bd7033a4198168866fe460d1269860 to your computer and use it in GitHub Desktop.
Save angeloped/c6bd7033a4198168866fe460d1269860 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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment