@@ -187,6 +187,8 @@ class SpotClient:
187187 :type secret: str, optional
188188 :param url: URL to access the Kraken API (default: https://api.kraken.com)
189189 :type url: str, optional
190+ :param proxy: proxy URL, may contain authentication information
191+ :type proxy: str, optional
190192 """
191193
192194 URL : str = "https://api.kraken.com"
@@ -201,6 +203,7 @@ def __init__(
201203 key : str = "" ,
202204 secret : str = "" ,
203205 url : str = "" ,
206+ proxy : str | None = None ,
204207 * ,
205208 use_custom_exceptions : bool = True ,
206209 ) -> None :
@@ -212,6 +215,13 @@ def __init__(
212215 self ._use_custom_exceptions : bool = use_custom_exceptions
213216 self ._err_handler : ErrorHandler = ErrorHandler ()
214217 self .__session : requests .Session = requests .Session ()
218+ if proxy is not None :
219+ self .__session .proxies .update (
220+ {
221+ "http" : proxy ,
222+ "https" : proxy ,
223+ },
224+ )
215225 self .__session .headers .update (self .HEADERS )
216226
217227 def _prepare_request (
@@ -469,13 +479,16 @@ class SpotAsyncClient(SpotClient):
469479 :type secret: str, optional
470480 :param url: URL to access the Kraken API (default: https://api.kraken.com)
471481 :type url: str, optional
482+ :param proxy: proxy URL, may contain authentication information
483+ :type proxy: str, optional
472484 """
473485
474486 def __init__ (
475487 self : SpotAsyncClient ,
476488 key : str = "" ,
477489 secret : str = "" ,
478490 url : str = "" ,
491+ proxy : str | None = None ,
479492 * ,
480493 use_custom_exceptions : bool = True ,
481494 ) -> None :
@@ -486,6 +499,7 @@ def __init__(
486499 use_custom_exceptions = use_custom_exceptions ,
487500 )
488501 self .__session = aiohttp .ClientSession (headers = self .HEADERS )
502+ self .proxy = proxy
489503
490504 async def request ( # type: ignore[override] # pylint: disable=invalid-overridden-method,too-many-arguments # noqa: PLR0913
491505 self : SpotAsyncClient ,
@@ -544,34 +558,37 @@ async def request( # type: ignore[override] # pylint: disable=invalid-overridde
544558
545559 if method in {"GET" , "DELETE" }:
546560 return await self .__check_response_data ( # type: ignore[return-value]
547- response = await self .__session .request ( # type: ignore[misc]
561+ response = await self .__session .request ( # type: ignore[misc,call-arg ]
548562 method = method ,
549563 url = f"{ url } ?{ query_params } " if query_params else url ,
550564 headers = headers ,
551565 timeout = timeout ,
566+ proxy = self .proxy ,
552567 ),
553568 return_raw = return_raw ,
554569 )
555570
556571 if do_json :
557572 return await self .__check_response_data ( # type: ignore[return-value]
558- response = await self .__session .request ( # type: ignore[misc]
573+ response = await self .__session .request ( # type: ignore[misc,call-arg ]
559574 method = method ,
560575 url = url ,
561576 headers = headers ,
562577 json = params ,
563578 timeout = timeout ,
579+ proxy = self .proxy ,
564580 ),
565581 return_raw = return_raw ,
566582 )
567583
568584 return await self .__check_response_data ( # type: ignore[return-value]
569- response = await self .__session .request ( # type: ignore[misc]
585+ response = await self .__session .request ( # type: ignore[misc,call-arg ]
570586 method = method ,
571587 url = url ,
572588 headers = headers ,
573589 data = params ,
574590 timeout = timeout ,
591+ proxy = self .proxy ,
575592 ),
576593 return_raw = return_raw ,
577594 )
@@ -646,6 +663,8 @@ class FuturesClient:
646663 :type url: str, optional
647664 :param sandbox: If set to ``True`` the URL will be https://demo-futures.kraken.com (default: ``False``)
648665 :type sandbox: bool, optional
666+ :param proxy: proxy URL, may contain authentication information
667+ :type proxy: str, optional
649668 """
650669
651670 URL : str = "https://futures.kraken.com"
@@ -661,6 +680,7 @@ def __init__(
661680 key : str = "" ,
662681 secret : str = "" ,
663682 url : str = "" ,
683+ proxy : str | None = None ,
664684 * ,
665685 sandbox : bool = False ,
666686 use_custom_exceptions : bool = True ,
@@ -686,6 +706,13 @@ def __init__(
686706 " (https://github.com/btschwertfeger/python-kraken-sdk)" ,
687707 },
688708 )
709+ if proxy is not None :
710+ self .__session .proxies .update (
711+ {
712+ "http" : proxy ,
713+ "https" : proxy ,
714+ },
715+ )
689716
690717 def _prepare_request (
691718 self : FuturesClient ,
@@ -931,6 +958,8 @@ class FuturesAsyncClient(FuturesClient):
931958 :param url: The URL to access the Futures Kraken API (default:
932959 https://futures.kraken.com)
933960 :type url: str, optional
961+ :param proxy: proxy URL, may contain authentication information
962+ :type proxy: str, optional
934963 :param sandbox: If set to ``True`` the URL will be
935964 https://demo-futures.kraken.com (default: ``False``)
936965 :type sandbox: bool, optional
@@ -941,6 +970,7 @@ def __init__(
941970 key : str = "" ,
942971 secret : str = "" ,
943972 url : str = "" ,
973+ proxy : str | None = None ,
944974 * ,
945975 sandbox : bool = False ,
946976 use_custom_exceptions : bool = True ,
@@ -953,6 +983,7 @@ def __init__(
953983 use_custom_exceptions = use_custom_exceptions ,
954984 )
955985 self .__session = aiohttp .ClientSession (headers = self .HEADERS )
986+ self .proxy = proxy
956987
957988 async def request ( # type: ignore[override] # pylint: disable=arguments-differ,invalid-overridden-method
958989 self : FuturesAsyncClient ,
@@ -976,35 +1007,38 @@ async def request( # type: ignore[override] # pylint: disable=arguments-differ,
9761007
9771008 if method in {"GET" , "DELETE" }:
9781009 return await self .__check_response_data (
979- response = await self .__session .request ( # type: ignore[misc]
1010+ response = await self .__session .request ( # type: ignore[misc,call-arg ]
9801011 method = method ,
9811012 url = url ,
9821013 params = query_string ,
9831014 headers = headers ,
9841015 timeout = timeout ,
1016+ proxy = self .proxy ,
9851017 ),
9861018 return_raw = return_raw ,
9871019 )
9881020
9891021 if method == "PUT" :
9901022 return await self .__check_response_data (
991- response = await self .__session .request ( # type: ignore[misc]
1023+ response = await self .__session .request ( # type: ignore[misc,call-arg ]
9921024 method = method ,
9931025 url = url ,
9941026 params = encoded_payload ,
9951027 headers = headers ,
9961028 timeout = timeout ,
1029+ proxy = self .proxy ,
9971030 ),
9981031 return_raw = return_raw ,
9991032 )
10001033
10011034 return await self .__check_response_data (
1002- response = await self .__session .request ( # type: ignore[misc]
1035+ response = await self .__session .request ( # type: ignore[misc,call-arg ]
10031036 method = method ,
10041037 url = url ,
10051038 data = encoded_payload ,
10061039 headers = headers ,
10071040 timeout = timeout ,
1041+ proxy = self .proxy ,
10081042 ),
10091043 return_raw = return_raw ,
10101044 )
0 commit comments