Jump to content
Twix mafia

Copy + calculate

Recommended Posts

Partially possible. SCAR does not allow for form manipulation. So the only way to log in would be to move the mouse and log in. Requiring you to store username and password in the script, type it in when needed at the correct position (x,y).

^ That will not be very flexible, if you resize the browser, you would need to change the login-box coordinates in scar as well (that sucks)...

 

You should consider Python (the language) for this - Python is very suited for such tasks.

 

A quick and dirty example in Python, could be made a LOT shorter, but it's based on the code you already have, so it's not very pythonic:

 

# -*- coding: utf-8 -*-import mechanizeimport reimport time#username and passname = 'blabla'pwd = 's0meP4ss'#Browserclass Exchange:   def __init__(self, user, pwd):       self.br = mechanize.Browser()       self.br_trading = mechanize.Browser()       self.name = user       self.pwd  = pwd   def login_in(self):       ''' #login to website '''       self.br_trading.open("http://mtgox.com")       self.br_trading.select_form(nr=1)       self.br_trading["user_session[username]"] = self.name       self.br_trading["user_session[password]"] = self.pwd       self.br_trading.submit()       print "logged in, and ready to sell and by!"   def buy(self, amount, price_per_btc):       ''' #buy x stocks for y price at n website '''       # self.br_trading.open("http://mtgox.com/some_url_to_buy_btc.html")        # self.br_trading.select_form(nr=0)  #form number (see html source of site)       # self.br_trading["user_session[price]"] = price       # self.br_trading["user_session[amount]"] = amount       # self.br_trading.submit()       print "Not implementetd (don't have an accound to test)"   def sell(self, amount, price_per_btc):       ''' this is similar to the above given example, but we sell now! '''       print "Not implementetd (don't have an accound to test)"   def rate(self, currency):       ''' # Get current exchangerate '''       while 1:         data = self.br.open("http://bitcoincharts.com/markets/mtgox%s.html" % currency)         html = data.read()         pattern = '<label>Last Trade</label><span>(.*?)</span>'         match = re.findall(pattern, html)         if match: break;       return float(match[0])   def currency_rate(self, amount, fromCurrency, toCurrency):       while 1:         data = self.br.open("http://www.x-rates.com/calculator/?from=%s&to=%s&amound=%s" % (fromCurrency, toCurrency, amount))                                                        html = data.read()         pattern = '<span class="ccOutputRslt">(.*?)<span class="ccOutputTrail">'         match = re.findall(pattern, html)         res = float(match[0])         if match:             pattern2 = '<span class="ccOutputTrail">(.*?)</span><span class="ccOutputCode">'             match2 = re.findall(pattern2, html)             if match2:                 res = float(match[0] + match2[0])         if res: break       return resif __name__ == '__main__': exc = Exchange('userName', 'p4ssw0rD') a = exc.rate('EUR')     c_rate = exc.currency_rate(1, 'EUR', 'USD') value = c_rate*a btc_usd_val = exc.rate('USD'); delta = btc_usd_val - value #Fees. Skal være mindre end `e`.  fee = (1/0.994) * (btc_usd_val - (0.994 * btc_usd_val)) if (delta > fee):    print(fee)   print 'w00p w00p!'   exc.login_in()   exc.buy(10, 115) else:    print 'bedre lykke neste gang..'   time.sleep(1800) #no luck? wait half an hour (or should we sell at this point?).

 

 

you could probably be able to sell and buy with only a few more lines, so it's pretty simple.

Edited by slacky
Link to comment
Share on other sites

Yes, that is correct. Most programming languages are similar in a sense, so it does not take much time to grasp python if you know some other language. My example is not the simplest to understand, as I am using a class, and a global name "self", which refers to "this class".

 

I often see some danish people on "www.diskusjon.no", and they got a good Python section (Scriptingspråk (Python, Perl, Ruby o.l.) - Forum - Hardware.no), and a lot of great programmers! So it's worth a try if you are in the mood! :-)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...