定制 mrteye/gdax 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

mrteye/gdax

Composer 安装命令:

composer require mrteye/gdax

包简介

API for GDAX A service provided by coinbase. (Unofficial)

README 文档

README

API for GDAX, A service provided by coinbase. (An Unofficial API)

Quick Use Sections:

The API methods in the Api class start at "getAccounts". Each method has basic usage information along with a reference link to the GDAX Api documentaiton on the internet.

The ApiInterface class has a cleaner represenation of methods and parameters without comments.

License

MIT - MIT License File: LICENSE

Installation

Copy the config.php.example file to config.php and place it in your document root. Add credentials for private API calls.

Public API calls will work without API credentials. Get credentials from the gdax site: Login and goto the Api section.

Composer
composer require mrteye/gdax

Usage Examples

The following three examples show how to use the mrteye\GDAX api. From basic to Advanced usage examples: public acces, private access, and extending the API into your own class.

Working examples are provided with index.php, located in the test folder.

Example #1 Basic. Public access, no authentication required.

<?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.';
}

Example #2 Basic. Private access, authentication is required.

// 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>';
}

Example #3 Advanced. Extend the Api class.

<?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 Summary

All $param properties are associative arrays with either API parameters or pagination parameters or both. The parameters for each method are documented in the Api class file, the ApiInterface file, and on the internet at the provided url.

Get accounts. https://docs.gdax.com/#list-accounts
public function getAccounts()
Get an account. https://docs.gdax.com/#get-an-account
public function getAccount($accountId)
Get account activity. https://docs.gdax.com/#get-account-history
This API is paginated.
public function getAccountHistory($accountId, $param)
Get order holds. https://docs.gdax.com/#get-holds
This API is paginated.
public function getAccountHolds($accountId, $param)
Place a new order. https://docs.gdax.com/#place-a-new-order
public function createOrder($param)
Cancel an order. https://docs.gdax.com/#cancel-an-order
public function cancelOrder($orderId)
Cancel all orders. https://docs.gdax.com/#cancel-all
public function cancelAllOrders($param)
Get open and unsettled orders. https://docs.gdax.com/#list-orders
This API is paginated.
public function getOrders($param)
Get a GDAX order. https://docs.gdax.com/#get-an-order
public function getOrder($orderId)
Get a list of fills. https://docs.gdax.com/#list-fills
This API is paginated.
public function getFills($param)
Get fundings. https://docs.gdax.com/#funding
This API is paginated.
public function getFundings($param)
Repay a funding record. https://docs.gdax.com/#repay
public function repay($param)
Transfer funds between a profile and a margin profile. https://docs.gdax.com/#margin-transfer
public function marginTransfer($param)
Get an overview of your profile. https://docs.gdax.com/#position
public function getPosition()
Close Position TODO: Identify this API. https://docs.gdax.com/#close
public function closePosition($param)
Deposit funds from a payment method. https://docs.gdax.com/#payment-method
public function deposit($param)
Deposit funds from a coinbase account. https://docs.gdax.com/#coinbase
public function depositCoinbase($param)
Widthdraw funds to a payment method. https://docs.gdax.com/#payment-method53
public function withdraw($param)
Withdraw funds to a coinbase account. https://docs.gdax.com/#coinbase54
public function withdrawCoinbase($param)
Withdraw funds to a crypto address. https://docs.gdax.com/#crypto
public function withdrawCrypto($param)
Get a list of your payment methods. https://docs.gdax.com/#payment-methods
public function getPaymentMethods()
Get a list of your coinbase accounts. https://docs.gdax.com/#list-accounts59
public function getCoinbaseAccounts()
Create a report. https://docs.gdax.com/#create-a-new-report
public function createReport($param)
Get report status. https://docs.gdax.com/#get-report-status
public function getReportStatus($reportId)
Get 30 day trailing volume. https://docs.gdax.com/#trailing-volume
public function getTrailingVolume()
Get available currency trading pairs. https://docs.gdax.com/#get-products
public function getProducts()
Get product order book. https://docs.gdax.com/#get-product-order-book.
public function getProductOrderBook($productId, $param)
Get product ticker. https://docs.gdax.com/#get-product-ticker
This API is paginated.
public function getProductTicker($productId)
Get the trades for a specific product. https://docs.gdax.com/#get-trades
This API is paginated.
public function getProductTrades($productId, $param)
Get historic rates for a product. Max 200 data points. https://docs.gdax.com/#get-historic-rates
public function getProductHistoricRates($productId, $param)
Get 24 hour statistics for a prdoduct. https://docs.gdax.com/#get-24hr-stats
public function getProduct24HrStats($productId)
Get list of known currencies. https://docs.gdax.com/#get-currencies
public function getCurrencies()
Get GDAX server time. https://docs.gdax.com/#time
public function getTime()

Contents

Resource Description

Contributions

Suggestions and code modifications are welcome. Create a pull/merge request, and tell me what you are thinking.

mrteye/gdax 适用场景与选型建议

mrteye/gdax 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.3k 次下载、GitHub Stars 达 19, 最近一次更新时间为 2017 年 08 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 mrteye/gdax 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 5.3k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 20
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 19
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-10