Repository navigation
FAQ
Questions you're probably asking. Answers that actually help.
- Go to BingX API Management
- Click "Create API"
- Save your Secret Key immediately — you'll only see it once!
- Set permissions based on what you need
| Task | Permissions Needed |
|---|---|
| View prices, charts | None (public data) |
| Check balance, positions | Read |
| Place orders | Read + Trade |
| Withdraw funds | Read + Trade + Withdraw |
Tip: Start with Read-only while testing. Add Trade when you're ready.
Common causes:
- Typo — Copy-paste, don't type manually
- Wrong key type — Make sure it's for Futures, not Spot
- IP restriction — Check if your IP is whitelisted
- Key disabled — Check API management page
// Test your connection
try {
$time = Bingx::market()->getServerTime();
echo "Connected! Server time: {$time['serverTime']}\n";
} catch (\Exception $e) {
echo "Connection failed: {$e->getMessage()}\n";
}Both work. BingX accepts either. We default to base64 because it's slightly more compact.
# In your .env file
BINGX_SIGNATURE_ENCODING=base64 # or 'hex'// Risk 2% of account with 5% stop loss at 10x leverage
$balance = Bingx::account()->getBalance()['balance']['availableMargin'];
$riskAmount = $balance * 0.02; // 2% risk
$stopLossPercent = 0.05; // 5% stop
$positionValue = $riskAmount / $stopLossPercent;
$marginNeeded = $positionValue / 10; // 10x leverage
$quantity = $positionValue / $currentPrice;- LONG = You profit when price goes UP
- SHORT = You profit when price goes DOWN
// Betting price goes up
->buy()->long()
// Betting price goes down
->sell()->short()One-Way Mode:
- One position per symbol
- Simpler to manage
- Good for beginners
Hedge Mode:
- Can have LONG and SHORT simultaneously
- More flexible strategies
- Required for some features (auto-add margin)
// Check current mode
$mode = Bingx::account()->getPositionMode();
// Switch to hedge mode
Bingx::account()->setPositionMode(true);Common reasons:
-
Insufficient margin
$balance = Bingx::account()->getBalance(); echo "Available: {$balance['balance']['availableMargin']}\n";
-
Invalid quantity — Check minimum order size
$info = Bingx::market()->getContractInfo('BTC-USDT'); echo "Min qty: {$info['minQty']}\n";
-
Price too far from market — For limit orders
-
Max open orders reached
-
Position mode mismatch — Check hedge vs one-way
// Method 1: With the order (recommended)
Bingx::trade()->order()
->futures()
->symbol('BTC-USDT')
->buy()->long()
->type('MARKET')
->margin(100)
->leverage(10)
->stopLossPercent(5) // 5% stop loss
->execute();
// Method 2: Separate order
Bingx::trade()->order()
->futures()
->symbol('BTC-USDT')
->sell()->long() // Close long position
->type('STOP_MARKET')
->stopPrice(48000)
->closePosition(true)
->execute();- STOP (or STOP_LIMIT) — Triggers a limit order at stop price
- STOP_MARKET — Triggers a market order at stop price
Use STOP_MARKET for stop losses — guaranteed execution.
$order = Bingx::trade()->order()
->type('TRAILING_STOP_MARKET')
->activationPrice(52000) // Start trailing at $52k
->callbackRate(2.0) // Trail 2% behind peak
->execute();- Price hits $52k → trailing starts
- Price goes to $55k → stop moves to $53.9k (2% below)
- Price goes to $60k → stop moves to $58.8k
- Price drops to $58.8k → order executes
// Klines (candlesticks)
$klines = Bingx::market()->getKlines(
symbol: 'BTC-USDT',
interval: '1h', // 1m, 5m, 15m, 30m, 1h, 4h, 1d, 1w
limit: 500 // Max 1000
);
// With time range
$klines = Bingx::market()->getKlines(
symbol: 'BTC-USDT',
interval: '1d',
startTime: strtotime('-30 days') * 1000,
endTime: time() * 1000
);1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M
$funding = Bingx::market()->getFundingRateInfo('BTC-USDT');
echo "Current rate: {$funding['fundingRate']}\n";
echo "Next funding: {$funding['nextFundingTime']}\n";Funding rates:
- Positive = Longs pay shorts
- Negative = Shorts pay longs
- Paid every 8 hours
BingX limits vary by endpoint:
- Market data: ~100 requests/second
- Account/Trade: ~10 requests/second
The SDK handles rate limit errors automatically with retries.
try {
$result = Bingx::trade()->createOrder([...]);
} catch (\Tigusigalpa\BingX\Exceptions\RateLimitException $e) {
// Wait and retry
sleep(1);
}use Tigusigalpa\BingX\Exceptions\{
ApiException,
AuthenticationException,
RateLimitException,
InsufficientBalanceException
};
try {
$order = Bingx::trade()->createOrder([...]);
} catch (AuthenticationException $e) {
// Invalid API key or signature
} catch (RateLimitException $e) {
// Too many requests
} catch (InsufficientBalanceException $e) {
// Not enough margin
} catch (ApiException $e) {
// Other API errors
echo "Code: {$e->getCode()}\n";
echo "Message: {$e->getMessage()}\n";
}Yes! Just make sure to handle exceptions:
class PlaceOrderJob implements ShouldQueue
{
public function handle()
{
Bingx::trade()->createOrder([...]);
}
public function failed(\Throwable $e)
{
// Log failure, notify admin, etc.
}
}The SDK requires PHP 8.1+ for:
- Named arguments
- Union types
- Enums
- Other modern features
Yes, create separate client instances:
use Tigusigalpa\BingX\BingxClient;
$mainAccount = new BingxClient(
apiKey: 'main_key',
apiSecret: 'main_secret'
);
$subAccount = new BingxClient(
apiKey: 'sub_key',
apiSecret: 'sub_secret'
);
$mainAccount->market()->getLatestPrice('BTC-USDT');
$subAccount->account()->getBalance();Use TWAP when:
- Order size > 1% of daily volume
- You want to minimize slippage
- You're building/exiting large positions
- You don't need immediate execution
Don't use TWAP when:
- Small orders (< $10k)
- You need instant execution
- Market is moving fast against you
No. Cancel it and create a new one.
Bingx::twap()->cancelOrder($orderId, 'BTC-USDT');
$newTwap = Bingx::twap()->buy(...);You keep whatever was filled. The rest expires.
$details = Bingx::twap()->getOrderDetail($orderId);
echo "Filled: {$details['executedQty']}/{$details['totalQty']}\n";| Situation | Use |
|---|---|
| Need to enter/exit NOW | Market |
| Want specific price | Limit |
| Stop loss | STOP_MARKET |
| Take profit | LIMIT or TAKE_PROFIT |
| Experience | Recommended |
|---|---|
| Beginner | 1-3x |
| Intermediate | 5-10x |
| Advanced | 10-20x |
| Professional | Case by case |
Rule: If you're asking this question, use lower leverage.
- Use stop losses — Always
- Size positions properly — Risk 1-2% per trade
- Monitor margin ratio — Stay below 50%
- Don't over-leverage — Start with 5x or less
- Enable auto-add margin — Extra safety net
// Monitor your risk
$risk = Bingx::account()->getPositionRisk('BTC-USDT');
if ($risk['marginRatio'] > 70) {
// Add margin or reduce position
}- Search the Wiki — Most answers are here
- Check GitHub Issues — Someone might have asked already
- Open an Issue — We respond quickly
- Read the Code — It's well-documented
Links: