Repository navigation
Risk Management
Leverage is a beautiful, terrible thing. It can make you rich. It can also wipe you out before lunch.
This guide is about staying in the game. Because you can't win if you're not playing.
$risk = Bingx::account()->getPositionRisk('BTC-USDT');
// Critical metrics
echo "Position Size: {$risk['positionAmt']}\n";
echo "Entry Price: {$risk['entryPrice']}\n";
echo "Mark Price: {$risk['markPrice']}\n";
echo "Liquidation Price: {$risk['liquidationPrice']}\n";
echo "Margin Ratio: {$risk['marginRatio']}%\n";
echo "Unrealized P&L: {$risk['unrealizedProfit']}\n";
echo "Leverage: {$risk['leverage']}x\n";Think of it like a health bar in a video game. When it hits 100%, game over.
- < 50% — You're chilling. Go get a coffee.
- 50-80% — Pay attention. Maybe don't go to sleep.
- 80-90% — 🚨 Red alert. Do something NOW.
- > 90% — You're about to lose money. Seriously.
- 100% — Gone. Your position is liquidated. Learn from this.
// This function might save your account. Set it up.
function monitorPositionRisk($symbol, $alertThreshold = 80) {
while (true) {
$risk = Bingx::account()->getPositionRisk($symbol);
if (empty($risk['positionAmt'])) {
echo "No position\n";
sleep(60);
continue;
}
$ratio = $risk['marginRatio'];
$liqPrice = $risk['liquidationPrice'];
$currentPrice = $risk['markPrice'];
// Calculate distance to liquidation
$distance = abs(($currentPrice - $liqPrice) / $currentPrice) * 100;
echo date('H:i:s') . " - Margin: {$ratio}%, ";
echo "Liq: {$liqPrice}, Distance: {$distance}%\n";
// Alert if approaching liquidation
if ($ratio > $alertThreshold) {
sendAlert("⚠️ Margin ratio at {$ratio}%! Liquidation at {$liqPrice}");
}
// Emergency close if critical
if ($ratio > 95) {
echo "EMERGENCY CLOSE!\n";
Bingx::trade()->closeAllPositions($symbol);
break;
}
sleep(60); // Check every minute
}
}
// Start monitoring
monitorPositionRisk('BTC-USDT', 75);It's 3 AM. You're asleep. Your position is dying. But wait — auto-add margin kicks in and saves you.
(Only works in hedge mode, but still. Pretty nice.)
// Enable for LONG positions
Bingx::trade()->setAutoAddMargin(
symbol: 'BTC-USDT',
positionSide: 'LONG',
enabled: true
);
// Check status
$status = Bingx::trade()->getAutoAddMargin('BTC-USDT', 'LONG');
if ($status['autoAddMargin']) {
echo "Auto-add margin is ON\n";
}Important:
- Only works in hedge mode
- Adds from available balance
- Not a substitute for proper risk management
- Can delay but not prevent liquidation
Most traders blow up because they bet too big. Don't be most traders.
function calculatePositionSize(
$accountBalance,
$riskPercent,
$entryPrice,
$stopLossPrice,
$leverage
) {
// How much you're willing to risk
$riskAmount = $accountBalance * ($riskPercent / 100);
// Distance to stop-loss
$stopDistance = abs($entryPrice - $stopLossPrice);
$stopPercent = ($stopDistance / $entryPrice) * 100;
// Position size
$positionValue = ($riskAmount / $stopPercent) * 100;
$quantity = $positionValue / $entryPrice;
// Margin needed
$marginNeeded = $positionValue / $leverage;
return [
'quantity' => $quantity,
'position_value' => $positionValue,
'margin_needed' => $marginNeeded,
'risk_amount' => $riskAmount,
'stop_percent' => $stopPercent
];
}
// Example: $10k account, risk 2%, 10x leverage
$size = calculatePositionSize(
accountBalance: 10000,
riskPercent: 2, // Risk 2% = $200
entryPrice: 50000,
stopLossPrice: 48000, // 4% stop
leverage: 10
);
echo "Position Size: {$size['quantity']} BTC\n";
echo "Position Value: ${$size['position_value']}\n";
echo "Margin Needed: ${$size['margin_needed']}\n";
echo "Risk Amount: ${$size['risk_amount']}\n";Never risk more than 1-2% of your account on a single trade.
This isn't optional. This isn't for beginners. This is for everyone.
$accountBalance = 10000;
$maxRisk = $accountBalance * 0.02; // 2% = $200
// If you lose, you only lose $200
// You can be wrong 50 times before account is gone
// Gives you room to learn and adaptA trade without a stop-loss is not a trade. It's a gamble.
$entry = 50000;
$stopPercent = 4; // 4% stop-loss
$stopPrice = $entry * (1 - $stopPercent / 100); // $48,000
$order = Bingx::trade()->order()
->futures()
->symbol('BTC-USDT')
->buy()
->long()
->type('LIMIT')
->price($entry)
->margin(1000)
->leverage(10)
->execute();
// Set stop-loss
$stop = Bingx::trade()->order()
->futures()
->symbol('BTC-USDT')
->sell()
->long()
->type('STOP_MARKET')
->stopPrice($stopPrice)
->quantity(/* position size */)
->execute();// Use Average True Range for dynamic stops
function calculateATRStop($symbol, $atrMultiplier = 2) {
$klines = Bingx::market()->getKlines($symbol, '1h', 14);
$atr = 0;
foreach ($klines as $i => $candle) {
if ($i === 0) continue;
$high = $candle[2];
$low = $candle[3];
$prevClose = $klines[$i-1][4];
$tr = max(
$high - $low,
abs($high - $prevClose),
abs($low - $prevClose)
);
$atr += $tr;
}
$atr = $atr / 14;
$currentPrice = $klines[count($klines) - 1][4];
$stopDistance = $atr * $atrMultiplier;
return [
'atr' => $atr,
'stop_distance' => $stopDistance,
'stop_price' => $currentPrice - $stopDistance
];
}
$atrStop = calculateATRStop('BTC-USDT', 2);
echo "ATR: {$atrStop['atr']}\n";
echo "Stop Price: {$atrStop['stop_price']}\n";// Protect profits while letting winners run
$order = Bingx::trade()->order()
->futures()
->symbol('BTC-USDT')
->sell()
->long()
->type('TRAILING_STOP_MARKET')
->activationPrice(52000.0) // Start trailing at 4% profit
->callbackRate(2.0) // Trail 2% behind
->quantity(1.0)
->execute();Perfect for:
- People who like sleeping at night
- Large positions
- "I've been burned before" traders
- Long-term holds
Vibe: Boring but profitable
Perfect for:
- Traders who know what they're doing
- Swing trades
- Clear trends
- People with actual stop-losses
Vibe: Exciting but controlled
Only for:
- Professionals who've done this for years
- Tiny positions
- Scalping with tight stops
- People who can afford to lose
Vibe: Heart-pounding
Good for:
- Absolutely nobody
- People who hate money
- Creating screenshots for Twitter loss porn
Vibe: Gambling with extra steps
function analyzeLeverage($entry, $leverage, $margin) {
$positionSize = $margin * $leverage;
$liquidationPercent = (1 / $leverage) * 100;
$liquidationPrice = $entry * (1 - $liquidationPercent / 100);
return [
'position_size' => $positionSize,
'liquidation_percent' => $liquidationPercent,
'liquidation_price' => $liquidationPrice,
'safe_stop_percent' => $liquidationPercent * 0.5, // 50% of liq distance
];
}
// Compare different leverage levels
foreach ([5, 10, 20, 50] as $lev) {
$analysis = analyzeLeverage(50000, $lev, 1000);
echo "\n{$lev}x Leverage:\n";
echo "Position: ${$analysis['position_size']}\n";
echo "Liquidation: {$analysis['liquidation_percent']}% ({$analysis['liquidation_price']})\n";
echo "Safe Stop: {$analysis['safe_stop_percent']}%\n";
}Your whole portfolio as collateral. More buying power. Also more ways to lose everything.
// Check if you're eligible
$rules = Bingx::trade()->getMultiAssetsRules();
print_r($rules);
// Enable
Bingx::trade()->switchMultiAssetsMode(true);
// Monitor total portfolio risk
$margin = Bingx::trade()->getMultiAssetsMargin();
echo "Total Collateral: {$margin['totalCollateral']}\n";
echo "Total Margin: {$margin['totalMargin']}\n";
echo "Available: {$margin['availableMargin']}\n";- Everything goes down together — One bad trade can liquidate ALL your positions
- Math gets complicated — Harder to know where you stand
- Mistakes spread — One bad trade infects your whole portfolio
- Not for newbies — Seriously, get some experience first
- You run hedged strategies
- You understand portfolio risk
- You actively manage positions
- You have experience with leverage
- You're new to trading
- You run directional strategies
- You don't monitor positions
- You use high leverage
class RiskManager {
private $maxDailyLoss;
private $maxPositionSize;
private $currentLoss = 0;
public function __construct($accountBalance) {
$this->maxDailyLoss = $accountBalance * 0.05; // 5% max daily loss
$this->maxPositionSize = $accountBalance * 0.20; // 20% max per position
}
public function canTrade() {
if ($this->currentLoss >= $this->maxDailyLoss) {
echo "Daily loss limit reached. Stop trading.\n";
return false;
}
return true;
}
public function recordTrade($pnl) {
if ($pnl < 0) {
$this->currentLoss += abs($pnl);
}
echo "Current daily loss: ${$this->currentLoss}\n";
echo "Remaining: $" . ($this->maxDailyLoss - $this->currentLoss) . "\n";
}
public function validatePositionSize($size) {
if ($size > $this->maxPositionSize) {
echo "Position too large. Max: ${$this->maxPositionSize}\n";
return false;
}
return true;
}
}
// Usage
$risk = new RiskManager(10000);
if ($risk->canTrade()) {
// Place trade
$pnl = -200; // Lost $200
$risk->recordTrade($pnl);
}When everything is on fire, here's what to do.
// Everything is going wrong. Get out. NOW.
Bingx::trade()->closeAllPositions('BTC-USDT');
// Or cancel all orders first
Bingx::trade()->cancelAllOrders();
Bingx::trade()->closeAllPositions('BTC-USDT');// Cut position in half
$positions = Bingx::account()->getPositions('BTC-USDT');
$currentSize = $positions[0]['positionAmt'];
$reduceBy = $currentSize / 2;
Bingx::trade()->order()
->futures()
->symbol('BTC-USDT')
->sell()
->long()
->type('MARKET')
->quantity($reduceBy)
->execute();// Manually add margin to avoid liquidation
Bingx::trade()->modifyPositionMargin(
symbol: 'BTC-USDT',
positionSide: 'LONG',
amount: 500, // Add $500
type: 1 // 1 = ADD, 2 = REDUCE
);Run through this. Every. Single. Time.
- Position size calculated (am I risking more than 2%?)
- Stop-loss SET (not "I'll set it later")
- Take-profit planned (where am I getting out?)
- Leverage reasonable (not 50x because I'm feeling lucky)
- Account balance checked (can I afford this?)
- Daily loss limit not exceeded (am I revenge trading?)
- Market makes sense (or am I just bored?)
- I actually understand this trade (or am I copying someone?)
// This is how accounts die
$order = Bingx::trade()->order()
->futures()
->type('MARKET')
->margin(1000)
->leverage(20)
->execute();
// "It'll come back." Famous last words.// This is not trading. This is gambling.
$order = Bingx::trade()->order()
->leverage(50)
->margin(10000) // Your entire account
->execute();
// A 2% move liquidates you. BTC moves 2% while you blink.// Your position is underwater.
// Your solution: add more money to the losing trade.
// This is how small losses become account-ending losses.
// Just. Take. The. Loss.// This thing charges you every 8 hours. Surprise!
$funding = Bingx::market()->getFundingRateInfo('BTC-USDT');
echo "Funding Rate: {$funding['fundingRate']}\n";
// Negative rate = longs pay shorts (expensive to be long)
// Positive rate = shorts pay longs (expensive to be short)
// Check this BEFORE you hold overnight. It adds up.The market will be here tomorrow.
Will your account?
Manage your risk. Use stop-losses. Size your positions properly. Live to trade another day.
The best traders aren't the ones who make the most money. They're the ones who stay in the game the longest.