Created
April 2, 2013 21:40
-
-
Save gdoteof/5296457 to your computer and use it in GitHub Desktop.
Does some wonky parsing to get latest btc,ltc,usd info from btc-e.com and sees if there are discrepancies in the mutual ratios.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib | |
import urllib | |
import json | |
pairs= { | |
'btc_usd' : "1", | |
'ltc_btc' : "10", | |
'ltc_usd' : "14" | |
} | |
def latest(pair): | |
params = {"act": "orders_update", "pair":pair} | |
params = urllib.urlencode(params) | |
headers = {"Content-type": "application/x-www-form-urlencoded"} | |
conn = httplib.HTTPSConnection("btc-e.com") | |
conn.request("POST", "/ajax/order.php", params, headers) | |
response = conn.getresponse() | |
#print response | |
#print response.status, response.reason | |
val = json.load(response) | |
print pairs.keys()[pairs.values().index(pair)], "is", val['last'][pair] | |
return val['last'][pair] | |
btc_usd = latest(pairs['btc_usd']) | |
ltc_btc = latest(pairs['ltc_btc']) | |
ltc_usd = latest(pairs['ltc_usd']) | |
dollars = 1000 | |
#1000 dollars in litecoin | |
num_ltc = dollars / float(ltc_usd) | |
print dollars, "dollars =", num_ltc, "litecoins" | |
#1000 dollars in bitcoin | |
num_btc = 1000 / float(btc_usd) | |
print dollars, "dollars =", num_btc, "bitcoins" | |
#In theory num_btc / ltc_btc should ruougly equal num_ltc | |
ideal_ltc = num_btc / ltc_btc | |
print "If we bought", dollars, "worth of bitcoin and then traded it for litecoin we would have", ideal_ltc | |
print "we actually have", num_ltc | |
profit = ideal_ltc - num_ltc | |
profitD = profit * ltc_usd | |
if(profit > 0): | |
print "that allows us to make a profit of", profit, "litecoins by going btc->ltc vs usd->ltc" | |
print "that is ", profitD, "dollars" | |
elif(profit < 0): | |
print "that allows us to make a profit of", profit * -1, "litecoins by going usd->ltc vs btc->ltc " | |
print "that is ", profitD * -1, "dollars" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this code. It currently complains that "No JSON object could be decoded" when I try to execute the code. Has this been blocked now?
Cheers
W