ладно поставлю вопрос по другому
как при помощи pool и map ускорить программу
#——————————————————————————-
# Name: module1
# Purpose:
#
# Author: msh
#
# Created: 05.08.2014
# Copyright: © msh 2014
# Licence: <your licence>
#——————————————————————————-
import httplib
import urllib
import urllib2
import json
import hashlib
import hmac
import time
nonce=1
BTC_key=“”
BTC_secret=“”
def get():
u = urllib2.urlopen("
https://btc-e.com/api/3/depth/usd_rur?limit=1")
str = u.read()
z = json.loads(str)
bids=z
return bids
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)
except:
conn
return
def getInfo():
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”:“getInfo”,
“nonce”: nonce}
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)
conn.close()
x=a
usd=x
rur=x
return usd,rur
def buy():
x=get()
c=getInfo()
print x
i=0
while i<1:
a=x+i
i=i-0.0052
print a
z=trade(“buy”,a , 0.17702070,“usd_rur”)
if a<38.5:
break
def sell():
x=get()
print x
i=0
while i<100:
a=x+i
i=i+0.0052
print a
z=trade(“sell”,a+0.19, 0.17666666,“usd_rur”)
if a>39.7:
break
def main():
while True:
try:
x=getInfo()
c=get()
print “Balance: ” + “usd: ” + str(x) + “ rur: ” + str(x)
if x > 12:
if c<39.5:
buy()
if x > 0.17666665:
sell()
except KeyboardInterrupt:
print “cancel user”
except:
print “IO error”
time.sleep(5)
continue
if __name__ == ‘__main__’:
main()