Skip to content

Commit

Permalink
Okex apiv5 (#549)
Browse files Browse the repository at this point in the history
* 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
twmeggs and bmoscon committed Jul 19, 2021
1 parent c21e4b0 commit eaa4990
Show file tree
Hide file tree
Showing 6 changed files with 322 additions and 33 deletions.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Cryptofeed was originally created by Bryant Moscon, but many others have contrib
* [Yoh Plala](https://github.com/yohplala) - <yoh.plala@gmail.com>
* [Alex](https://github.com/globophobe)
* [Michael Zhao](https://github.com/dynamikey) - <mr_michaelzhao@hotmail.com>
* [Tim Meggs](https://github.com/twmeggs) - <twmeggs@gmail.com>
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 1.9.3
* Bugfix: Fix demo.py
* Feature: Allow user to specify a delay when starting an exchange connection (useful for avoiding 429s when creating a large number of feeds)
* Update: Support Okex v5

### 1.9.2 (2021-07-14)
* Bugfix: add config kwarg to add_nbbo method
Expand Down
36 changes: 36 additions & 0 deletions cryptofeed/auth/okex.py
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
Loading

0 comments on commit eaa4990

Please sign in to comment.