Merge remote-tracking branch 'origin/future-private' into future-private

This commit is contained in:
mahdi msr 2025-09-29 00:31:31 +03:30
commit 38114203a1
6 changed files with 76 additions and 81 deletions

View File

@ -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
*/

View File

@ -6,15 +6,15 @@
* 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);
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
});

View File

@ -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);
}
});