forked from ccxt/ccxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
172 lines (126 loc) · 4.72 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
date_default_timezone_set ('UTC');
include 'ccxt.php';
include 'Console/Table.php';
date_default_timezone_set ('UTC');
function style ($s, $style) { return $style . $s . "\033[0m"; }
function green ($s) { return style ($s, "\033[92m"); }
function blue ($s) { return style ($s, "\033[94m"); }
function yellow ($s) { return style ($s, "\033[93m"); }
function red ($s) { return style ($s, "\033[91m"); }
function pink ($s) { return style ($s, "\033[95m"); }
function bold ($s) { return style ($s, "\033[1m"); }
function underline ($s) { return style ($s, "\033[4m"); }
function dump ($s) { echo implode (' ', func_get_args ()) . "\n"; }
$markets = null;
//-----------------------------------------------------------------------------
foreach (\ccxt\Market::$markets as $id) {
$market = '\\ccxt\\' . $id;
$markets[$id] = new $market (array (
'verbose' => true,
// 'proxy' => 'https://crossorigin.me/',
'proxy' => 'https://cors-anywhere.herokuapp.com/',
// 'proxy' => 'http://cors-proxy.htmldriven.com/?url=',
));
}
$config = json_decode (file_get_contents ('./keys.json'), true);
foreach ($config as $id => $params)
foreach ($params as $key => $value)
$markets[$id]->$key = $value;
$markets['gdax']->urls['api'] = 'https://api-public.sandbox.gdax.com';
$markets['anxpro']->proxy = 'https://cors-anywhere.herokuapp.com/';
function test_market_symbol_ticker ($market, $symbol) {
$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";
}
function test_market_symbol_orderbook ($market, $symbol) {
$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";
}
function test_market_symbol ($market, $symbol) {
$delay = $market->rateLimit * 1000;
usleep ($delay);
test_market_symbol_ticker ($market, $symbol);
usleep ($delay);
if ($market->id == 'coinmarketcap')
dump (var_export ($market->fetchGlobal ()));
else
test_market_symbol_orderbook ($market, $symbol);
}
function load_market ($market) {
$products = $market->load_products ();
$symbols = array_keys ($products);
echo $market->id . ' ' . count ($symbols) . " symbols: " . implode (", ", $symbols) . "\n";
}
function test_market ($market) {
$keys = array_keys ($market->products);
$delay = $market->rateLimit * 1000;
$symbol = $keys[0];
$symbols = array (
'BTC/USD',
'BTC/CNY',
'BTC/ETH',
'ETH/BTC',
'BTC/JPY',
'LTC/BTC',
);
foreach ($symbols as $s) {
if (in_array ($s, $keys)) {
$symbol = $s;
break;
}
}
if (strpos ($symbol, '.d') === false)
test_market_symbol ($market, $symbol);
// usleep ($delay);
// $trades = $market->fetch_trades (array_keys ($products)[0]);
// var_dump ($trades);
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]]) {
$id = $argv[1];
$market = $markets[$id];
load_market ($market);
if (count ($argv) > 2) {
test_market_symbol ($market, $argv[2]);
}
else
test_market ($market);
} else {
echo $argv[1] + " not found.\n";
}
} else {
foreach ($markets as $id => $market) {
try {
load_market ($market);
test_market ($market);
} catch (\ccxt\TimeoutError $e) {
dump (yellow ('[Timeout Error] ' . $e->getMessage () . ' (ignoring)'));
} catch (\ccxt\DDoSProtectionError $e) {
dump (yellow ('[DDoS Protection Error] ' . $e->getMessage () . ' (ignoring)'));
} catch (\ccxt\AuthenticationError $e) {
dump (yellow ('[Authentication Error] ' . $e->getMessage () . ' (ignoring)'));
} catch (\ccxt\MarketNotAvailableError $e) {
dump (yellow ('[Market Not Available Error] ' . $e->getMessage () . ' (ignoring)'));
} catch (Exception $e) {
dump (red ('[Error] ' . $e->getMessage () . ' (ignoring)'));
}
}
}
?>