|
|
|
@ -16,9 +16,6 @@ use Illuminate\Support\Facades\DB; |
|
|
|
use Illuminate\Support\Facades\Redis; |
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
use Illuminate\Support\Facades\Cache; |
|
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
use App\Models\DataTobr; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ContractRisk extends Form |
|
|
|
@ -36,62 +33,89 @@ class ContractRisk extends Form |
|
|
|
$now_min_s = date('s', $dotime); |
|
|
|
|
|
|
|
|
|
|
|
if ($now_min_s >= 45) { |
|
|
|
return $this->error('最后5秒不给更新'); |
|
|
|
} |
|
|
|
// if ($now_min_s >= 45) { |
|
|
|
// return $this->error('最后5秒不给更新'); |
|
|
|
// } |
|
|
|
// if ($now_min_s <= 5) { |
|
|
|
// return $this->error('开始5秒不给更新'); |
|
|
|
// } |
|
|
|
|
|
|
|
$symbols = ContractPair::query()->pluck('symbol'); |
|
|
|
$PlatformCoin = config('coin.exchange_symbols'); |
|
|
|
foreach ($PlatformCoin as $val => $key) { |
|
|
|
$PlatformCoinNew[] = $val; |
|
|
|
} |
|
|
|
// $PlatformCoin = config('coin.exchange_symbols'); |
|
|
|
// foreach ($PlatformCoin as $val => $key) { |
|
|
|
// $PlatformCoinNew[] = $val; |
|
|
|
// } |
|
|
|
foreach ($symbols as $symbol) { |
|
|
|
if (!empty($input[$symbol])) { |
|
|
|
$risk_key = 'fkJson:' . $symbol . '/USDT'; |
|
|
|
//获取传过来的数据 |
|
|
|
$data = $input[$symbol]; |
|
|
|
if (in_array($symbol, $PlatformCoinNew)) { |
|
|
|
if ($input[$symbol]['enabled'] == 1) { |
|
|
|
$dotime = strtotime(date('Y-m-d ', time()) . $input[$symbol]['strat_time']); |
|
|
|
// $doit = $this->PlatformCurrencyRiskControlTotalProcessing('AAAAA', $input[$symbol]); |
|
|
|
if ($input[$symbol]['pin'] == 1) { |
|
|
|
$doit = $this->PlatformCurrencyRiskControlTotalProcessing($symbol, $input[$symbol], $dotime); |
|
|
|
} else { |
|
|
|
$doit = $this->PlatformCurrencyRiskControlTotalProcessing($symbol, $input[$symbol], time()); |
|
|
|
} |
|
|
|
if ($doit) { |
|
|
|
return $this->error($doit); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// !blank($risk) |
|
|
|
//获取历史数据 |
|
|
|
$risk_key = 'fkJson:' . $symbol . '/USDT'; |
|
|
|
$old_data = json_decode(Redis::get($risk_key), true); |
|
|
|
if($old_data['now_time'] ==strtotime(date("Y-m-d H:i:00"))){ |
|
|
|
return $this->error('此根还在路上,请下一分钟再操作'); |
|
|
|
} |
|
|
|
if(empty($old_data['now_time']) || $old_data['enabled'] == 1 || $data['enabled'] == 1){ |
|
|
|
$data['now_time'] = strtotime(date("Y-m-d H:i:00")); |
|
|
|
|
|
|
|
if($data['enabled'] == 1 && $old_data['enabled'] == 1){ |
|
|
|
// // 二次改价 |
|
|
|
$data['back_count'] = $old_data['count']; |
|
|
|
}elseif ($data['enabled'] == 0 && $old_data['enabled'] == 1){ |
|
|
|
// // 关闭风控 |
|
|
|
$data['back_count'] = $data['count']; |
|
|
|
}else{ |
|
|
|
// // 开启风控 |
|
|
|
$data['back_count'] = $data['count']; |
|
|
|
//第一次开启 |
|
|
|
if($data['enabled'] == 1 && $old_data['enabled'] == 0){ |
|
|
|
$airCoins = \App\Models\Klike::query()->where('air_coin',$symbol)->get()->toArray(); |
|
|
|
$timmm = ['1min','5min','15min','30min','60min','1day','1week','1mon']; |
|
|
|
foreach ($timmm as $key => $value) { |
|
|
|
|
|
|
|
// if(!empty($airCoins)){ |
|
|
|
// $risk_key_d = 'swap:' . $airCoins[0]['like_coin'] . '_kline_'.$value; |
|
|
|
// $zheng = $airCoins[0]['percent']; |
|
|
|
// }else{ |
|
|
|
$risk_key_d = 'swap:' . $symbol . '_kline_'.$value; |
|
|
|
$zheng = 1; |
|
|
|
// } |
|
|
|
|
|
|
|
$old_data_d = Cache::store('redis')->get($risk_key_d); |
|
|
|
$data['hold'][$value]['price']=$old_data_d['open']*$zheng; |
|
|
|
$data['hold'][$value]['time']=$old_data_d['id']; |
|
|
|
|
|
|
|
} |
|
|
|
$data['xxx']=1; |
|
|
|
unset($airCoins); |
|
|
|
}else if($data['enabled'] == 1 && $old_data['enabled'] == 1){ |
|
|
|
//第二次修改 |
|
|
|
$airCoins = \App\Models\Klike::query()->where('air_coin',$symbol)->get()->toArray(); |
|
|
|
$timmm = ['1min','5min','15min','30min','60min','1day','1week','1mon']; |
|
|
|
foreach ($timmm as $key => $value) { |
|
|
|
|
|
|
|
// if(!empty($airCoins)){ |
|
|
|
// $risk_key_d = 'swap:' . $airCoins[0]['like_coin'] . '_kline_'.$value; |
|
|
|
// $zheng = $airCoins[0]['percent']; |
|
|
|
// }else{ |
|
|
|
$risk_key_d = 'swap:' . $symbol . '_kline_'.$value; |
|
|
|
$zheng = 1; |
|
|
|
// } |
|
|
|
|
|
|
|
$old_data_d = Cache::store('redis')->get($risk_key_d); |
|
|
|
$data['hold'][$value]['price']=$old_data_d['open']*$zheng; |
|
|
|
$data['hold'][$value]['time']=$old_data_d['id']; |
|
|
|
|
|
|
|
} |
|
|
|
$data['xxx']=$zheng; |
|
|
|
unset($airCoins); |
|
|
|
}elseif($data['enabled'] == 0 && $old_data['enabled'] == 1){ |
|
|
|
//关闭 |
|
|
|
$airCoins = \App\Models\Klike::query()->where('air_coin',$symbol)->get()->toArray(); |
|
|
|
$timmm = ['1min','5min','15min','30min','60min','1day','1week','1mon']; |
|
|
|
foreach ($timmm as $key => $value) { |
|
|
|
|
|
|
|
$risk_key_d = 'swap:' . $symbol . '_kline_'.$value; |
|
|
|
$zheng = 1; |
|
|
|
$old_data_d = Cache::store('redis')->get($risk_key_d); |
|
|
|
$data['hold'][$value]['price']=$old_data_d['open']*$zheng; |
|
|
|
$data['hold'][$value]['time']=$old_data_d['id']; |
|
|
|
|
|
|
|
}else{ |
|
|
|
if(empty($old_data['now_time'])){ |
|
|
|
$old_data['now_time'] = strtotime(date("Y-m-d H:i:00"))-180; |
|
|
|
} |
|
|
|
$data['now_time'] = $old_data['now_time']; |
|
|
|
$data['xxx']=3; |
|
|
|
unset($airCoins); |
|
|
|
}else{ |
|
|
|
$data=$old_data; |
|
|
|
$data['enabled'] = 0; |
|
|
|
} |
|
|
|
|
|
|
|
$data['coin'] = $symbol; |
|
|
|
// var_dump($data); |
|
|
|
Redis::set($risk_key, json_encode($data)); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -131,12 +155,22 @@ class ContractRisk extends Form |
|
|
|
|
|
|
|
// todo 测试固定model |
|
|
|
$model = $coins[$coin]; |
|
|
|
|
|
|
|
// $model = "App\Models\DataAaaaa"; |
|
|
|
|
|
|
|
// 更新当前一分钟数据 |
|
|
|
// 获取当前一分钟数据 |
|
|
|
$one_min_date = $model::query()->where('Date', $now_time)->where('is_1min', 1)->first()->toArray(); |
|
|
|
Log::info($one_min_date); |
|
|
|
$kline_book_key = 'swap:' . $coin . '_kline_book_1min'; |
|
|
|
|
|
|
|
$kline_book = Cache::store('redis')->get($kline_book_key); |
|
|
|
$one_min_date = end($kline_book); |
|
|
|
$one_min_date['Open'] = $one_min_date['open']; |
|
|
|
$one_min_date['High'] = $one_min_date['high']; |
|
|
|
$one_min_date['Low'] = $one_min_date['low']; |
|
|
|
|
|
|
|
// \Log::info(json_encode($one_min_date));exit; |
|
|
|
// $one_min_date = $model::query()->where('Date', $now_time)->where('is_1min', 1)->first()->toArray(); |
|
|
|
|
|
|
|
// 判断是涨还是跌 |
|
|
|
if ($one_min_date['Open'] > $data['count']) { |
|
|
|
$UpsAndDowns = 1; |
|
|
|
@ -144,13 +178,13 @@ class ContractRisk extends Form |
|
|
|
$UpsAndDowns = 0; |
|
|
|
} |
|
|
|
// 更新当前一分钟收盘数据 |
|
|
|
$this->UpdateTheCurrentMinute($UpsAndDowns, $data['count'], $now_time, $model, $one_min_date); |
|
|
|
$this->UpdateTheCurrentMinute($UpsAndDowns, $data['count'], $now_time, $model, $one_min_date,$coin); |
|
|
|
|
|
|
|
|
|
|
|
// 随机回调15-25条一分钟 |
|
|
|
// $NumberOfRecovery = mt_rand(15, 25); |
|
|
|
$NumberOfRecovery = 35; |
|
|
|
$end_open = $model::query()->where('Date', $now_time + $NumberOfRecovery * 60)->where('is_1min', 1)->first()->toArray(); |
|
|
|
$NumberOfRecovery = mt_rand(15, 25); |
|
|
|
// $end_open = $model::query()->where('Date', $now_time + $NumberOfRecovery * 60)->where('is_1min', 1)->first()->toArray(); |
|
|
|
$end_open = $one_min_date; |
|
|
|
|
|
|
|
// 判断修复,是涨还是跌 |
|
|
|
if ($end_open['Open'] > $data['count']) { |
|
|
|
@ -163,19 +197,6 @@ class ContractRisk extends Form |
|
|
|
$open_price = $data['count']; |
|
|
|
$close_price = $end_open['Open']; |
|
|
|
|
|
|
|
// 更新缓存最高最低 |
|
|
|
// $periods = ['5min', '15min', '30min', '60min']; |
|
|
|
// foreach ($periods as $period){ |
|
|
|
// Log::info($coin); |
|
|
|
// $old_per = Cache::store('redis')->get('swap:' . $coin . '_kline_' . $period); |
|
|
|
// Log::info($old_per); |
|
|
|
// // |
|
|
|
// $old_per['high'] = $old_per['open']; |
|
|
|
// $old_per['low'] = $old_per['open']; |
|
|
|
// Cache::store('redis')->put('swap:' . $coin . '_kline_' . $period,$old_per); |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// 生成随机修复分钟数 |
|
|
|
$period2_seconds = 60; |
|
|
|
$periodCount = $NumberOfRecovery; |
|
|
|
@ -243,8 +264,7 @@ class ContractRisk extends Form |
|
|
|
// $cc['time'] = date("Y-m-d H:i:s", $now_time); |
|
|
|
$model::query()->where('Date', $now_time + ($i * $period2_seconds) + 60)->where('is_1min', 1)->update($data_new_after); |
|
|
|
// dump($data_new_after); |
|
|
|
// Log::info(11111); |
|
|
|
$this->OtherPeriod($now_time + ($i * $period2_seconds), $data_new, $model); |
|
|
|
$this->OtherPeriod($now_time + ($i * $period2_seconds), $data_new, $model,$coin); |
|
|
|
// dd($open, $close, $high, $low); |
|
|
|
} |
|
|
|
// dd($cc); |
|
|
|
@ -261,21 +281,20 @@ class ContractRisk extends Form |
|
|
|
* Date: 2022/3/20 |
|
|
|
* Time: 18:00 |
|
|
|
*/ |
|
|
|
public function UpdateTheCurrentMinute($UpsAndDowns, $UpdateValue, $Timing = null, $model, $one_min_date = null) |
|
|
|
public function UpdateTheCurrentMinute($UpsAndDowns, $UpdateValue, $Timing = null, $model, $one_min_date = null,$coin) |
|
|
|
{ |
|
|
|
// Log::info(2222); |
|
|
|
if ($UpsAndDowns > 0) { |
|
|
|
$model::query()->where('Date', $Timing)->where('is_1min', 1)->update(['Low' => $UpdateValue, 'Close' => $UpdateValue, 'LastClose' => $UpdateValue]); |
|
|
|
// $model::query()->where('Date', $Timing + 60)->where('is_1min', 1)->update(['Low' => $UpdateValue, 'Open' => $UpdateValue]); |
|
|
|
|
|
|
|
$data_new_one = ['open' => $one_min_date['Open'], 'close' => $UpdateValue, 'high' => $one_min_date['High'], 'low' => $UpdateValue]; |
|
|
|
$this->OtherPeriod($Timing, $data_new_one, $model); |
|
|
|
$this->OtherPeriod($Timing, $data_new_one, $model,$coin); |
|
|
|
} else { |
|
|
|
$model::query()->where('Date', $Timing)->where('is_1min', 1)->update(['High' => $UpdateValue, 'Close' => $UpdateValue, 'LastClose' => $UpdateValue]); |
|
|
|
// $model::query()->where('Date', $Timing + 60)->where('is_1min', 1)->update(['High' => $UpdateValue, 'Open' => $UpdateValue]); |
|
|
|
|
|
|
|
$data_new_one = ['open' => $one_min_date['Open'], 'close' => $UpdateValue, 'high' => $UpdateValue, 'low' => $one_min_date['Low']]; |
|
|
|
$this->OtherPeriod($Timing, $data_new_one, $model); |
|
|
|
$this->OtherPeriod($Timing, $data_new_one, $model,$coin); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -288,7 +307,7 @@ class ContractRisk extends Form |
|
|
|
* Date: 2022/3/22 |
|
|
|
* Time: 17:39 |
|
|
|
*/ |
|
|
|
public function OtherPeriod($now_time, $data, $model) |
|
|
|
public function OtherPeriod($now_time, $data, $model,$coin) |
|
|
|
{ |
|
|
|
|
|
|
|
// $testtime = '1647959640'; |
|
|
|
@ -298,103 +317,57 @@ class ContractRisk extends Form |
|
|
|
$now_min = date('i', $now_time); |
|
|
|
|
|
|
|
|
|
|
|
$other_min['is_5min']['uup'] = strtotime(date('Y-m-d H:', $testtime) . intval($now_min / 5) * 5 . ":00")- 60 * 5; |
|
|
|
$other_min['is_5min']['start'] = strtotime(date('Y-m-d H:', $testtime) . intval($now_min / 5) * 5 . ":00"); |
|
|
|
$other_min['is_5min']['end'] = strtotime(date('Y-m-d H:', $testtime) . intval($now_min / 5) * 5 . ":00") + 60 * 4; |
|
|
|
$other_min['is_5min']['next'] = strtotime(date('Y-m-d H:', $testtime) . intval($now_min / 5) * 5 . ":00") + 60 * 5; |
|
|
|
$other_min['is_15min']['uup'] = strtotime(date('Y-m-d H:', $testtime) . intval($now_min / 15) * 15 . ":00") - 60 * 15; |
|
|
|
$other_min['is_15min']['start'] = strtotime(date('Y-m-d H:', $testtime) . intval($now_min / 15) * 15 . ":00"); |
|
|
|
$other_min['is_15min']['end'] = strtotime(date('Y-m-d H:', $testtime) . intval($now_min / 15) * 15 . ":00") + 60 * 15 - 60; |
|
|
|
$other_min['is_15min']['next'] = strtotime(date('Y-m-d H:', $testtime) . intval($now_min / 15) * 15 . ":00") + 60 * 15; |
|
|
|
$other_min['is_30min']['uup'] = strtotime(date('Y-m-d H:', $testtime) . intval($now_min / 30) * 30 . ":00")-60 * 30; |
|
|
|
$other_min['is_30min']['start'] = strtotime(date('Y-m-d H:', $testtime) . intval($now_min / 30) * 30 . ":00"); |
|
|
|
$other_min['is_30min']['end'] = strtotime(date('Y-m-d H:', $testtime) . intval($now_min / 30) * 30 . ":00") + 60 * 30 - 60; |
|
|
|
$other_min['is_30min']['next'] = strtotime(date('Y-m-d H:', $testtime) . intval($now_min / 30) * 30 . ":00") + 60 * 30; |
|
|
|
$other_min['is_1h']['uup'] = strtotime(date('Y-m-d H:', $testtime) . "00:00")-60 * 60; |
|
|
|
$other_min['is_1h']['start'] = strtotime(date('Y-m-d H:', $testtime) . "00:00"); |
|
|
|
$other_min['is_1h']['end'] = strtotime(date('Y-m-d H:', $testtime) . "00:00") + 60 * 60 - 60; |
|
|
|
$other_min['is_1h']['next'] = strtotime(date('Y-m-d H:', $testtime) . "00:00") + 60 * 60; |
|
|
|
$other_min['is_1h']['end'] = strtotime(date('Y-m-d H:', $testtime) . "00:00") + 60 * 60 - 60;; |
|
|
|
|
|
|
|
foreach ($other_min as $val => $key) { |
|
|
|
$kline_book_key = 'swap:' . $coin . '_kline_book_1min'; |
|
|
|
$kline_book = Cache::store('redis')->get($kline_book_key); |
|
|
|
|
|
|
|
$other_time_date = end($kline_book); |
|
|
|
// \Log::info();exit; |
|
|
|
foreach ($other_min as $val => $key) { |
|
|
|
$other_time_date['Open'] = $other_time_date['open']; |
|
|
|
$other_time_date['High'] = $other_time_date['high']; |
|
|
|
$other_time_date['Low'] = $other_time_date['low']; |
|
|
|
$other_time_date['Close'] = $other_time_date['close']; |
|
|
|
// 更新当前时间段最高最低 |
|
|
|
$other_time_date = $model::query()->where('Date', $now_time)->where('is_1min', 1)->first()->toArray(); |
|
|
|
// $other_time_date = $model::query()->where('Date', $now_time)->where('is_1min', 1)->first()->toArray(); |
|
|
|
$up_date['High'] = $high = max($other_time_date['Open'], $other_time_date['High'], $other_time_date['Low'], $other_time_date['Close'], $data['open'], $data['close'], $data['high'], $data['low']); |
|
|
|
$up_date['Low'] = $low = min($other_time_date['Open'], $other_time_date['High'], $other_time_date['Low'], $other_time_date['Close'], $data['open'], $data['close'], $data['high'], $data['low']); |
|
|
|
// $test_date[] = ['high' => $high, 'low' => $low, 'oldhigh' => $other_time_date['High'], 'oldlow' => $other_time_date['Low']]; |
|
|
|
// 如果是时间段开始时间更新开盘 |
|
|
|
if ($now_time === $key['start']) { |
|
|
|
$uup_data = $model::query()->where('Date', $key['uup'])->where($val, 1)->first()->toArray(); |
|
|
|
$up_date['Open'] = $open = $uup_data['Close']; |
|
|
|
// Log::info($data['open']); |
|
|
|
// Log::info($key['start']); |
|
|
|
// Log::info($uup_data['Close']); |
|
|
|
// Log::info($val); |
|
|
|
// Log::info($now_time); |
|
|
|
if($val == 'is_15min'){ |
|
|
|
Log::info($val); |
|
|
|
// Log::info($uup_data); |
|
|
|
Log::info($key['start']); |
|
|
|
Log::info($key['uup']); |
|
|
|
Log::info($key['next']); |
|
|
|
} |
|
|
|
$up_date['Open'] = $open = $data['open']; |
|
|
|
$other_time_date['open'] = $up_date['Open']; |
|
|
|
} |
|
|
|
// 如果是时间段收盘时间更新收盘 |
|
|
|
if ($now_time === $key['end']) { |
|
|
|
$up_date['Close'] = $close = $data['close']; |
|
|
|
$up_date['LastClose'] = $close = $data['close']; |
|
|
|
$next_line['Open'] = $data['close']; |
|
|
|
$model::query()->where('Date', $key['next'])->where($val, 1)->update($next_line); |
|
|
|
$other_time_date['close'] = $up_date['Close']; |
|
|
|
} |
|
|
|
|
|
|
|
// $up_date['time'] = date("Y-m-d H:i:s", $now_time); |
|
|
|
// $up_date['type'] = $val; |
|
|
|
// $up_date['kkyk'] = date("Y-m-d H:i:s", $now_time - 60); |
|
|
|
// $up_date['k1kyk'] = date("Y-m-d H:i:s", $key['start']); |
|
|
|
// $up_date['k2kyk'] = date("Y-m-d H:i:s", $key['end']); |
|
|
|
$model::query()->where('Date', $key['start'])->where($val, 1)->update($up_date); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//更新缓存 |
|
|
|
// Log::info($key['start']); |
|
|
|
// Log::info($now_time); |
|
|
|
// $period = 'is_'. $val; |
|
|
|
|
|
|
|
// 可能有用 |
|
|
|
// $now_high = $model::query()->where('is_1min', 1)->whereBetween('Date', [$key['start'],$now_time])->max('High'); |
|
|
|
// $now_low = $model::query()->where('is_1min', 1)->whereBetween('Date', [$key['start'],$now_time])->min('Low'); |
|
|
|
|
|
|
|
|
|
|
|
// $low = DataRao::query()->where('is_1min', 1)->whereBetween('Date', [$where_start, $where_end])->min('Low'); |
|
|
|
// $now_high = $model::query()->whereBetween('Date', $key['start'],$now_time)->where($period, 1)->max('High'); |
|
|
|
// $now_low = $model::query()->whereBetween('Date', $key['start'],$now_time)->where($period, 1)->max('Low'); |
|
|
|
// $periods = ['5min', '15min', '30min', '60min']; |
|
|
|
// foreach ($periods as $period){ |
|
|
|
// Log::info($coin); |
|
|
|
|
|
|
|
// 可能有用 |
|
|
|
// $old_per = Cache::store('redis')->get('swap:' . $other_time_date['Symbol'] . '_kline_' . $val); |
|
|
|
// $old_per['high'] = $now_high; |
|
|
|
// $old_per['low'] = $now_low; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Log::info($now_high); |
|
|
|
// Log::info($old_per); |
|
|
|
// // |
|
|
|
// $old_per['high'] = $old_per['open']; |
|
|
|
// $old_per['low'] = $old_per['open']; |
|
|
|
|
|
|
|
// 可能有用 |
|
|
|
// Cache::store('redis')->put('swap:' . $other_time_date['Symbol'] . '_kline_' . $val,$old_per); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
$other_time_date['high'] = $up_date['High']; |
|
|
|
$other_time_date['low'] = $up_date['Low']; |
|
|
|
unset($kline_book[array_key_last($kline_book)]); |
|
|
|
$kline_book = array_values($kline_book); |
|
|
|
array_push($kline_book, $other_time_date); |
|
|
|
Cache::store('redis')->put($kline_book_key,$kline_book); |
|
|
|
// $model::query()->where('Date', $key['start'])->where($val, 1)->update($up_date); |
|
|
|
// dump($up_date); |
|
|
|
unset($up_date); |
|
|
|
|
|
|
|
} |
|
|
|
// dd($up_date); |
|
|
|
|
|
|
|
|