Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f04b685496 | ||
|
|
85b677ee0e | ||
|
|
8ccede169c | ||
|
|
82a0ac77f4 | ||
|
|
5a6e9cca1d | ||
|
|
0a8ef0280f | ||
|
|
8b416c09e0 | ||
|
|
04ecce7bd7 | ||
|
|
578fac70a0 | ||
|
|
cf59fc1e59 | ||
|
|
3846263eb6 | ||
|
|
63a45260c9 | ||
|
|
27550372df | ||
|
|
db7f68ada8 | ||
|
|
6059ef32e0 | ||
|
|
60eb009213 |
No files matched your search
@@ -2,12 +2,9 @@ name: run-tests
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '**.php'
|
||||
- '.github/workflows/run-tests.yml'
|
||||
- 'phpunit.xml.dist'
|
||||
- 'composer.json'
|
||||
- 'composer.lock'
|
||||
branches: [main, dev]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
@@ -15,19 +12,20 @@ concurrency:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
php: [8.4, 8.3]
|
||||
php: [8.4]
|
||||
laravel: [12.*, 11.*]
|
||||
stability: [prefer-stable]
|
||||
include:
|
||||
- laravel: 12.*
|
||||
testbench: 10.*
|
||||
- laravel: 11.*
|
||||
- laravel: 10.*
|
||||
testbench: 9.*
|
||||
|
||||
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ A Laravel package for interacting with the Bitunix cryptocurrency exchange API.
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
composer require msr/laravel-bitunix-api
|
||||
composer require mahdimsr/laravel-bitunix-api
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"minimum-stability": "stable",
|
||||
"prefer-stable": true
|
||||
}
|
||||
@@ -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 = [
|
||||
|
||||
@@ -9,6 +9,7 @@ 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\PlaceOrderRequestContract;
|
||||
use Msr\LaravelBitunixApi\Requests\PlacePositionTpSlOrderRequestContract;
|
||||
use Msr\LaravelBitunixApi\Requests\PlaceTpSlOrderRequestContract;
|
||||
@@ -45,5 +46,6 @@ class LaravelBitunixApiServiceProvider extends PackageServiceProvider
|
||||
$this->app->bind(GetSingleAccountRequestContract::class, LaravelBitunixApi::class);
|
||||
$this->app->bind(PlaceTpSlOrderRequestContract::class, LaravelBitunixApi::class);
|
||||
$this->app->bind(PlacePositionTpSlOrderRequestContract::class, LaravelBitunixApi::class);
|
||||
$this->app->bind(GetTradingPairsRequestContract::class, LaravelBitunixApi::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Msr\LaravelBitunixApi\Requests;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
interface GetTradingPairsRequestContract
|
||||
{
|
||||
/**
|
||||
* Get future trading pair details
|
||||
*
|
||||
* @param string|null $symbols Trading pairs, comma-separated (e.g., "BTCUSDT,ETHUSDT,XRPUSDT")
|
||||
*/
|
||||
public function getTradingPairs(?string $symbols = null): ResponseInterface;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
use Msr\LaravelBitunixApi\Requests\GetTradingPairsRequestContract;
|
||||
|
||||
beforeEach(function () {
|
||||
config([
|
||||
'bitunix-api.future_base_uri' => '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);
|
||||
});
|
||||
Reference in new issue
Block a user