gateio / gateapi-python

247 stars 92 forks source link

Add proxy when initializing the client #86

Closed ghost closed 2 years ago

ghost commented 2 years ago

How do I add a HTTP proxy when initializing my API client? Right now Configuration function is documented as the following:

def __init__(self,
             host: str = "https://api.gateio.ws/api/v4",
             key: Any = None,
             secret: Any = None,
             username: Any = None,
             password: Any = None,
             discard_unknown_keys: bool = False) -> None

There's no place to add proxies! I'd appreciate a clear example code if possible. Thank you.

revilwang commented 2 years ago

The configuration has other attributes which you can set beyond initialization. Refer to its source code for details. For your case, it's proxy and proxy_headers

ghost commented 2 years ago

I tried with the following:

config = Configuration(key=auth['gateio_api'],
                               secret=auth['gateio_secret']).proxy('http://127.0.0.1:3128')

But I get this error:

File "/mnt/Work/MyProject/src/lib/gateclient.py", line 34, in initialize_client
    config = Configuration(key=auth['gateio_api'],
TypeError: 'NoneType' object is not callable

Can you add an example please?

revilwang commented 2 years ago
config = Configuration(key='xxx', secret='xxx')
config.proxy = 'http://xxx'

# then use `config` to initialize your client
spot_api = SpotApi(ApiClient(config))
ghost commented 2 years ago
config = Configuration(key='xxx', secret='xxx')
config.proxy = 'http://xxx'

# then use `config` to initialize your client
spot_api = SpotApi(ApiClient(config))

You're the best! Thank you! :)