Форум сайта python.su
пример кода изначальный
def trade(ord_type, ord_rate, ord_amount, p): try: nonce = int(int(time.time()*10)%(10*60*60*24*366*10)-867780726+26000000)*2+1 # method name and nonce go into the POST parameters params = {"method":"Trade", "nonce": nonce, "pair": p, "type": ord_type, "rate": ord_rate, "amount": ord_amount} params = urllib.urlencode(params) # Hash the params string to produce the Sign header value H = hmac.new(BTC_secret, digestmod=hashlib.sha512) H.update(params) sign = H.hexdigest() headers = {"Content-type": "application/x-www-form-urlencoded", "Key":BTC_key, "Sign":sign} conn = httplib.HTTPSConnection("btc-e.com") conn.request("POST", "/tapi", params, headers) response = conn.getresponse() a = json.load(response)
def buy(): x=get() i=0 z=0 while i<1: nonce = int(int(time.time()*10)%(10*60*60*24*366*10)-867780726+26000000)*2+1 a=x+i i=i-0.002 print a params={"method":"Trade", "nonce": nonce, "pair": "ppc_usd", "type": "buy", "rate": a, "amount": 0.11} # method name and nonce go into the POST parameters params = urllib.urlencode(params) # Hash the params string to produce the Sign header value H = hmac.new(BTC_secret, digestmod=hashlib.sha512) H.update(params) sign = H.hexdigest() headers = {"Content-type": "application/x-www-form-urlencoded", "Key":BTC_key, "Sign":sign} conn = httplib.HTTPSConnection("btc-e.com") try: conn.request("POST", "/tapi", params, headers) except httplib.HTTPException: raise BTCEError("HTTP error: " + response.reason) if a<0.7: break
Офлайн