obydul/lypto-api

Laravel 比特币交易 API。

v1.1.3 2022-12-26 11:40 UTC

This package is auto-updated.

Last update: 2024-09-26 15:55:21 UTC


README

Laravel 比特币交易 API。

安装

要求

  • 最低 Laravel 版本 7.0

使用以下命令进行安装

composer require obydul/lypto-api

运行以下命令以发布配置文件

php artisan vendor:publish --provider="Obydul\LyptoAPI\LyptoAPIServiceProvider" --tag="config"

(可选) Laravel 5.5 使用包自动发现,因此无需手动添加 ServiceProvider。如果您不使用自动发现,

// add the service provider to your `$providers` array in `config/app.php` file
Obydul\LyptoAPI\LyptoAPIServiceProvider::class

// and add these lines to `$aliases` array
'Binance' => Obydul\LyptoAPI\Facades\Binance::class,
'TAAPI' =>Obydul\LyptoAPI\Facades\TAAPI::class,

清除应用程序配置、缓存(可选)

php artisan optimize

安装完成。

配置

安装后,在 .env 文件中设置 API 密钥和密钥。

// exchange
LYPTO_API_MODE="sandbox" // sanbox or live
LYPTO_API_BINANCE_KEY="your-binane-api-key"
LYPTO_API_BINANCE_SECRET="your-binane-api-secret"

// tools
LYPTO_API_TAAPI_SECRET="your-taapi-secret"

交易所 & 工具

交易所

支持的交易所和功能

我们将很快添加更多交易所和 API。

工具

指标 API 列表

使用方法

创建 Lypto 请求

use Obydul\LyptoAPI\Libraries\LyptoRequest;

$request = new LyptoRequest();
$request->param1 = 'Value 1';
$request->param2 = "Value 2";
$request->param2 = "Value 2";

将 Laypto 请求传递给交易所的功能

// exchange object
$exchange->functionName($request);

// exchange facade
Exchange::functionName($request);

Binance

查看 Binance API 和参数

use Obydul\LyptoAPI\Exchanges\Binance;

// create a Binance object
$binance = new Binance();

// create order
$binance->createOrder($request);

// using facade
use Obydul\LyptoAPI\Facades\Binance;

Binance::createOrder($request);

在不使用 .env 文件的情况下传递 api 密钥、密钥和模式

$api_key = "YOUR_API_KEY";
$api_secret = "YOUR_API_SECRET";
$mode = "sandbox"; // default is live
$this->binance = new Binance($api_key, $api_secret, $mode); // mode doesn't need to pass for live
$this->binance = new Binance($api_key, $api_secret); // live

// using facade
use Obydul\LyptoAPI\Facades\Binance;
$account_info = Binance::config($api_key, $api_secret, $mode)->accountInfo(); // sandbox
$account_info = Binance::config($api_key, $api_secret)->accountInfo(); // live

可用方法

测试服务器

账户 & 钱包

现货交易

TAAPI

TAAPI 提供技术分析(TA)指标数据。

让我们看看使用方法

use Obydul\LyptoAPI\Tools\TAAPI;

$taapi = new TAAPI();
$request = new LyptoRequest();
$indicator_endpoint = "rsi";
$taapi->get($indicator_endpoint, $request);

// call via facade
use Obydul\LyptoAPI\Facades\TAAPI;

TAAPI::get($indicator_endpoint, $request);

在不使用 .env 文件的情况下传递 api 密钥

$api_key = "YOUR_API_KEY";
$response = TAAPI::config($api_key)->get($indicator_endpoint, $request);

示例

Binance
use Obydul\LyptoAPI\Exchanges\Binance;
use Obydul\LyptoAPI\Libraries\LyptoRequest;

private $binance;

/**
 * constructor.
 */
public function __construct()
{
    $this->binance = new Binance();
}

// account info
$account_info = $this->binance->accountInfo();
dd($account_info);

// account info using facade
use Obydul\LyptoAPI\Facades\Binance;

$account_info = Binance::accountInfo();
dd($account_info);

// create order
$request = new LyptoRequest();
$request->symbol = 'BTCUSDT';
$request->side = "SELL";
$request->type = "LIMIT";
$request->timeInForce = "GTC";
$request->quantity = 0.01;
$request->price = 9000;
$request->newClientOrderId = "my_order_id_1112";
$create_order = $this->binance->createOrder($request);
dd($create_order);

// account trade list
$request = new LyptoRequest();
$request->symbol = "BTCUSDT";
$trade_list = $this->binance->accountTradeList($request);
dd($trade_list);
TAAPI
use Obydul\LyptoAPI\Facades\TAAPI;
use Obydul\LyptoAPI\Libraries\LyptoRequest;

// lypto request
$request = new LyptoRequest();
$request->exchange = 'binance';
$request->symbol = "BTC/USDT";
$request->interval = "1h";

// indicator endpoint
$indicator_endpoint = "macd";

// get data
$response = TAAPI::get($indicator_endpoint, $request);

dd($response);

输出

array:3 [▼
  "valueMACD" => 289.32379962478
  "valueMACDSignal" => 257.39665148897
  "valueMACDHist" => 31.92714813581
]

信息

许可证

MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件

其他

如有任何问题,请在 问题 部分创建一个问题。

感谢您安装 LyptoAPI ❤️。