如何使用新加坡时间戳在BiteBTC Trading API上保持平衡,获得未经授权的错误


import hashlib
import pytz
import hmac
from time import time
import urllib
import requests
import datetime

class BiteBtc:
    def __init__(self):
        self.api_key = b'LvC6D-OMpm2tc-KNpGR-KOxQFukC318D'
        self.secret_key = b'r40u3jrWUDMfhHyMNNpxbPwsDPnkAoeVMJTzUhlm3cHHUXjRHLKdeiAtiqCEudlz'
    def get_balance(self):
        url = 'https://bitebtc.com/api/v1/trading/balances'
        payload = {
            'currencies': 'btc'
        }
        paybytes = urllib.parse.urlencode(payload).encode('utf8')
        ###
        sgt = pytz.timezone("Asia/Singapore")
        now = datetime.datetime.now()
        ts = now.astimezone(sgt).timestamp()
        ts = round(float(ts), 3)  # mili-sec
        nonce = str(ts).replace(".", "")
        ###

        headers = {
            'x-api-tonce': nonce,  #str(int(time() * 1000)),
            'x-api-key': self.api_key,
            'x-api-signature': hmac.new(self.secret_key, paybytes, 
hashlib.sha512).hexdigest()
        }
        r = requests.post(url, headers=headers, data=paybytes)
        return r.json()
bite=BiteBtc()
print(bite.get_balance())

您应该在https://bitebtc.com/profile/keys上确保API'启用'。默认情况下它是禁用的,我遇到了相同的问题,但是将其解决了。

最新更新