-
-
Notifications
You must be signed in to change notification settings - Fork 668
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update for v5 of Okex API * update get server time for new endpoint * style changes for flake8 pass * Changelog and contributors * change filled constant Co-authored-by: Bryant Moscon <bmoscon@gmail.com>
- Loading branch information
Showing
6 changed files
with
322 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
''' | ||
Copyright (C) 2017-2021 Bryant Moscon - bmoscon@gmail.com | ||
Please see the LICENSE file for the terms and conditions | ||
associated with this software. | ||
''' | ||
import base64 | ||
import hmac | ||
import requests | ||
|
||
def get_server_time(): | ||
url = "https://www.okex.com/api/v5/public/time" | ||
response = requests.get(url) | ||
if response.status_code == 200: | ||
return response.json()['data'][0]['ts'] | ||
else: | ||
return "" | ||
|
||
|
||
def server_timestamp(): | ||
server_time = get_server_time() | ||
return int(server_time) / 1000 | ||
|
||
|
||
def create_sign(timestamp: str, key_secret: str): | ||
message = timestamp + 'GET' + '/users/self/verify' | ||
mac = hmac.new(bytes(key_secret, encoding='utf8'), bytes(message, encoding='utf-8'), digestmod='sha256') | ||
d = mac.digest() | ||
sign = base64.b64encode(d) | ||
return sign | ||
|
||
|
||
def generate_token(key_id: str, key_secret: str) -> dict: | ||
timestamp = str(server_timestamp()) | ||
sign = create_sign(timestamp, key_secret) | ||
return timestamp, sign |
Oops, something went wrong.