forked from ccxt/ccxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
120 lines (79 loc) · 2.86 KB
/
test.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
date_default_timezone_set ('UTC');
include 'ccxt.php';
$markets = null;
$verbose = false;
if (file_exists ('config.php'))
include 'config.php';
else
$markets = array ();
//-----------------------------------------------------------------------------
foreach (\ccxt\Market::$markets as $id) {
$market = '\\ccxt\\' . $id;
$markets[$id] = new $market (array ('verbose' => $verbose));
}
function test_market ($market) {
$delay = 3 * 1000000;
echo "-----------------------------------------------------------------\n";
// echo $market->id . "\n";
$products = $market->load_products ();
// echo $market->id . " products:\n";
// var_dump ($products);
$symbols = array_keys ($products);
echo $market->id . ' ' . count ($symbols) . " symbols: " . implode (", ", $symbols) . "\n";
foreach ($symbols as $symbol) {
if (strpos ($symbol, '.d') === false) {
usleep ($delay);
$ticker = $market->fetch_ticker ($symbol);
echo implode (' ', array ($market->id, $symbol, 'ticker',
$ticker['datetime'],
'high: ' . $ticker['high'],
'low: ' . $ticker['low'],
'bid: ' . $ticker['bid'],
'ask: ' . $ticker['ask'],
'volume: ' . $ticker['quoteVolume'])) . "\n";
usleep ($delay);
$orderbook = $market->fetch_order_book ($symbol);
echo implode (' ', array ($market->id, $symbol, 'order book',
$orderbook['datetime'],
'bid: ' . @$orderbook['bids'][0][0],
'bidVolume: ' . @$orderbook['bids'][0][1],
'ask: ' . @$orderbook['asks'][0][0],
'askVolume: ' . @$orderbook['asks'][0][1])) . "\n";
}
}
// usleep ($delay);
// $orderbook = $market->fetch_order_book (array_keys ($products)[0]);
// var_dump ($orderbook);
// usleep ($delay);
// $trades = $market->fetch_trades (array_keys ($products)[0]);
// var_dump ($trades);
// usleep ($delay);
// $ticker = $market->fetch_ticker (array_keys ($products)[0]);
// $ticker = $market->fetch_ticker ('BTC/USD');
// var_dump ($ticker);
// usleep ($delay);
if ((!$market->apiKey) or (strlen ($market->apiKey) < 1))
return;
usleep ($delay);
$balance = $market->fetch_balance ();
var_dump ($balance);
}
if (count ($argv) > 1) {
if ($markets[$argv[1]]) {
$market = $markets[$argv[1]];
test_market ($market);
} else {
echo $argv[1] + " not found.\n";
}
} else {
foreach ($markets as $id => $market) {
try {
test_market ($market);
} catch (Exception $e) {
var_dump ($e->getMessage ());
break;
}
}
}
?>