From 5a6e9cca1df687593386413ce0ffe02825333d97 Mon Sep 17 00:00:00 2001 From: mahdi msr Date: Sun, 23 Nov 2025 15:45:43 +0330 Subject: [PATCH 1/2] dev: add trading pairs request --- src/LaravelBitunixApi.php | 18 ++- .../GetTradingPairsRequestContract.php | 17 +++ tests/GetTradingPairsTest.php | 109 ++++++++++++++++++ 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 src/Requests/GetTradingPairsRequestContract.php create mode 100644 tests/GetTradingPairsTest.php diff --git a/src/LaravelBitunixApi.php b/src/LaravelBitunixApi.php index 8699a75..f3176c2 100644 --- a/src/LaravelBitunixApi.php +++ b/src/LaravelBitunixApi.php @@ -9,13 +9,14 @@ use Msr\LaravelBitunixApi\Requests\FlashClosePositionRequestContract; use Msr\LaravelBitunixApi\Requests\FutureKLineRequestContract; use Msr\LaravelBitunixApi\Requests\GetPendingPositionsRequestContract; use Msr\LaravelBitunixApi\Requests\GetSingleAccountRequestContract; +use Msr\LaravelBitunixApi\Requests\GetTradingPairsRequestContract; use Msr\LaravelBitunixApi\Requests\Header; use Msr\LaravelBitunixApi\Requests\PlaceOrderRequestContract; 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, PlacePositionTpSlOrderRequestContract, PlaceTpSlOrderRequestContract +class LaravelBitunixApi implements ChangeLeverageRequestContract, ChangeMarginModeRequestContract, FlashClosePositionRequestContract, FutureKLineRequestContract, GetPendingPositionsRequestContract, GetSingleAccountRequestContract, GetTradingPairsRequestContract, PlaceOrderRequestContract, PlacePositionTpSlOrderRequestContract, PlaceTpSlOrderRequestContract { private Client $publicFutureClient; @@ -53,6 +54,21 @@ class LaravelBitunixApi implements ChangeLeverageRequestContract, ChangeMarginMo return $response; } + public function getTradingPairs(?string $symbols = null): ResponseInterface + { + $queryParams = []; + + if ($symbols !== null) { + $queryParams['symbols'] = $symbols; + } + + $response = $this->publicFutureClient->get('trading_pairs', [ + 'query' => $queryParams, + ]); + + return $response; + } + public function changeLeverage(string $symbol, string $marginCoin, int $leverage): ResponseInterface { $body = [ diff --git a/src/Requests/GetTradingPairsRequestContract.php b/src/Requests/GetTradingPairsRequestContract.php new file mode 100644 index 0000000..223cd04 --- /dev/null +++ b/src/Requests/GetTradingPairsRequestContract.php @@ -0,0 +1,17 @@ + 'https://fapi.bitunix.com/', + 'bitunix-api.api_key' => 'test-api-key', + 'bitunix-api.api_secret' => 'test-secret-key', + 'bitunix-api.language' => 'en-US', + ]); +}); + +it('check trading pairs request response code', function () { + $bootedClass = app(GetTradingPairsRequestContract::class); + $response = $bootedClass->getTradingPairs(); + expect($response->getStatusCode()) + ->toBe(200) + ->and(json_decode($response->getBody()->getContents(), true)) + ->toHaveKeys(['code', 'data', 'msg']); +}); + +it('can get trading pairs with specific symbols', function () { + $api = app(GetTradingPairsRequestContract::class); + + expect(fn () => $api->getTradingPairs('BTCUSDT,ETHUSDT')) + ->not->toThrow(Exception::class); +}); + +it('can get trading pairs without symbols parameter', function () { + $api = app(GetTradingPairsRequestContract::class); + + expect(fn () => $api->getTradingPairs()) + ->not->toThrow(Exception::class); +}); + +it('validates get trading pairs method exists', function () { + $api = app(GetTradingPairsRequestContract::class); + + expect(method_exists($api, 'getTradingPairs'))->toBeTrue(); +}); + +it('can handle single symbol', function () { + $api = app(GetTradingPairsRequestContract::class); + + expect(fn () => $api->getTradingPairs('BTCUSDT')) + ->not->toThrow(Exception::class); +}); + +it('can handle multiple symbols', function () { + $api = app(GetTradingPairsRequestContract::class); + + $symbols = 'BTCUSDT,ETHUSDT,XRPUSDT'; + expect(fn () => $api->getTradingPairs($symbols)) + ->not->toThrow(Exception::class); +}); + +it('validates trading pairs response structure', function () { + $api = app(GetTradingPairsRequestContract::class); + + $response = $api->getTradingPairs(); + $data = json_decode($response->getBody()->getContents(), true); + + expect($response->getStatusCode())->toBe(200) + ->and($data)->toHaveKeys(['code', 'data', 'msg']); + + if (isset($data['data']) && is_array($data['data']) && count($data['data']) > 0) { + $firstPair = $data['data'][0]; + expect($firstPair)->toHaveKeys([ + 'symbol', + 'base', + 'quote', + 'minTradeVolume', + 'minBuyPriceOffset', + 'maxSellPriceOffset', + 'maxLimitOrderVolume', + 'maxMarketOrderVolume', + 'basePrecision', + 'quotePrecision', + 'maxLeverage', + 'minLeverage', + 'defaultLeverage', + 'defaultMarginMode', + 'priceProtectScope', + 'symbolStatus', + ]); + } +}); + +it('can handle different symbol formats', function () { + $api = app(GetTradingPairsRequestContract::class); + + // Test with uppercase symbols + expect(fn () => $api->getTradingPairs('BTCUSDT')) + ->not->toThrow(Exception::class); + + // Test with lowercase symbols + expect(fn () => $api->getTradingPairs('btcusdt')) + ->not->toThrow(Exception::class); +}); + +it('can handle empty symbols parameter', function () { + $api = app(GetTradingPairsRequestContract::class); + + // Test with null (should return all trading pairs) + expect(fn () => $api->getTradingPairs(null)) + ->not->toThrow(Exception::class); +}); + From 82a0ac77f429afb9ab23db262f6ebd2fe34e8bc7 Mon Sep 17 00:00:00 2001 From: mahdimsr <32928013+mahdimsr@users.noreply.github.com> Date: Sun, 23 Nov 2025 12:16:16 +0000 Subject: [PATCH 2/2] Fix styling --- src/Requests/GetTradingPairsRequestContract.php | 4 +--- tests/GetTradingPairsTest.php | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Requests/GetTradingPairsRequestContract.php b/src/Requests/GetTradingPairsRequestContract.php index 223cd04..c5e7ac5 100644 --- a/src/Requests/GetTradingPairsRequestContract.php +++ b/src/Requests/GetTradingPairsRequestContract.php @@ -9,9 +9,7 @@ interface GetTradingPairsRequestContract /** * Get future trading pair details * - * @param string|null $symbols Trading pairs, comma-separated (e.g., "BTCUSDT,ETHUSDT,XRPUSDT") - * @return ResponseInterface + * @param string|null $symbols Trading pairs, comma-separated (e.g., "BTCUSDT,ETHUSDT,XRPUSDT") */ public function getTradingPairs(?string $symbols = null): ResponseInterface; } - diff --git a/tests/GetTradingPairsTest.php b/tests/GetTradingPairsTest.php index 4f590cc..3333694 100644 --- a/tests/GetTradingPairsTest.php +++ b/tests/GetTradingPairsTest.php @@ -106,4 +106,3 @@ it('can handle empty symbols parameter', function () { expect(fn () => $api->getTradingPairs(null)) ->not->toThrow(Exception::class); }); -