From 8d1c837092533579351caf169c228c03fc4987f2 Mon Sep 17 00:00:00 2001 From: mahdimsr <32928013+mahdimsr@users.noreply.github.com> Date: Sun, 28 Sep 2025 21:45:15 +0000 Subject: [PATCH] Fix styling --- examples/PlacePositionTpSlOrderExample.php | 32 ++++++++--------- examples/PlaceTpSlOrderExample.php | 20 +++++------ src/LaravelBitunixApi.php | 2 +- tests/PlacePositionTpSlOrderTest.php | 40 +++++++++++----------- tests/PlaceTpSlOrderTest.php | 32 ++++++++--------- 5 files changed, 63 insertions(+), 63 deletions(-) diff --git a/examples/PlacePositionTpSlOrderExample.php b/examples/PlacePositionTpSlOrderExample.php index 78fe45a..6773bd9 100644 --- a/examples/PlacePositionTpSlOrderExample.php +++ b/examples/PlacePositionTpSlOrderExample.php @@ -5,7 +5,7 @@ * * This example demonstrates how to use the LaravelBitunixApi package * to place position TP/SL orders on Bitunix exchange. - * + * * Note: When triggered, it will close the position at market price based on the position quantity at that time. * Each position can only have one Position TP/SL Order. */ @@ -107,7 +107,7 @@ try { foreach ($symbols as $symbol) { echo "Placing position TP/SL order for {$symbol}...\n"; - + $response = $api->placePositionTpSlOrder( $symbol, '111', @@ -116,7 +116,7 @@ try { '45000', 'LAST_PRICE' ); - + if ($response->getStatusCode() === 200) { $data = json_decode($response->getBody()->getContents(), true); if ($data['code'] === 0) { @@ -138,7 +138,7 @@ try { foreach ($positionIds as $positionId) { echo "Placing position TP/SL order for position ID {$positionId}...\n"; - + $response = $api->placePositionTpSlOrder( 'BTCUSDT', $positionId, @@ -147,7 +147,7 @@ try { '45000', 'LAST_PRICE' ); - + if ($response->getStatusCode() === 200) { $data = json_decode($response->getBody()->getContents(), true); if ($data['code'] === 0) { @@ -174,7 +174,7 @@ try { foreach ($stopTypeCombinations as $index => $combination) { echo "Placing position TP/SL order with stop types: {$combination[0]}, {$combination[1]}...\n"; - + $response = $api->placePositionTpSlOrder( 'BTCUSDT', '111', @@ -183,17 +183,17 @@ try { '45000', $combination[1] ); - + if ($response->getStatusCode() === 200) { $data = json_decode($response->getBody()->getContents(), true); if ($data['code'] === 0) { echo "✅ Position TP/SL order with {$combination[0]}/{$combination[1]} placed successfully!\n"; echo 'Order ID: '.$data['data']['orderId']."\n"; } else { - echo "❌ Failed to place position TP/SL order: ".$data['msg']."\n"; + echo '❌ Failed to place position TP/SL order: '.$data['msg']."\n"; } } else { - echo "❌ HTTP Error: ".$response->getStatusCode()."\n"; + echo '❌ HTTP Error: '.$response->getStatusCode()."\n"; } } @@ -202,7 +202,7 @@ try { // Example 7: Error handling echo "7. Error handling example...\n"; $response = $api->placePositionTpSlOrder('INVALID', '111'); - + if ($response->getStatusCode() === 200) { $data = json_decode($response->getBody()->getContents(), true); if ($data['code'] === 0) { @@ -221,31 +221,31 @@ try { /** * Place Position TP/SL Order Features: - * + * * - Place position TP/SL orders for existing positions * - Rate limit: 10 req/sec/UID * - Supports both take profit and stop loss * - When triggered, closes position at market price * - Each position can only have one Position TP/SL Order - * + * * Required Parameters: * - symbol: Trading pair * - positionId: Position ID associated with TP/SL - * + * * Optional Parameters: * - tpPrice: Take-profit trigger price * - tpStopType: Take-profit trigger type (LAST_PRICE/MARK_PRICE) * - slPrice: Stop-loss trigger price * - slStopType: Stop-loss trigger type (LAST_PRICE/MARK_PRICE) - * + * * Note: At least one of tpPrice or slPrice is required. - * + * * Key Differences from regular TP/SL Order: * - Simpler parameters (no order types, prices, quantities) * - Automatically closes position at market price when triggered * - One order per position limit * - Uses position/place_order endpoint - * + * * Environment Variables Required: * * BITUNIX_API_KEY=your-api-key diff --git a/examples/PlaceTpSlOrderExample.php b/examples/PlaceTpSlOrderExample.php index 535d651..e1ca7d7 100644 --- a/examples/PlaceTpSlOrderExample.php +++ b/examples/PlaceTpSlOrderExample.php @@ -124,7 +124,7 @@ try { foreach ($symbols as $symbol) { echo "Placing TP/SL order for {$symbol}...\n"; - + $response = $api->placeTpSlOrder( $symbol, '111', @@ -139,7 +139,7 @@ try { '1', '1' ); - + if ($response->getStatusCode() === 200) { $data = json_decode($response->getBody()->getContents(), true); if ($data['code'] === 0) { @@ -161,7 +161,7 @@ try { foreach ($positionIds as $positionId) { echo "Placing TP/SL order for position ID {$positionId}...\n"; - + $response = $api->placeTpSlOrder( 'BTCUSDT', $positionId, @@ -176,7 +176,7 @@ try { '1', '1' ); - + if ($response->getStatusCode() === 200) { $data = json_decode($response->getBody()->getContents(), true); if ($data['code'] === 0) { @@ -195,7 +195,7 @@ try { // Example 6: Error handling echo "6. Error handling example...\n"; $response = $api->placeTpSlOrder('INVALID', '111'); - + if ($response->getStatusCode() === 200) { $data = json_decode($response->getBody()->getContents(), true); if ($data['code'] === 0) { @@ -214,16 +214,16 @@ try { /** * Place TP/SL Order Features: - * + * * - Place TP/SL orders for existing positions * - Rate limit: 10 req/sec/UID * - Supports both take profit and stop loss * - Flexible parameter configuration - * + * * Required Parameters: * - symbol: Trading pair * - positionId: Position ID associated with TP/SL - * + * * Optional Parameters: * - tpPrice: Take-profit trigger price * - tpStopType: Take-profit trigger type (LAST_PRICE/MARK_PRICE) @@ -235,10 +235,10 @@ try { * - slOrderPrice: Stop-loss order price * - tpQty: Take-profit order quantity (base coin) * - slQty: Stop-loss order quantity (base coin) - * + * * Note: At least one of tpPrice or slPrice is required. * At least one of tpQty or slQty is required. - * + * * Environment Variables Required: * * BITUNIX_API_KEY=your-api-key diff --git a/src/LaravelBitunixApi.php b/src/LaravelBitunixApi.php index f04785d..8699a75 100644 --- a/src/LaravelBitunixApi.php +++ b/src/LaravelBitunixApi.php @@ -15,7 +15,7 @@ use Msr\LaravelBitunixApi\Requests\PlacePositionTpSlOrderRequestContract; use Msr\LaravelBitunixApi\Requests\PlaceTpSlOrderRequestContract; use Psr\Http\Message\ResponseInterface; -class LaravelBitunixApi implements ChangeLeverageRequestContract, ChangeMarginModeRequestContract, FlashClosePositionRequestContract, FutureKLineRequestContract, GetPendingPositionsRequestContract, GetSingleAccountRequestContract, PlaceOrderRequestContract, PlaceTpSlOrderRequestContract, PlacePositionTpSlOrderRequestContract +class LaravelBitunixApi implements ChangeLeverageRequestContract, ChangeMarginModeRequestContract, FlashClosePositionRequestContract, FutureKLineRequestContract, GetPendingPositionsRequestContract, GetSingleAccountRequestContract, PlaceOrderRequestContract, PlacePositionTpSlOrderRequestContract, PlaceTpSlOrderRequestContract { private Client $publicFutureClient; diff --git a/tests/PlacePositionTpSlOrderTest.php b/tests/PlacePositionTpSlOrderTest.php index 8fd3a8d..f9e8e67 100644 --- a/tests/PlacePositionTpSlOrderTest.php +++ b/tests/PlacePositionTpSlOrderTest.php @@ -14,14 +14,14 @@ beforeEach(function () { it('can place position TP/SL order with required parameters only', function () { $api = app(PlacePositionTpSlOrderRequestContract::class); - expect(fn() => $api->placePositionTpSlOrder('BTCUSDT', '111')) + expect(fn () => $api->placePositionTpSlOrder('BTCUSDT', '111')) ->not->toThrow(Exception::class); }); it('can place position TP/SL order with take profit only', function () { $api = app(PlacePositionTpSlOrderRequestContract::class); - expect(fn() => $api->placePositionTpSlOrder( + expect(fn () => $api->placePositionTpSlOrder( 'BTCUSDT', '111', '50000', // tpPrice @@ -32,7 +32,7 @@ it('can place position TP/SL order with take profit only', function () { it('can place position TP/SL order with stop loss only', function () { $api = app(PlacePositionTpSlOrderRequestContract::class); - expect(fn() => $api->placePositionTpSlOrder( + expect(fn () => $api->placePositionTpSlOrder( 'BTCUSDT', '111', null, // tpPrice @@ -45,7 +45,7 @@ it('can place position TP/SL order with stop loss only', function () { it('can place position TP/SL order with both take profit and stop loss', function () { $api = app(PlacePositionTpSlOrderRequestContract::class); - expect(fn() => $api->placePositionTpSlOrder( + expect(fn () => $api->placePositionTpSlOrder( 'BTCUSDT', '111', '50000', // tpPrice @@ -67,7 +67,7 @@ it('can handle different symbol formats', function () { $symbols = ['BTCUSDT', 'ETHUSDT', 'ADAUSDT']; foreach ($symbols as $symbol) { - expect(fn() => $api->placePositionTpSlOrder($symbol, '111')) + expect(fn () => $api->placePositionTpSlOrder($symbol, '111')) ->not->toThrow(Exception::class); } }); @@ -78,7 +78,7 @@ it('can handle different position ID formats', function () { $positionIds = ['111', 'position-123', '19848247723672']; foreach ($positionIds as $positionId) { - expect(fn() => $api->placePositionTpSlOrder('BTCUSDT', $positionId)) + expect(fn () => $api->placePositionTpSlOrder('BTCUSDT', $positionId)) ->not->toThrow(Exception::class); } }); @@ -89,7 +89,7 @@ it('can handle different stop types', function () { $stopTypes = ['LAST_PRICE', 'MARK_PRICE']; foreach ($stopTypes as $stopType) { - expect(fn() => $api->placePositionTpSlOrder( + expect(fn () => $api->placePositionTpSlOrder( 'BTCUSDT', '111', '50000', @@ -106,7 +106,7 @@ it('can handle different price formats', function () { $prices = ['50000', '50000.1', '50000.01', '50000.001']; foreach ($prices as $price) { - expect(fn() => $api->placePositionTpSlOrder( + expect(fn () => $api->placePositionTpSlOrder( 'BTCUSDT', '111', $price, @@ -128,7 +128,7 @@ it('can handle multiple place position TP/SL order calls', function () { ]; foreach ($calls as $params) { - expect(fn() => $api->placePositionTpSlOrder(...$params)) + expect(fn () => $api->placePositionTpSlOrder(...$params)) ->not->toThrow(Exception::class); } }); @@ -138,7 +138,7 @@ it('validates place position TP/SL order response structure', function () { // This test verifies the method can be called without throwing exceptions // The actual response structure will be validated by the API - expect(fn() => $api->placePositionTpSlOrder('BTCUSDT', '111')) + expect(fn () => $api->placePositionTpSlOrder('BTCUSDT', '111')) ->not->toThrow(Exception::class); }); @@ -146,11 +146,11 @@ it('can handle edge cases for position TP/SL order', function () { $api = app(PlacePositionTpSlOrderRequestContract::class); // Test with minimum required parameters - expect(fn() => $api->placePositionTpSlOrder('BTCUSDT', '111')) + expect(fn () => $api->placePositionTpSlOrder('BTCUSDT', '111')) ->not->toThrow(Exception::class); // Test with all parameters - expect(fn() => $api->placePositionTpSlOrder( + expect(fn () => $api->placePositionTpSlOrder( 'BTCUSDT', '111', '50000', @@ -164,11 +164,11 @@ it('can handle special characters in parameters', function () { $api = app(PlacePositionTpSlOrderRequestContract::class); // Test with special characters in position ID - expect(fn() => $api->placePositionTpSlOrder('BTCUSDT', 'pos-123-abc')) + expect(fn () => $api->placePositionTpSlOrder('BTCUSDT', 'pos-123-abc')) ->not->toThrow(Exception::class); // Test with decimal prices - expect(fn() => $api->placePositionTpSlOrder( + expect(fn () => $api->placePositionTpSlOrder( 'BTCUSDT', '111', '50000.123', @@ -182,19 +182,19 @@ it('can handle different combinations of parameters', function () { $api = app(PlacePositionTpSlOrderRequestContract::class); // Test with only TP price - expect(fn() => $api->placePositionTpSlOrder('BTCUSDT', '111', '50000')) + expect(fn () => $api->placePositionTpSlOrder('BTCUSDT', '111', '50000')) ->not->toThrow(Exception::class); // Test with only SL price - expect(fn() => $api->placePositionTpSlOrder('BTCUSDT', '111', null, null, '45000')) + expect(fn () => $api->placePositionTpSlOrder('BTCUSDT', '111', null, null, '45000')) ->not->toThrow(Exception::class); // Test with only TP stop type - expect(fn() => $api->placePositionTpSlOrder('BTCUSDT', '111', '50000', 'MARK_PRICE')) + expect(fn () => $api->placePositionTpSlOrder('BTCUSDT', '111', '50000', 'MARK_PRICE')) ->not->toThrow(Exception::class); // Test with only SL stop type - expect(fn() => $api->placePositionTpSlOrder('BTCUSDT', '111', null, null, '45000', 'MARK_PRICE')) + expect(fn () => $api->placePositionTpSlOrder('BTCUSDT', '111', null, null, '45000', 'MARK_PRICE')) ->not->toThrow(Exception::class); }); @@ -202,7 +202,7 @@ it('can handle position TP/SL order with mixed stop types', function () { $api = app(PlacePositionTpSlOrderRequestContract::class); // Test with different stop types for TP and SL - expect(fn() => $api->placePositionTpSlOrder( + expect(fn () => $api->placePositionTpSlOrder( 'BTCUSDT', '111', '50000', @@ -212,7 +212,7 @@ it('can handle position TP/SL order with mixed stop types', function () { ))->not->toThrow(Exception::class); // Test with opposite stop types - expect(fn() => $api->placePositionTpSlOrder( + expect(fn () => $api->placePositionTpSlOrder( 'BTCUSDT', '111', '50000', diff --git a/tests/PlaceTpSlOrderTest.php b/tests/PlaceTpSlOrderTest.php index 1baabaa..0e49800 100644 --- a/tests/PlaceTpSlOrderTest.php +++ b/tests/PlaceTpSlOrderTest.php @@ -14,14 +14,14 @@ beforeEach(function () { it('can place TP/SL order with required parameters only', function () { $api = app(PlaceTpSlOrderRequestContract::class); - expect(fn() => $api->placeTpSlOrder('BTCUSDT', '111')) + expect(fn () => $api->placeTpSlOrder('BTCUSDT', '111')) ->not->toThrow(Exception::class); }); it('can place TP/SL order with take profit only', function () { $api = app(PlaceTpSlOrderRequestContract::class); - expect(fn() => $api->placeTpSlOrder( + expect(fn () => $api->placeTpSlOrder( 'BTCUSDT', '111', '50000', // tpPrice @@ -40,7 +40,7 @@ it('can place TP/SL order with take profit only', function () { it('can place TP/SL order with stop loss only', function () { $api = app(PlaceTpSlOrderRequestContract::class); - expect(fn() => $api->placeTpSlOrder( + expect(fn () => $api->placeTpSlOrder( 'BTCUSDT', '111', null, // tpPrice @@ -59,7 +59,7 @@ it('can place TP/SL order with stop loss only', function () { it('can place TP/SL order with both take profit and stop loss', function () { $api = app(PlaceTpSlOrderRequestContract::class); - expect(fn() => $api->placeTpSlOrder( + expect(fn () => $api->placeTpSlOrder( 'BTCUSDT', '111', '50000', // tpPrice @@ -87,7 +87,7 @@ it('can handle different symbol formats', function () { $symbols = ['BTCUSDT', 'ETHUSDT', 'ADAUSDT']; foreach ($symbols as $symbol) { - expect(fn() => $api->placeTpSlOrder($symbol, '111')) + expect(fn () => $api->placeTpSlOrder($symbol, '111')) ->not->toThrow(Exception::class); } }); @@ -98,7 +98,7 @@ it('can handle different position ID formats', function () { $positionIds = ['111', 'position-123', '19848247723672']; foreach ($positionIds as $positionId) { - expect(fn() => $api->placeTpSlOrder('BTCUSDT', $positionId)) + expect(fn () => $api->placeTpSlOrder('BTCUSDT', $positionId)) ->not->toThrow(Exception::class); } }); @@ -109,7 +109,7 @@ it('can handle different stop types', function () { $stopTypes = ['LAST_PRICE', 'MARK_PRICE']; foreach ($stopTypes as $stopType) { - expect(fn() => $api->placeTpSlOrder( + expect(fn () => $api->placeTpSlOrder( 'BTCUSDT', '111', '50000', @@ -126,7 +126,7 @@ it('can handle different order types', function () { $orderTypes = ['LIMIT', 'MARKET']; foreach ($orderTypes as $orderType) { - expect(fn() => $api->placeTpSlOrder( + expect(fn () => $api->placeTpSlOrder( 'BTCUSDT', '111', '50000', @@ -147,7 +147,7 @@ it('can handle different quantity formats', function () { $quantities = ['1', '0.1', '10.5', '100']; foreach ($quantities as $qty) { - expect(fn() => $api->placeTpSlOrder( + expect(fn () => $api->placeTpSlOrder( 'BTCUSDT', '111', '50000', @@ -170,7 +170,7 @@ it('can handle different price formats', function () { $prices = ['50000', '50000.1', '50000.01', '50000.001']; foreach ($prices as $price) { - expect(fn() => $api->placeTpSlOrder( + expect(fn () => $api->placeTpSlOrder( 'BTCUSDT', '111', $price, @@ -196,7 +196,7 @@ it('can handle multiple place TP/SL order calls', function () { ]; foreach ($calls as $params) { - expect(fn() => $api->placeTpSlOrder(...$params)) + expect(fn () => $api->placeTpSlOrder(...$params)) ->not->toThrow(Exception::class); } }); @@ -206,7 +206,7 @@ it('validates place TP/SL order response structure', function () { // This test verifies the method can be called without throwing exceptions // The actual response structure will be validated by the API - expect(fn() => $api->placeTpSlOrder('BTCUSDT', '111')) + expect(fn () => $api->placeTpSlOrder('BTCUSDT', '111')) ->not->toThrow(Exception::class); }); @@ -214,11 +214,11 @@ it('can handle edge cases for TP/SL order', function () { $api = app(PlaceTpSlOrderRequestContract::class); // Test with minimum required parameters - expect(fn() => $api->placeTpSlOrder('BTCUSDT', '111')) + expect(fn () => $api->placeTpSlOrder('BTCUSDT', '111')) ->not->toThrow(Exception::class); // Test with all parameters - expect(fn() => $api->placeTpSlOrder( + expect(fn () => $api->placeTpSlOrder( 'BTCUSDT', '111', '50000', @@ -238,11 +238,11 @@ it('can handle special characters in parameters', function () { $api = app(PlaceTpSlOrderRequestContract::class); // Test with special characters in position ID - expect(fn() => $api->placeTpSlOrder('BTCUSDT', 'pos-123-abc')) + expect(fn () => $api->placeTpSlOrder('BTCUSDT', 'pos-123-abc')) ->not->toThrow(Exception::class); // Test with decimal prices - expect(fn() => $api->placeTpSlOrder( + expect(fn () => $api->placeTpSlOrder( 'BTCUSDT', '111', '50000.123',