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
<?php
namespace console\controllers;
use common\service\exchange\ExchangeFactory;
use Yii;
use linslin\yii2\curl\Curl;
use yii\console\Controller;
use voku\helper\HtmlDomParser;
use common\models\psources\CoinSupportedCurrency;
use common\service\exchange\ExchangeBuilderFactory;
class TickerController extends Controller
{
public function actionSort()
{
$class = ['Binance', 'Huobi', 'Zhaobi', 'Bitnasdaq'];
foreach ($class as $val) {
go(function () use ($val) {
\Co::sleep(0.5);
$ticker_builder = ExchangeBuilderFactory::create($val);
$ticker_builder->TickerSort();
});
}
echo date('Y-m-d H:i:s') . '排序更新成功' . PHP_EOL;
return 0;
}
public function actionHot()
{
$ticker_builder = ExchangeBuilderFactory::create('Huobi');
$ticker_builder->hotTickerUpdate();
echo date('Y-m-d H:i:s') . '更新成功' . PHP_EOL;
return 0;
}
public function actionExchange($exchange)
{
$ticker_builder = ExchangeFactory::createExchange($exchange);
$ticker_builder->setQuotation();
echo date('Y-m-d H:i:s') . $exchange. '更新成功' . PHP_EOL;
return 0;
}
public function actionCurrency()
{
$currency_model = CoinSupportedCurrency::find()->groupBy('currency_id')->all();
$curl = new Curl();
foreach ($currency_model as $val) {
if (1111 == $val->currency->pj_id) continue;
go(function () use ($val, $curl) {
\Co::sleep(0.5);
$response = $curl->setPostParams([
'erectDate' => '',
'nothing' => '',
'pjname' => $val->currency->pj_id
])->post('https://srh.bankofchina.com/search/whpj/search_cn.jsp');
$response = iconv('UTF-8', 'GBK//TRANSLIT', $response);
$html = HtmlDomParser::str_get_html($response);
$div = ($html->find('div.BOC_main'));
if ($div->find('td')) {
foreach ($div->find('td') as $key => $e) {
if ($key == 5) {
$key = 'quotation_boc_' . 'CNY_' . $val->currency->symbol;
$currency = rtrim(sprintf('%.6f', 1 / ($e->innertext / 100)), '0');
Yii::$app->redis_currency->hmset($key, 'low', $currency, 'high', $currency, 'last', $currency, 'open', $currency);
}
}
}
});
}
echo date('Y-m-d H:i:s') . '计价货币更新成功' . PHP_EOL;
return 0;
}
}