-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
/
coinbasepro-sandbox-fetch-ticker.php
62 lines (42 loc) · 1.32 KB
/
coinbasepro-sandbox-fetch-ticker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
$root = dirname(dirname(dirname(__FILE__)));
include $root . '/ccxt.php';
date_default_timezone_set('UTC');
echo "CCXT v." . \ccxt\Exchange::VERSION . "\n";
$exchange = new \ccxt\coinbasepro();
$exchange->set_sandbox_mode(true);
// preload the markets first
try {
$exchange->load_markets();
} catch (\ccxt\BaseError $e) {
echo 'Failed to load markets: ' . $e->getMessage() . "\n";
} catch (Exception $e) {
echo '[Error] ' . $e->getMessage() . "\n";
}
$symbol = 'ETH/BTC';
$market = null;
// check if the market in question is available
try {
$market = $exchange->market($symbol);
} catch (\ccxt\BaseError $e) {
echo $exchange->id . ' does not have market symbol ' . $symbol . "!\n";
echo 'Markets symbols supported by ' . $exchange->id . ":\n";
echo print_r($exchange->symbols, true) . "\n";
exit();
}
if($market['active']) {
try {
$result = $exchange->fetch_ticker($symbol);
var_dump($result);
} catch (\ccxt\NetworkError $e) {
echo '[Network Error] ' . $e->getMessage() . "\n";
} catch (\ccxt\ExchangeError $e) {
echo '[Exchange Error] ' . $e->getMessage() . "\n";
} catch (Exception $e) {
echo '[Error] ' . $e->getMessage() . "\n";
}
} else {
echo $exchange->id . ' market ' . $symbol . " is inactive!\n";
exit();
}
?>