Giter Club home page Giter Club logo

gdax's Introduction

Latest Stable Version Total Downloads License

GDAX PHP API Client Library

This is the unofficial client library for the GDAX API. Inspired by Coinbase PHP Library.

Installation

Install the library using Composer. Please read the Composer Documentation if you are unfamiliar with Composer or dependency managers in general.

composer require hellovoid/gdax

Authentication

Use an API key, secret and passphrase to access your own GDAX account.

use Hellovoid\Gdax\Configuration;
use Hellovoid\Gdax\Client;

$configuration = Configuration::apiKey($apiKey, $apiSecret, $apiPassphrase);
$client = Client::create($configuration);

Response

Every successful method request returns decoded json array.

Pagination #ref

Your requests should use these cursor values when making requests for pages after the initial request.

Parameter Description
$before Request page before (newer) this pagination id. (default null)
$after Request page after (older) this pagination id. (default null)
$limit Number of results per request. Maximum 100. (default 100)
use \Hellovoid\Gdax\Pagination;

$pagination = Pagination::create($before, null, $limit);

$client->setPagination($pagination);

$pagination->setEndingBefore(null);
$pagination->setStartingAfter($after);

Accounts #ref

List Accounts

$client->getAccounts();

Account details

$client->getAccount($accountId);

Account history

$client->getAccountHistory($accountId);

Account holds

$client->getAccountHolds($accountId);

Orders #ref

Place new order

$order = $client->placeOrder([
    'size'       => 0.1,
    'price'      => 0.1,
    'side'       => 'buy',
    'product_id' => 'BTC-USD'
]);

Cancel an order

try {
    $response = $client->orderCancel($orderId);
} catch (HttpException $e) { // Order could not be canceled
    $e->getMessage();
}

Cancel all orders

$response = $client->ordersCancel();

Cancel all orders for a specific product:

$response = $client->ordersCancel([
    'product_id' => $productId
]);

List orders

$response = $client->getOrders();

Get order details

$response = $client->getOrder($orderId);

Fills #ref

List fills

$response = $client->getFills([
    'order_id'   => 'all',
    'product_id' => 'all'
]);

Funding #ref

List fundings

Get fundings with status "settled".

$response = $client->getFundings([
    'status' => 'settled', // outstanding, settled, or rejected
]);

Repay

$response = $client->fundingRepay([
    'amount' => 1.00,
    'currency' => 'EUR',
]);

Margin Transfer #ref

$response = $client->marginTransfer([
    'margin_profile_id' => '45fa9e3b-00ba-4631-b907-8a98cbdf21be',
    'type'              => 'deposit',
    'currency'          => 'USD',
    'amount'            => 2,
]);

Position #ref

Get overview of your profile

$response = $client->position();

Close

$response = $client->positionClose([
    'repay_only' => true
]);

Deposits #ref

Payment method

$response = $client->depositPaymentMethod([
    'amount'            => 2.00,
    'currency'          => 'USD',
    'payment_method_id' => 'bc677162-d934-5f1a-968c-a496b1c1270b'
]);

Coinbase

Deposit funds from a coinbase account.

$response = $client->depositCoinbase([
    'amount'              => 2.00,
    'currency'            => 'BTC',
    'coinbase_account_id' => 'c13cd0fc-72ca-55e9-843b-b84ef628c198'
]);

Withdrawals #ref

Payment method

$response = $client->withdrawalPaymentMethod([
    'amount'            => 2.00,
    'currency'          => 'USD',
    'payment_method_id' => 'bc677162-d934-5f1a-968c-a496b1c1270b'
]);

Coinbase

Withdrawal funds to a coinbase account.

$response = $client->withdrawalCoinbase([
    'amount'              => 2.00,
    'currency'            => 'BTC',
    'coinbase_account_id' => 'c13cd0fc-72ca-55e9-843b-b84ef628c198'
]);

Crypto

Withdrawal funds to a crypto address.

$response = $client->withdrawalCoinbase([
    'amount'         => 0.01,
    'currency'       => 'BTC',
    'crypto_address' => '0x5ad5769cd04681FeD900BCE3DDc877B50E83d469'
]);

Payment methods #ref

Get a list of your payment methods.

$response = $client->getPaymentMethods();

Coinbase accounts #ref

Get a list of your coinbase accounts.

