Compare commits

..
Author SHA1 Message Date
dependabot[bot] 26a28e3d19 build(deps): bump ramsey/composer-install from 3 to 4
Bumps [ramsey/composer-install](https://github.com/ramsey/composer-install) from 3 to 4.
- [Release notes](https://github.com/ramsey/composer-install/releases)
- [Commits](https://github.com/ramsey/composer-install/compare/v3...v4)

---
updated-dependencies:
- dependency-name: ramsey/composer-install
  dependency-version: '4'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-16 21:22:34 +00:00
6 changed files with 7 additions and 89 deletions

No files matched your search

+1 -1
View File
@@ -22,7 +22,7 @@ jobs:
coverage: none
- name: Install composer dependencies
uses: ramsey/composer-install@v3
uses: ramsey/composer-install@v4
- name: Run PHPStan
run: ./vendor/bin/phpstan --error-format=github
+3 -8
View File
@@ -1,5 +1,5 @@
{
"name": "moltox/laravel-bitunix-api",
"name": "mahdimsr/laravel-bitunix-api",
"description": "composer package for using bitunix api trading",
"keywords": [
"msr",
@@ -13,17 +13,12 @@
"name": "mahdi mansouri",
"email": "mahdi.msr4@gmail.com",
"role": "Developer"
},
{
"name": "Maik Mueller ",
"email": "mueller.maik1@gmail.com",
"role": "Developer"
}
],
"require": {
"php": "^8.4",
"spatie/laravel-package-tools": "^1.16",
"illuminate/contracts": "^10.0||^11.0||^12.0||^13.0"
"illuminate/contracts": "^11.0||^12.0||^10.0"
},
"require-dev": {
"laravel/pint": "^1.14",
@@ -74,7 +69,7 @@
}
}
},
"version": "1.2.2",
"version": "1.1.0",
"minimum-stability": "stable",
"prefer-stable": true
}
-13
View File
@@ -1,13 +0,0 @@
<?php
namespace Msr\LaravelBitunixApi\Contracts;
interface RateLimiterContract
{
public function throttle(
string $bucket,
string $identity,
int $maxRequests,
float $perSeconds
): void;
}
+3 -1
View File
@@ -305,8 +305,10 @@ class LaravelBitunixApi implements ChangeLeverageRequestContract, ChangeMarginMo
$body['slStopType'] = $slStopType;
}
return $this->getPrivateFutureClient([], $body)->post('tpsl/position/place_order', [
$response = $this->getPrivateFutureClient([], $body)->post('tpsl/position/place_order', [
'json' => $body,
]);
return $response;
}
}
-9
View File
@@ -3,7 +3,6 @@
namespace Msr\LaravelBitunixApi;
use Msr\LaravelBitunixApi\Commands\LaravelBitunixApiCommand;
use Msr\LaravelBitunixApi\Contracts\RateLimiterContract;
use Msr\LaravelBitunixApi\Requests\ChangeLeverageRequestContract;
use Msr\LaravelBitunixApi\Requests\ChangeMarginModeRequestContract;
use Msr\LaravelBitunixApi\Requests\FlashClosePositionRequestContract;
@@ -14,10 +13,8 @@ use Msr\LaravelBitunixApi\Requests\GetTradingPairsRequestContract;
use Msr\LaravelBitunixApi\Requests\PlaceOrderRequestContract;
use Msr\LaravelBitunixApi\Requests\PlacePositionTpSlOrderRequestContract;
use Msr\LaravelBitunixApi\Requests\PlaceTpSlOrderRequestContract;
use Msr\LaravelBitunixApi\Support\CacheRateLimiter;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Illuminate\Contracts\Cache\Factory as CacheFactory;
class LaravelBitunixApiServiceProvider extends PackageServiceProvider
{
@@ -50,11 +47,5 @@ class LaravelBitunixApiServiceProvider extends PackageServiceProvider
$this->app->bind(PlaceTpSlOrderRequestContract::class, LaravelBitunixApi::class);
$this->app->bind(PlacePositionTpSlOrderRequestContract::class, LaravelBitunixApi::class);
$this->app->bind(GetTradingPairsRequestContract::class, LaravelBitunixApi::class);
$this->app->bind(RateLimiterContract::class, function ($app) {
return new CacheRateLimiter(
$app->make(CacheFactory::class)->store()
);
});
}
}
-57
View File
@@ -1,57 +0,0 @@
<?php
namespace Msr\LaravelBitunixApi\Support;
use Illuminate\Contracts\Cache\Repository;
use Msr\LaravelBitunixApi\Contracts\RateLimiterContract;
class CacheRateLimiter implements RateLimiterContract
{
public function __construct(
protected Repository $cache,
) {
}
public function throttle(
string $bucket,
string $identity,
int $maxRequests,
float $perSeconds
): void {
if ($maxRequests <= 0 || $perSeconds <= 0) {
return;
}
$cacheKey = $this->makeCacheKey($bucket, $identity);
$minIntervalMicroseconds = (int) (($perSeconds / $maxRequests) * 1_000_000);
$lastRequestAt = $this->cache->get($cacheKey);
if (is_numeric($lastRequestAt)) {
$elapsedMicroseconds = (int) ((microtime(true) - (float) $lastRequestAt) * 1_000_000);
if ($elapsedMicroseconds < $minIntervalMicroseconds) {
$sleepMicroseconds = $minIntervalMicroseconds - $elapsedMicroseconds;
if ($sleepMicroseconds > 0) {
usleep($sleepMicroseconds);
}
}
}
$this->cache->put(
$cacheKey,
microtime(true),
now()->addSeconds((int) max(1, ceil($perSeconds * 2)))
);
}
protected function makeCacheKey(string $bucket, string $identity): string
{
return sprintf(
'laravel_bitunix_api:rate_limit:%s:%s',
$bucket,
sha1($identity)
);
}
}