Bitcoin Forum
December 03, 2016, 11:49:20 AM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Determining exchange rates for a merchant site  (Read 1171 times)
Cryptoman
Hero Member
*****
Offline Offline

Activity: 728



View Profile
January 04, 2011, 05:03:14 PM
 #1

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?


"A small body of determined spirits fired by an unquenchable faith in their mission can alter the course of history." --Gandhi
1480765760
Hero Member
*
Offline Offline

Posts: 1480765760

View Profile Personal Message (Offline)

Ignore
1480765760
Reply with quote  #2

1480765760
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1480765760
Hero Member
*
Offline Offline

Posts: 1480765760

View Profile Personal Message (Offline)

Ignore
1480765760
Reply with quote  #2

1480765760
Report to moderator
1480765760
Hero Member
*
Offline Offline

Posts: 1480765760

View Profile Personal Message (Offline)

Ignore
1480765760
Reply with quote  #2

1480765760
Report to moderator
1480765760
Hero Member
*
Offline Offline

Posts: 1480765760

View Profile Personal Message (Offline)

Ignore
1480765760
Reply with quote  #2

1480765760
Report to moderator
davout
Legendary
*
Offline Offline

Activity: 1358


1davout


View Profile WWW
January 04, 2011, 05:08:03 PM
 #2

And maybe other bitcoin exchanges for the matter  Angry
For example the ones that allow you to trade LRUSD/LREUR/EUR/BTC for free  Kiss

mndrix
Michael Hendricks
VIP
Sr. Member
*
Offline Offline

Activity: 447


View Profile
January 04, 2011, 08:27:25 PM
 #3

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
Anonymous
Guest

January 04, 2011, 08:51:14 PM
 #4

bitcoinwatch  Huh


http://bitcoinwatch.com/
Cryptoman
Hero Member
*****
Offline Offline

Activity: 728



View Profile
January 04, 2011, 09:44:40 PM
 #5

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.  Cheesy

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  Angry
For example the ones that allow you to trade LRUSD/LREUR/EUR/BTC for free  Kiss

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

"A small body of determined spirits fired by an unquenchable faith in their mission can alter the course of history." --Gandhi
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!