Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if __name__ == "__main__":
- timeout = 1
- try:
- opts, args = getopt.getopt(sys.argv[1:], "hu:p:vt:")
- except getopt.GetoptError, err:
- print str(err)
- sys.exit(-1)
- for o, a in opts:
- if o == "-v":
- verbose = True
- elif o == "-u":
- user = a
- elif o == "-p":
- password = a
- elif o == "-t":
- timeout = float(a)
- elif o == "-h":
- print "pytrader"
- exit(0)
- else:
- assert False, "unhandled option"
- if user == '' or password == '':
- error("Need username and password")
- sys.exit(-1)
- upencoded = urllib.urlencode({'name':user, 'pass':password})
- market = Market(upencoded, user, password)
- market.refresh()
- funds.refresh()
- # trans = Transaction.Transaction(1, 0.9829)
- # transactions.append(trans)
- # print trans.profitable_sell(market.last)
- #main loop
- running = True
- last = 0
- bid = 0
- ask = 0
- iter = 0
- while running:
- i, o, e = select.select([sys.stdin], [], [], timeout)
- for s in i:
- #user input TODO
- if s == sys.stdin:
- input = sys.stdin.readline().strip().split(" ")
- exec_command(input, funds, market)
- market.refresh()
- funds.refresh()
- # Transaction updates
- for t in transactions:
- if (t.profitable(market.last) is True) and t.inprogress is False:
- t.transact(market, market.last)
- t.update(market)
- elif ((t.profitable(market.ask) is True) and (t.inprogress is False)
- and (t.direction == "USD)")):
- status("Not profitable at market but profitable at ask")
- t.transact(market, market.ask)
- t.update(market)
- elif ((t.profitable(market.bid) is True) and (t.inprogress is
- False) and (t.direction == "BTC")):
- status("Not profitable at market but profitable at bid")
- t.transact(market, market.bid)
- t.update(market)
- else:
- t.update(market)
- # else:
- # status("Not profitable, cost is $" + str(t.btc * t.usd) +
- # " worth $" + str(t.worth(market.last)))
- # UI updates
- if last != market.last:
- if last == 0:
- last = market.last
- elif last > market.last:
- status("-" + str((last - market.last)))
- elif last < market.last:
- status("+" + str((market.last - last)))
- market.pprint_last()
- last = market.last
- if (bid != market.bid) or (ask != market.ask):
- market.pprint_spread()
- ask = market.ask
- bid = market.bid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement