GoldCoin Talk
Economy => Trading Discussion => Topic started by: miner007 on December 06, 2013, 01:03:11 AM
-
Skillerz' Script seems to be non-functional as of now. So i took some time off today and wrote a CGI script in python to do exactly what he has done. Later i'll be updating the HTML code inside it to auto-update and support other currency stuff through CGI Forms.
Usage is quite simple. you just upload it to a webserver, and assuming you have python-cgi enabled, it will poll the Cryptsy and BTCe for the current prices, and do the calculations.
I have this working on my notebook which has LightHTTP installed to it. If you have a VPS and want to run this script on your server, i can supply you with my configuration scripts which enable python-CGI.
If you really like this script, please donate some GLD ^o^
#!/usr/bin/python
import httplib
import urllib
import json
from decimal import *
def CryptsyTickerAPI(marketID):
# Get current Buy/Sell values for a given marketID
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
params = ''
conn = httplib.HTTPConnection('pubapi.cryptsy.com:80')
# Sometimes the connection times out (slow connections) or the network is down
# Catch the error so that the entire script doesn't crash
try:
conn.request('GET', '/api.php?method=singlemarketdata&marketid=' + str(marketID), params, headers)
response = conn.getresponse()
data = json.load(response)
buyPrice = data["return"]["markets"]["GLD"]["buyorders"][0]['price']
sellPrice = data["return"]["markets"]["GLD"]["sellorders"][0]['price']
conn.close()
return buyPrice, sellPrice
except:
TickerAPI(marketID)
# Get current Buy/Sell data
def BTCeTicker(pair):
# pair can be: ltc_usd, btc_usd, etc...
# reqType can be: ticker, trades, or depth
# Get ticker information
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
params = ''
#conn = httplib.HTTPSConnection('btc-e.com')
try:
conn = httplib.HTTPSConnection("btc-e.com")
conn.request('GET', '/api/2/' + pair + 'ticker', params, headers)
response = conn.getresponse()
data = json.load(response)
buyPrice = data['ticker']['buy']
sellPrice = data['ticker']['sell']
conn.close()
return buyPrice, sellPrice
except:
print 'Connection failure...retrying.'
BTCeTicker(pair)
LTCGLD_currentPrice = CryptsyTickerAPI(36)
LTCUSD_currentPrice = BTCeTicker('ltc_usd/')
GLDUSD_currentBuy = round(Decimal(LTCGLD_currentPrice[0]) * Decimal(LTCUSD_currentPrice[0]), 6)
GLDUSD_currentSell = round(Decimal(LTCGLD_currentPrice[1]) * Decimal(LTCUSD_currentPrice[1]), 6)
print 'Content-type:text/html\r\n\r\n'
print '<html>'
print '<head>'
print '<title>Current GLD/USD exchange Prices on Cryptsy.com</title>'
print '</head>'
print '<body>'
print '<center>Current GLD/USD exchange Prices on Cryptsy.com</center>'
print '<center>compliments of the Cryptsy and BTC-e Ticker APIs</center>'
print '<p>'
print 'Current Buy: ' + '<b>' + str(GLDUSD_currentBuy) + '</b><br>'
print 'Current Sell: ' + '<b>' + str(GLDUSD_currentSell) + '</b>'
print '<p>'
print '<p>'
print 'Note ** Later versions of this script will include an interactive CGI interface so that more alt-currencies can be used'
print '<p><p>'
print 'If you found this script useful consider donating a little bit of GLD here:<p>'
print 'ECQatb9BMuEFmPDUmMWypvFpwiMUwEv6au <p>'
print 'contact: miner007 (celtic_tigger1(a.t.)hotmail.com)'
print '</body>'
print '</html>'
-
Well my script is working but there is just a temporary problem with mtgox's api for BTCUSD price which made the site inaccurate. Now its fixed and working good. :). And good that you made a script, it might be helpful for someone ;).
-Thanks-
-
i guess it was multiplying by zero somewhere. When i tried our script it showed zero for all numerals.
i'm thinking you could have an alternate API call if one of them fails. Less to maintain by you.
Btw, what did you write your script in? PHP? Just curious.
-
i guess it was multiplying by zero somewhere. When i tried our script it showed zero for all numerals.
i'm thinking you could have an alternate API call if one of them fails. Less to maintain by you.
Btw, what did you write your script in? PHP? Just curious.
Nope its not the prob, MtGox api doesn't retrieved btc price for a while so in number format the value will be zero. Anyway now its working good.
-Thanks-