Здравствуйте
не могли бы подсказать что делаю не так
# -*- coding: utf-8 -*-
import http.client
import urllib.request, urllib.parse, urllib.error
import json
import hashlib
import hmac
import time
class api:
__api_key = '';
__api_secret= '';
__nonce_v = 1;
__wait_for_nonce = False
def __init__(self,api_key,api_secret,wait_for_nonce=False):
self.__api_key = api_key
self.__api_secret = api_secret
self.__wait_for_nonce = wait_for_nonce
def __nonce(self):
if self.__wait_for_nonce: time.sleep(1)
self.__nonce_v = str(time.time()).split('.')[0]
def __signature(self, params):
sig = hmac.new(self.__api_secret.encode(), params.encode(), hashlib.sha512)
return sig.hexdigest()
def __api_call(self,method,params):
self.__nonce()
params['method'] = method
params['nonce'] = str(self.__nonce_v)
params = urllib.parse.urlencode(params)
headers = {"Content-type" : "application/x-www-form-urlencoded",
"Key" : self.__api_key,
"Sign" : self.__signature(params)}
conn = http.client.HTTPSConnection("wex.nz")
conn.request("POST", "/tapi", params, headers)
response = conn.getresponse().read().decode()
data = json.loads(response)
conn.close()
return data
def get_param(self, couple, param):
conn = http.client.HTTPSConnection("wex.nz")
conn.request("GET", "/api/3/"+couple+"/"+param)
response = conn.getresponse().read().decode()
data = json.loads(response)
conn.close()
return data
def getInfo(self):
return self.__api_call('getInfo', {})
def TransHistory(self, tfrom, tcount, tfrom_id, tend_id, torder, tsince, tend):
params = {
"from" : tfrom,
"count" : tcount,
"from_id" : tfrom_id,
"end_id" : tend_id,
"order" : torder,
"since" : tsince,
"end" : tend}
return self.__api_call('TransHistory', params)
def TradeHistory(self, tfrom, tcount, tfrom_id, tend_id, torder, tsince, tend, tpair):
params = {
"from" : tfrom,
"count" : tcount,
"from_id" : tfrom_id,
"end_id" : tend_id,
"order" : torder,
"since" : tsince,
"end" : tend,
"pair" : tpair}
return self.__api_call('TradeHistory', params)
def ActiveOrders(self, tpair):
params = { "pair" : tpair }
return self.__api_call('ActiveOrders', params)
def Trade(self, tpair, ttype, trate, tamount):
params = {
"pair" : tpair,
"type" : ttype,
"rate" : trate,
"amount" : tamount,}
return self.__api_call('Trade', params)
def CancelOrder(self, torder_id):
params = { "order_id" : torder_id }
return self.__api_call('CancelOrder', params)
вызвал модуль так
# -*- coding: utf-8 -*-
import btceapipython
btceapipython.Trade(self, tpair='usd_rur', ttype='buy',trate=55,tamount=1)
пишет
btceapipython.Trade(self, tpair='usd_rur', ttype='buy',trate=55,tamount=1)
NameError: name 'self' is not defined
селф же не может быть именем и параметром, что надо что бы код отправил запрос на покупку?
как понимать это отсутствие селфа