2017 © Pedro Peláez
 

library cryptowatch-http-api

Package for the client implementation of the cryptowatch HTTP API

image

djansen20/cryptowatch-http-api

Package for the client implementation of the cryptowatch HTTP API

  • Sunday, April 8, 2018
  • by Djansen20
  • Repository
  • 1 Watchers
  • 1 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 29 % Grown

The README.md

Cryptowatch HTTP API client

A rough implementation of the Cryptowatch HTTP API, (*1)

Minimum PHP Version, (*2)

Installation

This package can be installed using composer, (*3)

composer require djansen20/cryptowatch-http-api:^1.0

Or add the following directly into your composer.json, (*4)

{
    "require": {
        "djansen20/cryptowatch-http-api": "^1.0"
    }
}

Usage

In order to use this library, include the following namespace into you project, (*5)

use Cryptowatch\CryptowatchHttpApi

All methods will return a response object that can be convertd to json or to a usable array, (*6)

# To get data as array
$array = $response->asArray();

# Get data as json
$json = $response->jsonSerialize();

Rate limiting

Cryptowatch gives each client 8 seconds of CPU time per hour. Currently this client does not read this limit or does anything with it. If you get a response with status code 429 it means the request limit has been reached. The library will probably crap out earlier though., (*7)

Methods

All methods are called statically so there is no need to create an object. Currently there are 5 possible static methods., (*8)

getAssets

An asset can be a crypto or fiat currency, (*9)

Example request, (*10)

$asset = 'neo';
$responseObject = CryptowatchHttpApi::getAssets($asset);
$data = $responseObject->asArray();

Example response, (*11)

array(2) {
  ["result"]=>
  array(5) {
    ["id"]=>
    int(66)
    ["symbol"]=>
    string(3) "neo"
    ["name"]=>
    string(3) "NEO"
    ["fiat"]=>
    bool(false)
    ["markets"]=>
    array(1) {
      ["base"]=>
      array(11) {
        [0]=>
        array(5) {
          ["id"]=>
          int(643)
          ["exchange"]=>
          string(6) "bitmex"
          ["pair"]=>
          string(22) "neobtc-monthly-futures"
          ["active"]=>
          bool(true)
          ["route"]=>
          string(62) "https://api.cryptowat.ch/markets/bitmex/neobtc-monthly-futures"
        }
        [1]=>
        array(5) {
          ["id"]=>
          int(661)
          ["exchange"]=>
          string(6) "bitmex"
          ["pair"]=>
          string(24) "neobtc-quarterly-futures"
          ["active"]=>
          bool(true)
          ["route"]=>
          string(64) "https://api.cryptowat.ch/markets/bitmex/neobtc-quarterly-futures"
        }
        ...
      }
    }
  }
  ["allowance"]=>
  array(2) {
    ["cost"]=>
    int(113410)
    ["remaining"]=>
    int(7947157629)
  }
}

getPairs

A pair of assets. Each pair has a base and a quote. For example, btceur has base btc and quote eur., (*12)

Example Request, (*13)

$pair = 'neotbtc'
$responseObject = CryptowatchHttpApi::getPairs($pair);
$data = $responseObject->asArray();

Example Response, (*14)

array(2) {
  ["result"]=>
  array(6) {
    ["symbol"]=>
    string(6) "neobtc"
    ["id"]=>
    int(86)
    ["base"]=>
    array(5) {
      ["id"]=>
      int(66)
      ["symbol"]=>
      string(3) "neo"
      ["name"]=>
      string(3) "NEO"
      ["fiat"]=>
      bool(false)
      ["route"]=>
      string(35) "https://api.cryptowat.ch/assets/neo"
    }
    ["quote"]=>
    array(5) {
      ["id"]=>
      int(60)
      ["symbol"]=>
      string(3) "btc"
      ["name"]=>
      string(7) "Bitcoin"
      ["fiat"]=>
      bool(false)
      ["route"]=>
      string(35) "https://api.cryptowat.ch/assets/btc"
    }
    ["route"]=>
    string(37) "https://api.cryptowat.ch/pairs/neobtc"
    ["markets"]=>
    array(3) {
      [0]=>
      array(5) {
        ["id"]=>
        int(582)
        ["exchange"]=>
        string(7) "binance"
        ["pair"]=>
        string(6) "neobtc"
        ["active"]=>
        bool(true)
        ["route"]=>
        string(47) "https://api.cryptowat.ch/markets/binance/neobtc"
      }
      [1]=>
      array(5) {
        ["id"]=>
        int(34)
        ["exchange"]=>
        string(8) "bitfinex"
        ["pair"]=>
        string(6) "neobtc"
        ["active"]=>
        bool(true)
        ["route"]=>
        string(48) "https://api.cryptowat.ch/markets/bitfinex/neobtc"
      }
      [2]=>
      array(5) {
        ["id"]=>
        int(383)
        ["exchange"]=>
        string(7) "bittrex"
        ["pair"]=>
        string(6) "neobtc"
        ["active"]=>
        bool(true)
        ["route"]=>
        string(47) "https://api.cryptowat.ch/markets/bittrex/neobtc"
      }
    }
  }
  ["allowance"]=>
  array(2) {
    ["cost"]=>
    int(224791)
    ["remaining"]=>
    int(7946932838)
  }
}

