Fix styling
This commit is contained in:
1 parent
38114203a1
commit
526ef64ad8
10 files changed
+151
-154
No files matched your search
@@ -28,19 +28,19 @@ try {
|
||||
// Example 1: Flash close a single position
|
||||
echo "1. Flash closing position...\n";
|
||||
$positionId = '19848247723672';
|
||||
|
||||
|
||||
$response = $api->flashClosePosition($positionId);
|
||||
|
||||
if ($response->getStatusCode() === 200) {
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if ($data['code'] === 0) {
|
||||
echo "✅ Position flash closed successfully!\n";
|
||||
echo "Position ID: " . $data['data']['positionId'] . "\n";
|
||||
echo 'Position ID: '.$data['data']['positionId']."\n";
|
||||
} else {
|
||||
echo "❌ API Error: " . $data['msg'] . "\n";
|
||||
echo '❌ API Error: '.$data['msg']."\n";
|
||||
}
|
||||
} else {
|
||||
echo "❌ HTTP Error: " . $response->getStatusCode() . "\n";
|
||||
echo '❌ HTTP Error: '.$response->getStatusCode()."\n";
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
@@ -50,23 +50,23 @@ try {
|
||||
$positionIds = [
|
||||
'19848247723672',
|
||||
'19848247723673',
|
||||
'19848247723674'
|
||||
'19848247723674',
|
||||
];
|
||||
|
||||
foreach ($positionIds as $positionId) {
|
||||
echo "Closing position: {$positionId}...\n";
|
||||
|
||||
|
||||
$response = $api->flashClosePosition($positionId);
|
||||
|
||||
|
||||
if ($response->getStatusCode() === 200) {
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if ($data['code'] === 0) {
|
||||
echo "✅ Position {$positionId} closed successfully!\n";
|
||||
} else {
|
||||
echo "❌ Failed to close position {$positionId}: " . $data['msg'] . "\n";
|
||||
echo "❌ Failed to close position {$positionId}: ".$data['msg']."\n";
|
||||
}
|
||||
} else {
|
||||
echo "❌ HTTP Error for position {$positionId}: " . $response->getStatusCode() . "\n";
|
||||
echo "❌ HTTP Error for position {$positionId}: ".$response->getStatusCode()."\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,19 +75,19 @@ try {
|
||||
// Example 3: Error handling
|
||||
echo "3. Error handling example...\n";
|
||||
$invalidPositionId = 'invalid-position-id';
|
||||
|
||||
|
||||
$response = $api->flashClosePosition($invalidPositionId);
|
||||
|
||||
|
||||
if ($response->getStatusCode() === 200) {
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if ($data['code'] === 0) {
|
||||
echo "✅ Position closed successfully!\n";
|
||||
} else {
|
||||
echo "❌ API Error: " . $data['msg'] . "\n";
|
||||
echo '❌ API Error: '.$data['msg']."\n";
|
||||
echo "This is expected for invalid position ID\n";
|
||||
}
|
||||
} else {
|
||||
echo "❌ HTTP Error: " . $response->getStatusCode() . "\n";
|
||||
echo '❌ HTTP Error: '.$response->getStatusCode()."\n";
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
@@ -96,19 +96,19 @@ try {
|
||||
|
||||
/**
|
||||
* Flash Close Position Features:
|
||||
*
|
||||
*
|
||||
* - Closes position by position ID
|
||||
* - Rate limit: 5 req/sec/uid
|
||||
* - Immediate position closure
|
||||
* - No additional parameters required
|
||||
*
|
||||
*
|
||||
* Important Notes:
|
||||
*
|
||||
*
|
||||
* - Position ID must be valid and exist
|
||||
* - Position must be open to be closed
|
||||
* - This is an immediate action (flash close)
|
||||
* - Use with caution as it closes positions immediately
|
||||
*
|
||||
*
|
||||
* Environment Variables Required:
|
||||
*
|
||||
* BITUNIX_API_KEY=your-api-key
|
||||
|
||||
@@ -33,23 +33,23 @@ try {
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if ($data['code'] === 0) {
|
||||
echo "✅ Pending positions retrieved successfully!\n";
|
||||
echo "Number of positions: " . count($data['data']) . "\n";
|
||||
|
||||
echo 'Number of positions: '.count($data['data'])."\n";
|
||||
|
||||
foreach ($data['data'] as $position) {
|
||||
echo " - Position ID: " . $position['positionId'] . "\n";
|
||||
echo " Symbol: " . $position['symbol'] . "\n";
|
||||
echo " Side: " . $position['side'] . "\n";
|
||||
echo " Quantity: " . $position['qty'] . "\n";
|
||||
echo " Unrealized PnL: " . $position['unrealizedPNL'] . "\n";
|
||||
echo " Margin: " . $position['margin'] . "\n";
|
||||
echo " Leverage: " . $position['leverage'] . "\n";
|
||||
echo ' - Position ID: '.$position['positionId']."\n";
|
||||
echo ' Symbol: '.$position['symbol']."\n";
|
||||
echo ' Side: '.$position['side']."\n";
|
||||
echo ' Quantity: '.$position['qty']."\n";
|
||||
echo ' Unrealized PnL: '.$position['unrealizedPNL']."\n";
|
||||
echo ' Margin: '.$position['margin']."\n";
|
||||
echo ' Leverage: '.$position['leverage']."\n";
|
||||
echo " ---\n";
|
||||
}
|
||||
} else {
|
||||
echo "❌ API Error: " . $data['msg'] . "\n";
|
||||
echo '❌ API Error: '.$data['msg']."\n";
|
||||
}
|
||||
} else {
|
||||
echo "❌ HTTP Error: " . $response->getStatusCode() . "\n";
|
||||
echo '❌ HTTP Error: '.$response->getStatusCode()."\n";
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
@@ -62,21 +62,21 @@ try {
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if ($data['code'] === 0) {
|
||||
echo "✅ BTCUSDT pending positions retrieved successfully!\n";
|
||||
echo "Number of BTCUSDT positions: " . count($data['data']) . "\n";
|
||||
|
||||
echo 'Number of BTCUSDT positions: '.count($data['data'])."\n";
|
||||
|
||||
foreach ($data['data'] as $position) {
|
||||
echo " - Position ID: " . $position['positionId'] . "\n";
|
||||
echo " Entry Value: " . $position['entryValue'] . "\n";
|
||||
echo " Average Open Price: " . $position['avgOpenPrice'] . "\n";
|
||||
echo " Liquidation Price: " . $position['liqPrice'] . "\n";
|
||||
echo " Margin Rate: " . $position['marginRate'] . "\n";
|
||||
echo ' - Position ID: '.$position['positionId']."\n";
|
||||
echo ' Entry Value: '.$position['entryValue']."\n";
|
||||
echo ' Average Open Price: '.$position['avgOpenPrice']."\n";
|
||||
echo ' Liquidation Price: '.$position['liqPrice']."\n";
|
||||
echo ' Margin Rate: '.$position['marginRate']."\n";
|
||||
echo " ---\n";
|
||||
}
|
||||
} else {
|
||||
echo "❌ API Error: " . $data['msg'] . "\n";
|
||||
echo '❌ API Error: '.$data['msg']."\n";
|
||||
}
|
||||
} else {
|
||||
echo "❌ HTTP Error: " . $response->getStatusCode() . "\n";
|
||||
echo '❌ HTTP Error: '.$response->getStatusCode()."\n";
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
@@ -90,36 +90,36 @@ try {
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if ($data['code'] === 0) {
|
||||
echo "✅ Position {$positionId} retrieved successfully!\n";
|
||||
|
||||
if (!empty($data['data'])) {
|
||||
|
||||
if (! empty($data['data'])) {
|
||||
$position = $data['data'][0];
|
||||
echo " Position Details:\n";
|
||||
echo " Position ID: " . $position['positionId'] . "\n";
|
||||
echo " Symbol: " . $position['symbol'] . "\n";
|
||||
echo " Side: " . $position['side'] . "\n";
|
||||
echo " Quantity: " . $position['qty'] . "\n";
|
||||
echo " Entry Value: " . $position['entryValue'] . "\n";
|
||||
echo " Average Open Price: " . $position['avgOpenPrice'] . "\n";
|
||||
echo " Unrealized PnL: " . $position['unrealizedPNL'] . "\n";
|
||||
echo " Realized PnL: " . $position['realizedPNL'] . "\n";
|
||||
echo " Margin: " . $position['margin'] . "\n";
|
||||
echo " Leverage: " . $position['leverage'] . "\n";
|
||||
echo " Margin Mode: " . $position['marginMode'] . "\n";
|
||||
echo " Position Mode: " . $position['positionMode'] . "\n";
|
||||
echo " Liquidation Price: " . $position['liqPrice'] . "\n";
|
||||
echo " Margin Rate: " . $position['marginRate'] . "\n";
|
||||
echo " Fee: " . $position['fee'] . "\n";
|
||||
echo " Funding: " . $position['funding'] . "\n";
|
||||
echo " Created: " . date('Y-m-d H:i:s', $position['ctime'] / 1000) . "\n";
|
||||
echo " Modified: " . date('Y-m-d H:i:s', $position['mtime'] / 1000) . "\n";
|
||||
echo ' Position ID: '.$position['positionId']."\n";
|
||||
echo ' Symbol: '.$position['symbol']."\n";
|
||||
echo ' Side: '.$position['side']."\n";
|
||||
echo ' Quantity: '.$position['qty']."\n";
|
||||
echo ' Entry Value: '.$position['entryValue']."\n";
|
||||
echo ' Average Open Price: '.$position['avgOpenPrice']."\n";
|
||||
echo ' Unrealized PnL: '.$position['unrealizedPNL']."\n";
|
||||
echo ' Realized PnL: '.$position['realizedPNL']."\n";
|
||||
echo ' Margin: '.$position['margin']."\n";
|
||||
echo ' Leverage: '.$position['leverage']."\n";
|
||||
echo ' Margin Mode: '.$position['marginMode']."\n";
|
||||
echo ' Position Mode: '.$position['positionMode']."\n";
|
||||
echo ' Liquidation Price: '.$position['liqPrice']."\n";
|
||||
echo ' Margin Rate: '.$position['marginRate']."\n";
|
||||
echo ' Fee: '.$position['fee']."\n";
|
||||
echo ' Funding: '.$position['funding']."\n";
|
||||
echo ' Created: '.date('Y-m-d H:i:s', $position['ctime'] / 1000)."\n";
|
||||
echo ' Modified: '.date('Y-m-d H:i:s', $position['mtime'] / 1000)."\n";
|
||||
} else {
|
||||
echo "No position found with ID: {$positionId}\n";
|
||||
}
|
||||
} else {
|
||||
echo "❌ API Error: " . $data['msg'] . "\n";
|
||||
echo '❌ API Error: '.$data['msg']."\n";
|
||||
}
|
||||
} else {
|
||||
echo "❌ HTTP Error: " . $response->getStatusCode() . "\n";
|
||||
echo '❌ HTTP Error: '.$response->getStatusCode()."\n";
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
@@ -132,12 +132,12 @@ try {
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if ($data['code'] === 0) {
|
||||
echo "✅ Filtered positions retrieved successfully!\n";
|
||||
echo "Number of filtered positions: " . count($data['data']) . "\n";
|
||||
echo 'Number of filtered positions: '.count($data['data'])."\n";
|
||||
} else {
|
||||
echo "❌ API Error: " . $data['msg'] . "\n";
|
||||
echo '❌ API Error: '.$data['msg']."\n";
|
||||
}
|
||||
} else {
|
||||
echo "❌ HTTP Error: " . $response->getStatusCode() . "\n";
|
||||
echo '❌ HTTP Error: '.$response->getStatusCode()."\n";
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
@@ -146,13 +146,13 @@ try {
|
||||
|
||||
/**
|
||||
* Get Pending Positions Features:
|
||||
*
|
||||
*
|
||||
* - Get all pending positions
|
||||
* - Filter by trading pair (symbol)
|
||||
* - Filter by position ID
|
||||
* - Get detailed position information
|
||||
* - Rate limit: 10 req/sec/uid
|
||||
*
|
||||
*
|
||||
* Response includes:
|
||||
* - positionId: Position ID
|
||||
* - symbol: Trading pair
|
||||
@@ -172,7 +172,7 @@ try {
|
||||
* - avgOpenPrice: Average open price
|
||||
* - ctime: Create timestamp
|
||||
* - mtime: Latest modify timestamp
|
||||
*
|
||||
*
|
||||
* Environment Variables Required:
|
||||
*
|
||||
* BITUNIX_API_KEY=your-api-key
|
||||
|
||||
@@ -33,23 +33,23 @@ try {
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if ($data['code'] === 0) {
|
||||
echo "✅ USDT account details retrieved successfully!\n";
|
||||
|
||||
|
||||
$account = $data['data'][0];
|
||||
echo "Account Details:\n";
|
||||
echo " Margin Coin: " . $account['marginCoin'] . "\n";
|
||||
echo " Available: " . $account['available'] . "\n";
|
||||
echo " Frozen: " . $account['frozen'] . "\n";
|
||||
echo " Margin: " . $account['margin'] . "\n";
|
||||
echo " Transfer: " . $account['transfer'] . "\n";
|
||||
echo " Position Mode: " . $account['positionMode'] . "\n";
|
||||
echo " Cross Unrealized PnL: " . $account['crossUnrealizedPNL'] . "\n";
|
||||
echo " Isolation Unrealized PnL: " . $account['isolationUnrealizedPNL'] . "\n";
|
||||
echo " Bonus: " . $account['bonus'] . "\n";
|
||||
echo ' Margin Coin: '.$account['marginCoin']."\n";
|
||||
echo ' Available: '.$account['available']."\n";
|
||||
echo ' Frozen: '.$account['frozen']."\n";
|
||||
echo ' Margin: '.$account['margin']."\n";
|
||||
echo ' Transfer: '.$account['transfer']."\n";
|
||||
echo ' Position Mode: '.$account['positionMode']."\n";
|
||||
echo ' Cross Unrealized PnL: '.$account['crossUnrealizedPNL']."\n";
|
||||
echo ' Isolation Unrealized PnL: '.$account['isolationUnrealizedPNL']."\n";
|
||||
echo ' Bonus: '.$account['bonus']."\n";
|
||||
} else {
|
||||
echo "❌ API Error: " . $data['msg'] . "\n";
|
||||
echo '❌ API Error: '.$data['msg']."\n";
|
||||
}
|
||||
} else {
|
||||
echo "❌ HTTP Error: " . $response->getStatusCode() . "\n";
|
||||
echo '❌ HTTP Error: '.$response->getStatusCode()."\n";
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
@@ -62,23 +62,23 @@ try {
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if ($data['code'] === 0) {
|
||||
echo "✅ BTC account details retrieved successfully!\n";
|
||||
|
||||
|
||||
$account = $data['data'][0];
|
||||
echo "Account Details:\n";
|
||||
echo " Margin Coin: " . $account['marginCoin'] . "\n";
|
||||
echo " Available: " . $account['available'] . "\n";
|
||||
echo " Frozen: " . $account['frozen'] . "\n";
|
||||
echo " Margin: " . $account['margin'] . "\n";
|
||||
echo " Transfer: " . $account['transfer'] . "\n";
|
||||
echo " Position Mode: " . $account['positionMode'] . "\n";
|
||||
echo " Cross Unrealized PnL: " . $account['crossUnrealizedPNL'] . "\n";
|
||||
echo " Isolation Unrealized PnL: " . $account['isolationUnrealizedPNL'] . "\n";
|
||||
echo " Bonus: " . $account['bonus'] . "\n";
|
||||
echo ' Margin Coin: '.$account['marginCoin']."\n";
|
||||
echo ' Available: '.$account['available']."\n";
|
||||
echo ' Frozen: '.$account['frozen']."\n";
|
||||
echo ' Margin: '.$account['margin']."\n";
|
||||
echo ' Transfer: '.$account['transfer']."\n";
|
||||
echo ' Position Mode: '.$account['positionMode']."\n";
|
||||
echo ' Cross Unrealized PnL: '.$account['crossUnrealizedPNL']."\n";
|
||||
echo ' Isolation Unrealized PnL: '.$account['isolationUnrealizedPNL']."\n";
|
||||
echo ' Bonus: '.$account['bonus']."\n";
|
||||
} else {
|
||||
echo "❌ API Error: " . $data['msg'] . "\n";
|
||||
echo '❌ API Error: '.$data['msg']."\n";
|
||||
}
|
||||
} else {
|
||||
echo "❌ HTTP Error: " . $response->getStatusCode() . "\n";
|
||||
echo '❌ HTTP Error: '.$response->getStatusCode()."\n";
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
@@ -89,19 +89,19 @@ try {
|
||||
|
||||
foreach ($marginCoins as $marginCoin) {
|
||||
echo "Getting {$marginCoin} account details...\n";
|
||||
|
||||
|
||||
$response = $api->getSingleAccount($marginCoin);
|
||||
|
||||
|
||||
if ($response->getStatusCode() === 200) {
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if ($data['code'] === 0) {
|
||||
$account = $data['data'][0];
|
||||
echo "✅ {$marginCoin} account: Available={$account['available']}, Frozen={$account['frozen']}, Margin={$account['margin']}\n";
|
||||
} else {
|
||||
echo "❌ Failed to get {$marginCoin} account: " . $data['msg'] . "\n";
|
||||
echo "❌ Failed to get {$marginCoin} account: ".$data['msg']."\n";
|
||||
}
|
||||
} else {
|
||||
echo "❌ HTTP Error for {$marginCoin}: " . $response->getStatusCode() . "\n";
|
||||
echo "❌ HTTP Error for {$marginCoin}: ".$response->getStatusCode()."\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,19 +110,19 @@ try {
|
||||
// Example 4: Error handling
|
||||
echo "4. Error handling example...\n";
|
||||
$invalidMarginCoin = 'INVALID';
|
||||
|
||||
|
||||
$response = $api->getSingleAccount($invalidMarginCoin);
|
||||
|
||||
|
||||
if ($response->getStatusCode() === 200) {
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if ($data['code'] === 0) {
|
||||
echo "✅ Account details retrieved successfully!\n";
|
||||
} else {
|
||||
echo "❌ API Error: " . $data['msg'] . "\n";
|
||||
echo '❌ API Error: '.$data['msg']."\n";
|
||||
echo "This is expected for invalid margin coin\n";
|
||||
}
|
||||
} else {
|
||||
echo "❌ HTTP Error: " . $response->getStatusCode() . "\n";
|
||||
echo '❌ HTTP Error: '.$response->getStatusCode()."\n";
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
@@ -131,12 +131,12 @@ try {
|
||||
|
||||
/**
|
||||
* Get Single Account Features:
|
||||
*
|
||||
*
|
||||
* - Get account details for specific margin coin
|
||||
* - Rate limit: 10 req/sec/uid
|
||||
* - Returns comprehensive account information
|
||||
* - Supports multiple margin coins
|
||||
*
|
||||
*
|
||||
* Response includes:
|
||||
* - marginCoin: Margin Coin
|
||||
* - available: Available quantity in the account
|
||||
@@ -147,7 +147,7 @@ try {
|
||||
* - crossUnrealizedPNL: Unrealized PnL for cross positions
|
||||
* - isolationUnrealizedPNL: Unrealized PnL for isolation positions
|
||||
* - bonus: Futures Bonus
|
||||
*
|
||||
*
|
||||
* Environment Variables Required:
|
||||
*
|
||||
* BITUNIX_API_KEY=your-api-key
|
||||
|
||||
Reference in new issue
Block a user