承接 adman9000/laravel-binance 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

adman9000/laravel-binance

Composer 安装命令:

composer require adman9000/laravel-binance

包简介

Laravel implementation of the Binance crypto exchange trading API

README 文档

README

Laravel implementation of the Binance Spot trading API.

Tests

Requirements

  • PHP 8.1+
  • Laravel 10, 11, or 12

Install

composer require adman9000/laravel-binance

Publish the config file:

php artisan vendor:publish --provider="adman9000\binance\BinanceServiceProvider"

Add your credentials to .env:

BINANCE_KEY=your-api-key
BINANCE_SECRET=your-api-secret

Usage

Via facade

use Binance;

$balances = Binance::getBalances();
$price    = Binance::getTickers('BTCUSDT');

Via dependency injection

use adman9000\binance\BinanceAPI;

class TradingService
{
    public function __construct(private BinanceAPI $binance) {}
}

Direct instantiation

$binance = new BinanceAPI([
    'auth'     => ['key' => 'your-key', 'secret' => 'your-secret'],
    'urls'     => ['api' => 'https://api.binance.com/api/', 'sapi' => 'https://api.binance.com/sapi/'],
    'settings' => ['timing' => 5000, 'timeout' => 30, 'connect_timeout' => 10],
]);

Available Methods

Public (no authentication required)

Method Description
getServerTime() Server timestamp in milliseconds
getTickers(string $symbol = '') All symbol prices, or a single price
getMarkets() Exchange trading rules and symbol info
getOrderBook(string $symbol, int $limit = 100) Bids and asks for a symbol
getPublicTrades(string $symbol, int $limit = 500) Recent trades for a symbol
getAggTrades(string $symbol, int $limit = 500) Compressed/aggregate trade list
getCandlesticks(string $symbol, string $interval = '1h', int $limit = 500) Kline/candlestick data
getAvgPrice(string $symbol) Current average price
getTickerChange(string $symbol = '') 24hr rolling window price change
getBookTicker(string $symbol = '') Best price/qty on the order book

Valid $interval values: 1s, 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M

Private (API key + secret required)

Method Description
getBalances() All account balances
getBalance(string $asset) Balance for a single asset (e.g. 'BTC'), or null if not found
getRecentTrades(string $symbol, int $limit = 500) Your trade history for a symbol
getOpenOrders(string $symbol = '') Current open orders
getAllOrders(string $symbol) All orders for a symbol
marketBuy(string $symbol, string $quantity) Market buy order
marketSell(string $symbol, string $quantity) Market sell order
limitBuy(string $symbol, string $quantity, float $price) Limit buy order
limitSell(string $symbol, string $quantity, float $price) Limit sell order
trade(string $symbol, string $quantity, string $side, string $type, ?float $price) Raw order placement
depositAddress(string $coin) Deposit address for an asset

Configuration

// config/binance.php
return [
    'auth' => [
        'key'    => env('BINANCE_KEY', ''),
        'secret' => env('BINANCE_SECRET', ''),
    ],
    'urls' => [
        'api'  => env('BINANCE_API_URL', 'https://api.binance.com/api/'),
        'sapi' => env('BINANCE_SAPI_URL', 'https://api.binance.com/sapi/'),
    ],
    'settings' => [
        'timing'          => env('BINANCE_TIMING', 5000),         // recvWindow in ms
        'timeout'         => env('BINANCE_TIMEOUT', 30),          // request timeout in seconds
        'connect_timeout' => env('BINANCE_CONNECT_TIMEOUT', 10),  // connection timeout in seconds
    ],
];

Testnet

To use the Binance testnet, add to your .env:

BINANCE_API_URL=https://testnet.binance.vision/api/
BINANCE_SAPI_URL=https://testnet.binance.vision/sapi/

Binance US

BINANCE_API_URL=https://api.binance.us/api/
BINANCE_SAPI_URL=https://api.binance.us/sapi/

Error handling

All API errors throw adman9000\binance\Exceptions\BinanceApiException:

use adman9000\binance\Exceptions\BinanceApiException;

try {
    $order = Binance::limitBuy('BTCUSDT', '0.001', 1.0);
} catch (BinanceApiException $e) {
    // $e->getMessage() — Binance error message
    // $e->getResponse() — full response array including error code
}

Upgrading from v1

  • getTicker($symbol) is deprecated — use getTickers($symbol) instead
  • getCurrencies() has been removed (it returned false)
  • depositAddress($symbol) now takes a coin ticker as $coin (same value, renamed parameter)
  • wapi config URL removed — replaced by sapi (https://api.binance.com/sapi/)
  • ext-curl is no longer required
  • Errors now throw BinanceApiException instead of \Exception

Running tests

composer install
./vendor/bin/phpunit

Licence

MIT

adman9000/laravel-binance 适用场景与选型建议

adman9000/laravel-binance 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 465 次下载、GitHub Stars 达 22, 最近一次更新时间为 2017 年 11 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 adman9000/laravel-binance 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 adman9000/laravel-binance 我们能提供哪些服务?
定制开发 / 二次开发

基于 adman9000/laravel-binance 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 465
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 22
  • 点击次数: 7
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 22
  • Watchers: 4
  • Forks: 23
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-18