502 Bad Gateway on Create Order in Production

I fail with the code 502 Bad Gateway when I try to POST a new Order (POST /api/v3/order (HMAC SHA256)) or to Test a new Order (POST /api/v3/order/test (HMAC SHA256)) on Production Binance.

However, I successfully use the following API’s on Production:
GET /sapi/v1/capital/config/getall (HMAC SHA256)
GET /sapi/v1/capital/deposit/subAddress (HMAC SHA256)

And for Websocket:
POST /api/v3/userDataStream
… and successfully receive the messages via Websocket

A sample Order call that fails with 502 Bad Gateway is:
https/api.binance.com/api/v3/order/test?newClientOrderId=8855577942&quoteOrderQty=0.1&recvWindow=60000&side=BUY&signature=9be63d57ec229aefb49234d689933af2024da69b80f0250d25179636b3d6a7b8&symbol=DREPBTC&timestamp=1662464804143&type=MARKET

In Binance, the API keys for this master account have been setup and the options seem valid. Spot trading is enabled (and still valid), and IP restrictions turned off.

Any suggestions how to avoid / overcome this error? Thanks!

p.s. i successfully ran the API for GET /sapi/v1/account/apiRestrictions (HMAC SHA256), and the settings for these API keys seem fine:
name : “success”
result :
body :
createTime : 1662451901000
enableFutures : false
enableInternalTransfer : true
enableMargin : false
enableReading : true
enableSpotAndMarginTrading : true
enableVanillaOptions : false
enableWithdrawals : false
ipRestrict : false
permitsUniversalTransfer : true
tradingAuthorityExpirationTime : 1670198400000

So the problem doesn’t seem to be with the parameters, rather the server connection?

Tested it out with your parameters and it works fine on my end. Can you try again and see if 502 occurs?

hi Chai! I changed the API server to https://api3.binance.com, and now it works! Does that make any sense, is there any material difference between https://api3.binance.com and https://api.binance.com? Could api3 be less busy and faster?

Thanks for your checking. Unfortunately i still have the same problem. Definitely yes, it should work, but it doesn’t sigh.

Are you familiar with any server connection problems that can cause 502 Bad Gateway?

I’ve tested so many API’s, and it’s only the POST Order and POST Order Test that have this issue. Unfortunately they’re the most important!

502 is actually a Server Error (HTTP 502 status code (Bad Gateway) - Amazon CloudFront). There are multiple layers of network frameworks that the request has to go through before hitting our API server and failure could happen at anywhere.
During trade spikes, one server might be overloaded therefore we provide alternate routes like (api1, api2, api3) for users to route to a less congested network. But do also take note that there is still load balancing done on our end, meaning to say that we can’t confirm that api3 is always less congested than api. All in all, it’s good to have a backup strategy where in case one request fails, you can send the request again using alternate base urls provided.