Ai
2 Star 4 Fork 3

Suuuch/Open-API-SDK-V5

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
utils.py 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
okex 提交于 2021-07-20 09:26 +08:00 . PYTHON UPDATE
import hmac
import base64
import time
import datetime
from . import consts as c
def sign(message, secretKey):
mac = hmac.new(bytes(secretKey, encoding='utf8'), bytes(message, encoding='utf-8'), digestmod='sha256')
d = mac.digest()
return base64.b64encode(d)
def pre_hash(timestamp, method, request_path, body):
print('body: ',body)
return str(timestamp) + str.upper(method) + request_path + body
def get_header(api_key, sign, timestamp, passphrase, flag):
header = dict()
header[c.CONTENT_TYPE] = c.APPLICATION_JSON
header[c.OK_ACCESS_KEY] = api_key
header[c.OK_ACCESS_SIGN] = sign
header[c.OK_ACCESS_TIMESTAMP] = str(timestamp)
header[c.OK_ACCESS_PASSPHRASE] = passphrase
header['x-simulated-trading'] = flag
print('header: ',header)
return header
def parse_params_to_str(params):
url = '?'
for key, value in params.items():
url = url + str(key) + '=' + str(value) + '&'
print('url:',url)
return url[0:-1]
def get_timestamp():
now = datetime.datetime.utcnow()
t = now.isoformat("T", "milliseconds")
return t + "Z"
def signature(timestamp, method, request_path, body, secret_key):
if str(body) == '{}' or str(body) == 'None':
body = ''
message = str(timestamp) + str.upper(method) + request_path + str(body)
mac = hmac.new(bytes(secret_key, encoding='utf8'), bytes(message, encoding='utf-8'), digestmod='sha256')
d = mac.digest()
return base64.b64encode(d)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/suuuch/Open-API-SDK-V5.git
git@gitee.com:suuuch/Open-API-SDK-V5.git
suuuch
Open-API-SDK-V5
Open-API-SDK-V5
main

搜索帮助