Browse Source

获取air币的新方法

master
453530270@qq.com 2 years ago
parent
commit
82888400c6
  1. 79
      app/Admin/Controllers/KlineLikeController.php
  2. 255
      app/Admin/Forms/ContractRisk.php
  3. 7
      app/Admin/routes.php
  4. 16
      app/Models/Klike.php

79
app/Admin/Controllers/KlineLikeController.php

@ -0,0 +1,79 @@
<?php
/*
* @Descripttion:
* @version:
* @Author: GuaPi
* @Date: 2021-07-29 10:40:49
* @LastEditors: GuaPi
* @LastEditTime: 2021-08-09 17:44:06
*/
namespace App\Admin\Controllers;
use App\Admin\Actions\User\AddPromotionUser;
use App\Admin\Actions\User\AddSystemUser;
use App\Admin\Actions\User\AddUser;
use App\Admin\Renderable\Parents;
use App\Admin\Renderable\UserTradeStatistics;
use App\Admin\Renderable\UserWalletExpand;
use App\Handlers\ContractTool;
// use App\Handlers\Kline;
use App\Models\AgentGrade;
use App\Models\CoinConfig;
use App\Models\CoinData;
use App\Models\DataTobr;
use App\Models\Klike;
use App\Models\SustainableAccount;
use App\Models\User;
use App\Models\UserAuth;
use App\Models\UserGrade;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
class KlineLikeController extends AdminController
{
protected $title = '新空气币设置';
public function grid()
{
return Grid::make(new Klike(), function (Grid $grid) {
$grid->column('id', '姓名');
$grid->column('air_coin', '姓名');
$grid->column('like_coin', '姓名');
$grid->column('percent', '姓名');
$grid->column('created_at', '姓名');
$grid->column('updated_at', '姓名');
});
}
protected function detail($id)
{
return Show::make($id, new Klike(), function (Show $show) {
$show->id;
$show->air_coin;
$show->like_coin;
$show->percent;
});
}
protected function form()
{
return Form::make(new Klike(), function (Form $form) {
$form->text('id')->readOnly();
$form->text('air_coin')->rules("required:users,username");
$form->text('like_coin');
$form->text('percent');
});
}
}

255
app/Admin/Forms/ContractRisk.php

@ -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);

7
app/Admin/routes.php

@ -89,9 +89,7 @@ Route::group([
$router->resource('inside-trade-deal-robot', 'InsideTradeDealRobotController');
$router->resource('contract-deal-robot', 'ContractDealRobotController');
$router->resource('contract-risk', 'ContractRiskController');
$router->resource('contract-risknew', 'ContractRisknewController');
$router->resource('contract-share', 'ContractShareController');
$router->post('symbol-detal', 'ContractRisknewController@symbolDetal');
// 法币交易
$router->resource('otc-coinlist', 'OtcCoinlistController');
@ -107,6 +105,11 @@ Route::group([
$router->post('kline-save', 'KlineRobotController@kline_save');
$router->get('getKlineConfig', 'KlineRobotController@getKlineConfig');
// 新平台币设置
$router->resource('kline-like', 'KlineLikeController');
// $router->get('klike', 'KlineRobotlikeController@klike');
$router->resource('klike', 'KlikeController');
$router->resource('place', 'PlaceController');
$router->resource('invite-poster', 'InvitePosterController');

16
app/Models/Klike.php

@ -0,0 +1,16 @@
<?php
namespace App\Models;
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class Klike extends Model{
protected $table = 'air_coin';
}
Loading…
Cancel
Save