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
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.
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 Gdax('https://api-public.sandbox.gdax.com');
// Example usage of public calls.
$products = $gdax->getProducts();
$productOrderBook = $gdax->getProductOrderBook('BTC-USD', $param);
'level' => 1
]);
$productTrades = $gdax->getProductTrades($productId, $param = [
'before' => 1,
'limit' => 100
]);
Example #2 Basic. Private access, authentication is required.
use mrteye\Gdax\Api as Api;
use mrteye\Gdax\Auth as Auth;
// Create authentication credentials on the GDAX site for Private API calls.
$key = 'web';
$secret = 'web';
$pass = 'web';
// Create a GDAX object; the GDAX time API is optional.
$gdax_time_api = 'https://api-public.sandbox.gdax.com/time';
$auth = new Auth($key, $secret, $pass, $gdax_time_api);
// Get the GDAX API and start making calls.
$api_url = 'https://api-public.sandbox.gdax.com"';
$gdax = new Gdax($api_url, $auth);
// 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'
]);
Example #3 Advanced. Extend the Api class.
<?php
use mrteye\Gdax\Api as Api;
use mrteye\Gdax\Auth as Auth;
class AppGdaxApi extends Api {
function __construct($private = false) {
// 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($key, $secret, $pass, $gdax_time_api);
}
// Load the Gdax API.
parent::__construct($api_url, $auth);
}
function setDebug($bool) {
$this->_setDebug($bool);
}
function getError() {
return (empty($this->_error) ? []: $this->_error);
}
}
// Example usage of the AppGdaxApi class
$gdax = new AppGdaxApi(true);
// Turn on detailed error logging.
$gdax->setDebug(true);
// Get all accounts and products.
$accounts = $gdax->getAccounts();
$products = $gdax->getProducts();
// Get any errors if they exists.
$errors = $gdax->getError();
API Summary
All $param properties are associate 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.
https://docs.gdax.com/#list-accounts
Get accounts.public function getAccounts()
https://docs.gdax.com/#get-an-account
Get an account.public function getAccount($accountId)
https://docs.gdax.com/#get-account-history
Get account activity.This API is paginated.
public function getAccountHistory($accountId, $param)
https://docs.gdax.com/#get-holds
Get order holds.This API is paginated.
public function getAccountHolds($accountId, $param)
https://docs.gdax.com/#place-a-new-order
Place a new order.public function createOrder($param)
https://docs.gdax.com/#cancel-an-order
Cancel an order.public function cancelOrder($orderId)
https://docs.gdax.com/#cancel-all
Cancel all orders.public function cancelAllOrders($param)
https://docs.gdax.com/#list-orders
Get open and unsettled orders.This API is paginated.
public function getOrders($param)
https://docs.gdax.com/#get-an-order
Get a GDAX order.public function getOrder($orderId)
https://docs.gdax.com/#list-fills
Get a list of fills.This API is paginated.
public function getFills($param)
https://docs.gdax.com/#funding
Get fundings.This API is paginated.
public function getFundings($param)
https://docs.gdax.com/#repay
Repay a funding record.public function repay($param)
https://docs.gdax.com/#margin-transfer
Transfer funds between a profile and a margin profile.public function marginTransfer($param)
https://docs.gdax.com/#position
Get an overview of your profile.public function getPosition()
https://docs.gdax.com/#close
Close Position TODO: Identify this API.public function closePosition($param)
https://docs.gdax.com/#payment-method
Deposit funds from a payment method.public function deposit($param)
https://docs.gdax.com/#coinbase
Deposit funds from a coinbase account.public function depositCoinbase($param)
https://docs.gdax.com/#payment-method53
Widthdraw funds to a payment method.public function withdraw($param)
https://docs.gdax.com/#coinbase54
Withdraw funds to a coinbase account.public function withdrawCoinbase($param)
https://docs.gdax.com/#crypto
Withdraw funds to a crypto address.public function withdrawCrypto($param)
https://docs.gdax.com/#payment-methods
Get a list of your payment methods.public function getPaymentMethods()
https://docs.gdax.com/#list-accounts59
Get a list of your coinbase accounts.public function getCoinbaseAccounts()
https://docs.gdax.com/#create-a-new-report
Create a report.public function createReport($param)
https://docs.gdax.com/#get-report-status
Get report status.public function getReportStatus($reportId)
https://docs.gdax.com/#trailing-volume
Get 30 day trailing volume.public function getTrailingVolume()
https://docs.gdax.com/#get-products
Get available currency trading pairs.public function getProducts()
https://docs.gdax.com/#get-product-order-book.
Get product order book.public function getProductOrderBook($productId, $param)
https://docs.gdax.com/#get-product-ticker
Get product ticker.This API is paginated.
public function getProductTicker($productId)
https://docs.gdax.com/#get-trades
Get the trades for a specific product.This API is paginated.
public function getProductTrades($productId, $param)
https://docs.gdax.com/#get-historic-rates
Get historic rates for a product. Max 200 data points.public function getProductHistoricRates($productId, $param)
https://docs.gdax.com/#get-24hr-stats
Get 24 hour statistics for a prdoduct.public function getProduct24HrStats($productId)
https://docs.gdax.com/#get-currencies
Get list of known currencies.public function getCurrencies()
https://docs.gdax.com/#time
Get GDAX server 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.