forked from binance-exchange/php-binance-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp-binance-api-test.php
More file actions
505 lines (458 loc) · 18.2 KB
/
Copy pathphp-binance-api-test.php
File metadata and controls
505 lines (458 loc) · 18.2 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
<?php
/* ============================================================
* php-binance-api
* https://github.com/jaggedsoft/php-binance-api
* ============================================================
* Copyright 2017-, Jon Eyrick
* Released under the MIT License
* ============================================================ */
declare(strict_types=1);
require 'php-binance-api.php';
require 'vendor/autoload.php';
file_put_contents( getenv("HOME") . "/.config/jaggedsoft/php-binance-api.json" ,
"{ \"api-key\": \"z5RQZ9n8JcS3HLDQmPpfLQIGGQN6TTs5pCP5CTnn4nYk2ImFcew49v4ZrmP3MGl5\",
\"api-secret\": \"ZqePF1DcLb6Oa0CfcLWH0Tva59y8qBBIqu789JEY27jq0RkOKXpNl9992By1PN9Z\" }");
use PHPUnit\Framework\TestCase;
final class BinanceTest extends TestCase
{
private $_testable = null;
public static function setUpBeforeClass() {
fwrite(STDOUT, __METHOD__ . "\n");
if( file_exists( getenv("HOME") . "/.config/jaggedsoft/php-binance-api.json" ) == false ) {
fwrite(STDERR, __METHOD__ . ": " . getenv("HOME") . "/.config/jaggedsoft/php-binance-api.json not found\n");
exit;
}
}
protected function setUp() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->_testable = new Binance\API();
$this->assertInstanceOf('Binance\API', $this->_testable);
}
public function testInstantiate() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->_testable = new Binance\API();
$this->assertInstanceOf('Binance\API', $this->_testable);
}
public function testAccount() {
fwrite(STDOUT, __METHOD__ . "\n");
$details = $this->_testable->account();
$check_keys = array( 'makerCommission',
'takerCommission',
'buyerCommission',
'sellerCommission',
'canTrade',
'canWithdraw',
'canDeposit',
'updateTime',
'balances' );
foreach ($check_keys as $check_key) {
$this->assertTrue( isset( $details[ $check_key ] ) );
if( isset( $details[ $check_key ] ) == false ) {
fwrite(STDOUT, __METHOD__ . ": exchange info error: $check_key missing\n");
}
}
$this->assertTrue( count( $details[ 'balances' ] ) > 0 );
}
public function testBuy() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->buy( "TRXBTC", "5", "0.001" );
$this->assertTrue( isset( $result['code'] ) );
if( isset( $result['code'] ) ) {
$this->assertTrue( $result['code'] == "-2010" );
}
if( isset( $result['code'] ) == false ) {
fwrite(STDOUT, __METHOD__ . ": shouldn't be any money in the account\n");
}
}
public function testBuyTest() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->buyTest( "TRXBTC", "5", "0.001" );
$this->assertTrue( ( isset( $result['code'] ) == false ) );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testSell() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->sell( "TRXBTC", "5", "0.001" );
$this->assertTrue( isset( $result['code'] ) );
if( isset( $result['code'] ) ) {
$this->assertTrue( $result['code'] == "-2010" );
}
if( isset( $result['code'] ) == false ) {
fwrite(STDOUT, __METHOD__ . ": shouldn't be any code in the account\n");
}
}
public function testSellTest() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->sellTest( "TRXBTC", "5", "0.001" );
$this->assertTrue( ( isset( $result['code'] ) == false ) );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": sell error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testMarketBuy() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->marketBuy( "TRXBTC", "5" );
$this->assertTrue( isset( $result['code'] ) );
if( isset( $result['code'] ) ) {
$this->assertTrue( $result['code'] == "-2010" );
}
if( isset( $result['code'] ) == false ) {
fwrite(STDOUT, __METHOD__ . ": shouldn't be any code in the account\n");
}
}
public function testMarketBuyTest() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->marketBuyTest( "TRXBTC", "5" );
$this->assertTrue( ( isset( $result['code'] ) == false ) );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": market buy error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testMarketSell() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->marketSell( "TRXBTC", "5" );
$this->assertTrue( isset( $result['code'] ) );
if( isset( $result['code'] ) ) {
$this->assertTrue( $result['code'] == "-2010" );
}
if( isset( $result['code'] ) == false ) {
fwrite(STDOUT, __METHOD__ . ": shouldn't be any code in the account\n");
}
}
public function testMarketSellTest() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->marketSellTest( "TRXBTC", "5" );
$this->assertTrue( ( isset( $result['code'] ) == false ) );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": market sell error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testCancel() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->cancel( "TRXBTC", "55555555" );
$this->assertTrue( isset( $result['code'] ) );
if( isset( $result['code'] ) ) {
$this->assertTrue( $result['code'] == "-2011" );
}
if( isset( $result['code'] ) == false ) {
fwrite(STDOUT, __METHOD__ . ": shouldn't be anything to cancel\n");
}
}
public function testOrderStatus() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->orderStatus( "TRXBTC", "55555555" );
$this->assertTrue( isset( $result['code'] ) );
if( isset( $result['code'] ) ) {
$this->assertTrue( $result['code'] == "-2013" );
}
if( isset( $result['code'] ) == false ) {
fwrite(STDOUT, __METHOD__ . ": shouldn't be any order with this id\n");
}
}
public function testOpenOrders() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->openOrders( "TRXBTC" );
$this->assertTrue( ( isset( $result['code'] ) == false ) );
$this->assertTrue( is_array( $result ) );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": open orders error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testOrders() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->orders( "TRXBTC" );
$this->assertTrue( ( isset( $result['code'] ) == false ) );
$this->assertTrue( is_array( $result ) );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": orders error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testHistory() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->history( "TRXBTC" );
$this->assertTrue( ( isset( $result['code'] ) == false ) );
$this->assertTrue( is_array( $result ) );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": my trades error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testUseServerTime() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->_testable->useServerTime();
$this->assertTrue( true );
}
public function testTime() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->time();
$this->assertTrue( ( isset( $result['code'] ) == false ) );
$this->assertTrue( isset( $result[ 'serverTime' ] ) );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": server time error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testExchangeInfo() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->exchangeInfo();
$this->assertTrue( ( isset( $result['code'] ) == false ) );
$check_keys = array( 'timezone', 'serverTime', 'rateLimits', 'exchangeFilters', 'symbols' );
foreach ($check_keys as $check_key) {
$this->assertTrue( isset( $result[ $check_key ] ) );
if( isset( $result[ $check_key ] ) == false ) {
fwrite(STDOUT, __METHOD__ . ": exchange info error: $check_key missing\n");
}
}
$this->assertTrue( count( $result[ 'symbols' ] ) > 0 );
$this->assertTrue( count( $result[ 'rateLimits' ] ) > 0 );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": exchange info error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testWithdraw() {
fwrite(STDOUT, __METHOD__ . "\n");
$asset = "BTC";
$address = "1C5gqLRs96Xq4V2ZZAR1347yUCpHie7sa";
$amount = 0.2;
$result = $this->_testable->withdraw($asset, $address, $amount, false);
$this->assertTrue( true );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": withdraw error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testDepositAddress() {
fwrite(STDOUT, __METHOD__ . "\n");
$asset = "BTC";
$result = $this->_testable->depositAddress($asset);
$this->assertTrue( true );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": depsoit error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testDepositHistory() {
fwrite(STDOUT, __METHOD__ . "\n");
$asset = "BTC";
$result = $this->_testable->depositHistory();
$this->assertTrue( true );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": deposit history error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testWithdrawHistory() {
fwrite(STDOUT, __METHOD__ . "\n");
$asset = "BTC";
$result = $this->_testable->withdrawHistory();
$this->assertTrue( true );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": withdraw history error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testPrices() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->prices();
$this->assertTrue( ( isset( $result['code'] ) == false ) );
$this->assertTrue( count( $result ) > 0 );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": prices error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testBookPrices() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->bookPrices();
$this->assertTrue( ( isset( $result['code'] ) == false ) );
$this->assertTrue( count( $result ) > 0 );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": book prices error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testPrevDay() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->prevDay( "TRXBTC" );
$this->assertTrue( ( isset( $result['code'] ) == false ) );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": previous day error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testAggTrades() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->aggTrades( "TRXBTC" );
$this->assertTrue( ( isset( $result['code'] ) == false ) );
$this->assertTrue( count( $result ) > 0 );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": agg trades error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testDepth() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->depth( "TRXBTC" );
$this->assertTrue( ( isset( $result['code'] ) == false ) );
$this->assertTrue( isset( $result['bids'] ) );
$this->assertTrue( isset( $result['asks'] ) );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": depth error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testBalances() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->balances();
$this->assertTrue( ( isset( $result['code'] ) == false ) );
$this->assertTrue( is_array( $result ) );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": balances error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testGetProxyUriString() {
fwrite(STDOUT, __METHOD__ . "\n");
$proxyConf = [
'proto' => 'http',
'address' => '192.168.1.1',
'port' => '8080',
'user' => 'dude',
'pass' => 'd00d'
];
$this->_testable->setProxy( $proxyConf );
$uri = $this->_testable->getProxyUriString();
$this->assertTrue( $uri == $proxyConf['proto'] . "://" . $proxyConf['address'] . ":" . $proxyConf['port'] );
}
public function testHttpRequest() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testOrder() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testOrderTest() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testCandlesticks() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->candlesticks("BNBBTC", "5m");
$this->assertTrue( is_array( $result ) );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": candlesticks error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testBalanceData() {
fwrite(STDOUT, __METHOD__ . "\n");
$ticker = $this->_testable->prices();
$result = $this->_testable->balances( $ticker );
$this->assertTrue( is_array( $result ) );
if( isset( $result['code'] ) ) {
fwrite(STDOUT, __METHOD__ . ": balances error: " . $result['code'] . ":" . $result['msg'] ."\n");
}
}
public function testBalanceHandler() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testTickerStreamHandler() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testExecutionHandler() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testChartData() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testBookPriceData() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testPriceData() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testCumulative() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->depth( "TRXBTC" );
$this->assertTrue( ( isset( $result['code'] ) == false ) );
$this->assertTrue( isset( $result['bids'] ) );
$this->assertTrue( isset( $result['asks'] ) );
$result = $this->_testable->cumulative( $result );
$this->assertTrue( isset( $result['bids'] ) );
$this->assertTrue( isset( $result['asks'] ) );
$this->assertTrue( is_array( $result['bids'] ) );
$this->assertTrue( is_array( $result['asks'] ) );
$this->assertTrue( count( $result['bids'] ) > 0);
$this->assertTrue( count( $result['asks'] ) > 0);
}
public function testHighstock() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testDepthHandler() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testChartHandler() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testFirst() {
fwrite(STDOUT, __METHOD__ . "\n");
$arr = array( "one" => 6, "two" => 7, "three" => 8 );
$this->assertTrue( $this->_testable->first( $arr ) == "one" );
$arr = array();
$this->assertTrue( $this->_testable->first( $arr ) == null );
}
public function testLast() {
fwrite(STDOUT, __METHOD__ . "\n");
$arr = array( "one" => 6, "two" => 7, "three" => 8 );
$this->assertTrue( $this->_testable->last( $arr ) == "three" );
$arr = array();
$this->assertTrue( $this->_testable->last( $arr ) == null );
}
public function testDisplayDepth() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->depth( "TRXBTC" );
$this->assertTrue( ( isset( $result['code'] ) == false ) );
$this->assertTrue( isset( $result['bids'] ) );
$this->assertTrue( isset( $result['asks'] ) );
$result = $this->_testable->displayDepth( $result );
$this->assertTrue( is_string( $result ) );
$this->assertTrue( $result != "" );
}
public function testSortDepth() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testDepthData() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testDepthCache() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testTicker() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testChart() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testKeepAlive() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testMiniTicker() {
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue( true );
}
public function testGetTransfered() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->getTransfered();
$this->assertTrue( true );
}
public function testGetRequestCount() {
fwrite(STDOUT, __METHOD__ . "\n");
$result = $this->_testable->getRequestCount();
$this->assertTrue( true );
}
}