Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use logger instead of print #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions okx/okxclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import httpx
from httpx import Client
from loguru import logger

from . import consts as c, utils, exceptions

Expand Down Expand Up @@ -33,8 +34,8 @@ def _request(self, method, request_path, params):
header = utils.get_header_no_sign(self.flag, self.debug)
response = None
if self.debug == True:
print('domain:',self.domain)
print('url:',request_path)
logger.debug(f'domain: {self.domain}')
logger.debug(f'url: {request_path}')
if method == c.GET:
response = self.get(request_path, headers=header)
elif method == c.POST:
Expand Down
10 changes: 6 additions & 4 deletions okx/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import datetime
from . import consts as c

from loguru import logger


def sign(message, secretKey):
mac = hmac.new(bytes(secretKey, encoding='utf8'), bytes(message, encoding='utf-8'), digestmod='sha256')
Expand All @@ -12,7 +14,7 @@ def sign(message, secretKey):

def pre_hash(timestamp, method, request_path, body,debug = True):
if debug == True:
print('body: ',body)
logger.debug(f'body: {body}')
return str(timestamp) + str.upper(method) + request_path + body


Expand All @@ -25,15 +27,15 @@ def get_header(api_key, sign, timestamp, passphrase, flag,debug = True):
header[c.OK_ACCESS_PASSPHRASE] = passphrase
header['x-simulated-trading'] = flag
if debug == True:
print('header: ',header)
logger.debug(f'header: {header}')
return header

def get_header_no_sign(flag,debug = True):
header = dict()
header[c.CONTENT_TYPE] = c.APPLICATION_JSON
header['x-simulated-trading'] = flag
if debug == True:
print('header: ',header)
logger.debug(f'header: {header}')
return header

def parse_params_to_str(params):
Expand All @@ -42,7 +44,7 @@ def parse_params_to_str(params):
if(value != ''):
url = url + str(key) + '=' + str(value) + '&'
url = url[0:-1]
#print('url:',url)
#logger.debug(f'url: {url}')
return url


Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"importlib-metadata",
"httpx[http2]",
"keyring",
"loguru",
"requests",
"Twisted",
"pyOpenSSL"
Expand Down