getExchanges

Get information on a specific exchange, (*15)

Example Request, (*16)

$exchange = 'bitstamp';
$responseObject = CryptowatchHttpApi::getExchanges($exchange);
$data = $responseObject->asArray();

Example Response, (*17)

array(2) {
  ["result"]=>
  array(5) {
    ["id"]=>
    int(3)
    ["symbol"]=>
    string(8) "bitstamp"
    ["name"]=>
    string(8) "Bitstamp"
    ["active"]=>
    bool(true)
    ["routes"]=>
    array(1) {
      ["markets"]=>
      string(41) "https://api.cryptowat.ch/markets/bitstamp"
    }
  }
  ["allowance"]=>
  array(2) {
    ["cost"]=>
    int(29870)
    ["remaining"]=>
    int(7946902968)
  }
}

getMarkets

A market is a pair listed on an exchange. For example, pair btceur on exchange kraken is a market., (*18)

There are various subcommands available for each exchange / pair combo. - price // Returns a market’s last price. - summary // Returns a market’s last price as well as other stats based on a 24-hour sliding window. - trades // Returns a market’s most recent trades, incrementing chronologically. - orderbook // Returns a market’s order book. - ohlc // Returns a market’s OHLC candlestick data. Returns data as lists of lists of numbers for each time period integer., (*19)

Example Request, (*20)

$exchange = 'bitstamp';
$pair = 'btcusd';
$subcommand = 'ohlc';

$params = [
    'after' => 1481563244
    'before' => 1481663244
    'periods' => 86400
];

$responseObject = CryptowatchHttpApi::getMarkets($exchange, $pair, $subcommand, $params);
$data = $responseObject->asArray();

Example Response, (*21)

array(2) {
  ["result"]=>
  array(1) {
    [86400]=>
    array(2) {
      [0]=>
      array(7) {
        [0]=>
        int(1481587200)
        [1]=>
        float(768.97)
        [2]=>
        int(779)
        [3]=>
        float(768.96)
        [4]=>
        float(776.9)
        [5]=>
        float(2802.0916)
        [6]=>
        int(0)
      }
      [1]=>
      array(7) {
        [0]=>
        int(1481673600)
        [1]=>
        int(777)
        [2]=>
        float(793.27)
        [3]=>
        float(765.1)
        [4]=>
        float(775.35)
        [5]=>
        float(4918.8164)
        [6]=>
        int(0)
      }
    }
  }
  ["allowance"]=>
  array(2) {
    ["cost"]=>
    int(2032490)
    ["remaining"]=>
    int(7943769676)
  }
}

getAggregate

Markets are identified by a slug, which is the exchange name and currency pair concatenated with a colon., (*22)

There are currently 2 aggregates available - prices // Returns the current price for all supported markets. Some values may be out of date by a few seconds. - summaries // Returns the market summary for all supported markets. Some values may be out of date by a few seconds., (*23)

Example Request, (*24)

$method = 'prices';
$responseObject = CryptowatchHttpApi::getAggregate($method);
$data = $responseObject->asArray();

Example Response, (*25)

array(2) {
  ["result"]=>
  array(726) {
    ["binance:adabtc"]=>
    float(2.165E-5)
    ["binance:adaeth"]=>
    float(0.00033469)
    ["binance:arkbtc"]=>
    float(0.0003211)
    ["binance:batbtc"]=>
    float(2.413E-5)
    ["binance:bateth"]=>
    float(0.00037179)
    ["binance:bccbtc"]=>
    float(0.115777)
    ["binance:bcceth"]=>
    float(1.79409)
    ["binance:bccusdt"]=>
    float(989.7)
  ...
  }
  ["allowance"]=>
  array(2) {
    ["cost"]=>
    int(1039078)
    ["remaining"]=>
    int(7941514860)
  }
}

The Versions

08/04 2018

dev-master

9999999-dev

Package for the client implementation of the cryptowatch HTTP API

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Danny Jansen

api cryptowatch

08/04 2018

v0.6

0.6.0.0

Package for the client implementation of the cryptowatch HTTP API

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Danny Jansen

api cryptowatch

20/03 2018

v0.5

0.5.0.0

Package for the client implementation of the cryptowatch HTTP API

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Danny Jansen

api cryptowatch