From c7cb61a20f9caed79c73b14c64855abefc7e5e9c Mon Sep 17 00:00:00 2001 From: j4c0b1 Date: Sun, 24 Sep 2023 20:31:28 +0200 Subject: [PATCH] add ssl_verify option --- README.md | 3 ++- btcde.py | 9 +++++---- tests/test_btcde_func.py | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 82ed1b0..8707afa 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,8 @@ import btcde # create a object for the connection settings api_key = api_secret = -conn = btcde.Connection(api_key, api_secret) +# ssl_verify - Set to True or False to enable or disable SSL verification +conn = btcde.Connection(api_key, api_secret, ssl_verify=True) orderbook = conn.showOrderbook('buy', 'btceur') print(f'API Credits Left: {orderbook["credits"]}') orders = orderbook['orders'] diff --git a/btcde.py b/btcde.py index 2dd488d..931b256 100644 --- a/btcde.py +++ b/btcde.py @@ -107,7 +107,7 @@ def HandleAPIErrors(r): class Connection(object): """To provide connection credentials to the trading API""" - def __init__(self, api_key, api_secret): + def __init__(self, api_key, api_secret, ssl_verify=False): self.api_key = api_key self.api_secret = api_secret # set initial self.nonce @@ -116,6 +116,7 @@ def __init__(self, api_key, api_secret): self.apihost = 'https://api.bitcoin.de' self.apiversion = 'v4' self.apibase = f'{self.apihost}/{self.apiversion}/' + self.ssl_verify = ssl_verify # avoid warnings for ssl-cert def build_hmac_sign(self, md5string, method, url): hmac_data = '#'.join([method, url, self.api_key, str(self.nonce), md5string]) @@ -142,13 +143,13 @@ def set_header(self, url, method, encoded_string): def send_request(self, url, method, header, encoded_string): if method == 'GET': r = requests.get(url, headers=(header), - stream=True, verify=False) + stream=True, verify=self.ssl_verify) elif method == 'POST': r = requests.post(url, headers=(header), data=encoded_string, - stream=True, verify=False) + stream=True, verify=self.ssl_verify) elif method == 'DELETE': r = requests.delete(url, headers=(header), - stream=True, verify=False) + stream=True, verify=self.ssl_verify) return r def APIConnect(self, method, params): diff --git a/tests/test_btcde_func.py b/tests/test_btcde_func.py index 0c0c179..2f3c553 100644 --- a/tests/test_btcde_func.py +++ b/tests/test_btcde_func.py @@ -53,7 +53,7 @@ def verifySignature(self, url, method, nonce, params): def setUp(self): self.XAPIKEY = 'f00b4r' self.XAPISECRET = 'b4rf00' - self.conn = btcde.Connection(self.XAPIKEY, self.XAPISECRET) + self.conn = btcde.Connection(self.XAPIKEY, self.XAPISECRET, ssl_verify=True) self.XAPINONCE = self.conn.nonce def tearDown(self): @@ -549,7 +549,7 @@ def sampleData(self, file): def setUp(self): self.XAPIKEY = 'f00b4r' self.XAPISECRET = 'b4rf00' - self.conn = btcde.Connection(self.XAPIKEY, self.XAPISECRET) + self.conn = btcde.Connection(self.XAPIKEY, self.XAPISECRET, ssl_verify=True) self.XAPINONCE = self.conn.nonce def tearDown(self):