$response = $client->getCoinbaseAccounts();

Reports #ref

Create a new report

$response = $client->createReport([
    'type' => 'fills',
    'start_date' => '2014-11-01T00:00:00.000Z',
    'end_date' => '2014-11-30T23:59:59.000Z'
]);

Get report status

$response = $client->getReportStatus($reportId);

Products #ref

Get products

$response = $client->getProducts();

Get Product Order Book

$response = $client->getProductOrderBook($productId);

Get Product Ticker

$response = $client->getProductTicker($productId);

Get Product Trades

$response = $client->getProductTrades($productId);

Get Historic Rates

$response = $client->getProductHistoricRates($productId);

Get 24hr Stats

$response = $client->getProductLast24HrStats($productId);

Currencies #ref

$response = $client->getCurrencies();

Get Time #ref

$response = $client->getTime();

gdax's People

Contributors

hellovoid avatar jmca2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gdax's Issues

exceptions everywhere

The Guzzle dependency is throwing fatal exceptions everytime anything it doesn't like happens, and your script doesn't appear to handle these at all.

For example, if I create an order and use your script to check that order every second until it has filled, then if I go into the GDAX site by hand and cancel the order, the script will crash because Guzzle cries when it's not able to find the order.

Is there a way to make these exceptions less fatal? I mean, something as simple as returning false should be enough. it's not necessary to totally destroy the running instance just because the network is wobbly or because something is not where it was expected to be.

ServerTime: Recommended Feature

I recommend adding this code to the very end of Client.php file:

public function getServerTime() { return $this->getAndDecodeData('time'); }

It returns the current Server Time in both ISO and Unix EPOCH formats. Example use would be if you want to fetch historic data that goes right up to the most recent moment in time. You need the server time to do that.

Working Example

I tried the following code and I am getting blank output. Can you please provide a working code to getAccounts?

require_once DIR . '/composer/autoload_real.php';
return ComposerAutoloaderInitc4aca15140bd590e171ded1912c8b2a0::getLoader();

use Hellovoid\Gdax\Configuration;
use Hellovoid\Gdax\Client;

$apiKey = 'myapikey';
$apiSecret = 'mysecretky';
$apiPassphrase = 'mypassphrase';

$configuration = Configuration::apiKey($apiKey, $apiSecret, $apiPassphrase);
$client = Client::create($configuration);
print_r($client->getAccounts());

Send BTC to LTC

Hi,
I have BTC address and LTC address created with coinbase API, so is it possible for transfer BTC to LTC using API ?
Thanks in advance.

Unsupported operand types

Fatal error: Uncaught Error: Unsupported operand types in /vendor/hellovoid/gdax/src/Client.php:67 Stack trace: #0 /vendor/hellovoid/gdax/src/Client.php(88): Hellovoid\Gdax\Client->getAndDecodeData('accounts') #1 gdax.php(33): Hellovoid\Gdax\Client->getAccounts() #2 /modules/tests/gdax.php(75): gdax_get_balances(2) #3 /web/rr/index.php(123): require_once('...') #4 {main} thrown in /vendor/hellovoid/gdax/src/Client.php on line 67

Unsupported Operand Types - GitHub User Error???

I installed the library using "composer require hellovoid/gdax" as directed. Everything seemed to work fine.

When I attempted to call $client->position(); I got the Unsupported Operands error mentioned on this issue:
https://github.com/hellovoid/gdax/issues/3

So I checked the changed code on the commit regarding the issue and saw the line 66 change from "null" to "[]". I made the change in my own copy of hellovoid/gdax/src/Client.php and it fixed the problem.

My question is: Why did my brand new installed copy of Client.php still have the old code with the line 66 saying "null" instead of the change that was made 16 days ago.

Am I using GitHub incorrectly? I somehow ended up with an older committed version?

Error in \hellovoid\gdax\src\Exception\HttpException.php

Catchable fatal error: Argument 1 passed to Hellovoid\Gdax\Exception\HttpException::exceptionClass() must be an instance of Psr\Http\Message\ResponseInterface, null given, called in C:\inetpub\wwwroot\vendor\hellovoid\gdax\src\Exception\HttpException.php on line 28 and defined in C:\inetpub\wwwroot\vendor\hellovoid\gdax\src\Exception\HttpException.php on line 69

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.