Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Cryptoman on January 04, 2011, 05:03:14 PM



Title: Determining exchange rates for a merchant site
Post by: Cryptoman on January 04, 2011, 05:03:14 PM
I was wondering if the community had thoughts on what is the best way to come up with BTC/USD, BTC/EUR, etc. exchange rates for pricing goods and services on a merchant site.  I wrote a little script to grab the LAST trade from MtGox:

Code:
#!/usr/bin/env ruby
require 'open-uri'
btc_per_usd = 0.0
quote_str = open('http://mtgox.com/code/data/ticker.php').read
quote_str = quote_str.gsub(/["{}]/,'')
quote_str = quote_str.gsub(/ticker:/, '')
quotes = quote_str.split(',')
#puts quotes
quotes.each {|q| btc_per_usd = q.delete('a-z:').to_f if q[/last:/] }
#puts btc_per_usd

There are several problems with doing it this way.  The last trade could have been unusually large or small in volume and not indicative of the true current exchange rate.  Also, it doesn't make sense to continually update the exchange rate in real time because the price in BTC of items could fluctuate during the order completion process.  I'm thinking that the rate should be set once per day from a cron job by taking some sort of average of the previous day's MtGox transactions.  Any ideas or scripts you'd like to share?



Title: Re: Determining exchange rates for a merchant site
Post by: davout on January 04, 2011, 05:08:03 PM
And maybe other bitcoin exchanges for the matter  >:(
For example the ones that allow you to trade LRUSD/LREUR/EUR/BTC for free  :-*


Title: Re: Determining exchange rates for a merchant site
Post by: mndrix on January 04, 2011, 08:27:25 PM
I was wondering if the community had thoughts on what is the best way to come up with BTC/USD, BTC/EUR, etc. exchange rates for pricing goods and services on a merchant site.

My favorite is the 24 hour, volume-weighted price listed in the right column of http://www.taters.net/cgi-bin/btc/matrix.pl?axisinc=0.01


Title: Re: Determining exchange rates for a merchant site
Post by: Anonymous on January 04, 2011, 08:51:14 PM
bitcoinwatch  ???


http://bitcoinwatch.com/ (http://bitcoinwatch.com/)


Title: Re: Determining exchange rates for a merchant site
Post by: Cryptoman on January 04, 2011, 09:44:40 PM
My favorite is the 24 hour, volume-weighted price listed in the right column of http://www.taters.net/cgi-bin/btc/matrix.pl?axisinc=0.01

Great idea!  I've updated my script to calculate a 48-hour (MtGox recent trades) volume-weighted price.  I would do a 24-hour volume-weighted price if I weren't too lazy to deal with the date arithmetic.  :D

Code:
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
total_vol = 0.0
price_vol_product = 0.0
quote_str = open('http://mtgox.com/code/data/getTrades.php').read
quotes = JSON.parse(quote_str)
#puts quotes
quotes.each do |q|
   price_vol_product += q["price"] * q["amount"]
   total_vol += q["amount"]
end
usd_per_btc = price_vol_product/total_vol
#puts usd_per_btc


And maybe other bitcoin exchanges for the matter  >:(
For example the ones that allow you to trade LRUSD/LREUR/EUR/BTC for free  :-*

...and the trade data APIs for these other sites can be found...where?  :P