what is the base url for the binance margin testnet.

What is the base url for the margin testnet?

The following code 404s when using a margin endpoint but is fine when I use the spot api.

testnet_base = "https://testnet.binance.vision"

def timestamp():
    return round(time() * 1000)

"""USE ORDERED DICT FOR PARAMS"""
def make_url(url_base, api_path, params=None):
    if params is None:
        params = OrderedDict()

    params["timestamp"] = timestamp()
    query_string = urlencode(params)

    signature = hmac.new(secret_key, query_string.encode(), hashlib.sha256).hexdigest()

    return f"{url_base}{api_path}?{query_string}&signature={signature}"

def get_account_data():
    url = make_url(testnet_base, "/api/v3/account")
    req = requests.get(url, headers={"X-MBX-APIKEY": api_key})
    return json.loads(req.text)


pprint(get_account_data()) # this is fine
req = requests.get(make_url(testnet_base, "/sapi/v1/margin/pair"), headers={"X-MBX-APIKEY": api_key})
print(req.status_code) # 404
print(req.text) # ''

urls: {
base: ‘https://testnet.binance.vision/api/’,
},

Even though this is what the docs say - a lot of the api endpoints as stated in docs include the /api/ prefix so it shouldn’t be included in the base url

1 Like

“/sapi/*” endpoints are not supported in the testnet.

1 Like