-- coding: utf-8 --
import time, datetime
import requests
import hashlib
import json
import csv
url = ‘xxx’
def get_time_stamp13(datetime_obj, last_3digits_not_zero=0):
# 生成最后三位3位,微秒
data_microsecond = ‘000’
if last_3digits_not_zero == 1:
data_microsecond = str("%06d" % datetime_obj.microsecond)[0:3]
datetime_str = datetime.datetime.strftime(datetime_obj, '%Y-%m-%d %H:%M:%S')
datetime_obj = datetime.datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S')
date_stamp = str(int(time.mktime(datetime_obj.timetuple())))
date_stamp = date_stamp + data_microsecond
return int(date_stamp)
API_Secret = ‘aaaaaaaaaaaaaaaaaaaaaaaaaaa’
timestamp = str(get_time_stamp13(datetime.datetime.now(), last_3digits_not_zero=1))
nonce = ‘1111’
print(’[API_Secret]: %s\n[nonce]: %s\n[timestamp]: %s\n’ %(API_Secret, nonce, timestamp))
data_cyper = {
‘API_Secret’: API_Secret,
‘timestamp’: ‘’,
‘nonce’: ‘1111’,
}
data_cyper[‘timestamp’] = timestamp
print(’[signature字典]:’,data_cyper,end=’\n\n’)
#字典排序
data2 = sorted(data_cyper.values())
print(’[排序]:’,data2,end=’\n\n’)
passwd = ‘’
for i in data2:
passwd += i
print(’[拼接值]:’,passwd,end=’\n\n’)
x=hashlib.sha256()
x.update(passwd.encode(‘utf-8’))
enpasswd = x.hexdigest()
print(’[SHA256]:’,enpasswd,end=’\n\n’)
data={
‘username’: ‘xxx’,
‘signature’: ‘’,
‘timestamp’: ‘’,
‘nonce’: ‘1111’,
}
data[‘signature’] = enpasswd
data[‘timestamp’] = timestamp
for key,value in data.items():
# print(key,value)
resl= requests.post(url = url, data=data)
time_24h_before=str(int(timestamp)-86400000)
print(‘24小时前时间戳:’,time_24h_before)
#资产总数
url_ass_total = ‘xxx’
auth_token=‘Bearer ‘+resl.text[1:-1]
headers = {
‘Authorization’: auth_token
}
print(’[Authorization]:’,auth_token)
resp_ass_total = requests.get(url_ass_total, headers=headers)
print(’[总数]:’,resp_ass_total.json())