You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
5.0 KiB
114 lines
5.0 KiB
<?php
|
|
require "../index.php";
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Redis;
|
|
use Workerman\Connection\AsyncTcpConnection;
|
|
use Workerman\Lib\Timer;
|
|
use Workerman\Worker;
|
|
use GatewayWorker\Lib\Gateway;
|
|
use App\Models\NewKline;
|
|
|
|
$worker = new Worker();
|
|
$worker->count = 1;
|
|
|
|
|
|
$worker->onWorkerStart = function ($worker) {
|
|
|
|
// 每2.5秒执行一次
|
|
$time_interval = 1;
|
|
Timer::add($time_interval, function () {
|
|
//echo "task 1min run\n";
|
|
//echo time()."\n";
|
|
$do_time = strtotime(date('Y-m-d H:i', time()) . ":00");
|
|
if($do_time === time()){
|
|
// echo "******".time()."\n";
|
|
}
|
|
|
|
//$aa = \App\Models\NewKline::TotalRiskControl();
|
|
////$aa = "1111222";
|
|
//var_dump($aa);
|
|
//exit();
|
|
//$day_kline = Cache::store('redis')->get('swap:' . 'BTC' . '_kline_' . '1min');
|
|
//$day_kline = Cache::store('redis')->get('swap:BTC_kline_1min');
|
|
|
|
//所有交易对
|
|
$symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
|
|
$symbols = config('coin.exchange_symbols');
|
|
//var_dump($symbols);
|
|
foreach ($symbols as $symbol => $key) {
|
|
if ($symbol == "CKL" || $symbol == "NYI" || $symbol == "HNA" || $symbol == "PVR" || $symbol == "GFTL") {
|
|
//if ($symbol == "YFT") {
|
|
$model = "\App\Models\Data" . ucfirst(strtolower($symbol));
|
|
|
|
$now_time = strtotime(date('Y-m-d H:i', time()) . ":00") + 60;
|
|
$now_min = date('i', time());
|
|
//echo date('Y-m-d H:i:s', time())."\n";
|
|
// 慢一分钟,更新当前下一分钟k线
|
|
|
|
$other_min['is_5min'] = strtotime(date('Y-m-d H:', time()) . intval($now_min / 5) * 5 . ":00");
|
|
$other_min['is_15min'] = strtotime(date('Y-m-d H:', time()) . intval($now_min / 15) * 15 . ":00");
|
|
$other_min['is_30min'] = strtotime(date('Y-m-d H:', time()) . intval($now_min / 30) * 30 . ":00");
|
|
$other_min['is_1h'] = strtotime(date('Y-m-d H:', time()) . "00:00");
|
|
|
|
// 获取风控任务
|
|
$risk_key = 'fkJson:' . $symbol . '/USDT';
|
|
$risk = json_decode(Redis::get($risk_key), true);
|
|
$minUnit = $risk['minUnit'] ?? 0;
|
|
$count = $risk['count'] ?? 0;
|
|
$enabled = $risk['enabled'] ?? 0;
|
|
$strat_time = strtotime(date("Y-m-d ", time()) . $risk['strat_time']) ?? 0;
|
|
|
|
$seconds = 60;
|
|
$subaa = 'swap:' . $symbol . '_kline_' . '1min';
|
|
$sendsub = 'swapKline_' . $symbol . '_1min';
|
|
if ($strat_time === $now_time-60) {
|
|
if (!blank($risk) && $enabled == 1 && $strat_time <= $now_time && $risk['pin'] == 1) {
|
|
|
|
//$cache_data = Cache::store('redis')->get($subaa);
|
|
//$one_min_date = \App\Models\DataYft::query()->where('Date', $now_time)->where('is_1min', 1)->first()->toArray();
|
|
$one_min_date = $model::query()->where('Date', $now_time)->where('is_1min', 1)->first()->toArray();
|
|
// 修改价格
|
|
$change = $minUnit * $count;
|
|
if ($minUnit > 0) {
|
|
$high = PriceCalculate($one_min_date['High'], '+', $change, 8);
|
|
$model::query()->where('Date', $now_time)->where('is_1min', 1)->update(['High' => $high]);
|
|
foreach ($other_min as $item => $value) {
|
|
$up_other = $model::query()->where('Date', $value)->where($item, 1)->first('High');
|
|
if ($up_other['high'] < $high) {
|
|
$model::query()->where('Date', $value)->where($item, 1)->update(['High' => $high]);
|
|
// echo $item . "----" . $value . "****" . $up_other['high'] . "\n";
|
|
|
|
}
|
|
|
|
}
|
|
} else {
|
|
$Low = PriceCalculate($one_min_date['Low'], '+', $change, 8);
|
|
$model::query()->where('Date', $now_time)->where('is_1min', 1)->update(['Low' => $Low]);
|
|
foreach ($other_min as $item => $value) {
|
|
$up_other = $model::query()->where('Date', $value)->where($item, 1)->first('Low');
|
|
if ($up_other['low'] > $Low) {
|
|
$model::query()->where('Date', $value)->where($item, 1)->update(['Low' => $Low]);
|
|
// echo $item . "----" . $value . "****" . $up_other['Low'] . "\n";
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
Gateway::$registerAddress = '127.0.0.1:1238';
|
|
|
|
};
|
|
|
|
Worker::runAll();
|
|
|