From 10e9a84d3611d34988189ddc3efcdca488cd902d Mon Sep 17 00:00:00 2001 From: mahdimsr <32928013+mahdimsr@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:07:30 +0000 Subject: [PATCH] Fix styling --- examples/PlaceOrderExample.php | 19 ++++---- scripts/check-config.php | 46 +++++++++---------- .../ChangeMarginModeRequestContract.php | 7 ++- src/Requests/PlaceOrderRequestContract.php | 38 ++++++++------- tests/ChangeMarginModeTest.php | 16 +++---- tests/PlaceOrderTest.php | 31 ++++++------- 6 files changed, 76 insertions(+), 81 deletions(-) diff --git a/examples/PlaceOrderExample.php b/examples/PlaceOrderExample.php index 12f21a4..14a9843 100644 --- a/examples/PlaceOrderExample.php +++ b/examples/PlaceOrderExample.php @@ -39,9 +39,9 @@ try { $data = json_decode($response->getBody()->getContents(), true); if ($data['code'] === 0) { echo "✅ Market order placed successfully!\n"; - echo "Order ID: " . $data['data']['orderId'] . "\n"; + echo 'Order ID: '.$data['data']['orderId']."\n"; } else { - echo "❌ API Error: " . $data['msg'] . "\n"; + echo '❌ API Error: '.$data['msg']."\n"; } } @@ -74,10 +74,10 @@ try { $data = json_decode($response->getBody()->getContents(), true); if ($data['code'] === 0) { echo "✅ Limit order with TP/SL placed successfully!\n"; - echo "Order ID: " . $data['data']['orderId'] . "\n"; - echo "Client ID: " . $data['data']['clientId'] . "\n"; + echo 'Order ID: '.$data['data']['orderId']."\n"; + echo 'Client ID: '.$data['data']['clientId']."\n"; } else { - echo "❌ API Error: " . $data['msg'] . "\n"; + echo '❌ API Error: '.$data['msg']."\n"; } } @@ -99,9 +99,9 @@ try { $data = json_decode($response->getBody()->getContents(), true); if ($data['code'] === 0) { echo "✅ Close position order placed successfully!\n"; - echo "Order ID: " . $data['data']['orderId'] . "\n"; + echo 'Order ID: '.$data['data']['orderId']."\n"; } else { - echo "❌ API Error: " . $data['msg'] . "\n"; + echo '❌ API Error: '.$data['msg']."\n"; } } @@ -126,9 +126,9 @@ try { $data = json_decode($response->getBody()->getContents(), true); if ($data['code'] === 0) { echo "✅ Reduce only order placed successfully!\n"; - echo "Order ID: " . $data['data']['orderId'] . "\n"; + echo 'Order ID: '.$data['data']['orderId']."\n"; } else { - echo "❌ API Error: " . $data['msg'] . "\n"; + echo '❌ API Error: '.$data['msg']."\n"; } } @@ -165,4 +165,3 @@ try { * BITUNIX_API_SECRET=your-api-secret * BITUNIX_LANGUAGE=en-US */ - diff --git a/scripts/check-config.php b/scripts/check-config.php index deed70a..fe03a15 100644 --- a/scripts/check-config.php +++ b/scripts/check-config.php @@ -2,19 +2,19 @@ /** * Configuration Check Script - * + * * This script helps you verify that your Bitunix API configuration is working correctly. */ -require_once __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__.'/../vendor/autoload.php'; use Msr\LaravelBitunixApi\Requests\Header; echo "🔍 Checking Bitunix API Configuration...\n\n"; // Check if .env file exists -$envFile = __DIR__ . '/../.env'; -if (!file_exists($envFile)) { +$envFile = __DIR__.'/../.env'; +if (! file_exists($envFile)) { echo "❌ .env file not found. Please create one based on .env.example\n"; exit(1); } @@ -24,8 +24,8 @@ if (file_exists($envFile)) { $lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach ($lines as $line) { if (strpos($line, '=') !== false && strpos($line, '#') !== 0) { - list($key, $value) = explode('=', $line, 2); - putenv(trim($key) . '=' . trim($value)); + [$key, $value] = explode('=', $line, 2); + putenv(trim($key).'='.trim($value)); } } } @@ -36,9 +36,9 @@ $apiSecret = getenv('BITUNIX_API_SECRET'); $language = getenv('BITUNIX_LANGUAGE') ?: 'en-US'; echo "📋 Environment Variables:\n"; -echo " BITUNIX_API_KEY: " . (empty($apiKey) ? "❌ Not set" : "✅ Set (" . substr($apiKey, 0, 8) . "...)") . "\n"; -echo " BITUNIX_API_SECRET: " . (empty($apiSecret) ? "❌ Not set" : "✅ Set (" . substr($apiSecret, 0, 8) . "...)") . "\n"; -echo " BITUNIX_LANGUAGE: " . ($language) . "\n\n"; +echo ' BITUNIX_API_KEY: '.(empty($apiKey) ? '❌ Not set' : '✅ Set ('.substr($apiKey, 0, 8).'...)')."\n"; +echo ' BITUNIX_API_SECRET: '.(empty($apiSecret) ? '❌ Not set' : '✅ Set ('.substr($apiSecret, 0, 8).'...)')."\n"; +echo ' BITUNIX_LANGUAGE: '.($language)."\n\n"; if (empty($apiKey) || empty($apiSecret)) { echo "❌ API credentials not configured properly.\n"; @@ -55,27 +55,27 @@ config([ ]); echo "🔧 Configuration Test:\n"; -echo " Base URI: " . config('bitunix-api.future_base_uri') . "\n"; -echo " API Key: " . substr(config('bitunix-api.api_key'), 0, 8) . "...\n"; -echo " API Secret: " . substr(config('bitunix-api.api_secret'), 0, 8) . "...\n"; -echo " Language: " . config('bitunix-api.language') . "\n\n"; +echo ' Base URI: '.config('bitunix-api.future_base_uri')."\n"; +echo ' API Key: '.substr(config('bitunix-api.api_key'), 0, 8)."...\n"; +echo ' API Secret: '.substr(config('bitunix-api.api_secret'), 0, 8)."...\n"; +echo ' Language: '.config('bitunix-api.language')."\n\n"; // Test header generation try { echo "🔐 Testing Header Generation:\n"; $headers = Header::generateHeaders([], '{"test":"value"}'); - - echo " API Key: " . $headers['api-key'] . "\n"; - echo " Sign: " . substr($headers['sign'], 0, 16) . "...\n"; - echo " Nonce: " . $headers['nonce'] . "\n"; - echo " Timestamp: " . $headers['timestamp'] . "\n"; - echo " Language: " . $headers['language'] . "\n"; - echo " Content-Type: " . $headers['Content-Type'] . "\n\n"; - + + echo ' API Key: '.$headers['api-key']."\n"; + echo ' Sign: '.substr($headers['sign'], 0, 16)."...\n"; + echo ' Nonce: '.$headers['nonce']."\n"; + echo ' Timestamp: '.$headers['timestamp']."\n"; + echo ' Language: '.$headers['language']."\n"; + echo ' Content-Type: '.$headers['Content-Type']."\n\n"; + echo "✅ Configuration is working correctly!\n"; echo "You can now use the Bitunix API package in your application.\n"; - + } catch (Exception $e) { - echo "❌ Error generating headers: " . $e->getMessage() . "\n"; + echo '❌ Error generating headers: '.$e->getMessage()."\n"; exit(1); } diff --git a/src/Requests/ChangeMarginModeRequestContract.php b/src/Requests/ChangeMarginModeRequestContract.php index 3f2b6c9..1abaeef 100644 --- a/src/Requests/ChangeMarginModeRequestContract.php +++ b/src/Requests/ChangeMarginModeRequestContract.php @@ -9,10 +9,9 @@ interface ChangeMarginModeRequestContract /** * Change margin mode for a trading pair * - * @param string $symbol Trading pair (e.g., 'BTCUSDT') - * @param string $marginCoin Margin coin (e.g., 'USDT') - * @param string $marginMode Margin mode ('ISOLATION' or 'CROSS') - * @return ResponseInterface + * @param string $symbol Trading pair (e.g., 'BTCUSDT') + * @param string $marginCoin Margin coin (e.g., 'USDT') + * @param string $marginMode Margin mode ('ISOLATION' or 'CROSS') */ public function changeMarginMode(string $symbol, string $marginCoin, string $marginMode): ResponseInterface; } diff --git a/src/Requests/PlaceOrderRequestContract.php b/src/Requests/PlaceOrderRequestContract.php index 6cd136c..47a0488 100644 --- a/src/Requests/PlaceOrderRequestContract.php +++ b/src/Requests/PlaceOrderRequestContract.php @@ -9,25 +9,24 @@ interface PlaceOrderRequestContract /** * Place a new order * - * @param string $symbol Trading pair (e.g., 'BTCUSDT') - * @param string $qty Amount (base coin) - * @param string $side Order direction ('BUY' or 'SELL') - * @param string $tradeSide Direction ('OPEN' or 'CLOSE') - * @param string $orderType Order type ('LIMIT' or 'MARKET') - * @param string|null $price Price of the order (required for LIMIT orders) - * @param string|null $positionId Position ID (required when tradeSide is 'CLOSE') - * @param string|null $effect Order expiration date - * @param string|null $clientId Customize order ID - * @param bool|null $reduceOnly Whether to just reduce the position - * @param string|null $tpPrice Take profit trigger price - * @param string|null $tpStopType Take profit trigger type - * @param string|null $tpOrderType Take profit trigger place order type - * @param string|null $tpOrderPrice Take profit trigger place order price - * @param string|null $slPrice Stop loss trigger price - * @param string|null $slStopType Stop loss trigger type - * @param string|null $slOrderType Stop loss trigger place order type - * @param string|null $slOrderPrice Stop loss trigger place order price - * @return ResponseInterface + * @param string $symbol Trading pair (e.g., 'BTCUSDT') + * @param string $qty Amount (base coin) + * @param string $side Order direction ('BUY' or 'SELL') + * @param string $tradeSide Direction ('OPEN' or 'CLOSE') + * @param string $orderType Order type ('LIMIT' or 'MARKET') + * @param string|null $price Price of the order (required for LIMIT orders) + * @param string|null $positionId Position ID (required when tradeSide is 'CLOSE') + * @param string|null $effect Order expiration date + * @param string|null $clientId Customize order ID + * @param bool|null $reduceOnly Whether to just reduce the position + * @param string|null $tpPrice Take profit trigger price + * @param string|null $tpStopType Take profit trigger type + * @param string|null $tpOrderType Take profit trigger place order type + * @param string|null $tpOrderPrice Take profit trigger place order price + * @param string|null $slPrice Stop loss trigger price + * @param string|null $slStopType Stop loss trigger type + * @param string|null $slOrderType Stop loss trigger place order type + * @param string|null $slOrderPrice Stop loss trigger place order price */ public function placeOrder( string $symbol, @@ -50,4 +49,3 @@ interface PlaceOrderRequestContract ?string $slOrderPrice = null ): ResponseInterface; } - diff --git a/tests/ChangeMarginModeTest.php b/tests/ChangeMarginModeTest.php index 7ffa918..b811057 100644 --- a/tests/ChangeMarginModeTest.php +++ b/tests/ChangeMarginModeTest.php @@ -14,9 +14,9 @@ beforeEach(function () { it('can change margin mode successfully', function () { $api = app(ChangeMarginModeRequestContract::class); - expect(fn() => $api->changeMarginMode('BTCUSDT', 'USDT', 'ISOLATION')) + expect(fn () => $api->changeMarginMode('BTCUSDT', 'USDT', 'ISOLATION')) ->not->toThrow(Exception::class) - ->and(fn() => $api->changeMarginMode('BTCUSDT', 'USDT', 'CROSS')) + ->and(fn () => $api->changeMarginMode('BTCUSDT', 'USDT', 'CROSS')) ->not->toThrow(Exception::class); }); @@ -24,9 +24,9 @@ it('can change margin mode successfully', function () { it('validates required parameters for change margin mode', function () { $api = app(ChangeMarginModeRequestContract::class); - expect(fn() => $api->changeMarginMode('BTCUSDT', 'USDT', 'ISOLATION')) + expect(fn () => $api->changeMarginMode('BTCUSDT', 'USDT', 'ISOLATION')) ->not->toThrow(Exception::class) - ->and(fn() => $api->changeMarginMode('ETHUSDT', 'USDT', 'CROSS')) + ->and(fn () => $api->changeMarginMode('ETHUSDT', 'USDT', 'CROSS')) ->not->toThrow(Exception::class); }); @@ -45,9 +45,9 @@ it('handles different margin modes correctly', function () { it('validates margin mode parameter values', function () { $api = app(ChangeMarginModeRequestContract::class); - expect(fn() => $api->changeMarginMode('BTCUSDT', 'USDT', 'ISOLATION')) + expect(fn () => $api->changeMarginMode('BTCUSDT', 'USDT', 'ISOLATION')) ->not->toThrow(Exception::class) - ->and(fn() => $api->changeMarginMode('BTCUSDT', 'USDT', 'CROSS')) + ->and(fn () => $api->changeMarginMode('BTCUSDT', 'USDT', 'CROSS')) ->not->toThrow(Exception::class); }); @@ -88,9 +88,9 @@ it('validates margin mode constants', function () { it('handles edge cases for margin mode', function () { $api = app(ChangeMarginModeRequestContract::class); - expect(fn() => $api->changeMarginMode('BTCUSDT', 'USDT', 'ISOLATION')) + expect(fn () => $api->changeMarginMode('BTCUSDT', 'USDT', 'ISOLATION')) ->not->toThrow(Exception::class) - ->and(fn() => $api->changeMarginMode('ETHUSDT', 'USDT', 'CROSS')) + ->and(fn () => $api->changeMarginMode('ETHUSDT', 'USDT', 'CROSS')) ->not->toThrow(Exception::class); }); diff --git a/tests/PlaceOrderTest.php b/tests/PlaceOrderTest.php index c429d40..8485bdc 100644 --- a/tests/PlaceOrderTest.php +++ b/tests/PlaceOrderTest.php @@ -14,7 +14,7 @@ beforeEach(function () { it('can place a basic market order', function () { $api = app(PlaceOrderRequestContract::class); - expect(fn() => $api->placeOrder( + expect(fn () => $api->placeOrder( 'BTCUSDT', '0.1', 'BUY', @@ -26,7 +26,7 @@ it('can place a basic market order', function () { it('can place a limit order with price', function () { $api = app(PlaceOrderRequestContract::class); - expect(fn() => $api->placeOrder( + expect(fn () => $api->placeOrder( 'BTCUSDT', '0.1', 'BUY', @@ -39,7 +39,7 @@ it('can place a limit order with price', function () { it('can place an order with all optional parameters', function () { $api = app(PlaceOrderRequestContract::class); - expect(fn() => $api->placeOrder( + expect(fn () => $api->placeOrder( 'BTCUSDT', '0.1', 'BUY', @@ -64,7 +64,7 @@ it('can place an order with all optional parameters', function () { it('can place a close position order', function () { $api = app(PlaceOrderRequestContract::class); - expect(fn() => $api->placeOrder( + expect(fn () => $api->placeOrder( 'BTCUSDT', '0.1', 'SELL', @@ -78,9 +78,9 @@ it('can place a close position order', function () { it('validates required parameters for place order', function () { $api = app(PlaceOrderRequestContract::class); - expect(fn() => $api->placeOrder('BTCUSDT', '0.1', 'BUY', 'OPEN', 'MARKET')) + expect(fn () => $api->placeOrder('BTCUSDT', '0.1', 'BUY', 'OPEN', 'MARKET')) ->not->toThrow(Exception::class) - ->and(fn() => $api->placeOrder('BTCUSDT', '0.1', 'SELL', 'OPEN', 'MARKET')) + ->and(fn () => $api->placeOrder('BTCUSDT', '0.1', 'SELL', 'OPEN', 'MARKET')) ->not->toThrow(Exception::class); }); @@ -90,7 +90,7 @@ it('handles different order types correctly', function () { $orderTypes = ['LIMIT', 'MARKET']; foreach ($orderTypes as $orderType) { - expect(fn() => $api->placeOrder( + expect(fn () => $api->placeOrder( 'BTCUSDT', '0.1', 'BUY', @@ -107,7 +107,7 @@ it('handles different trade sides correctly', function () { $tradeSides = ['OPEN', 'CLOSE']; foreach ($tradeSides as $tradeSide) { - expect(fn() => $api->placeOrder( + expect(fn () => $api->placeOrder( 'BTCUSDT', '0.1', 'BUY', @@ -125,7 +125,7 @@ it('can handle different trading pairs', function () { $tradingPairs = ['BTCUSDT', 'ETHUSDT', 'ADAUSDT']; foreach ($tradingPairs as $symbol) { - expect(fn() => $api->placeOrder($symbol, '0.1', 'BUY', 'OPEN', 'MARKET')) + expect(fn () => $api->placeOrder($symbol, '0.1', 'BUY', 'OPEN', 'MARKET')) ->not->toThrow(Exception::class); } }); @@ -136,7 +136,7 @@ it('validates order side parameter values', function () { $sides = ['BUY', 'SELL']; foreach ($sides as $side) { - expect(fn() => $api->placeOrder('BTCUSDT', '0.1', $side, 'OPEN', 'MARKET')) + expect(fn () => $api->placeOrder('BTCUSDT', '0.1', $side, 'OPEN', 'MARKET')) ->not->toThrow(Exception::class); } }); @@ -147,7 +147,7 @@ it('validates trade side parameter values', function () { $tradeSides = ['OPEN', 'CLOSE']; foreach ($tradeSides as $tradeSide) { - expect(fn() => $api->placeOrder( + expect(fn () => $api->placeOrder( 'BTCUSDT', '0.1', 'BUY', @@ -162,7 +162,7 @@ it('validates trade side parameter values', function () { it('can handle take profit and stop loss parameters', function () { $api = app(PlaceOrderRequestContract::class); - expect(fn() => $api->placeOrder( + expect(fn () => $api->placeOrder( 'BTCUSDT', '0.1', 'BUY', @@ -187,7 +187,7 @@ it('can handle take profit and stop loss parameters', function () { it('can handle reduce only orders', function () { $api = app(PlaceOrderRequestContract::class); - expect(fn() => $api->placeOrder( + expect(fn () => $api->placeOrder( 'BTCUSDT', '0.1', 'SELL', @@ -204,7 +204,7 @@ it('can handle reduce only orders', function () { it('can handle custom client ID', function () { $api = app(PlaceOrderRequestContract::class); - expect(fn() => $api->placeOrder( + expect(fn () => $api->placeOrder( 'BTCUSDT', '0.1', 'BUY', @@ -223,7 +223,7 @@ it('can handle different effect types', function () { $effects = ['IOC', 'FOK', 'GTC', 'POST_ONLY']; foreach ($effects as $effect) { - expect(fn() => $api->placeOrder( + expect(fn () => $api->placeOrder( 'BTCUSDT', '0.1', 'BUY', @@ -235,4 +235,3 @@ it('can handle different effect types', function () { ))->not->toThrow(Exception::class); } }); -