mrabdelaziz/binance-api
Composer 安装命令:
composer require mrabdelaziz/binance-api
包简介
A comprehensive Laravel package for Binance Spot API integration with account management
README 文档
README
A comprehensive Laravel package for Binance Spot API integration with full account management capabilities.
Features
- Account Management: Get account information, balances, and trading status
- Order Management: Place, cancel, and query orders with full order lifecycle support
- Position Tracking: Real-time position monitoring and historical data
- Market Data: Real-time prices, 24h tickers, and market information
- Security: HMAC-SHA256 signature authentication for all account endpoints
- Rate Limiting: Built-in rate limiting and retry mechanisms
- Error Handling: Comprehensive error handling with detailed logging
- Laravel Integration: Service provider, facades, and configuration
- Testable: Full test suite with mocking capabilities
Installation
You can install the package via composer:
composer require MrAbdelaziz/binance-api
You can publish the config file with:
php artisan vendor:publish --tag="binance-api-config"
Add your Binance API credentials to your .env file:
BINANCE_API_KEY=your_api_key_here BINANCE_API_SECRET=your_api_secret_here BINANCE_BASE_URL=https://api.binance.com BINANCE_TESTNET=false
Quick Start
Account Information
use MrAbdelaziz\BinanceApi\Facades\BinanceApi; // Get account information $account = BinanceApi::account()->getAccountInfo(); // Get account balances $balances = BinanceApi::account()->getAccountBalances(); // Get account trading status $status = BinanceApi::account()->getAccountStatus();
Order Management
// Place a market buy order $order = BinanceApi::orders()->marketBuy('BTCUSDT', 0.001); // Place a limit sell order $order = BinanceApi::orders()->limitSell('BTCUSDT', 0.001, 50000); // Cancel an order $cancelled = BinanceApi::orders()->cancelOrder('BTCUSDT', $orderId); // Get order status $orderStatus = BinanceApi::orders()->getOrder('BTCUSDT', $orderId); // Get all orders for a symbol $orders = BinanceApi::orders()->getAllOrders('BTCUSDT');
Market Data
// Get current price $price = BinanceApi::market()->getPrice('BTCUSDT'); // Get 24hr ticker $ticker = BinanceApi::market()->get24hrTicker('BTCUSDT'); // Get exchange info $exchangeInfo = BinanceApi::market()->getExchangeInfo();
Position Tracking
// Get open positions $positions = BinanceApi::positions()->getOpenPositions(); // Get position for specific symbol $position = BinanceApi::positions()->getPosition('BTCUSDT'); // Get position history $history = BinanceApi::positions()->getPositionHistory('BTCUSDT');
Advanced Usage
Error Handling
use MrAbdelaziz\BinanceApi\Exceptions\BinanceApiException; try { $order = BinanceApi::orders()->marketBuy('BTCUSDT', 0.001); } catch (BinanceApiException $e) { // Handle Binance API errors Log::error('Binance API Error: ' . $e->getMessage()); Log::error('Error Code: ' . $e->getCode()); Log::error('Error Data: ' . json_encode($e->getData())); }
Rate Limiting
The package automatically handles rate limiting. You can configure the rate limits in the config file:
'rate_limits' => [ 'requests_per_minute' => 1200, 'orders_per_second' => 10, 'orders_per_day' => 200000, ],
Custom Configuration
// Using custom configuration $customApi = new BinanceApi([ 'api_key' => 'custom_key', 'api_secret' => 'custom_secret', 'base_url' => 'https://testnet.binance.vision', ]); $account = $customApi->account()->getAccountInfo();
Testing
composer test
Documentation
For detailed documentation visit the following files:
Security
- All account endpoints use HMAC-SHA256 signature authentication
- API keys are never logged or exposed in error messages
- Timestamps are automatically synchronized with Binance servers
- All requests use HTTPS
Contributing
Please see CONTRIBUTING.md for details.
License
The MIT License (MIT). Please see License File for more information.
mrabdelaziz/binance-api 适用场景与选型建议
mrabdelaziz/binance-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「laravel」 「portfolio」 「cryptocurrency」 「trading」 「spot」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mrabdelaziz/binance-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mrabdelaziz/binance-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mrabdelaziz/binance-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Portfolio Package for Laravel Nova CMS
Alfabank REST API integration
Portfolio.
Simple list of references bundled in archives
Manage portfolio projects and clients
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 39
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-22