Latest version now converts ftc price to usd/gbp/eur/aud/cad to whole value pennies (0.01), percent price diff now displays correct sign(i.e. up or down), and some timeout errors are handled. Note some server errors may still occur due to an inability to contact the host site for the prices - I am currently trying to work around these but I hope you enjoy this version :D
download:
http://uploaded.net/file/durqk8pa
copy & paste code:
import json
import urllib2
from pprint import pprint
import time
from time import strftime
import math
import httplib
#get initial prices and exchange rates & trading volume on script start
initial_scan = json.load(urllib2.urlopen(“https://btc-e.com/api/2/ftc_btc/ticker”))
initial_ftcprice = initial_scan[‘ticker’][‘last’]
initial_btcusdscan = json.load(urllib2.urlopen(“https://btc-e.com/api/2/btc_usd/ticker”))
initial_btcusd = initial_btcusdscan[‘ticker’][‘last’]
initial_btceurscan = json.load(urllib2.urlopen(“https://btc-e.com/api/2/btc_eur/ticker”))
initial_btceur = initial_btceurscan[‘ticker’][‘last’]
initial_usdgbpscan = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=GBP&q=1”))
initial_usdgbp = initial_usdgbpscan[“rate”]
initial_usdaudscan = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=AUD&q=1”))
initial_usdaud = initial_usdaudscan[“rate”]
initial_usdcadscan = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=CAD&q=1”))
initial_usdcad = initial_usdcadscan[“rate”]
initial_volinftc = initial_scan[‘ticker’][‘vol_cur’]
initial_volinbtc = initial_scan[‘ticker’][‘vol’]
currenttime = strftime(“%Y-%m-%d %H:%M:%S”)
#do currency conversions from ftc-btc & btc-usd prices
initial_ftcusd = math.ceil(initial_ftcprice*initial_btcusd*100)/100
initial_ftceur = math.ceil(initial_ftcprice*initial_btceur*100)/100
initial_ftcgbp = math.ceil(initial_ftcprice*initial_btcusd*initial_usdgbp*100)/100
initial_ftcaud = math.ceil(initial_ftcprice*initial_btcusd*initial_usdaud*100)/100
initial_ftccad = math.ceil(initial_ftcprice*initial_btcusd*initial_usdcad*100)/100
#print initial prices & trading volume
print (str(initial_ftcprice) + " BTC")
print (str(initial_ftcusd) + " USD")
print (str(initial_ftceur) + " EUR")
print (str(initial_ftcgbp) + " GBP")
print (str(initial_ftcaud) + " AUD")
print (str(initial_ftccad) + " CAD")
print (“Trading Volume: " + str(initial_volinftc) + " FTC / " + str(initial_volinbtc) + " BTC”)
print currenttime
print (“==================================================”)
while True:
#scan for prices & trading volume again
try:
data = json.load(urllib2.urlopen(“https://btc-e.com/api/2/ftc_btc/ticker”, timeout = 3))
data2 = json.load(urllib2.urlopen(“https://btc-e.com/api/2/btc_usd/ticker”, timeout = 3))
data3 = json.load(urllib2.urlopen(“https://btc-e.com/api/2/btc_eur/ticker”, timeout = 3))
data4 = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=GBP&q=1”, timeout = 3))
data5 = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=AUD&q=1”, timeout = 3))
data6 = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=CAD&q=1”, timeout = 3))
except (urllib2.HTTPError, urllib2.URLError, httplib.BadStatusLine, SSLError) as err:
print (“Unable to load source for ticker!”)
time.sleep(1)
else:
btcEUR = data3[‘ticker’][‘last’]
btcUSD = data2[‘ticker’][‘last’]
usdGBP = data4[“rate”]
usdAUD = data5[“rate”]
usdCAD = data6[“rate”]
volFTC = data[‘ticker’][‘vol_cur’]
volBTC = data[‘ticker’][‘vol’]
#new prices
ftcBTC = data[‘ticker’][‘last’]
ftcUSD = math.ceil(ftcBTC*btcUSD*100)/100
ftcEUR = math.ceil(ftcBTC*btcEUR*100)/100
ftcGBP = math.ceil(ftcUSD*usdGBP*100)/100
ftcAUD = math.ceil(ftcUSD*usdAUD*100)/100
ftcCAD = math.ceil(ftcUSD*usdCAD*100)/100
newtime = strftime(“%Y-%m-%d %H:%M:%S”)
#percent change in price
diff = initial_ftcprice - ftcBTC
a = abs(diff)
change = math.ceil(100*100*a/initial_ftcprice)/100
#are the new prices different from the old ones?
if ftcBTC != initial_ftcprice:
print (str(ftcBTC) + " BTC")
print (str(ftcUSD) + " USD")
print (str(ftcEUR) + " EUR")
print (str(ftcGBP) + " GBP")
print (str(ftcAUD) + " AUD")
print (str(ftcCAD) + " CAD")
print(“Trading Volume: " + str(volFTC) + " FTC / " + str(volBTC) + " BTC”)
if diff < 0:
print(“Price Change: +” + str(change) + “%”)
elif diff > 0:
print(“Price Change: -” + str(change) + “%”)
print newtime
print(“==================================================”)
initial_ftcprice = ftcBTC
time.sleep(1)
[attachment deleted by admin]