Author

Topic: My Program - Pulls Market Values from tradehill and bitmarket (Read 1933 times)

hero member
Activity: 566
Merit: 500
auto refresh is very simple.

if you are using VB .Net, just create a timer. once you have one, click on it to get the onTimer event. timer's have an interval, and once that interval is reached, the onTimer event runs.

you can enable or disable the timer with a button and even have the user set an interval.

let me know if you need any help. i have a bot that buys and sells at mt gox for me and plan on expanding it to trade hill here soon.
newbie
Activity: 35
Merit: 0
updated some more stuff...now pulls data from all 3 major exchanges [mtgox, tradehill, and bitmarket] also has a refresh button now as well....I hope to get auto refresh working at some point in the near future......Hopefully this is actually useful to people now that mtgox is up and working.
newbie
Activity: 35
Merit: 0
updated some things....added validation in case data cannot be pulled, also did a little bit of code cleanup, removed references to mtgox (for now).  Not too sure how much more I can do with this as of the moment, however if I have some more free time, I will keep hacking away at it.
newbie
Activity: 35
Merit: 0
thanks, that may be of use whenever i get a little more free time to work on this......I still don't know why their ticker doesn't work directly whereas the other ones do....makes it a little harder than it probably should be for such an easy task.
sr. member
Activity: 339
Merit: 250
I made a simple program to pull the current market values from tradehill and bitmarket....as of right now, it's still in very early stages, so it literally does NOTHING else (including no autorefreshing or anything fun like that....yet.....) however I figured some people may find this a bit more useful than trying to pull two separate values to find out where to buy or sell coins at...also before anyone asks, yes, I am in fact trying to get MtGox in there as well, however their API just isn't cooperating with me......hopefully in the near future.

https://github.com/dubbz82/Bitcoin-Price-Calculator

We might have some code to contribute on the MtGox side. We haven't tested it since they upgraded their backend.  If it still works we will contribute it.  Will post the code later this evening(EST time).

This is in python but it might help you see how we solved the parsing.  There may be a couple of bugs in this version.  We have a newer version laying around somewhere once we find it.

Code:
#!/usr/bin/env python

import simplejson
import urllib
import urllib2
import urlparse

market_depth_url = "http://mtgox.com/code/data/getDepth.php"
ticker_data_url = "http://mtgox.com/code/data/ticker.php"
recent_trades_url = "http://mtgox.com/code/data/getTrades.php"
current_balance_url = "https://mtgox.com/code/getFunds.php?name=blah&pass=blah"
buy_order_url = "https://mtgox.com/code/buyBTC.php?name=blah&pass=blah&amount=number&price=number"
sell_order_url = "https://mtgox.com/code/sellBTC.php?name=blah&pass=blah&amount=number&price=number"
open_order_url = "https://mtgox.com/code/getOrders.php?name=blah&pass=blah"
cancel_order_url = "https://mtgox.com/code/cancelOrder.php?name=blah&pass=blah&oid=number&type=number"
send_btc_url = "https://mtgox.com/code/withdraw.php?name=blah&pass=blah&group1=BTC&btca=bitcoin_address_to_send_to&amount=number"
checkout_url = "https://mtgox.com/merch/checkout"
verify_transaction_url = "https://mtgox.com/code/gateway/checkTxn.php"

def getBitcoinSellValue(quantity):
    data = simplejson.load(urllib2.urlopen(market_depth_url))
    data['bids'].sort(reverse=True)
    
    market_USD_value = 0
    total_bitcoins = 0
    
    for i in data['bids']:
        market_USD_value = market_USD_value + ((i[0]) * (i[1]))
        total_bitcoins = total_bitcoins + (i[1])
        
        if total_bitcoins >= quantity:
            bitcoin_value = market_USD_value / total_bitcoins
            return bitcoin_value


def getBitcoinBuyValue(quantity):
    data = simplejson.load(urllib2.urlopen(market_depth_url))
    data['asks'].sort()
    
    market_USD_value = 0
    total_bitcoins = 0
    
    for i in data['asks']:
        market_USD_value = market_USD_value + ((i[0]) * (i[1]))
        total_bitcoins = total_bitcoins + (i[1])
        if total_bitcoins >= quantity:
            bitcoin_value = market_USD_value / total_bitcoins
            return bitcoin_value

        
