Page cover

Test your API key !

After writing your APIs, click the test key button. This will test your API key. If successful, the save button will be activated.

Binance API Self-Test Endpoint This script defines a single API endpoint, POST /binance, designed to perform a comprehensive self-test on a user's Binance API key and secret. It validates connectivity, permissions, security settings, and trading capability for the Futures market.

Here is a breakdown of the specific tests performed:

  1. API Credentials Presence:

It checks if the apiKey and apiSecret are provided in the request body.

  1. Futures API Connectivity (pingOk):

It sends a request to the /fapi/v1/ping endpoint to verify that the Binance Futures API servers are online and reachable.

  1. Server Time Synchronization (driftOk):

It fetches the official Binance server time and compares it to the local server's time.

It passes the test if the time difference (driftMs) is less than 2000 milliseconds, which is critical for time-sensitive signed requests.

  1. API Key Permissions (apiRestrictions):

Futures Trading (futuresPermission): It verifies that the API key is explicitly enabled for Futures trading (enableFutures).

Withdrawal Security (withdrawEnabled / withdrawSafe): It checks if the API key has withdrawal permissions enabled. For security, the overall test (ok) will only pass if withdrawals are disabled (withdrawSafe).

IP Restriction (ipRestrictEnabled): It checks if the API key is restricted to specific IP addresses.

  1. Account Configuration & Status:

Position Mode (positionMode): It queries the /fapi/v1/positionSide/dual endpoint to determine if the user's account is set to "HEDGE" mode or "ONE_WAY" mode.

Account Trading Status (canTrade): It checks the futures account details to ensure the account is permitted to trade.

  1. Exchange & Symbol Information:

It fetches the exchange's trading rules (exchangeInfo) for the BTCUSDT symbol.

It extracts the minimum order quantity increment (stepSize) and the minimum order value (minNotional) for BTCUSDT.

  1. Test Order Creation (testOrderOk):

It attempts to create a test order using the /fapi/v1/order/test endpoint.

This is a critical validation that confirms the API key and secret can correctly sign a trading request and have the necessary permissions to place an order without actually executing a live trade. This will always result in a 400 error because the order is being placed with a very small amount. So, a successful result is 400. However, 404, 500, and 502 indicate errors.

The final ok: true response is returned only if the most critical checks pass: API connectivity, time synchronization, futures permission, trading ability, and withdrawal security (withdrawals disabled).

Last updated