Skip to content

Commit 73c59e4

Browse files
committed
Added testnet flag in client and options testnet support
1 parent cea537f commit 73c59e4

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

binance/client.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Client(object):
2020
FUTURES_COIN_URL = "https://dapi.binance.{}/dapi"
2121
FUTURES_COIN_DATA_URL = "https://dapi.binance.{}/futures/data"
2222
OPTIONS_URL = 'https://vapi.binance.{}/vapi'
23+
OPTIONS_TESTNET_URL = 'https://testnet.binanceops.{}/vapi'
2324
PUBLIC_API_VERSION = 'v1'
2425
PRIVATE_API_VERSION = 'v3'
2526
WITHDRAW_API_VERSION = 'v3'
@@ -102,7 +103,7 @@ class Client(object):
102103
MINING_TO_USDT_FUTURE = "MINING_UMFUTURE"
103104
MINING_TO_FIAT = "MINING_C2C"
104105

105-
def __init__(self, api_key=None, api_secret=None, requests_params=None, tld='com'):
106+
def __init__(self, api_key=None, api_secret=None, requests_params=None, tld='com', testnet=False):
106107
"""Binance API Client constructor
107108
108109
:param api_key: Api Key
@@ -111,6 +112,8 @@ def __init__(self, api_key=None, api_secret=None, requests_params=None, tld='com
111112
:type api_secret: str.
112113
:param requests_params: optional - Dictionary of requests params to use for all calls
113114
:type requests_params: dict.
115+
:param testnet: Use testnet environment - only available for vanilla options at the moment
116+
:type testnet: bool
114117
115118
"""
116119

@@ -123,12 +126,14 @@ def __init__(self, api_key=None, api_secret=None, requests_params=None, tld='com
123126
self.FUTURES_COIN_URL = self.FUTURES_COIN_URL.format(tld)
124127
self.FUTURES_COIN_DATA_URL = self.FUTURES_COIN_DATA_URL.format(tld)
125128
self.OPTIONS_URL = self.OPTIONS_URL.format(tld)
129+
self.OPTIONS_TESTNET_URL = self.OPTIONS_TESTNET_URL.format(tld)
126130

127131
self.API_KEY = api_key
128132
self.API_SECRET = api_secret
129133
self.session = self._init_session()
130134
self._requests_params = requests_params
131135
self.response = None
136+
self.testnet = testnet
132137
self.timestamp_offset = 0
133138

134139
# init DNS and SSL cert
@@ -172,7 +177,11 @@ def _create_futures_coin_data_api_url(self, path, version=1):
172177
return self.FUTURES_COIN_DATA_URL + "/" + path
173178

174179
def _create_options_api_uri(self, path):
175-
return self.OPTIONS_URL + '/' + self.OPTIONS_API_VERSION + '/' + path
180+
if self.testnet:
181+
url = self.OPTIONS_TESTNET_URL
182+
else:
183+
url = self.OPTIONS_URL
184+
return url + '/' + self.OPTIONS_API_VERSION + '/' + path
176185

177186
def _generate_signature(self, data):
178187

0 commit comments

Comments
 (0)