def createSellOrder(username, password, amount, price):
    format_url = urlparse.urlparse(sell_order_url)
    new_url = format_url.scheme + ":" + "//" + format_url.netloc + format_url.path
    query = urlparse.parse_qs(format_url.query)
    
    query['price'] = price
    query['amount'] = amount
    query['name'] = username
    query['pass'] = password
    
    f = urllib.urlopen(new_url, urllib.urlencode(query))
    
    return f.read()
    
    
def createBuyOrder(username, password, amount, price):
    format_url = urlparse.urlparse(buy_order_url)
    new_url = format_url.scheme + ":" + "//" + format_url.netloc + format_url.path
    query = urlparse.parse_qs(format_url.query)
    
    query['price'] = price
    query['amount'] = amount
    query['name'] = username
    query['pass'] = password
    
    f = urllib.urlopen(new_url, urllib.urlencode(query))
    
    return f.read()
    
    
def getBalance(username, password):
    format_url = urlparse.urlparse(current_balance_url)
    new_url = format_url.scheme + ":" + "//" + format_url.netloc + format_url.path
    query = urlparse.parse_qs(format_url.query)
    
    query['name'] = username
    query['pass'] = password
    
    f = urllib.urlopen(new_url, urllib.urlencode(query))
    
    return f.read()
    
    
def getOpenOrders(username, password):
    format_url = urlparse.urlparse(open_order_url)
    new_url = format_url.scheme + ":" + "//" + format_url.netloc + format_url.path
    query = urlparse.parse_qs(format_url.query)
    
    query['name'] = username
    query['pass'] = password
    
    f = urllib.urlopen(new_url, urllib.urlencode(query))
    
    return f.read()
    
    
def cancelOrder(username, password, orderid, type):
    format_url = urlparse.urlparse(cancel_order_url)
    new_url = format_url.scheme + ":" + "//" + format_url.netloc + format_url.path
    query = urlparse.parse_qs(format_url.query)
    
    query['oid'] = orderid
    query['type'] = type
    query['name'] = username
    query['pass'] = password
    
    f = urllib.urlopen(new_url, urllib.urlencode(query))
    
    return f.read()
    
    
def sendBTC(username, password, destination, amount):
    format_url = urlparse.urlparse(send_btc_url)
    new_url = format_url.scheme + ":" + "//" + format_url.netloc + format_url.path
    query = urlparse.parse_qs(format_url.query)
    
    query['btca'] = destination
    query['amount'] = amount
    query['name'] = username
    query['pass'] = password
    query['group1'] = 'BTC'
    
    f = urllib.urlopen(new_url, urllib.urlencode(query))
    
    return f.read()
    
    
def checkout(notify_url, username, currency_code, amount, item_name, custom, return_url):
    format_url = urlparse.urlparse(checkout_url)
    new_url = format_url.scheme + ":" + "//" + format_url.netloc + format_url.path
    query = urlparse.parse_qs(format_url.query)
    
    query['notify_url'] = notify_url
    query['business'] = username
    query['currency_code'] = currency_code
    query['amount'] = amount
    query['item_name'] = item_name
    query['custom'] = custom
    query['return'] = return_url
    
    f = urllib.urlopen(new_url, urllib.urlencode(query))
    
    return f.read()
    
    
def receiveTransaction(txn_id, payer_username, currency_code, amount, custom):
    {
        
    }
    
    
def verifyTransaction(txn_id, merchID, amount):
    format_url = urlparse.urlparse(verify_transaction_url)
    new_url = format_url.scheme + ":" + "//" + format_url.netloc + format_url.path
    query = urlparse.parse_qs(format_url.query)
    
    query['txn_id'] = txn_id
    query['amount'] = amount
    query['merchID'] = merchID
    
    f = urllib.urlopen(new_url, urllib.urlencode(query))
    
    return f.read()
newbie
Activity: 35
Merit: 0
I made a simple program to pull the current market values from tradehill and bitmarket....as of right now, it's still in very early stages, so it literally does NOTHING else (including no autorefreshing or anything fun like that....yet.....) however I figured some people may find this a bit more useful than trying to pull two separate values to find out where to buy or sell coins at...also before anyone asks, yes, I am in fact trying to get MtGox in there as well, however their API just isn't cooperating with me......hopefully in the near future.

https://github.com/dubbz82/Bitcoin-Price-Calculator

Image (note, I still don't have much on the order of "calculator" functionality...it's still in the works):
http://img696.imageshack.us/img696/5262/newbitmapimagern.png 
Jump to: