arnezt/binancephpsdk
Composer 安装命令:
composer require arnezt/binancephpsdk
包简介
This repository contains the PHP-SDK to interact with Binance DEX. It's supported by mostly pure PHP code.
README 文档
README
(Fork from hammadtq/binance-php-sdk Porting to composer)
This repository contains the PHP-SDK to interact with Binance DEX. It's supported by mostly pure PHP code. The documentation for Binance DEX supported methods is here.
Installation
At the moment, you will have to clone the repo and include it in your project. In the future, it will be available through composer. (Added: Available via composer):
composer require arnezt/binancephpsdk
The SDK relies on secp256k1-php. There is currently no easy method to install secp256k1-php extension, you will need compile it yourself.
To Install:
(First check (Ubuntu/Debian) if phpize has available: sudo apt install php7.x-dev)
libsecp256k1:
git clone git@github.com:bitcoin-core/secp256k1 && \
cd secp256k1 && \
./autogen.sh && \
./configure --enable-experimental --enable-module-{ecdh,recovery} && \
make && \
sudo make install && \
cd ../
secp256k1-php:
git clone git@github.com:Bit-Wasp/secp256k1-php && \
cd secp256k1-php/secp256k1 && \
phpize && \
./configure --with-secp256k1 && \
make && sudo make install && \
cd ../../
(Optional) - Enable extension by default!
If you're a heavy user, you can add this line to your php.ini files for php-cli, apache2, or php-fpm.
extension=secp256k1.so
(Added: Check php conf (php7.x-fpm if using fpm) change x with your php version):
$ sudo nano /etc/php/7.x/mods-available/secp256k1.ini
add: extension=secp256k1.so
$ sudo ln -s /etc/php/7.x/mods-available/secp256k1.ini /etc/php/7.x/fpm/conf.d/20-secp256k1.ini (for fpm)
$ sudo ln -s /etc/php/7.x/mods-available/secp256k1.ini /etc/php/7.x/cli/conf.d/20-secp256k1.ini (for cli)
The repository was made on Mac OSX using PHP version 7.15.3. You will also need a version above 7. It is advised to go with native PHP installation instead of going with XAMPP or WAMPP so to take advantage of secp256k1-php natively. Also, you may need gmp extension.
To handle big numbers, the SDK makes use of brick/math precision library. Please consider using this or another bcmath or gmp based solutions while dealing with blockchain based numbers.
Examples
Note: Please see Issue Tracker to understand what methods are currently available in the sdk.
You can find full example scripts in the src folder.
Few examples to interact with SDK are below:
Keystore reload and getting private key
$keystoreData = '{paste keystore data here or read from a file}'; $keystore= new Keystore(); $keystore->RestoreKeyStore($keystoreData, "{keystore-password}", "tbnb"); $privateKey = $keystore->getPrivateKey();
Similary, if you want to see the hex of private key, simply use this method:
$keystore->getPrivateKey()->getHex();
A typical transfer request will look something like this:
$bncClient = new BncClient('https://data-seed-pre-2-s1.binance.org'); $bncClient->initChain(); $bncClient->chooseNetwork("testnet"); // or this can be "mainnet" $bncClient->setPrivateKey($privateKey); $response = $bncClient->transfer("tbnb1yqyppmev2m4z96r4svwtjq8eqp653pt6elq33r", "tbnb1hgm0p7khfk85zpz5v0j8wnej3a90w709zzlffd", 0.001, "BNB", "3423423");
Placing an order
$response = $bncClient->NewOrder("BNB_USDT.B-B7C", 1, 0.001, 1, 0, 1); //Symbol, side, price, quantity, sequence, timeinfore
Amino Encoding
The SDK uses Google proto3 generator to support Binance's aminor encoding/decoding. If you ever include new messages to the proto file, run following command to run the generator from the root:
protoc --proto_path=proto --php_out=./gen proto/dex.proto
Key Generation
Key generation is supported via secp256k1-php library as well.
Once you generate an address, make sure to send an amount on it as the Binance DEX will not make an account unless a transaction is received on an address.
$keystore = new Keystore(); $privateKey = Byte::init($keystore->createPrivateKey()); $publicKey = $keystore->createPublicKey($privateKey); $address = $keystore->publicKeyToAddress($publicKey, 'tbnb');
Supported Methods
- Keypair generation
- Keypair generation with mnemonic
- Keystore reload
- Fetching JSON-RPC functions
- Fetch API functions
- Transactions: Transfer, NewOrder, CancelOrder, TokenFreeze, TokenUnFreeze, Issue, Mint, Burn, HTLT, DepositHTLT, ClaimHTLT, RefundHTLT, TimeLock, TimeRelock, TimeUnlock
Many thanks to https://github.com/hammadtq/binance-php-sdk has provided the original source code.
arnezt/binancephpsdk 适用场景与选型建议
arnezt/binancephpsdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 31 次下载、GitHub Stars 达 3, 最近一次更新时间为 2020 年 12 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Binance Chain PHP SDK」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arnezt/binancephpsdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arnezt/binancephpsdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arnezt/binancephpsdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Chain Adapter for Secretary
Binance API Like the official document interface, Support for arbitrary extension.
This package provides a generic processor chain to process a given object with processors/task (kind of a pipline, command chain pattern).
Register a chain of calls that will be applied on an instance later
Deferred batch construction for Laravel job chains
Easily apply middleware support to any class
统计信息
- 总下载量: 31
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-12-27