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

Add proxy support in API definition #36

Closed
wants to merge 1 commit into from
Closed
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 krakenex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class API(object):
pair, the effects are undefined.

"""
def __init__(self, key='', secret='', conn=None):
def __init__(self, key='', secret='', conn=None, proxy=''):
""" Create an object with authentication information.

:param key: key required to make queries to the API
Expand All @@ -70,6 +70,7 @@ def __init__(self, key='', secret='', conn=None):
self.uri = 'https://api.kraken.com'
self.apiversion = '0'
self.conn = conn
self.proxy = proxy
return

def load_key(self, path):
Expand Down Expand Up @@ -140,7 +141,7 @@ def _query(self, urlpath, req, conn=None, headers=None):

if conn is None:
if self.conn is None:
self.conn = connection.Connection()
self.conn = connection.Connection(proxy=self.proxy)
conn = self.conn

if headers is None:
Expand Down
10 changes: 8 additions & 2 deletions krakenex/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,27 @@ class Connection(object):

"""

def __init__(self, uri='api.kraken.com', timeout=30):
def __init__(self, uri='api.kraken.com', timeout=30, proxy=''):
""" Create an object for reusable connections.

:param uri: URI to connect to
:type uri: str
:param timeout: blocking operations' timeout (in seconds)
:type timeout: int
:param proxy: URL of the proxy
:type proxy: str
:returns: None

"""
self.headers = {
'User-Agent': 'krakenex/' + version.__version__ +
' (+' + version.__url__ + ')'
}
self.conn = http.client.HTTPSConnection(uri, timeout=timeout)
if proxy == '':
self.conn = http.client.HTTPSConnection(uri, timeout = timeout)
else:
self.conn = http.client.HTTPSConnection(proxy, timeout=timeout)
self.conn.set_tunnel(uri)
return

def close(self):
Expand Down