PHP code example of djansen20 / cryptowatch-http-api
1. Go to this page and download the library: Download djansen20/cryptowatch-http-api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
djansen20 / cryptowatch-http-api example snippets
composer
use Cryptowatch\CryptowatchHttpApi
# To get data as array
$array = $response->asArray();
# Get data as json
$json = $response->jsonSerialize();
$asset = 'neo';
$responseObject = CryptowatchHttpApi::getAssets($asset);
$data = $responseObject->asArray();
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)
}
}
$pair = 'neotbtc'
$responseObject = CryptowatchHttpApi::getPairs($pair);
$data = $responseObject->asArray();
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)
}
}
$exchange = 'bitstamp';
$responseObject = CryptowatchHttpApi::getExchanges($exchange);
$data = $responseObject->asArray();
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)
}
}
$exchange = 'bitstamp';
$pair = 'btcusd';
$subcommand = 'ohlc';
$params = [
'after' => 1481563244
'before' => 1481663244
'periods' => 86400
];
$responseObject = CryptowatchHttpApi::getMarkets($exchange, $pair, $subcommand, $params);
$data = $responseObject->asArray();
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)
}
}
$method = 'prices';
$responseObject = CryptowatchHttpApi::getAggregate($method);
$data = $responseObject->asArray();
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)
}
}