Skip to content

Instantly share code, notes, and snippets.

@Michael-J-Ward
Created March 5, 2019 19:55
Show Gist options
  • Save Michael-J-Ward/c9366fcd0f4e869e8f5defc86a43a507 to your computer and use it in GitHub Desktop.
Save Michael-J-Ward/c9366fcd0f4e869e8f5defc86a43a507 to your computer and use it in GitHub Desktop.
import base64
import datetime
import hmac
def get_timestamp() -> str:
"""
The OKEX api requires the timestamp to be in exactly this format
example: '2018-10-23T17:27:40.340Z'
"""
now = datetime.datetime.utcnow()
return now.strftime('%Y-%m-%dT%H:%M:%S') + now.strftime('.%f')[:4] + 'Z'
def make_signature(timestamp: str, method: str, request_path: str,
body: Optional[str], secret_key: str) -> str:
body = body or ''
message = timestamp + method.upper() + request_path + body
mac = hmac.new(secret_key.encode('utf-8'), message.encode('utf-8'),
digestmod='sha256')
d = mac.digest()
return base64.b64encode(d).decode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment