Repository navigation
API v3 Features
Remember when only hedge funds had access to algorithmic trading? Those days are over.
API v3 brings the big-boy tools to your PHP code. Let's see what you can do now.
Ever tried to buy a lot of Bitcoin and watched the price jump up as you bought? Yeah, that's you moving the market. Against yourself. Not great.
TWAP fixes this. Instead of one big order, it breaks your trade into tiny pieces spread over time. The market barely notices you're there.
// Execute 10 BTC over 1 hour
$twap = Bingx::twap()->buy(
symbol: 'BTC-USDT',
quantity: 10.0,
duration: 3600,
positionSide: 'LONG'
);
// Monitor progress
$details = Bingx::twap()->getOrderDetail($twap['orderId']);
echo "Executed: {$details['executedQty']}/{$details['totalQty']}\n";When should you use this?
- You're buying/selling more than pocket change
- You're tired of seeing worse fills than expected
- You want to accumulate without tipping off the market
Here's a story: You buy BTC at $50k. Set stop-loss at $45k. Price goes to $60k. You're feeling great! Then it drops to $46k. Your stop doesn't trigger. Then $44k. NOW it triggers. You lost money on a trade that was up 20%.
Trailing stops fix this. They follow the price up, locking in your gains. When the price was at $60k, your stop would have moved up too. When it dropped, you'd have exited with profit, not loss.
$order = Bingx::trade()->order()
->futures()
->symbol('BTC-USDT')
->sell() // Close long position
->long()
->type('TRAILING_STOP_MARKET')
->activationPrice(50000) // Start trailing at $50k
->callbackRate(2.0) // Trail 2% behind peak
->quantity(1.0)
->execute();Watch it work:
- Price hits $50k → "Okay, start trailing me"
- Price climbs to $55k → Stop follows to $53.9k (2% behind)
- Price rockets to $60k → Stop moves up to $58.8k
- Price drops to $58.8k → SOLD! You kept most of that $10k gain.
Without trailing stop? You'd still be holding, hoping, praying. 😬
Picture this: You've got $10k in BTC, $5k in ETH, $3k in USDT. You want to open a position but your USDT is tied up. Meanwhile, your BTC and ETH are just... sitting there.
Multi-assets margin changes the game. Now your entire portfolio backs your positions. More buying power, less wasted capital.
// Enable portfolio margin
Bingx::trade()->switchMultiAssetsMode(true);
// Check your margin status
$margin = Bingx::trade()->getMultiAssetsMargin();
echo "Total Collateral: {$margin['totalCollateral']}\n";
echo "Available Margin: {$margin['availableMargin']}\n";
// Get margin rules
$rules = Bingx::trade()->getMultiAssetsRules();The upside:
- Lower margin requirements (especially if you're hedged)
- All your assets work together
- More trades with the same capital
- Portfolio strategies become possible
The catch (there's always a catch):
- If you get liquidated, EVERYTHING gets liquidated
- Risk management gets trickier
- Probably not for your first week of trading
Leverage is fun until you get liquidated. And the worst part? Most people don't even know it's coming until their position disappears.
Now you can see it coming. Real-time risk metrics show you exactly how close to the edge you are.
$risk = Bingx::account()->getPositionRisk('BTC-USDT');
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";Set up a guardian angel:
// This little loop might save your account
while (true) {
$risk = Bingx::account()->getPositionRisk('BTC-USDT');
if ($risk['marginRatio'] > 80) {
// WAKE UP! You're about to lose money!
sendAlert("🚨 Margin at {$risk['marginRatio']}%! DO SOMETHING!");
}
sleep(60); // Check every minute. Your future self will thank you.
}The market just did a 180. You're long. You need to be short. NOW.
Old way: Close long (slippage), wait, open short (more slippage), pray nothing moved too much.
New way: One click. Done. You're now short. No gap, no drama.
// Currently LONG 1.0 BTC
// This closes the long AND opens SHORT 1.0 BTC atomically
Bingx::trade()->oneClickReversePosition('BTC-USDT');
// Now you're SHORT 1.0 BTC - no gap, no slippagePerfect for:
- "Oh crap, I was wrong" moments
- Trend reversal strategies
- Stop-and-reverse systems
- Anyone who's ever fumbled two orders and lost money in between
You started with $10k. Now you have $9.5k. You thought you were profitable. What happened?
Now you can find out. Every dollar in, every dollar out, broken down by type.
// Get all income types
$income = Bingx::account()->getIncomeHistory(
symbol: 'BTC-USDT',
limit: 100
);
// Filter by type
$pnl = Bingx::account()->getIncomeHistory(
symbol: 'BTC-USDT',
incomeType: 'REALIZED_PNL' // Actual profits/losses
);
$funding = Bingx::account()->getIncomeHistory(
symbol: 'BTC-USDT',
incomeType: 'FUNDING_FEE' // 8-hour funding payments
);
$fees = Bingx::account()->getCommissionHistory('BTC-USDT');Where your money actually goes:
-
REALIZED_PNL— What you made (or lost) on actual trades -
FUNDING_FEE— That thing that charges you every 8 hours (surprise!) -
COMMISSION— BingX's cut on every trade -
TRANSFER— Money moving between accounts -
INSURANCE_CLEAR— Rare, but it happens
Build a P&L dashboard:
$stats = [
'total_pnl' => 0,
'total_fees' => 0,
'total_funding' => 0,
];
$income = Bingx::account()->getIncomeHistory(limit: 1000);
foreach ($income as $record) {
switch ($record['incomeType']) {
case 'REALIZED_PNL':
$stats['total_pnl'] += $record['income'];
break;
case 'COMMISSION':
$stats['total_fees'] += $record['income'];
break;
case 'FUNDING_FEE':
$stats['total_funding'] += $record['income'];
break;
}
}
echo "Net P&L: {$stats['total_pnl']}\n";
echo "Fees Paid: {$stats['total_fees']}\n";
echo "Funding Received: {$stats['total_funding']}\n";The best traders don't just look at price. They look at everything. Now you can too.
// Open Interest - how much is currently open
$oi = Bingx::market()->getOpenInterest('BTC-USDT');
echo "Open Interest: {$oi['openInterest']}\n";
// Historical OI with different periods
$oiHistory = Bingx::market()->getOpenInterestHistory(
symbol: 'BTC-USDT',
period: '5m', // 5m, 15m, 30m, 1h, 4h, 1d
limit: 100
);
// Funding Rate Info
$funding = Bingx::market()->getFundingRateInfo('BTC-USDT');
echo "Current Rate: {$funding['fundingRate']}\n";
echo "Next Payment: {$funding['fundingTime']}\n";
// Book Ticker - best bid/ask without full depth
$ticker = Bingx::market()->getBookTicker('BTC-USDT');
echo "Best Bid: {$ticker['bidPrice']} @ {$ticker['bidQty']}\n";
echo "Best Ask: {$ticker['askPrice']} @ {$ticker['askQty']}\n";
// Index Price
$index = Bingx::market()->getIndexPrice('BTC-USDT');
echo "Index: {$index['indexPrice']}\n";It's 3 AM. You're asleep. Your position is getting liquidated.
Or not. Auto-add margin watches your back, adding margin when things get dicey.
// Enable auto-add margin 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";
}Reality check:
- Only works in hedge mode (sorry, one-way folks)
- Uses your available balance (can't add what you don't have)
- It's a safety net, not a strategy
- If you're relying on this, you're probably over-leveraged
Worried about breaking changes? Don't be. Everything you wrote before still works exactly the same.
v3 features are opt-in. Use them when you're ready:
// This still works exactly as before
$order = Bingx::trade()->createOrder([
'symbol' => 'BTC-USDT',
'side' => 'BUY',
'type' => 'MARKET',
'quantity' => 0.001
]);
// Use v3 features when you're ready
$twap = Bingx::twap()->buy('BTC-USDT', 10.0, 3600);- Read this page (you're doing great!)
- Try TWAP with a tiny order — see how it feels
- Set up a trailing stop on a small position
- Add risk monitoring to your bot (seriously, do this)
- Look at your income history — where's your money going?
- Consider multi-assets margin (only if you know what you're doing)
- Brag to your friends about your institutional-grade trading setup
- TWAP Deep Dive — Master algorithmic execution
- All The Order Types — Trailing stops, triggers, and more
- Risk Management — How to not blow up your account
- Migration Guide — Coming from v1? Easy upgrade.
Still confused? That's okay. Check the FAQ, search GitHub Issues, or just ask. We're friendly.
Now go build something cool. 🚀