回答編集履歴
4
見直し
test
CHANGED
@@ -70,17 +70,17 @@
|
|
70
70
|
|
71
71
|
|
72
72
|
|
73
|
-
function market_filter($result) {
|
73
|
+
function market_filter($result, $key, $target) {
|
74
74
|
|
75
|
-
if (
|
75
|
+
if (array_search($result['MarketName'], $target) !== false) {
|
76
76
|
|
77
|
-
|
77
|
+
// こういうことをしたいのかな?
|
78
78
|
|
79
|
-
|
79
|
+
echo $result['MarketName'] . "\n";
|
80
80
|
|
81
|
-
el
|
81
|
+
echo 'Bid -> ' . $result['Bid'] . "\n";
|
82
82
|
|
83
|
-
re
|
83
|
+
echo 'Ask -> ' . $result['Ask'] . "\n";
|
84
84
|
|
85
85
|
}
|
86
86
|
|
@@ -90,10 +90,16 @@
|
|
90
90
|
|
91
91
|
if ($bittrex_data['success']) {
|
92
92
|
|
93
|
-
|
93
|
+
array_walk($bittrex_data['result'], 'market_filter', ['USDT-BTC', 'USDT-ETH', 'USDT-BCC']);
|
94
94
|
|
95
|
-
|
95
|
+
|
96
96
|
|
97
97
|
}
|
98
98
|
|
99
99
|
```
|
100
|
+
|
101
|
+
array_filter()でコールバック関数を使うと引数を与えられないので、
|
102
|
+
|
103
|
+
むしろarray_walk()でコールバック関数のための引数を与えられるようにすることで、
|
104
|
+
|
105
|
+
コールバック関数を無駄に増やすことなく実行可能になるのかな、と。
|
3
見直し
test
CHANGED
@@ -45,3 +45,55 @@
|
|
45
45
|
}
|
46
46
|
|
47
47
|
```
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
---
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
foreach()使わず、特定のMarketNameだけ使う場合:
|
56
|
+
|
57
|
+
```php
|
58
|
+
|
59
|
+
<?php
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
$bittrex_url="https://bittrex.com/api/v1.1/public/getmarketsummaries";
|
64
|
+
|
65
|
+
$bittrex_response = file_get_contents($bittrex_url, false);
|
66
|
+
|
67
|
+
$bittrex_data = json_decode($bittrex_response, true);
|
68
|
+
|
69
|
+
//var_dump($bittrex_data['result']);
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
function market_filter($result) {
|
74
|
+
|
75
|
+
if ( ($result['MarketName'] === 'USDT-BTC') || ($result['MarketName'] === 'USDT-ETH') || ($result['MarketName'] === 'USDT-BCC') ) {
|
76
|
+
|
77
|
+
return true;
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
else {
|
82
|
+
|
83
|
+
return false;
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
if ($bittrex_data['success']) {
|
92
|
+
|
93
|
+
$target_market_result = array_filter($bittrex_data['result'], 'market_filter');
|
94
|
+
|
95
|
+
var_dump($target_market_result);
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
```
|
2
加筆修正
test
CHANGED
@@ -5,6 +5,10 @@
|
|
5
5
|
`foreach ($bittrex_data['result'] as $arr) {`
|
6
6
|
|
7
7
|
|
8
|
+
|
9
|
+
手元のテストコード、晒します。
|
10
|
+
|
11
|
+
(実行するたびに先方のサーバーからデータを取ってしまうと迷惑がかかるので、ローカルに保存したファイルでテストしましたけども。)
|
8
12
|
|
9
13
|
```php
|
10
14
|
|
@@ -32,7 +36,7 @@
|
|
32
36
|
|
33
37
|
if ($result['MarketName'] == $coin) {
|
34
38
|
|
35
|
-
var_dump($result);
|
39
|
+
var_dump($result); // お好きなことをどうぞ
|
36
40
|
|
37
41
|
}
|
38
42
|
|
1
加筆修正
test
CHANGED
@@ -3,3 +3,41 @@
|
|
3
3
|
じゃなく
|
4
4
|
|
5
5
|
`foreach ($bittrex_data['result'] as $arr) {`
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
```php
|
10
|
+
|
11
|
+
<?php
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
$bittrex_url="https://bittrex.com/api/v1.1/public/getmarketsummaries";
|
16
|
+
|
17
|
+
$bittrex_response = file_get_contents($bittrex_url, false);
|
18
|
+
|
19
|
+
//$bittrex_response = file_get_contents('getmarketsummaries.json', false);
|
20
|
+
|
21
|
+
$bittrex_data = json_decode($bittrex_response, true);
|
22
|
+
|
23
|
+
//var_dump($bittrex_data['result']);
|
24
|
+
|
25
|
+
$coin = 'USDT-BTC';
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
if ($bittrex_data['success']) {
|
30
|
+
|
31
|
+
foreach ($bittrex_data['result'] as $result) {
|
32
|
+
|
33
|
+
if ($result['MarketName'] == $coin) {
|
34
|
+
|
35
|
+
var_dump($result);
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
```
|