Skip to content

Commit

Permalink
add ssl_verify option
Browse files Browse the repository at this point in the history
  • Loading branch information
cj4c0b1 authored and peshay committed Oct 7, 2023
1 parent a9644ed commit c7cb61a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import btcde
# create a object for the connection settings
api_key = <YourAPIKey>
api_secret = <YourAPISecret>
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']
Expand Down
9 changes: 5 additions & 4 deletions btcde.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_btcde_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c7cb61a

Please sign in to comment.