forked from ccxt/ccxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoinbasepro-sandbox-fetch-ticker-async.php
72 lines (50 loc) · 1.76 KB
/
coinbasepro-sandbox-fetch-ticker-async.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
63
64
65
66
67
68
69
70
71
72
<?php
$root = dirname (dirname (dirname (__FILE__)));
include $root . '/ccxt.php';
date_default_timezone_set ('UTC');
$loop = \React\EventLoop\Factory::create();
$kernel = \Recoil\React\ReactKernel::create($loop);
echo "CCXT v." . \ccxt\Exchange::VERSION . "\n";
$kernel->execute(function() use ($loop, $kernel) {
$exchange = new \ccxt_async\coinbasepro (array(
'loop' => $loop,
'kernel' => $kernel,
'enableRateLimit' => true,
));
$exchange->urls['api'] = $exchange->urls['test'];
// preload the markets first
try {
yield $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 = yield $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 ();
}
}, $loop);
$kernel->run();