feat: 后端全量更新 - 含所有本次需求
- Contract.php: 返回合约账户余额(balance_contract) - My.php: 地址管理增加BTC/ETH - AppContract.php: 一键平仓(closeall) - AppProxy.php: 代理专属注册链接 + 分级权限(L1/L2) - site.php: 手续费减半(0.018→0.009) - agent_permission_setup.sql: 代理权限SQL - crypto_news_crawler.py: 新闻自动采集脚本
This commit is contained in:
Executable
+295
@@ -0,0 +1,295 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: cchhyy
|
||||
* Date: 2021/2/4
|
||||
* Time: 5:39 PM
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
use app\common\controller\Api;
|
||||
use think\Db;
|
||||
use think\Config;
|
||||
|
||||
ignore_user_abort(); // 后台运行
|
||||
set_time_limit(0); // 取消脚本运行时间的超时上限
|
||||
|
||||
/**
|
||||
* 首页接口
|
||||
*/
|
||||
class Synccoin extends Api
|
||||
{
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
public function test()
|
||||
{
|
||||
$i = 1;
|
||||
while($i<=10000)
|
||||
{
|
||||
$this->saveLog("test", '定时循环:'.$i);
|
||||
$i++;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//btcusdt
|
||||
public function syncbtcusdt()
|
||||
{
|
||||
// $i = 1;
|
||||
// while(1)
|
||||
// {
|
||||
$data = json_decode(http_curl('https://api.huobi.pro/market/history/trade?period=1min&size=20&symbol=btcusdt','get')
|
||||
,true);
|
||||
if(!$data || !isset($data['data']) || empty($data['data']))
|
||||
{
|
||||
$this->saveLog("sync_btcusdt", '————数据错误:' . json_encode($data));
|
||||
}else {
|
||||
$btcusdt = Db::name('hb_1s_btc')->order('ts', 'desc')
|
||||
->limit(20)->select();
|
||||
$btcarr = array_column($btcusdt,'id','ts');
|
||||
$data1 = $data['data'];
|
||||
// $nextsecond = $btcusdt[0]['ts'];
|
||||
$datas = array_column($data1, 'ts');
|
||||
array_multisort($datas, SORT_ASC, $data1);
|
||||
$havedata = [];
|
||||
$insert = [];
|
||||
foreach ($data1 as $key => $value) {
|
||||
$nextsecond = substr($value['ts'],0,10);
|
||||
$nextseconds = $nextsecond.'000';
|
||||
if(!in_array($nextsecond,$havedata) && !isset($btcarr[$nextsecond])){
|
||||
foreach ($data['data'] as $k=>$val)
|
||||
{
|
||||
if(strpos($val['ts'],$nextsecond) !== false)
|
||||
{
|
||||
$pricedata = $val['data'][0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$insert[] = [
|
||||
'symbol' => 'btcusdt',
|
||||
'ts' => $nextsecond,
|
||||
'price' => $pricedata['price'],
|
||||
'amount' => $pricedata['amount'],
|
||||
];
|
||||
$havedata[] = $nextsecond;
|
||||
}
|
||||
|
||||
}
|
||||
if(!empty($insert))
|
||||
{
|
||||
Db::name('hb_1s_btc')->insertAll($insert);
|
||||
}
|
||||
|
||||
$this->saveLog("sync_btcusdt", 'btcusdt价格同步到:' . date('Y-m-d H:i:s',$nextsecond));
|
||||
}
|
||||
// $i++;
|
||||
// }
|
||||
}
|
||||
|
||||
public function syncethusdt()
|
||||
{
|
||||
$data = json_decode(http_curl('https://api.huobi.pro/market/history/trade?period=1min&size=20&symbol=ethusdt','get')
|
||||
,true);
|
||||
if(!$data || !isset($data['data']) || empty($data['data']))
|
||||
{
|
||||
$this->saveLog("sync_ethusdt", '————数据错误:' . json_encode($data));
|
||||
}else {
|
||||
$btcusdt = Db::name('hb_1s_eth')->order('ts', 'desc')
|
||||
->limit(20)->select();
|
||||
$btcarr = array_column($btcusdt,'id','ts');
|
||||
$data1 = $data['data'];
|
||||
// $nextsecond = $btcusdt[0]['ts'];
|
||||
$datas = array_column($data1, 'ts');
|
||||
array_multisort($datas, SORT_ASC, $data1);
|
||||
$havedata = [];
|
||||
$insert = [];
|
||||
foreach ($data1 as $key => $value) {
|
||||
$nextsecond = substr($value['ts'],0,10);
|
||||
$nextseconds = $nextsecond.'000';
|
||||
if(!in_array($nextsecond,$havedata) && !isset($btcarr[$nextsecond])){
|
||||
foreach ($data['data'] as $k=>$val)
|
||||
{
|
||||
if(strpos($val['ts'],$nextsecond) !== false)
|
||||
{
|
||||
$pricedata = $val['data'][0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$insert[] = [
|
||||
'symbol' => 'ethusdt',
|
||||
'ts' => $nextsecond,
|
||||
'price' => $pricedata['price'],
|
||||
'amount' => $pricedata['amount'],
|
||||
];
|
||||
$havedata[] = $nextsecond;
|
||||
}
|
||||
|
||||
}
|
||||
if(!empty($insert))
|
||||
{
|
||||
Db::name('hb_1s_eth')->insertAll($insert);
|
||||
}
|
||||
|
||||
$this->saveLog("sync_ethusdt", 'ethusdt价格同步到:' . date('Y-m-d H:i:s',$nextsecond));
|
||||
}
|
||||
}
|
||||
|
||||
public function syncltcusdt()
|
||||
{
|
||||
$data = json_decode(http_curl('https://api.huobi.pro/market/history/trade?period=1min&size=20&symbol=ltcusdt','get')
|
||||
,true);
|
||||
if(!$data || !isset($data['data']) || empty($data['data']))
|
||||
{
|
||||
$this->saveLog("sync_ltcusdt", '————数据错误:' . json_encode($data));
|
||||
}else {
|
||||
$btcusdt = Db::name('hb_1s_ltc')->order('ts', 'desc')
|
||||
->limit(20)->select();
|
||||
$btcarr = array_column($btcusdt,'id','ts');
|
||||
$data1 = $data['data'];
|
||||
// $nextsecond = $btcusdt[0]['ts'];
|
||||
$datas = array_column($data1, 'ts');
|
||||
array_multisort($datas, SORT_ASC, $data1);
|
||||
$havedata = [];
|
||||
$insert = [];
|
||||
foreach ($data1 as $key => $value) {
|
||||
$nextsecond = substr($value['ts'],0,10);
|
||||
$nextseconds = $nextsecond.'000';
|
||||
if(!in_array($nextsecond,$havedata) && !isset($btcarr[$nextsecond])){
|
||||
foreach ($data['data'] as $k=>$val)
|
||||
{
|
||||
if(strpos($val['ts'],$nextsecond) !== false)
|
||||
{
|
||||
$pricedata = $val['data'][0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$insert[] = [
|
||||
'symbol' => 'ltcusdt',
|
||||
'ts' => $nextsecond,
|
||||
'price' => $pricedata['price'],
|
||||
'amount' => $pricedata['amount'],
|
||||
];
|
||||
$havedata[] = $nextsecond;
|
||||
}
|
||||
|
||||
}
|
||||
if(!empty($insert))
|
||||
{
|
||||
Db::name('hb_1s_ltc')->insertAll($insert);
|
||||
}
|
||||
|
||||
$this->saveLog("sync_ltcusdt", 'ltcusdt价格同步到:' . date('Y-m-d H:i:s',$nextsecond));
|
||||
}
|
||||
}
|
||||
|
||||
public function syncbchusdt()
|
||||
{
|
||||
$data = json_decode(http_curl('https://api.huobi.pro/market/history/trade?period=1min&size=20&symbol=bchusdt','get')
|
||||
,true);
|
||||
if(!$data || !isset($data['data']) || empty($data['data']))
|
||||
{
|
||||
$this->saveLog("sync_bchusdt", '————数据错误:' . json_encode($data));
|
||||
}else {
|
||||
$btcusdt = Db::name('hb_1s_bch')->order('ts', 'desc')
|
||||
->limit(20)->select();
|
||||
$btcarr = array_column($btcusdt,'id','ts');
|
||||
$data1 = $data['data'];
|
||||
// $nextsecond = $btcusdt[0]['ts'];
|
||||
$datas = array_column($data1, 'ts');
|
||||
array_multisort($datas, SORT_ASC, $data1);
|
||||
$havedata = [];
|
||||
$insert = [];
|
||||
foreach ($data1 as $key => $value) {
|
||||
$nextsecond = substr($value['ts'],0,10);
|
||||
$nextseconds = $nextsecond.'000';
|
||||
if(!in_array($nextsecond,$havedata) && !isset($btcarr[$nextsecond])){
|
||||
foreach ($data['data'] as $k=>$val)
|
||||
{
|
||||
if(strpos($val['ts'],$nextsecond) !== false)
|
||||
{
|
||||
$pricedata = $val['data'][0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$insert[] = [
|
||||
'symbol' => 'bchusdt',
|
||||
'ts' => $nextsecond,
|
||||
'price' => $pricedata['price'],
|
||||
'amount' => $pricedata['amount'],
|
||||
];
|
||||
$havedata[] = $nextsecond;
|
||||
}
|
||||
|
||||
}
|
||||
if(!empty($insert))
|
||||
{
|
||||
Db::name('hb_1s_bch')->insertAll($insert);
|
||||
}
|
||||
|
||||
$this->saveLog("sync_bchusdt", 'bchusdt价格同步到:' . date('Y-m-d H:i:s',$nextsecond));
|
||||
}
|
||||
}
|
||||
|
||||
public function synceosusdt()
|
||||
{
|
||||
$data = json_decode(http_curl('https://api.huobi.pro/market/history/trade?period=1min&size=20&symbol=eosusdt','get')
|
||||
,true);
|
||||
if(!$data || !isset($data['data']) || empty($data['data']))
|
||||
{
|
||||
$this->saveLog("sync_eosusdt", '————数据错误:' . json_encode($data));
|
||||
}else {
|
||||
$btcusdt = Db::name('hb_1s_eos')->order('ts', 'desc')
|
||||
->limit(20)->select();
|
||||
$btcarr = array_column($btcusdt,'id','ts');
|
||||
$data1 = $data['data'];
|
||||
// $nextsecond = $btcusdt[0]['ts'];
|
||||
$datas = array_column($data1, 'ts');
|
||||
array_multisort($datas, SORT_ASC, $data1);
|
||||
$havedata = [];
|
||||
$insert = [];
|
||||
foreach ($data1 as $key => $value) {
|
||||
$nextsecond = substr($value['ts'],0,10);
|
||||
$nextseconds = $nextsecond.'000';
|
||||
if(!in_array($nextsecond,$havedata) && !isset($btcarr[$nextsecond])){
|
||||
foreach ($data['data'] as $k=>$val)
|
||||
{
|
||||
if(strpos($val['ts'],$nextsecond) !== false)
|
||||
{
|
||||
$pricedata = $val['data'][0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$insert[] = [
|
||||
'symbol' => 'eosusdt',
|
||||
'ts' => $nextsecond,
|
||||
'price' => $pricedata['price'],
|
||||
'amount' => $pricedata['amount'],
|
||||
];
|
||||
$havedata[] = $nextsecond;
|
||||
}
|
||||
|
||||
}
|
||||
if(!empty($insert))
|
||||
{
|
||||
Db::name('hb_1s_eos')->insertAll($insert);
|
||||
}
|
||||
|
||||
$this->saveLog("sync_eosusdt", 'eosusdt价格同步到:' . date('Y-m-d H:i:s',$nextsecond));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function saveLog($symbol, $msg){
|
||||
$dir = __DIR__ ."/logs";
|
||||
if( !file_exists($dir) ) mkdir($dir, 0777);
|
||||
$today = date('Ymd');
|
||||
$file_path =$dir."/".$symbol."-".$today.".log";
|
||||
$handle = fopen($file_path, "a+");
|
||||
@fwrite($handle, date("H:i:s"). $msg . "\r\n");
|
||||
@fclose($handle);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user