future-public: add kline request
This commit is contained in:
parent
429c956e37
commit
0503da7349
|
|
@ -3,4 +3,5 @@
|
|||
// config for Msr/LaravelBitunixApi
|
||||
return [
|
||||
|
||||
'future_base_uri' => 'https://fapi.bitunix.com/',
|
||||
];
|
||||
|
|
|
|||
|
|
@ -2,4 +2,34 @@
|
|||
|
||||
namespace Msr\LaravelBitunixApi;
|
||||
|
||||
class LaravelBitunixApi {}
|
||||
use GuzzleHttp\Client;
|
||||
use Msr\LaravelBitunixApi\Requests\FutureKLineRequestContract;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class LaravelBitunixApi implements FutureKLineRequestContract
|
||||
{
|
||||
private Client $publicFutureClient;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->publicFutureClient = new Client([
|
||||
'base_uri' => config('bitunix-api.future_base_uri') . '/api/v1/futures/market/',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getFutureKline(string $symbol, string $interval, int $limit = 100, ?int $startTime = null, ?int $endTime = null, string $type = 'LAST_PRICE'): ResponseInterface
|
||||
{
|
||||
$response = $this->publicFutureClient->get('kline', [
|
||||
'query' => [
|
||||
'symbol' => $symbol,
|
||||
'interval' => $interval,
|
||||
'limit' => $limit,
|
||||
'startTime' => $startTime,
|
||||
'endTime' => $endTime,
|
||||
'type' => $type,
|
||||
]
|
||||
]);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Msr\LaravelBitunixApi;
|
||||
|
||||
use Msr\LaravelBitunixApi\Requests\FutureKLineRequestContract;
|
||||
use Spatie\LaravelPackageTools\Package;
|
||||
use Spatie\LaravelPackageTools\PackageServiceProvider;
|
||||
use Msr\LaravelBitunixApi\Commands\LaravelBitunixApiCommand;
|
||||
|
|
@ -22,4 +23,11 @@ class LaravelBitunixApiServiceProvider extends PackageServiceProvider
|
|||
->hasMigration('create_laravel_bitunix_api_table')
|
||||
->hasCommand(LaravelBitunixApiCommand::class);
|
||||
}
|
||||
|
||||
public function packageRegistered(): void
|
||||
{
|
||||
parent::packageRegistered();
|
||||
|
||||
$this->app->bind(FutureKLineRequestContract::class, LaravelBitunixApi::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Msr\LaravelBitunixApi\Requests;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
interface FutureKLineRequestContract
|
||||
{
|
||||
/**
|
||||
* @param string $symbol
|
||||
* @param string $interval
|
||||
* @param int $limit
|
||||
* @param int|null $startTime
|
||||
* @param int|null $endTime
|
||||
* @param string $type
|
||||
* @return ResponseInterface
|
||||
*
|
||||
* interval could be: 1m 5m 15m 30m 1h 2h 4h 6h 8h 12h 1d 3d 1w 1M
|
||||
* limit: max is 200
|
||||
* startTime : milliseconds format
|
||||
* endTime : milliseconds format
|
||||
* type could be: LAST_PRICE, MARK_PRICE
|
||||
*/
|
||||
public function getFutureKline(string $symbol,
|
||||
string $interval,
|
||||
int $limit = 100,
|
||||
?int $startTime = null,
|
||||
?int $endTime = null,
|
||||
string $type = 'LAST_PRICE'): ResponseInterface;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
use Msr\LaravelBitunixApi\Requests\FutureKLineRequestContract;
|
||||
|
||||
it('check kline request response code', function () {
|
||||
|
||||
$bootedClass = app(FutureKLineRequestContract::class);
|
||||
$response = $bootedClass->getFutureKline('BTCUSDT', '1h', 100, now()->subHours(6)->milliseconds, now()->milliseconds);
|
||||
expect($response->getStatusCode())
|
||||
->toBe(200)
|
||||
->and(json_decode($response->getBody()->getContents()))
|
||||
->toHaveKeys(['code', 'data', 'msg']);
|
||||
});
|
||||
Loading…
Reference in New Issue