buttercoin/buttercoin-sdk

用于连接Buttercoin API的PHP库

0.0.6 2014-10-08 17:22 UTC

This package is not auto-updated.

Last update: 2024-09-24 05:46:05 UTC


README

通过我们的API轻松集成Buttercoin交易平台。

使用Composer安装

$ php composer.phar require buttercoin/buttercoin-sdk:~0.0.6

用法

有关Composer文档,请参阅getcomposer.org

此客户端使用Guzzle构建,Guzzle是一个PHP HTTP客户端和用于构建RESTful Web服务客户端的框架。

当您首次创建一个新的ButtercoinClient实例时,您可以传递publicKeyprivateKeyenvironment作为配置设置。这些是可选的,以后也可以通过setter方法指定。

对于需要身份验证的API资源,需要publicKeysecretKey,也可以在配置数组中将它们传递给工厂方法。默认的environment配置设置为'production'

有关不同API端点的必需和可用参数的列表,请参阅Buttercoin API参考文档

配置客户端

工厂方法接受一个配置设置数组,用于Buttercoin Web服务客户端。

示例
require 'vendor/autoload.php';
use Buttercoin\Client\ButtercoinClient;
date_default_timezone_set('UTC'); // for $timestamp

$client = ButtercoinClient::factory([
	'publicKey' => '<public_key>',
	'secretKey' => '<secret_key>',
	'environment' => 'sandbox' // leave this blank for production
]);

配置可以更新以重用相同的客户端

您可以通过可用的getter和setter重新配置Buttercoin客户端配置选项。您可以获取和设置以下选项:publicKeysecretKeyenvironmentversion

示例
$client->getSecretKey();
$client->setSecretKey('<new_secret_key>');

技巧

关于发送到所有客户端方法的timestamp参数的说明:此参数必须始终递增,并且在Buttercoin服务器时间(GMT)的5分钟内。这是为了防止对您的数据进行重放攻击。

在每次调用之前,获取一个新的时间戳。(您只需要设置一次时区)

date_default_timezone_set('UTC'); // Do this only once
$timestamp = round(microtime(true) * 1000);
$client->getKey($timestamp);

此外,为了方便,如果您没有包含时间戳参数,它将默认为当前时间戳。

$client->getKey();

警告

对于查询和Post参数,来自Guzzle库的限制是您必须按照在下面的表中显示的顺序将参数添加到数组中。如果不这样做,HMAC-SHA256签名将不正确,您将收到401请求错误。

获取数据

未认证

获取订单簿
返回Buttercoin订单簿中当前订单的数组

$client->getOrderBook();

获取交易历史
返回最后100笔交易的数组

$client->getTradeHistory();

获取行情
返回Buttercoin平台上当前的买入价、卖出价和最后卖出价

$client->getTicker();
已认证

密钥权限
返回与该密钥关联的权限数组

$client->getKey($timestamp);

余额
返回该账户的余额数组

$client->getBalances($timestamp);

存款地址
返回存款到Buttercoin平台的比特币地址字符串

$client->getDepositAddress($timestamp);

获取订单
返回包含关于买卖订单信息的数组数组

有效的参数包括(必须按此顺序添加到数组中)

// query for multiple orders
$orderParams = [ "status" => "canceled", "side" => "sell" ];

$client->getOrders($orderParams, $timestamp);

// single order by id
$orderId = '<order_id>';

$client->getOrderById($orderId, $timestamp);

// single order by url
$url = 'https://api.buttercoin.com/v1/orders/{order_id}';

$client->getOrderByUrl($url, $timestamp);

获取交易
返回包含关于存款和提款操作的数组数组

有效的参数包括(必须按此顺序添加到数组中)

// query for multiple transactions
$trxnParams = [ "status" => "funded", "transactionType" => "deposit" ];

$client->getTransactions($trxnParams, $timestamp);

$trxnId = '53a22ce164f23e7301a4fee5';

$client->getTransactionById($trxnId, $timestamp);

// single transaction by url
$url = 'https://api.buttercoin.com/v1/transactions/{transaction_id}';

$client->getTransactionByUrl($url, $timestamp);

创建新操作

创建订单

有效的订单参数包括

// create an array with the following params
$order = [
  "instrument" => "BTC_USD",
  "side" => "buy",
  "orderType" => "limit",
  "price" => "700.00"
  "quantity" => "5"
];

$client->createOrder($order, $timestamp);

创建交易

在通过API创建USD存款之前,请联系Buttercoin支持。

存款交易参数包括

// create deposit
$trxnObj = [
  "method" => "wire",
  "currency" => "USD",
  "amount" => "5002"
];

$client->createDeposit($trxnObj, $timestamp);

取款交易参数包括

// create withdrawal
$trxnObj = [
  "method" => "check",
  "currency" => "USD",
  "amount" => "900.23"
];

$client->createWithdrawal($trxnObj, $timestamp);

发送比特币交易参数包括

// send bitcoins to an address
$trxnObj = [
  "currency" => "BTC",
  "amount" => "100.231231",
  "destination" => "<bitcoin_address>"
];

$client->sendCrypto($trxnObj, $timestamp);

取消操作

所有成功的取消调用API返回状态码204,并带有可读的成功信息

取消订单
取消一个待处理的买入或卖出订单

$client->cancelOrder($orderId, $timestamp);

取消交易
取消一个待处理的存款或取款操作

$client->cancelTransaction($trxnId, $timestamp);

进一步阅读

Buttercoin - 网站
Buttercoin API 文档

贡献

这是一个开源项目,我们欢迎社区参与!请向我们发送pull请求和问题。

目标是采纳您的优秀想法,让每个人使用Buttercoin的体验更加出色。贡献越多越好!

版本历史

0.0.6

  • 添加了交易历史端点

0.0.5

  • 将测试环境改为沙盒

0.0.3

  • 将取款端点从/withdrawal更改为/withdraw

0.0.2

  • 将时间戳字段设为可选,默认为当前时间戳
  • 修复了README文件中的错误

0.0.1

  • 第一个版本。

许可证

许可协议为MIT许可。