Skip to content

Instantly share code, notes, and snippets.

@arnuschky
Created April 13, 2015 18:34
Show Gist options
  • Save arnuschky/55553910393b516f7d02 to your computer and use it in GitHub Desktop.
Save arnuschky/55553910393b516f7d02 to your computer and use it in GitHub Desktop.
Script that displays prices for XMR->BTC
import sys
import json
import urllib2
def jsonApiCall(url):
try:
req = urllib2.Request(url, headers={'User-Agent' : "Magic Browser"})
con = urllib2.urlopen(req)
data = json.load(con)
except Exception as e:
sys.stderr.write("Failed in API call " + url + "\n")
sys.stderr.write(str(e))
sys.exit(1)
return data
poloniex = float(jsonApiCall('https://poloniex.com/public?command=returnTicker')['BTC_XMR']['highestBid'])
poloniex *= 0.998 # 0.2% fee
xmrto = float(jsonApiCall('https://xmr.to/api/v1/xmr2btc/order_parameter_query')['price'])
shapeshift = float(jsonApiCall('https://shapeshift.io/rate/xmr_btc')['rate'])
# shapeshift applies a 0.0001 btc fee per transaction, which we won't factor in here
print
print "-----------------------------------"
print " Price for buying 1 XMR"
print "-----------------------------------"
print " Poloniex %10.8f BTC" % poloniex
print " XMR.TO %10.8f BTC" % xmrto
print " shapeshift %10.8f BTC" % shapeshift
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment