Giter Site home page Giter Site logo

gdax-php's Introduction

Unofficial GDAX PHP library.

This library is still very much in alpha state.

Use with caution and keep an eye on your transaction if you trade with real money.

Installation

composer require benfranke/gdax-php

Examples

PublicClient

$client = new \GDAX\Clients\PublicClient();

Returns: GDAX\Clients\PublicClient

Sandbox

Override the baseURL Property of the Client:

$client->setBaseURL(\GDAX\Utilities\GDAXConstants::GDAX_API_SANDBOX_URL);

Get Products

$client->getProducts();

Returns: GDAX\Types\Response\Market\Product[]

Get Product Order Book
$product = (new GDAX\Types\Request\Market\Product())->setProductId(\GDAX\Utilities\GDAXConstants::PRODUCT_ID_BTC_USD)->setLevel(3);
$productOrderBook = $client->getProductOrderBook($product);

Returns: GDAX\Types\Response\Market\ProductOrderBook

Get Product Ticker
$product = (new GDAX\Types\Request\Market\Product())->setProductId(\GDAX\Utilities\GDAXConstants::PRODUCT_ID_BTC_USD);
$productTicker = $client->getProductTicker($product);

Returns: GDAX\Types\Response\Market\ProductTicker

Get Product Trades
$product = (new GDAX\Types\Request\Market\Product())
    ->setProductId(\GDAX\Utilities\GDAXConstants::PRODUCT_ID_BTC_USD)
    ->setStart(new DateTime('2017-01-01'))
    ->setEnd(new DateTime())
    ->setGranularity(1200);

$productTrades = $publicClient->getTrades($product);

Returns: GDAX\Types\Response\Market\Trade[]

Get 24hr Stats
$product = (new GDAX\Types\Request\Market\Product())->setProductId(\GDAX\Utilities\GDAXConstants::PRODUCT_ID_BTC_USD);
$product24HourStats = $publicClient->getProduct24HrStats($product);

Returns: GDAX\Types\Response\Market\Product24HourStats

Get currencies
$products = $publicClient->getCurrencies();

Returns: GDAX\Types\Response\Market\Currency[]

Get the API server time
$time = $publicClient->getTime();

Returns: GDAX\Types\Response\Market\Time

AuthenticatedClient

$client = new \GDAX\Clients\AuthenticatedClient(
    API_KEY
    API_KEY_SECRET
    API_KEY_PASSPHRASE
);

Returns: GDAX\Clients\AuthenticatedClient

List Accounts
$accounts = $client->getAccounts();

Returns: GDAX\Types\Response\Authenticated\Account[]

Get an Account
$account = (new GDAX\Types\Request\Authenticated\Account())->setId('c7f461b7-d91e-499f-...');
$accountData = $client->getAccount($account);

Returns: GDAX\Types\Response\Authenticated\Account

Get Account History
$account = (new GDAX\Types\Request\Authenticated\Account())->setId('c7f461b7-d91e-499f-9f59-...')->toPaginated();
$accountHistory = $client->getAccountHistory($account);

Returns: GDAX\Types\Response\Authenticated\Ledger[]

Get Holds
$account = (new GDAX\Types\Request\Authenticated\Account())->setId('c7f461b7-d91e-499f-9f59-...')->toPaginated();
$accountHolds = $client->getAccountHolds($account);

Returns: GDAX\Types\Response\Authenticated\Hold

Place order
$order = (new GDAX\Types\Request\Authenticated\Order())
    ->setType(\GDAX\Utilities\GDAXConstants::ORDER_TYPE_LIMIT)
    ->setProductId(\GDAX\Utilities\GDAXConstants::PRODUCT_ID_BTC_USD)
    ->setSize(0.01)
    ->setSide(\GDAX\Utilities\GDAXConstants::ORDER_SIDE_BUY)
    ->setPrice(3800)
    ->setPostOnly(true)
    ->setStp(\GDAX\Utilities\GDAXConstants::STP_CO);

$response = $client->placeOrder($order);

Returns: GDAX\Types\Response\Authenticated\Order

Check for $response->getMessage() or $response->getRejectReason() to see if the order has been placed correctly.

Cancel an order
$order = (new GDAX\Types\Request\Authenticated\Order())->setId($id);
$response = $client->cancelOrder($order);

Returns: GDAX\Types\Response\RawData

Check $response->getData() to see if your order id was cancelled.

Cancel all orders
$response = $client->cancelOrders();

Returns: GDAX\Types\Response\RawData

Check $response->getData() for an array of order ids that were cancelled.

List Orders
$listOrders = (new GDAX\Types\Request\Authenticated\ListOrders())
    ->setStatus(\GDAX\Utilities\GDAXConstants::ORDER_STATUS_ALL)
    ->setProductId(\GDAX\Utilities\GDAXConstants::PRODUCT_ID_BTC_USD);
    
$orders = $client->getOrders($listOrders);

Returns: GDAX\Types\Response\Authenticated\Order[]

Get an Order
$order = (new GDAX\Types\Request\Authenticated\Order())->setId($id);
$orderData = $client->getOrder($order);

Returns: GDAX\Types\Response\Authenticated\Order

List Fills
$fill = (new \GDAX\Types\Request\Authenticated\Fill())
    ->setProductId(\GDAX\Utilities\GDAXConstants::PRODUCT_ID_BTC_USD);

$fillData = $client->getFills($fill);

Returns: GDAX\Types\Response\Authenticated\Fill[]

List Fundings
$funding = (new \GDAX\Types\Request\Authenticated\Funding())
    ->setStatus(\GDAX\Utilities\GDAXConstants::FUNDING_STATUS_SETTLED);

$fundingData = $client->getFundings($funding);

Returns: GDAX\Types\Response\Authenticated\Funding[]

Repay Funding
$funding = (new \GDAX\Types\Request\Authenticated\Funding())
    ->setAmount(600)
    ->setCurrency(\GDAX\Utilities\GDAXConstants::CURRENCY_USD);

$repay = $client->repay($funding);

Returns: GDAX\Types\Response\Authenticated\RawData

Margin Transfer
$marginTransfer = (new GDAX\Types\Request\Authenticated\MarginTransfer())
    ->setType(\GDAX\Utilities\GDAXConstants::MARGIN_TRANSFER_TYPE_WITHDRAW)
    ->setCurrency(\GDAX\Utilities\GDAXConstants::CURRENCY_USD)
    ->setMarginProfileId('c1a8236e-19b8-4cec-...')
    ->setAmount(10);

$marginTransferData = $client->marginTransfer($marginTransfer);

Returns: GDAX\Types\Response\Authenticated\MarginTransfer

Get Position
$position = $client->getPosition();

Returns: GDAX\Types\Response\Authenticated\Position


Donations are very welcome

BTC: 1KaFMrUdrwyEdPbMFDzSgy3PfH79nWvFYh
ETH: 0x47c080504a6db77dFD4551EA7589969D39866894

gdax-php's People

Contributors

benfranke avatar

Watchers

 avatar  avatar

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.