bitmain-hmac示例

 import time

import hmac, hashlib

import ssl, requests

api_key = 'xxx'

api_sec = 'yyy'

sub_user_id='zzz'

coin_type = 'BTC'  # 币种

sign_id = sub_user_id  # 子账号名

sign_key = api_key  # 密钥

sign_SECRET = api_sec  # 密码

html_poolstats = 'https://antpool.com/api/poolStats.htm'

html_balance = 'https://antpool.com/api/account.htm'

html_hashrate_user = 'https://antpool.com/api/hashrate.htm'

html_hashrate_miner = 'https://antpool.com/api/workers.htm'

html_payment = 'https://antpool.com/api/paymentHistory.htm'

html_pool_stats = 'https://antpool.com/api/poolStats.htm'


def get_signature():  # 签名操作

    nonce = int(time.time() * 1000)  # 毫秒时间戳

    msgs = sign_id + sign_key + str(nonce)

    ret = []

    ret.append(hmac.new(sign_SECRET.encode(encoding="utf-8"), msg=msgs.encode(encoding="utf-8"), digestmod=hashlib.sha256).hexdigest().upper())  # 签名

    ret.append(nonce)  # 时间戳

    return ret



def get_messages(url):  # POST

    api_sign = get_signature()

    post_data = {'key': sign_key, 'nonce': api_sign[1], 'signature': api_sign[0], 'coin':coin_type}  # 这里是POST参数根据接口自行更改

    request = requests.post(url, data=post_data)

    return(request.text)



def main():

    print(get_messages(html_pool_stats))



main()