2017-10-15 187 views
0

我想連接到通過Python中V2 Bitfinex REST API,但我不斷收到錯誤:Bitfinex API REST V2 - API無效鍵

error 10100 apikey: invalid 

然而,當我使用相同的密鑰對V1,一切工作正常。這是我的Python代碼:

class MyTradeClient: 
    def __init__(self): 
     self.URL = "{0:s}://{1:s}/{2:s}".format(PROTOCOL, HOST, VERSION) 
     self.KEY = public 
     self.SECRET = secret 

    @property 
    def _nonce(self): 
     return str(int(time.time() * 100000)) 

    def _sign_payload(self, payload): 
     j = json.dumps(payload) 
     data = base64.standard_b64encode(j.encode('utf8')) 

     h = hmac.new(self.SECRET.encode('utf8'), data, hashlib.sha384) 
     signature = h.hexdigest() 
     return { 
      "X-BFX-APIKEY": self.KEY, 
      "X-BFX-SIGNATURE": signature, 
      "X-BFX-PAYLOAD": data 
     } 

    def wallets(self): 
     payload = { 
      "request": "/v2/auth/r/wallets", 
      #"options": {"autoOpen": False}, # READ IT SOMEWHERE ON THE INTERNET, NOT SURE OF THE MEANING 
      "nonce": self._nonce} 
     signed_payload = self._sign_payload(payload) 
     r = requests.post(self.URL + "/auth/r/wallets", headers=signed_payload, verify=True) 
     if r.status_code == 200: 
      return r.json() 
     else: 
      print('error, status_code = ', r.status_code) 
      print(r.text) 
      return '' 

有沒有人知道如何解決這個問題?

回答

0

你的頭是錯誤的:

「BFX-現時」:現時, 「BFX-apikey」:self.api, 「BFX簽名」:簽名