mrteye / gdax
GDAX API,Coinbase 提供的服务。(非官方)
v1.2.0
2018-01-18 20:24 UTC
Requires
- php: >=5.4
- curl/curl: >=1.7.1
This package is not auto-updated.
Last update: 2024-09-29 04:49:23 UTC
README
GDAX API,Coinbase 提供的服务。(非官方 API)
快速使用部分
Api 类中的 API 方法从 "getAccounts" 开始。每个方法都有基本使用信息,以及指向互联网上 GDAX API 文档的参考链接。
ApiInterface 类提供了不带注释的方法和参数的更清晰的表示。
许可证
MIT - MIT 许可证文件: LICENSE
安装
将 config.php.example 文件复制到 config.php 并将其放置在您的文档根目录中。添加私人 API 调用的凭据。
公共 API 调用将无需 API 凭据。从 gdax 网站:登录并转到 API 部分。
Composer
composer require mrteye/gdax
使用示例
以下三个示例显示了如何使用 mrteye\GDAX API。从基本到高级使用示例:公开访问、私人访问以及将 API 扩展到您的类。
提供带有 index.php 的工作示例,位于测试文件夹中。
示例 #1 基本使用。公开访问,无需身份验证。
<?php use mrteye\Gdax\Api as Api; use mrteye\Gdax\Auth as Auth; // Get the GDAX API and start making calls. $gdax = new Api('https://api-public.sandbox.gdax.com'); $products = false; try { // Example usage of public calls. $products = $gdax->getProducts(); $productId = 'BTC-USD'; $productOrderBook = $gdax->getProductOrderBook($productId, $param = [ 'level' => 1 ]); $productTrades = $gdax->getProductTrades($productId, $param = [ 'before' => 1, 'limit' => 100 ]); } catch (\Exception $e) { echo $e->getMessage(); echo '<pre>'. print_r($gdax->getError(), true) .'</pre>'; } if ($products) { echo 'Products: <pre>'. print_r($products, true) .'</pre>'; } else { echo 'Something went wrong.'; }
示例 #2 基本使用。私人访问,需要身份验证。
// An example config file is provided. include 'config.php'; use mrteye\Gdax\Api as Api; use mrteye\Gdax\Auth as Auth; // Authenticate per GDAX documentation; the time url is optional. $auth = new Auth( $config->key, $config->secret, $config->pass, $config->time_url ); // Get the API and start making calls. $gdax = new Api($config->api_url, $auth); $accounts = false; try { // Usage examples with some private calls. $accounts = $gdax->getAccounts(); $account = $gdax->getAccount($accounts[0]->id); $order = $gdax->createOrder([ // Common Order Parameters 'type' => 'limit', 'side' => 'buy', 'product_id' => 'BTC-USD', // Limit Order Parameters 'price' => ".01", 'size' => ".01" ]); $orders = $gdax->getOrders($param = [ 'status' => 'open', 'product_id' => '', 'before' => 0, 'after' => 1000, 'limit' => 100 ]); $uuids = $gdax->cancelOrder($orders[0]->id); $uuids = $gdax->cancelAllOrders($param = [ 'product_id' => 'BTC-USD' ]); } catch (\Exception $e) { echo '<pre>gdax-private: '. print_r($gdax->getError(), true). '</pre>'; } if ($accounts) { echo 'Accounts: <pre>'. print_r($accounts, true) .'</pre>'; }
示例 #3 高级使用。扩展 Api 类。
<?php use mrteye\Gdax\Api as Api; use mrteye\Gdax\Auth as Auth; use mrteye\Gdax\AppCurl; class MyBot extends Api { function __construct($private = false, $config) { // Create an authentication object if necessary. $auth = false; if ($private) { // TODO: Reminder; define values for key, secret, pass and gdax_time_api. // These values should be stored in an external file or other source. // - OR - you could simply hard code them here. $auth = new Auth( $config->key, $config->secret, $config->pass, $config->time_url ); } // Load the Gdax API. parent::__construct($config->api_url, $auth); // Set a different timeout for curl. $this->curl = new AppCurl(2000); } // ~ Add custom methods application methods... } // Example usage of the AppGdaxApi class $gdax = new MyBot(true, $config); $accounts = false; // Detail debugging is on by default. //$gdax->setDebug(true); try { // Get all accounts and products. $accounts = $gdax->getAccounts(); $products = $gdax->getProducts(); } catch (\Exception $e) { echo $e->getMessage(); // Get debug info. $errors = $gdax->getError(); } if ($accounts) { echo 'Accounts: <pre>'. print_r($accounts, true) .'</pre>'; }
API 概述
所有 $param 属性都是关联数组,包含 API 参数、分页参数或两者兼有。每个方法的参数在 Api 类文件、ApiInterface 文件以及提供的网址上的互联网上均有文档说明。
获取账户。 https://docs.gdax.com/#list-accounts
public function getAccounts()
获取一个账户。 https://docs.gdax.com/#get-an-account
public function getAccount($accountId)
获取账户活动。 https://docs.gdax.com/#get-account-history
This API is paginated.
public function getAccountHistory($accountId, $param)
获取订单挂起。 https://docs.gdax.com/#get-holds
This API is paginated.
public function getAccountHolds($accountId, $param)
放置新订单。 https://docs.gdax.com/#place-a-new-order
public function createOrder($param)
取消订单。 https://docs.gdax.com/#cancel-an-order
public function cancelOrder($orderId)
取消所有订单。 https://docs.gdax.com/#cancel-all
public function cancelAllOrders($param)
获取开放和未平仓订单。 https://docs.gdax.com/#list-orders
This API is paginated.
public function getOrders($param)
获取 GDAX 订单。 https://docs.gdax.com/#get-an-order
public function getOrder($orderId)
获取填充列表。 https://docs.gdax.com/#list-fills
This API is paginated.
public function getFills($param)
获取资金。 https://docs.gdax.com/#funding
This API is paginated.
public function getFundings($param)
偿还资金记录。 https://docs.gdax.com/#repay
public function repay($param)
在个人资料和保证金个人资料之间转移资金。 https://docs.gdax.com/#margin-transfer
public function marginTransfer($param)
获取您的个人资料概览。 https://docs.gdax.com/#position
public function getPosition()
关闭头寸 TODO:识别此 API。 https://docs.gdax.com/#close
public function closePosition($param)
从支付方式存款。 https://docs.gdax.com/#payment-method
public function deposit($param)
从coinbase账户存款。 https://docs.gdax.com/#coinbase
public function depositCoinbase($param)
将资金提现到支付方式。 https://docs.gdax.com/#payment-method53
public function withdraw($param)
将资金提现到coinbase账户。 https://docs.gdax.com/#coinbase54
public function withdrawCoinbase($param)
将资金提现到加密货币地址。 https://docs.gdax.com/#crypto
public function withdrawCrypto($param)
获取您的支付方式列表。 https://docs.gdax.com/#payment-methods
public function getPaymentMethods()
获取您的coinbase账户列表。 https://docs.gdax.com/#list-accounts59
public function getCoinbaseAccounts()
创建报告。 https://docs.gdax.com/#create-a-new-report
public function createReport($param)
获取报告状态。 https://docs.gdax.com/#get-report-status
public function getReportStatus($reportId)
获取过去30天的交易量。 https://docs.gdax.com/#trailing-volume
public function getTrailingVolume()
获取可用的货币交易对。 https://docs.gdax.com/#get-products
public function getProducts()
获取产品订单簿。 https://docs.gdax.com/#get-product-order-book。
public function getProductOrderBook($productId, $param)
获取产品行情。 https://docs.gdax.com/#get-product-ticker
This API is paginated.
public function getProductTicker($productId)
获取特定产品的交易。 https://docs.gdax.com/#get-trades
This API is paginated.
public function getProductTrades($productId, $param)
获取产品的历史汇率。最多200个数据点。 https://docs.gdax.com/#get-historic-rates
public function getProductHistoricRates($productId, $param)
获取产品的24小时统计数据。 https://docs.gdax.com/#get-24hr-stats
public function getProduct24HrStats($productId)
获取已知货币列表。 https://docs.gdax.com/#get-currencies
public function getCurrencies()
获取GDAX服务器时间。 https://docs.gdax.com/#time
public function getTime()
内容
贡献
欢迎提出建议和代码修改。创建一个拉取/合并请求,并告诉我你的想法。