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"eOrderQty=0.1&recvWindow=60000&side=BUY&signature=9be63d57ec229aefb49234d689933af2024da69b80f0250d25179636b3d6a7b8&symbol=DREPBTC×tamp=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?
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.