I have written a Python program that looks at bitcoinchart's API and finds the median price. This might be useful if you wanted to automatically adjust prices in an online store.
import urllib2
import json
def average(l):
return sum(l)/float(len(l))
#From fraxel
def median(mylist):
sorts = sorted(mylist)
length = len(sorts)
if not length % 2:
return (sorts[length / 2] + sorts[length / 2 - 1]) / 2.0
return sorts[length / 2]
currency = "USD"
url = "http://api.bitcoincharts.com/v1/markets.json"
result = urllib2.urlopen(url).read()
prices = json.loads(result)
def by_currency(symbol):
def f(ticker):
return ticker['currency'] == symbol
return f
def by_volume(min_volume):
def f(ticker):
return ticker['currency_volume'] > min_volume
return f
def get_price(ticker):
try:
return average((ticker['ask'], ticker['bid']))
except:
pass
print ticker
raise Exception("Can't find price in ticker")
# Avoid prices in wrong currencies
prices = filter(by_currency(currency), prices)
# Exclude small exchanges
prices = filter(by_volume(100), prices)
prices = map(get_price, prices)
single_price = median(prices)
print single_price
2As a merchant, won't the exchange rate you base your rate on be the exchange that you will be cashing out at? i.e., would it matter what Mt. Gox's exchange rate is if you will be cashing out at BITSTAMP, for example? – Stephen Gornick – 2013-07-16T23:37:58.750