Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.87 KB | None | 0 0
  1. if __name__ == "__main__":
  2.     timeout = 1
  3.  
  4.     try:
  5.         opts, args = getopt.getopt(sys.argv[1:], "hu:p:vt:")
  6.     except getopt.GetoptError, err:
  7.         print str(err)
  8.         sys.exit(-1)
  9.  
  10.     for o, a in opts:
  11.         if o == "-v":
  12.             verbose = True
  13.         elif o == "-u":
  14.             user = a
  15.         elif o == "-p":
  16.             password = a
  17.         elif o == "-t":
  18.             timeout = float(a)
  19.         elif o == "-h":
  20.             print "pytrader"
  21.             exit(0)
  22.         else:
  23.             assert False, "unhandled option"
  24.  
  25.     if user == '' or password == '':
  26.         error("Need username and password")
  27.         sys.exit(-1)
  28.  
  29.     upencoded = urllib.urlencode({'name':user, 'pass':password})
  30.  
  31.     market = Market(upencoded, user, password)
  32.     market.refresh()
  33.     funds.refresh()
  34.  
  35. #    trans = Transaction.Transaction(1, 0.9829)
  36. #    transactions.append(trans)
  37. #    print trans.profitable_sell(market.last)
  38.  
  39.     #main loop
  40.     running = True
  41.     last = 0
  42.     bid = 0
  43.     ask = 0
  44.     iter = 0
  45.  
  46.     while running:
  47.         i, o, e = select.select([sys.stdin], [], [], timeout)
  48.  
  49.         for s in i:
  50.             #user input TODO
  51.             if s == sys.stdin:
  52.                 input = sys.stdin.readline().strip().split(" ")
  53.                 exec_command(input, funds, market)
  54.  
  55.         market.refresh()
  56.         funds.refresh()
  57.  
  58.         # Transaction updates
  59.         for t in transactions:
  60.             if (t.profitable(market.last) is True) and t.inprogress is False:
  61.                 t.transact(market, market.last)
  62.                 t.update(market)
  63.             elif ((t.profitable(market.ask) is True) and (t.inprogress is False)
  64.             and (t.direction == "USD)")):
  65.                 status("Not profitable at market but profitable at ask")
  66.                 t.transact(market, market.ask)
  67.                 t.update(market)
  68.             elif ((t.profitable(market.bid) is True) and (t.inprogress is
  69.                 False) and (t.direction == "BTC")):
  70.                 status("Not profitable at market but profitable at bid")
  71.                 t.transact(market, market.bid)
  72.                 t.update(market)
  73.             else:
  74.                 t.update(market)
  75. #            else:
  76. #                status("Not profitable, cost is $" + str(t.btc * t.usd) +
  77. #                        " worth $" + str(t.worth(market.last)))
  78.  
  79.         # UI updates
  80.         if last != market.last:
  81.             if last == 0:
  82.                 last = market.last
  83.             elif last > market.last:
  84.                 status("-" + str((last - market.last)))
  85.             elif last < market.last:
  86.                 status("+" + str((market.last - last)))
  87.  
  88.             market.pprint_last()
  89.             last = market.last
  90.  
  91.         if (bid != market.bid) or (ask != market.ask):
  92.             market.pprint_spread()
  93.             ask = market.ask
  94.             bid = market.bid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement