Browse Source

更新平台使用市场

master
torsenli 2 years ago
parent
commit
835ca6a4a4
  1. 79
      app/Admin/Controllers/KlineLikeController.php
  2. 164
      app/Admin/Forms/ContractRisk.php
  3. 5
      app/Admin/routes.php
  4. 24
      app/Http/Controllers/Api/V1/ContractController.php
  5. 28
      app/Http/Controllers/Appapi/V1/ContractController.php
  6. 124
      app/Models/DataMxsm.php
  7. 16
      app/Models/Klike.php
  8. 1
      app/Services/CoinService.php
  9. 2
      app/Services/UdunWalletService.php
  10. 14
      app/Services/UserWalletService.php
  11. 2
      app/Workerman/Option/Events.php
  12. 110
      app/Workerman/Swap/Events.php
  13. 130
      public/swap/swap_depth.php
  14. 6
      public/swap/swap_fk_todo.php
  15. 116
      public/swap/swap_getoldkline.php
  16. 213
      public/swap/swap_kline_15min.php
  17. 180
      public/swap/swap_kline_1day.php
  18. 249
      public/swap/swap_kline_1min.php
  19. 121
      public/swap/swap_kline_1mon.php
  20. 122
      public/swap/swap_kline_1week.php
  21. 159
      public/swap/swap_kline_30min.php
  22. 168
      public/swap/swap_kline_4hour.php
  23. 211
      public/swap/swap_kline_5min.php
  24. 146
      public/swap/swap_kline_60min.php
  25. 4
      public/swap/swap_kline_repair.php
  26. 100
      public/swap/swap_market.php
  27. 2
      public/swap/swap_start.sh
  28. 51
      public/swap/swap_trade.php
  29. 49
      resources/views/admin/klike.blade.php
  30. 19
      resources/views/admin/kline.blade.php
  31. 13
      resources/views/admin/klineRobotlike.blade.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');
});
}
}

164
app/Admin/Forms/ContractRisk.php

@ -15,6 +15,8 @@ use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\Cache;
class ContractRisk extends Form
{
@ -31,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));
}
}
@ -126,11 +155,21 @@ 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();
$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']) {
@ -139,12 +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);
$end_open = $model::query()->where('Date', $now_time + $NumberOfRecovery * 60)->where('is_1min', 1)->first()->toArray();
// $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']) {
@ -224,7 +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);
$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);
@ -241,20 +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)
{
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);
}
}
@ -267,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';
@ -286,30 +326,48 @@ class ContractRisk extends Form
$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;;
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']) {
$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'];
$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);
$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);

5
app/Admin/routes.php

@ -105,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');

24
app/Http/Controllers/Api/V1/ContractController.php

@ -235,16 +235,16 @@ class ContractController extends ApiController
$data['status'] = 'ok';
$coins = config('coin.swap_symbols');
foreach ($coins as $coin => $class) {
if ($symbol == $coin) {
$data['data'] = $class::getKlineData($symbol, $params['period'], $params['size']);
$data['ch'] = "swap." . $symbol . ".kline." . $params['period'];
$data['ts'] = Carbon::now()->getPreciseTimestamp(3);
$data['status'] = 'ok';
break;
}
}
// foreach ($coins as $coin => $class) {
// if ($symbol == $coin) {
// $data['data'] = $class::getKlineData($symbol, $params['period'], $params['size']);
// $data['ch'] = "swap." . $symbol . ".kline." . $params['period'];
// $data['ts'] = Carbon::now()->getPreciseTimestamp(3);
// $data['status'] = 'ok';
// break;
// }
// }
if ($zip) {
$json = json_encode($data['data']);
@ -297,7 +297,7 @@ class ContractController extends ApiController
$params = $request->all();
$data = $this->service->contractAccountFlow($user, $params);
foreach ($data as &$value) {
$value['created_at']=date("Y-m-d H:i:s",strtotime($value['created_at'])-60*60*12);
$value['created_at']=date("Y-m-d H:i:s",strtotime($value['created_at'])-60*60*13);
}
return $this->successWithData($data);
@ -567,7 +567,7 @@ class ContractController extends ApiController
// $data2 = json_decode($data, true);
foreach ($data as $key => $value) {
//历史订单时间为时间戳
$value['updated_ats'] = strtotime($value['updated_at'])-60*60*12;
$value['updated_ats'] = strtotime($value['updated_at'])-60*60*13;
// Log::info($value['updated_ats']);
}
// Log::info($data);

28
app/Http/Controllers/Appapi/V1/ContractController.php

@ -242,16 +242,16 @@ class ContractController extends ApiController
$data['status'] = 'ok';
$coins = config('coin.swap_symbols');
foreach ($coins as $coin => $class) {
if ($symbol == $coin) {
$data['data'] = $class::getKlineData($symbol, $params['period'], $params['size']);
$data['ch'] = "swap." . $symbol . ".kline." . $params['period'];
$data['ts'] = Carbon::now()->getPreciseTimestamp(3);
$data['status'] = 'ok';
break;
}
}
// foreach ($coins as $coin => $class) {
// if ($symbol == $coin) {
// $data['data'] = $class::getKlineData($symbol, $params['period'], $params['size']);
// $data['ch'] = "swap." . $symbol . ".kline." . $params['period'];
// $data['ts'] = Carbon::now()->getPreciseTimestamp(3);
// $data['status'] = 'ok';
//
// break;
// }
// }
// 使Size参数有效
// if ($size) {
// // $data['data'] =
@ -324,7 +324,7 @@ class ContractController extends ApiController
// $value['created_at'] = date('Y / m / d',(strtotime($value['created_at'])-60*60*12)/1000);
// $value['aaa'] = strtotime($value['created_at'])-60*60*12;
// unset($value['created_at']);
$value['bb'] = date("m/d/Y H:i:s",strtotime($value['created_at'])-60*60*12);
$value['bb'] = date("m/d/Y H:i:s",strtotime($value['created_at'])-60*60*13);
}
return $this->successWithData($data);
@ -549,9 +549,9 @@ class ContractController extends ApiController
$data = $this->service->getHistoryEntrust($user, $params);
foreach ($data as &$value) {
$value['created_at'] = date("Y-m-d H:i:s",strtotime($value['created_at'])-60*60*12);
$value['updated_at'] = date("Y-m-d H:i:s",strtotime($value['updated_at'])-60*60*12);
$value['ts'] = $value['ts']-60*60*12;
$value['created_at'] = date("Y-m-d H:i:s",strtotime($value['created_at'])-60*60*13);
$value['updated_at'] = date("Y-m-d H:i:s",strtotime($value['updated_at'])-60*60*13);
$value['ts'] = $value['ts']-60*60*13;
}
return $this->successWithData($data);
}

124
app/Models/DataMxsm.php

@ -0,0 +1,124 @@
<?php
/*
* @Descripttion:
* @version:
* @Author: GuaPi
* @Date: 2021-07-29 10:40:49
* @LastEditors: GuaPi
* @LastEditTime: 2021-08-09 17:41:16
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class DataMxsm extends Model
{
protected $primaryKey = 'id';
protected $table = 'data_mxsm';
protected $guarded = [];
public $timestamps = false;
public $attributes = [
'pid' => 0,
'Symbol' => 'MXSM',
'Name' => 'MXSM',
'Price2' => 0,
'Price3' => 0,
'Open_Int' => 0,
'is_1min' => 0,
'is_5min' => 0,
'is_15min' => 0,
'is_30min' => 0,
'is_1h' => 0,
'is_2h' => 0,
'is_4h' => 0,
'is_6h' => 0,
'is_12h' => 0,
'is_day' => 0,
'is_week' => 0,
'is_month' => 0,
];
public static function getKlineData($symbol, $period, $size)
{
$builder = self::query();
$wheres = [
'1min' => 'is_1min',
'5min' => 'is_5min',
'15min' => 'is_15min',
'30min' => 'is_30min',
'60min' => 'is_1h',
'4hour' => 'is_4hour',
'1day' => 'is_day',
'1week' => 'is_week',
'1mon' => 'is_month',
];
$where = $wheres[$period] ?? 'is_1min';
$builder->where($where, 1);
$data = $builder->where('Date', '<', time())->limit($size)->orderByDesc('Date')->get();
if (blank($data)) return [];
$data = $data->sortBy('Date')->values()->map(function ($kline) {
$item = [
"id" => $kline['Date'],
"amount" => $kline['Amount'],
"count" => $kline['Amount'],
"open" => $kline['Open'],
"close" => $kline['Close'],
"low" => $kline['Low'],
"high" => $kline['High'],
"vol" => $kline['Volume']
];
$item['price'] = $item['close'];
return $item;
})->toArray();
// 重设数组最后一组数据的值
$time = time();
$data = self::getlastData($data, $period, $time);
return $data;
}
/**
* @description: 获取最新5分钟线 十五分钟线 30分钟线 1小时线 4小时线 1天线 1周线 一月线
* @param {*}
* @return {*}
*/
public static function getlastData($data, $period, $time)
{
$periodMap = [
'1min' => ['column' => 'is_1min', 'seconds' => 60],
'5min' => ['column' => 'is_5min', 'seconds' => 300],
'15min' => ['column' => 'is_15min', 'seconds' => 900],
'30min' => ['column' => 'is_30min', 'seconds' => 1800],
'60min' => ['column' => 'is_1h', 'seconds' => 3600],
'4hour' => ['column' => 'is_4hour', 'seconds' => 14400],
'1day' => ['column' => 'is_day', 'seconds' => 86400],
'1week' => ['column' => 'is_week', 'seconds' => 604800],
'1mon' => ['column' => 'is_month', 'seconds' => 2592000],
];
$tmp = $data[array_key_last($data)];
if ($period == '1mon') {
$res = self::query()
->whereBetween('Date', [\Carbon\Carbon::now()->firstOfMonth()->timestamp, $time])
->where('is_1min', 1)
->get();
} else {
$res = self::query()
->whereBetween('Date', [$time - $time % $periodMap[$period]['seconds'], $time])
->where('is_1min', 1)
->get();
}
$data[array_key_last($data)] = [
"id" => $tmp['id'],
"amount" => $res->sum('Amount'),
"count" => $res->sum('Amount'),
"open" => $res->first()->Open,
"close" => $res->last()->Close, //最新价
"low" => $res->min('Low'),
"high" => $res->max('High'),
"vol" => $res->sum('Volume'),
"price" => $res->last()->Close
];
return $data;
}
}

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';
}

1
app/Services/CoinService.php

@ -100,6 +100,7 @@ class CoinService
'SHIB' => 60,
'DOGE' => 60,
'USDT' => 60,
'USDC' => 60,
];
// dd($map,$coin_name);
$coinType = $map[$coin_name] ?? null;

2
app/Services/UdunWalletService.php

@ -53,7 +53,7 @@ class UdunWalletService
// 回调
//$callUrl = config('app.url') . '/api/udun/notify';
// $callUrl = env('NOTIFY_URL') . '/api/udun/notify';
$callUrl = 'https://xmg.xusexchange.com/api/udun/notify';
$callUrl = 'https://aj.ajcoins.com/api/udun/notify';
$body = array(
'merchantId' => $this->merchantId,

14
app/Services/UserWalletService.php

@ -336,9 +336,9 @@ class UserWalletService
{
$result = Recharge::query()->with(['coin'])->where(['user_id' => $user_id])->orderBy("id", 'desc')->paginate();
foreach ($result as &$row) {
$row['created_at'] =date("Y-m-d H:i:s",strtotime($row['created_at'])-60*60*12);
$row['updated_at'] =date("Y-m-d H:i:s",strtotime($row['updated_at'])-60*60*12);
$row['datetime'] =$row['datetime']-60*60*12;
$row['created_at'] =date("Y-m-d H:i:s",strtotime($row['created_at'])-60*60*13);
$row['updated_at'] =date("Y-m-d H:i:s",strtotime($row['updated_at'])-60*60*13);
$row['datetime'] =$row['datetime']-60*60*13;
if($row['coin_id'] == 1){
if($row['note']){
$row['coin_name'] = "USDT-TRC20";
@ -477,7 +477,7 @@ class UserWalletService
$result = Withdraw::query()->with(['coin'])->where(['user_id' => $user_id])->orderBy("id", 'desc')->paginate();
foreach ($result as &$row) {
// $row['updated_at'] = date("Y-m-d H:i:s",strtotime($row['updated_at'])-60*60*12);
$row['datetime'] = $row['datetime']-60*60*12;
$row['datetime'] = $row['datetime']-60*60*13;
if($row['address_type']){
if($row['address_type'] == '2'){
$row['coin_name'] = "USDT-ERC20";
@ -590,7 +590,7 @@ class UserWalletService
{
$result = TransferRecord::query()->with(['coin'])->where(['user_id' => $user_id])->orderBy("id", 'desc')->paginate();
foreach ($result as &$row) {
$row['datetime'] = $row['datetime']-60*60*12;
$row['datetime'] = $row['datetime']-60*60*13;
}
return api_response()->success('SUCCESS', $result);
}
@ -605,7 +605,7 @@ class UserWalletService
//$item['payment_currency'] .= "111";
$item['increase_ratio'] = ($currency_price - $item['currency_price']) / $item['currency_price'] *100; // 涨幅比例
$item['total_value'] = $item['subscription_currency_amount']*$currency_price; // 总值
$item['subscription_time'] = $item['subscription_time']-60*60*12;
$item['subscription_time'] = $item['subscription_time']-60*60*13;
}
//Log::info($result['data']);
return api_response()->success('SUCCESS', $result);
@ -617,7 +617,7 @@ class UserWalletService
// global $price;
// $btc_tickers = Cache::store('redis')->get('market:' . 'btcusdt' . '_detail')['close'];
// $eth_tickers = Cache::store('redis')->get('market:' . 'ethusdt' . '_detail')['close'];
// $eos_tickers = Cache::store('redis')->get('market:' . 'eosusdt' . '_detail')['close'];
// $eos_tickers = Cache::store('redis')->get('market:' . 'eosusdt' . '_detai.l')['close'];
// $etc_tickers = Cache::store('redis')->get('market:' . 'etcusdt' . '_detail')['close'];
// $wallet_data = [];
// $result = SustainableAccount::query()->where(['user_id' => $user_id])->paginate();

2
app/Workerman/Option/Events.php

@ -488,7 +488,7 @@ class Events
public static function onMessage($client_id, $message)
{
// if (strlen($message) > Events::MAX_PACKAGE) Gateway::closeClient($client_id);
echo $message .':'. $client_id . "--onMessage\r\n";
// echo $message .':'. $client_id . "--onMessage\r\n";
$message = json_decode($message);
if(isset($message->cmd)){

110
app/Workerman/Swap/Events.php

@ -31,18 +31,31 @@ class Events
// COIN_SYMBOL -- START
$coins = config('coin.swap_symbols');
$seconds = 0.5;
// \Log::info('ttttttttttt');
// \Log::info(json_encode($coins));
// var_dump($coins);
foreach ($coins as $coin1 => $class) {
// if ($coin1 == 'AAAAA' || $coin1 == 'SWTS' || $coin1 == 'MXSM' || $coin1 == 'CLP' || $coin1 == 'LYH' || $coin1 == 'DWS' || $coin1 == 'AASZ' || $coin1 == 'BBWL') {
// break;
// }
if($coin1 == 'AAAAA'){
continue;
}
// $airCoin = \App\Models\Klike::query()->where('air_coin',$coin1)->first();
// \Log::info(json_encode($airCoin).$coin1);
// if($airCoin){
// continue;
// }
Timer::add($seconds, function ($coin1, $class) {
$symbol = $coin1;
$group_id = 'swapBuyList_' . $symbol;
if (Gateway::getClientIdCountByGroup($group_id) > 0) {
$data = Events::getCoinBuyList($symbol, $class);
$message = json_encode(['code' => 0, 'msg' => 'success', 'data' => $data, 'sub' => $group_id]);
Gateway::sendToGroup($group_id, $message);
// $message = json_encode(['code' => 0, 'msg' => 'success', 'data' => $data, 'sub' => $group_id]);
// Gateway::sendToGroup($group_id, $message);
}
}, [$coin1, $class]);
if ($coin1 != strtolower(config('coin.coin_symbol'))) {
@ -50,9 +63,9 @@ class Events
$symbol = $coin1;
$group_id = 'swapSellList_' . $symbol;
if (Gateway::getClientIdCountByGroup($group_id) > 0) {
$data = Events::getCoinBuyList($symbol, $class);
$message = json_encode(['code' => 0, 'msg' => 'success', 'data' => $data, 'sub' => $group_id]);
Gateway::sendToGroup($group_id, $message);
// $data = Events::getCoinBuyList($symbol, $class);
// $message = json_encode(['code' => 0, 'msg' => 'success', 'data' => $data, 'sub' => $group_id]);
// Gateway::sendToGroup($group_id, $message);
}
}, [$coin1, $class]);
}
@ -60,9 +73,9 @@ class Events
$symbol = $coin1;
$group_id = 'swapTradeList_' . $symbol;
if (Gateway::getClientIdCountByGroup($group_id) > 0) {
$data = Events::getCoinTradeItem($symbol, $class);
$message = json_encode(['code' => 0, 'msg' => 'success', 'type' => 'dynamic', 'data' => $data, 'sub' => $group_id]);
Gateway::sendToGroup($group_id, $message);
// $data = Events::getCoinTradeItem($symbol, $class);
// $message = json_encode(['code' => 0, 'msg' => 'success', 'type' => 'dynamic', 'data' => $data, 'sub' => $group_id]);
// Gateway::sendToGroup($group_id, $message);
}
}, [$coin1, $class]);
@ -75,20 +88,27 @@ class Events
$data['high'] = $data['open'];
$data['low'] = $data['open'];
}
Cache::store('redis')->put('swap:' . $symbol . '_kline_' . $period, $data);
// if ($symbol != 'AAAAA' && $symbol != 'SWTS' && $symbol != 'MXSM' && $symbol != 'CLP' && $symbol != 'LYH' && $symbol != 'DWS' && $symbol != 'AASZ' && $symbol != 'BBWL') {
if($data['high']){
Cache::store('redis')->put('swap:' . $symbol . '_kline_' . $period, $data);
}
// }
$group_id = 'swapKline_' . $symbol . '_' . $period;
if (Gateway::getClientIdCountByGroup($group_id) > 0) {
$message = json_encode(['code' => 0, 'msg' => 'success', 'data' => $data, 'sub' => $group_id, 'type' => 'dynamic']);
Gateway::sendToGroup($group_id, $message);
// $message = json_encode(['code' => 0, 'msg' => 'success', 'data' => $data, 'sub' => $group_id, 'type' => 'dynamic']);
// Gateway::sendToGroup($group_id, $message);
}
}
}, [$periods, $coin1, $class]);
Timer::add(5, function ($coin1, $class) {
Timer::add(1, function ($coin1, $class) {
$coin1_symbol = $coin1;
$kline = $class::query()->where('Date', '<', time())->where('is_1min', 1)->orderByDesc('Date')->first();
$day_kline = $class::query()->where('Date', Carbon::yesterday()->getTimestamp())->where('is_day', 1)->orderByDesc('Date')->first();
$now_price_key = 'swap:trade_nowprice_' . $coin1_symbol;
$now_price = Cache::store('redis')->get($now_price_key);
$now_price_key2 = 'swap:'. $coin1_symbol .'_detail_new';
$now_price2 = Cache::store('redis')->get($now_price_key2);
// echo 3333;
if (blank($kline)) {
// echo 555;
@ -126,11 +146,11 @@ class Events
}
$cache_data['price'] = $cache_data['close'];
echo "test---";
echo $cache_data['open'];
echo "test---";
echo $day_kline;
if (isset($cache_data['open']) && $cache_data['open'] != 0 && $day_kline['Symbol']!='AAAAA') {
// echo "test---";
// echo $cache_data['open'];
// echo "test---";
// echo $day_kline;
if (isset($cache_data['open']) && $cache_data['open'] != 0 && $day_kline['Symbol'] != 'AAAAA') {
if (blank($day_kline)) {
if (($cache_data['close'] - $cache_data['open']) == 0) {
$increase = 0;
@ -138,11 +158,11 @@ class Events
$increase = round(($cache_data['close'] - $cache_data['open']) / $cache_data['open'], 4);
}
} else {
echo 2222;
// echo 2222;
if (($cache_data['close'] - $day_kline['Close']) == 0) {
$increase = 0;
} else {
echo 33333;
// echo 33333;
$increase = round(($cache_data['close'] - $day_kline['Close']) / $day_kline['Close'], 4);
}
}
@ -183,7 +203,7 @@ class Events
$cache_data['prices'] = $prices;
//todo 更新24小时最高价格
// Log::info('更新24小时最高价格');
echo $coin1_symbol;
// echo $coin1_symbol;
$new_cache = $cache_data;
//当天第一分钟
$day_time_one = strtotime(date('Y-m-d') . ' 00:00:00');
@ -196,22 +216,46 @@ class Events
if ($new_cache['low'] > $low['Low']) {
$new_cache['low'] = $low['Low'];
}
//var_dump($new_cache);
// 去除逗号
$new_cache['close'] = str_replace(',', '', $now_price['price']);
$cache_data['close'] = str_replace(',', '', $now_price['price']);
$cache_data['price'] = str_replace(',', '', $now_price['price']);
$new_cache['low'] = $now_price2['low'];
$new_cache['high'] = $now_price2['high'];
$new_cache['vol'] = $now_price2['vol'];
$new_cache['increase'] = $now_price2['increase'];
$new_cache['increaseStr'] = $now_price2['increaseStr'];
Cache::store('redis')->put('swap:' . $coin1_symbol . '_detail', $new_cache);
if (!blank($cache_data2)) {
Cache::store('redis')->put('swap:trade_detail_' . $coin1_symbol, $cache_data);
//缓存历史价格数据book
if (blank($new_price_book)) {
Cache::store('redis')->put($new_price_book_key, [$cache_data2]);
} else {
array_push($new_price_book, $cache_data2);
if (count($new_price_book) > 200) {
array_shift($new_price_book);
if (!blank($cache_data2)) {
Cache::store('redis')->put('swap:trade_detail_' . $coin1_symbol, $cache_data);
//缓存历史价格数据book
if (blank($new_price_book)) {
// \Log::info($cache_data2['id']);
Cache::store('redis')->put($new_price_book_key, [$cache_data2]);
} else {
array_push($new_price_book, $cache_data2);
if (count($new_price_book) > 200) {
array_shift($new_price_book);
}
Cache::store('redis')->put($new_price_book_key, $new_price_book);
}
Cache::store('redis')->put($new_price_book_key, $new_price_book);
}
}
// }
// Cache::store('redis')->put('swap:' . $coin1_symbol . '_detail', $new_cache);
// if (!blank($cache_data2)) {
// //缓存历史价格数据book
// if (blank($new_price_book)) {
// Cache::store('redis')->put($new_price_book_key, [$cache_data2]);
// } else {
// array_push($new_price_book, $cache_data2);
// if (count($new_price_book) > 200) {
// array_shift($new_price_book);
// }
// Cache::store('redis')->put($new_price_book_key, $new_price_book);
// }
// }
}, [$coin1, $class]);
}
// COIN_SYMBOL -- END

130
public/swap/swap_depth.php

@ -37,6 +37,10 @@ $worker->onWorkerStart = function($worker){
$con->onConnect = function($con) {
//所有交易对
$symbols = \App\Models\ContractPair::query()->where('status',1)->pluck('symbol');
$airCoins = \App\Models\Klike::query()->pluck('like_coin');
$arr1 = array_collapse([$symbols,$airCoins]);
$symbols = array_values(array_unique($arr1));
// \Log::info(json_encode($symbols));
$msg1 =null;
foreach ($symbols as $symbol){
// $symbol = strtolower($symbol . 'USDT')."@depth20";
@ -108,7 +112,7 @@ $worker->onWorkerStart = function($worker){
$change = $minUnit * $count;
$cacheBuyList[$key1]['price'] = PriceCalculate($original_price ,'+', $change,8);
}else{
$cacheBuyList[$key1]['price'] = $item1[0];
$cacheBuyList[$key1]['price'] = $item1[0]+0;
}
}
@ -134,7 +138,7 @@ $worker->onWorkerStart = function($worker){
$change = $minUnit * $count;
$cacheSellList[$key2]['price'] = PriceCalculate($original_price ,'+', $change,8);
}else{
$cacheSellList[$key2]['price'] = $item2[0];
$cacheSellList[$key2]['price'] = $item2[0]+0;
}
}
Cache::store('redis')->put('swap:' . $symbol . '_depth_buy',$cacheBuyList);
@ -155,6 +159,128 @@ $worker->onWorkerStart = function($worker){
Gateway::sendToGroup($group_id1, json_encode(['code'=>0,'msg'=>'success','data'=>$cacheBuyList,'sub'=>$group_id1]));
Gateway::sendToGroup($group_id2, json_encode(['code'=>0,'msg'=>'success','data'=>$cacheSellList,'sub'=>$group_id2]));
}
$airCoins = \App\Models\Klike::query()->where('like_coin',$symbol)->get()->toArray();
foreach($airCoins as $item){
if($item['like_coin'] == $symbol){
$symbolNew = $item['air_coin'];
// 获取风控任务
$risk_key = 'fkJson:' . $symbolNew . '/USDT';
$risk = json_decode( Redis::get($risk_key) ,true);
$minUnit = $risk['minUnit'] ?? 0;
$count = $risk['count'] ?? 0;
$enabled = $risk['enabled'] ?? 0;
foreach ($buyList as $key1 => $item1){
$cacheBuyList[$key1]['id'] = Str::uuid()->toString();
// $buy_amount = intval(substr($item1[1],-2));
$buy_amount = $item1[1];
if($buy_amount == 0){
$buy_amount = 1;
}
$cacheBuyList[$key1]['amount'] = $buy_amount;
if(!blank($risk) && $enabled == 1){
// 修改买盘价格
$original_price = $item1[0];
if($item['calculation'] == '*'){
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$original_price = $original_price * $item['percent'];
}
if($item['calculation'] == '/'){
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$original_price = $original_price / $item['percent'];
}
$tmp = explode('.',$original_price);
if(sizeof($tmp) > 1){
$size = strlen(end($tmp));
}else{
$size = 0;
}
$change = $minUnit * $count;
$cacheBuyList[$key1]['price'] = PriceCalculate($original_price ,'+', $change,8);
$cacheBuyList[$key1]['price'] = number_format($cacheBuyList[$key1]['price'],intval($item['point']));
// 去除逗号
$cacheBuyList[$key1]['price'] = str_replace(',','',$cacheBuyList[$key1]['price']);
}else{
if($item['calculation'] == '*'){
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$item1[0] = $item1[0] * $item['percent'];
}
if($item['calculation'] == '/'){
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$item1[0] = $item1[0] / $item['percent'];
}
$cacheBuyList[$key1]['price'] = $item1[0]+0;
$cacheBuyList[$key1]['price'] = number_format($cacheBuyList[$key1]['price'],intval($item['point']));
// 去除逗号
$cacheBuyList[$key1]['price'] = str_replace(',','',$cacheBuyList[$key1]['price']);
}
}
foreach ($sellList as $key2 => $item2){
$cacheSellList[$key2]['id'] = Str::uuid()->toString();
// $sell_amount = intval(substr($item2[1],-2));
$sell_amount = $item2[1];
if($sell_amount == 0){
$sell_amount = 1;
}
$cacheSellList[$key2]['amount'] = $sell_amount;
if(!blank($risk) && $enabled == 1){
// 修改卖盘价格
$original_price = $item2[0];
if($item['calculation'] == '*'){
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$original_price = $original_price * $item['percent'];
}
if($item['calculation'] == '/'){
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$original_price = $original_price / $item['percent'];
}
$tmp = explode('.',$original_price);
if(sizeof($tmp) > 1){
$size = strlen(end($tmp));
}else{
$size = 0;
}
$change = $minUnit * $count;
$cacheSellList[$key2]['price'] = PriceCalculate($original_price ,'+', $change,8);
$cacheSellList[$key2]['price'] = number_format($cacheSellList[$key2]['price'],intval($item['point']));
// 去除逗号
$cacheSellList[$key2]['price'] = str_replace(',','',$cacheSellList[$key2]['price']);
}else{
if($item['calculation'] == '*'){
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$item2[0] = $item2[0] * $item['percent'];
}
if($item['calculation'] == '/'){
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$item2[0] = $item2[0] / $item['percent'];
}
$cacheSellList[$key2]['price'] = $item2[0]+0;
$cacheSellList[$key2]['price'] = number_format($cacheSellList[$key2]['price'],intval($item['point']));
// 去除逗号
$cacheSellList[$key2]['price'] = str_replace(',','',$cacheSellList[$key2]['price']);
}
}
Cache::store('redis')->put('swap:' . $symbolNew . '_depth_buy',$cacheBuyList);
Cache::store('redis')->put('swap:' . $symbolNew . '_depth_sell',$cacheSellList);
if($swap_buy = Cache::store('redis')->get('swap_buyList_' . $symbolNew)){
Cache::store('redis')->forget('swap_buyList_' . $symbolNew);
array_unshift($cacheBuyList,$swap_buy);
}
if($swap_sell = Cache::store('redis')->get('swap_sellList_' . $symbolNew)){
Cache::store('redis')->forget('swap_sellList_' . $symbolNew);
array_unshift($cacheSellList,$swap_sell);
}
$group_id1 = 'swapBuyList_' . $symbolNew;
$group_id2 = 'swapSellList_' . $symbolNew;
if(Gateway::getClientIdCountByGroup($group_id1) > 0){
Gateway::sendToGroup($group_id1, json_encode(['code'=>0,'msg'=>'success','data'=>$cacheBuyList,'sub'=>$group_id1]));
Gateway::sendToGroup($group_id2, json_encode(['code'=>0,'msg'=>'success','data'=>$cacheSellList,'sub'=>$group_id2]));
}
}
}
}
}

6
public/swap/swap_fk_todo.php

@ -25,7 +25,7 @@ $worker->onWorkerStart = function ($worker) {
//echo time()."\n";
$do_time = strtotime(date('Y-m-d H:i', time()) . ":00");
if($do_time === time()){
echo "******".time()."\n";
// echo "******".time()."\n";
}
//$aa = \App\Models\NewKline::TotalRiskControl();
@ -80,7 +80,7 @@ $worker->onWorkerStart = function ($worker) {
$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";
// echo $item . "----" . $value . "****" . $up_other['high'] . "\n";
}
@ -92,7 +92,7 @@ $worker->onWorkerStart = function ($worker) {
$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";
// echo $item . "----" . $value . "****" . $up_other['Low'] . "\n";
}
}

116
public/swap/swap_getoldkline.php

@ -13,17 +13,19 @@ use GatewayWorker\Lib\Gateway;
$symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
$airCoins = \App\Models\Klike::query()->pluck('like_coin');
$arr1 = array_collapse([$symbols,$airCoins]);
$symbols = array_values(array_unique($arr1));
// $interval = '1m'; //某时间线线 3m-5m-15m-30m-1h-2h-4h-6h-8h-12h-1d-3d-1w-1M
foreach ($symbols as $symbol) {
$period = '1min'; //1
if ($symbol == "BGV" || $symbol == "NEC" || $symbol == "RVM" || $symbol == "MPGB" || $symbol == "STE" ||
$symbol == "GLPE" || $symbol == "UNQ" || $symbol == "TZW" || $symbol == "GLPE" || $symbol == "YERT" ||
$symbol == "EODC" || $symbol == "BGK"
) {
if ($symbol == "SWTS" || $symbol == "MXSM" || $symbol == "CLP" || $symbol == "LYH" || $symbol == "BBWL" ||
$symbol == "DWS" || $symbol == "AASZ") {
continue;
}
// if($symbol != "BTC"){
// if($symbol != "ETH"){
// continue;
// }
@ -55,7 +57,7 @@ foreach ($symbols as $symbol) {
if (!blank($kline_book)) {
for ($i = 0; $i < $llimint; $i++) {
array_pop($kline_book);
Cache::store('redis')->put($kline_book_key, $kline_book);
// Cache::store('redis')->put($kline_book_key, $kline_book);
}
}
foreach ($aa as $k => $v) {
@ -98,10 +100,10 @@ foreach ($symbols as $symbol) {
} else {
$last_item1 = array_pop($kline_book);
if ($last_item1['id'] == $cache_data['id']) {
echo 111;
// echo 111;
array_push($kline_book, $cache_data);
} else {
echo 2222;
// echo 2222;
array_push($kline_book, $last_item1, $cache_data);
}
@ -111,6 +113,104 @@ foreach ($symbols as $symbol) {
Cache::store('redis')->put($kline_book_key, $kline_book);
}
}
$airCoins = \App\Models\Klike::query()->where('like_coin',$symbol)->get()->toArray();
foreach($airCoins as $item){
$doittime = time();
$symbol = $symbol;
$symbol_get = $symbol . 'USDT';
$aa = $bass->bbgetKlines($symbol_get, $interval, $doittime - $periodMap[$period]['seconds'] * $llimint . '000', $doittime . '000', $llimint);
if($item['like_coin'] == $symbol){
$symbolNew = $item['air_coin'];
}
$kline_book_key = 'swap:' . $symbolNew . '_kline_book_' . $period;
$kline_book = Cache::store('redis')->get($kline_book_key);
if (!blank($kline_book)) {
for ($i = 0; $i < $llimint; $i++) {
array_pop($kline_book);
Cache::store('redis')->put($kline_book_key, $kline_book);
}
}
foreach ($aa as $k => $v) {
if($item['calculation'] == '*'){
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$v['2'] = $v['2'] * $item['percent'];
$v['1'] = $v['1'] * $item['percent'];
$v['3'] = $v['3'] * $item['percent'];
$v['4'] = $v['4'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
if($item['calculation'] == '/'){
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$v['2'] = $v['2'] / $item['percent'];
$v['1'] = $v['1'] / $item['percent'];
$v['3'] = $v['3'] / $item['percent'];
$v['4'] = $v['4'] / $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
// var_dump($v);
// 1分钟基线
$cache_data = [
"id" => intval(substr($v['0'], 0, 10)),
// "id" => $v['0'],
"open" => floatval(number_format($v['1'],$item['point'], '.', '')),
"close" => floatval(number_format($v['4'],$item['point'], '.', '')),
"low" => floatval(number_format($v['3'],$item['point'], '.', '')),
"high" => floatval(number_format($v['2'],$item['point'], '.', '')),
"amount" => $v['5'] * 1,
'vol' => $v['5'] * 1*1000,
'trade_turnover' => $v['10'] * 1*10,
'count' => round($v['5']*100,0),
];
$last_close = $v['4'] * 1;
$kline_book_key = 'swap:' . $symbolNew . '_kline_book_' . $period;
$kline_book = Cache::store('redis')->get($kline_book_key);
if (!blank($kline_book)) {
$prev_id = $cache_data['id'] - $seconds;
$prev_item = array_last($kline_book, function ($value, $key) use ($prev_id) {
return $value['id'] == $prev_id;
});
// $cache_data['open'] = $prev_item['close'];
}
// var_dump($cache_data);
// echo time();
if ($cache_data['id'] == strtotime(date("Y-m-d H:i:00", $doittime))) {
echo 333;
// var_dump($cache_data);
$cache_data['open'] = $last_close;
$cache_on = $cache_data;
$cache_on['last_now'] = $cache_data['id'];
Cache::store('redis')->put('swap:' . $symbolNew . '_kline_' . $period, $cache_on);
}
if (blank($kline_book)) {
Cache::store('redis')->put($kline_book_key, [$cache_data]);
} else {
$last_item1 = array_pop($kline_book);
if ($last_item1['id'] == $cache_data['id']) {
echo 111;
array_push($kline_book, $cache_data);
} else {
echo 2222;
array_push($kline_book, $last_item1, $cache_data);
}
if (count($kline_book) > 3000) {
array_shift($kline_book);
}
Cache::store('redis')->put($kline_book_key, $kline_book);
}
}
}
}

213
public/swap/swap_kline_15min.php

@ -73,9 +73,12 @@ $worker->onWorkerStart = function ($worker) {
// $symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
// todo: 修改获取当前行情配置
$period = '15m'; //3m-5m-15m-30m-1h-2h-4h-6h-8h-12h-1d-3d-1w-1M
$seconds = 900; //60 300 900 1800 3600 86400 604800 2592000
$seconds = 900; //60 300 900 1800 3600 86400 604800 2592000
$symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
$symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
$airCoins = \App\Models\Klike::query()->pluck('like_coin');
$arr1 = array_collapse([$symbols, $airCoins]);
$symbols = array_values(array_unique($arr1));
foreach ($symbols as $symbol) {
$symbol = strtolower($symbol);
$symbol_list[] = $symbol . "usdt@kline_" . $period;
@ -89,7 +92,7 @@ $worker->onWorkerStart = function ($worker) {
};
$con->onMessage = function ($con, $data) {
echo $data;
// echo $data;
// $data = json_decode(gzdecode($data), true);
$data = json_decode($data, true);
@ -104,25 +107,25 @@ $worker->onWorkerStart = function ($worker) {
// if ($ch) {
if ($ch) {
// todo: 修改获取当前行情配置
$period = '15min'; //1min 5min 15min 30min 60min 1day 1week 1mon
$now = $data['k'];
$kklinekey = 'swap:' . $symbol . '_kline_' . $period;
$period = '15min'; //1min 5min 15min 30min 60min 1day 1week 1mon
$now = $data['k'];
$kklinekey = 'swap:' . $symbol . '_kline_' . $period;
$oneminopen = json_decode(Redis::get($kklinekey), true);
if($oneminopen['last_now'] == strtotime(date("Y-m-d H:i:00", time()))){
if ($oneminopen['last_now'] == strtotime(date("Y-m-d H:i:00", time()))) {
$now['o'] = $oneminopen['open'];
}
$now['t']=substr($now['t'],0,10);
$now['t'] = substr($now['t'], 0, 10);
// echo json_encode($cache_data) . "\r\n";
$cache_data = [
"id" => $now['t']*1,
"open" => $now['o']*1,
"close" => $now['c']*1,
"low" => $now['l']*1,
"high" => $now['h']*1,
"amount" => $now['V']*1,
'vol' => $now['V']*1000,
'trade_turnover' => $now['Q']*1,
'count' => round($now['V']*100,0),
$cache_data = [
"id" => $now['t'] * 1,
"open" => $now['o'] * 1,
"close" => $now['c'] * 1,
"low" => $now['l'] * 1,
"high" => $now['h'] * 1,
"amount" => $now['V'] * 1,
'vol' => $now['V'] * 1000,
'trade_turnover' => $now['Q'] * 1,
'count' => round($now['V'] * 100, 0),
];
// echo json_encode($cache_data) . "\r\n";
// $cache_data['time'] = time();
@ -138,22 +141,167 @@ $worker->onWorkerStart = function ($worker) {
$count = $risk['count'] ?? 0;
$enabled = $risk['enabled'] ?? 0;
$seconds = 60;
// 当前一分钟 开盘对接
if (!blank($risk) && $enabled == 1) {
// 修改价格
$change = $minUnit * $count;
$cache_data['close'] = PriceCalculate($cache_data['close'], '+', $change, 8);
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['high'] = PriceCalculate($cache_data['high'], '+', $change, 8);
$cache_data['low'] = PriceCalculate($cache_data['low'], '+', $change, 8);
// 当前一分钟 开盘对接
if(($now['t']==$risk['hold']['15min']['time'])){
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['15min']['price'];
}else{
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
}
}
if(!empty($risk['hold'])){
if (!blank($risk) && $enabled == 0 && $count != 0 && $minUnit != 0 && $now['t'] == $risk['hold']['15min']['time']) {
// $change = $minUnit * $count;
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['15min']['price'];
}
}
// 1分钟基线
if (!blank($kline_book)) {
$prev_id = $cache_data['id'] - $seconds;
$prev_item = array_last($kline_book, function ($value, $key) use ($prev_id) {
return $value['id'] == $prev_id;
});
// $cache_data['open'] = $prev_item['close'];
}
// echo json_encode($cache_data) . "\r\n";
if (blank($kline_book)) {
Cache::store('redis')->put($kline_book_key, [$cache_data]);
} else {
$last_item1 = array_pop($kline_book);
if ($last_item1['id'] == $cache_data['id']) {
array_push($kline_book, $cache_data);
} else {
array_push($kline_book, $last_item1, $cache_data);
}
if (count($kline_book) > 3000) {
array_shift($kline_book);
}
Cache::store('redis')->put($kline_book_key, $kline_book);
}
Cache::store('redis')->put('swap:' . $symbol . '_kline_' . $period, $cache_data);
$group_id2 = 'swapKline_' . $symbol . '_' . $period;
//var_dump($group_id2);
//echo Gateway::getClientIdCountByGroup($group_id2);
if (Gateway::getClientIdCountByGroup($group_id2) > 0) {
// $cache_data['time'] = $cache_data['time'] - 43200;
Gateway::sendToGroup($group_id2, json_encode(['code' => 0, 'msg' => 'success', 'data' => $cache_data, 'sub' => $group_id2, 'type' => 'dynamic']));
}
//var_dump($cache_data);
// echo(date("Y-m-d H:i:s",$kline_book['id'])). "\r\n";
// echo $kline_book['id'];
}
$airCoins = \App\Models\Klike::query()->where('like_coin', $symbol)->get()->toArray();
foreach ($airCoins as $item) {
if ($ch) {
if ($item['like_coin'] == $symbol) {
$symbolNew = $item['air_coin'];
}
// todo: 修改获取当前行情配置
$period = '15min'; //1min 5min 15min 30min 60min 1day 1week 1mon
$now = $data['k'];
$kklinekey = 'swap:' . $symbolNew . '_kline_' . $period;
$oneminopen = json_decode(Redis::get($kklinekey), true);
if ($oneminopen['last_now'] == strtotime(date("Y-m-d H:i:00", time()))) {
$now['o'] = $oneminopen['open'];
}
$now['t'] = substr($now['t'], 0, 10);
// \Log::info('222222222222222222'.$now['t']);
if ($item['calculation'] == '*') {
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] * $item['percent'];
$now['c'] = $now['c'] * $item['percent'];
$now['h'] = $now['h'] * $item['percent'];
$now['l'] = $now['l'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
if ($item['calculation'] == '/') {
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] / $item['percent'];
$now['c'] = $now['c'] / $item['percent'];
$now['h'] = $now['h'] / $item['percent'];
$now['l'] = $now['l'] / $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
// echo json_encode($cache_data) . "\r\n";
$cache_data = [
"id" => $now['t'] * 1,
"open" => $now['o'] * 1,
"close" => $now['c'] * 1,
"low" => $now['l'] * 1,
"high" => $now['h'] * 1,
"amount" => $now['V'] * 1,
'vol' => $now['V'] * 1000,
'trade_turnover' => $now['Q'] * 1,
'count' => round($now['V'] * 100, 0),
];
// echo json_encode($cache_data) . "\r\n";
// $cache_data['time'] = time();
$kline_book_key = 'swap:' . $symbolNew . '_kline_book_' . $period;
$kline_book = Cache::store('redis')->get($kline_book_key);
// 获取风控任务
$risk_key = 'fkJson:' . $symbolNew . '/USDT';
//echo $risk_key;
$risk = json_decode(Redis::get($risk_key), true);
$minUnit = $risk['minUnit'] ?? 0;
$count = $risk['count'] ?? 0;
$enabled = $risk['enabled'] ?? 0;
$seconds = 60;
// 当前一分钟 开盘对接
if (!blank($risk) && $enabled == 1) {
// 修改价格
$change = $minUnit * $count;
$cache_data['close'] = PriceCalculate($cache_data['close'], '+', $change, 8);
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['high'] = PriceCalculate($cache_data['high'], '+', $change, 8);
$cache_data['low'] = PriceCalculate($cache_data['low'], '+', $change, 8);
// 当前一分钟 开盘对接
if(($now['t']==$risk['hold']['15min']['time'])){
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['15min']['price'];
}else{
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
}
}
if(!empty($risk['hold'])){
if (!blank($risk) && $enabled == 0 && $count != 0 && $minUnit != 0 && $now['t'] == $risk['hold']['15min']['time']) {
// $change = $minUnit * $count;
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['15min']['price'];
}
}
$cache_data['close'] = floatval(number_format($cache_data['close'],$item['point'], '.', ''));
$cache_data['open'] = floatval(number_format($cache_data['open'],$item['point'], '.', ''));
$cache_data['high'] = floatval(number_format($cache_data['high'],$item['point'], '.', ''));
$cache_data['low'] = floatval(number_format($cache_data['low'],$item['point'], '.', ''));
// 1分钟基线
if (!blank($kline_book)) {
$prev_id = $cache_data['id'] - $seconds;
$prev_item = array_last($kline_book, function ($value, $key) use ($prev_id) {
$prev_id = $cache_data['id'] - $seconds;
$prev_item = array_last($kline_book, function ($value, $key) use ($prev_id) {
return $value['id'] == $prev_id;
});
// $cache_data['open'] = $prev_item['close'];
@ -176,17 +324,18 @@ $worker->onWorkerStart = function ($worker) {
}
Cache::store('redis')->put('swap:' . $symbol . '_kline_' . $period, $cache_data);
Cache::store('redis')->put('swap:' . $symbolNew . '_kline_' . $period, $cache_data);
$group_id2 = 'swapKline_' . $symbol . '_' . $period;
//var_dump($group_id2);
//echo Gateway::getClientIdCountByGroup($group_id2);
if (Gateway::getClientIdCountByGroup($group_id2) > 0) {
// $cache_data['time'] = $cache_data['time'] - 43200;
Gateway::sendToGroup($group_id2, json_encode(['code' => 0, 'msg' => 'success', 'data' => $cache_data, 'sub' => $group_id2, 'type' => 'dynamic']));
$group_id2 = 'swapKline_' . $symbolNew . '_' . $period;
//var_dump($group_id2);
//echo Gateway::getClientIdCountByGroup($group_id2);
if (Gateway::getClientIdCountByGroup($group_id2) > 0) {
// $cache_data['time'] = $cache_data['time'] - 43200;
Gateway::sendToGroup($group_id2, json_encode(['code' => 0, 'msg' => 'success', 'data' => $cache_data, 'sub' => $group_id2, 'type' => 'dynamic']));
}
}
}
}
}
}

180
public/swap/swap_kline_1day.php

@ -76,6 +76,9 @@ $worker->onWorkerStart = function ($worker) {
$seconds = 86400; //60 300 900 1800 3600 86400 604800 2592000
$symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
$airCoins = \App\Models\Klike::query()->pluck('like_coin');
$arr1 = array_collapse([$symbols,$airCoins]);
$symbols = array_values(array_unique($arr1));
foreach ($symbols as $symbol) {
$symbol = strtolower($symbol);
$symbol_list[] = $symbol . "usdt@kline_" . $period;
@ -89,7 +92,7 @@ $worker->onWorkerStart = function ($worker) {
};
$con->onMessage = function ($con, $data) {
echo $data;
// echo $data;
// $data = json_decode(gzdecode($data), true);
$data = json_decode($data, true);
@ -246,6 +249,181 @@ $worker->onWorkerStart = function ($worker) {
}
}
$airCoins = \App\Models\Klike::query()->where('like_coin',$symbol)->get()->toArray();
foreach($airCoins as $item){
if ($ch) {
// \Log::info($symbol.json_encode($cache_data));
if($item['like_coin'] == $symbol){
$symbolNew = $item['air_coin'];
}
// todo: 修改获取当前行情配置
$period = '1day'; //1min 5min 15min 30min 60min 1day 1week 1mon
$now = $data['k'];
$kklinekey = 'swap:' . $symbolNew . '_kline_' . $period;
$oneminopen = json_decode(Redis::get($kklinekey), true);
if($oneminopen['last_now'] == strtotime(date("Y-m-d H:i:00", time()))){
$now['o'] = $oneminopen['open'];
}
$now['t']=substr($now['t'],0,10);
if($item['calculation'] == '*'){
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] * $item['percent'];
$now['c'] = $now['c'] * $item['percent'];
$now['h'] = $now['h'] * $item['percent'];
$now['l'] = $now['l'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
if($item['calculation'] == '/'){
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] / $item['percent'];
$now['c'] = $now['c'] / $item['percent'];
$now['h'] = $now['h'] / $item['percent'];
$now['l'] = $now['l'] / $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
// echo json_encode($cache_data) . "\r\n";
$cache_data = [
"id" => $now['t']*1,
"open" => $now['o']*1,
"close" => $now['c']*1,
"low" => $now['l']*1,
"high" => $now['h']*1,
"amount" => $now['V']*1,
'vol' => $now['V']*1000,
'trade_turnover' => $now['Q']*1,
'count' => round($now['V']*100,0),
];
// echo json_encode($cache_data) . "\r\n";
// $cache_data['time'] = time();
$kline_book_key = 'swap:' . $symbolNew . '_kline_book_' . $period;
$kline_book = Cache::store('redis')->get($kline_book_key);
// 获取风控任务
$risk_key = 'fkJson:' . $symbolNew . '/USDT';
//echo $risk_key;
$risk = json_decode(Redis::get($risk_key), true);
$minUnit = $risk['minUnit'] ?? 0;
$count = $risk['count'] ?? 0;
$enabled = $risk['enabled'] ?? 0;
$seconds = 60;
if (!blank($risk) && $enabled == 1) {
// 修改价格
$change = $minUnit * $count;
$cache_data['close'] = PriceCalculate($cache_data['close'], '+', $change, 8);
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['high'] = PriceCalculate($cache_data['high'], '+', $change, 8);
$cache_data['low'] = PriceCalculate($cache_data['low'], '+', $change, 8);
}
$cache_data['close']= floatval(number_format($cache_data['close'],$item['point'], '.', ''));
$cache_data['open'] = floatval(number_format($cache_data['open'],$item['point'], '.', ''));
$cache_data['high'] = floatval(number_format($cache_data['high'],$item['point'], '.', ''));
$cache_data['low'] = floatval(number_format($cache_data['low'],$item['point'], '.', ''));
// var_dump($cache_data);
// echo(date("Y-m-d H:i:s",$kline_book['id'])). "\r\n";
// echo $kline_book['id'];
if ($period == '1min') {
// 1分钟基线
if (!blank($kline_book)) {
$prev_id = $cache_data['id'] - $seconds;
$prev_item = array_last($kline_book, function ($value, $key) use ($prev_id) {
return $value['id'] == $prev_id;
});
// $cache_data['open'] = $prev_item['close'];
}
// echo json_encode($cache_data) . "\r\n";
if (blank($kline_book)) {
Cache::store('redis')->put($kline_book_key, [$cache_data]);
} else {
$last_item1 = array_pop($kline_book);
if ($last_item1['id'] == $cache_data['id']) {
array_push($kline_book, $cache_data);
} else {
array_push($kline_book, $last_item1, $cache_data);
}
if (count($kline_book) > 3000) {
array_shift($kline_book);
}
Cache::store('redis')->put($kline_book_key, $kline_book);
}
} else {
// 其他长周期K线都以前一周期作为参考 比如5minK线以1min为基础
$periodMap = [
'5min' => ['period' => '1min', 'seconds' => 60],
'15min' => ['period' => '5min', 'seconds' => 300],
'30min' => ['period' => '5min', 'seconds' => 300],
'60min' => ['period' => '5min', 'seconds' => 300],
'1day' => ['period' => '60min', 'seconds' => 3600],
'1week' => ['period' => '1day', 'seconds' => 86400],
'1mon' => ['period' => '1day', 'seconds' => 86400],
];
$map = $periodMap[$period] ?? null;
$kline_base_book = Cache::store('redis')->get('swap:' . $symbolNew . '_kline_book_' . $map['period']);
if (!blank($kline_base_book)) {
// 以5min周期为例 这里一次性取出1min周期前后10个
$first_item_id = $cache_data['id'];
$last_item_id = $cache_data['id'] + $seconds - $map['seconds'];
$items1 = array_where($kline_base_book, function ($value, $key) use ($first_item_id, $last_item_id) {
return $value['id'] >= $first_item_id && $value['id'] <= $last_item_id;
});
if (!blank($items1)) {
$cache_data['open'] = array_first($items1)['open'] ?? $cache_data['open'];
$cache_data['close'] = array_last($items1)['close'] ?? $cache_data['close'];
$cache_data['high'] = max(array_pluck($items1, 'high')) ?? $cache_data['high'];
$cache_data['low'] = min(array_pluck($items1, 'low')) ?? $cache_data['low'];
}
if (blank($kline_book)) {
Cache::store('redis')->put($kline_book_key, [$cache_data]);
} else {
$last_item1 = array_pop($kline_book);
if ($last_item1['id'] == $cache_data['id']) {
array_push($kline_book, $cache_data);
} else {
$update_last_item1 = $last_item1;
// 有新的周期K线生成 此时尝试更新$last_item1
$first_item_id2 = $cache_data['id'] - $seconds;
$last_item_id2 = $cache_data['id'] - $map['seconds'];
$items2 = array_where($kline_base_book, function ($value, $key) use ($first_item_id2, $last_item_id2) {
return $value['id'] >= $first_item_id2 && $value['id'] <= $last_item_id2;
});
if (!blank($items2)) {
$update_last_item1['open'] = array_first($items2)['open'] ?? $update_last_item1['open'];
$update_last_item1['close'] = array_last($items2)['close'] ?? $update_last_item1['close'];
$update_last_item1['high'] = max(array_pluck($items2, 'high')) ?? $update_last_item1['high'];
$update_last_item1['low'] = min(array_pluck($items2, 'low')) ?? $update_last_item1['low'];
}
array_push($kline_book, $update_last_item1, $cache_data);
}
if (count($kline_book) > 3000) {
array_shift($kline_book);
}
Cache::store('redis')->put($kline_book_key, $kline_book);
}
}
}
Cache::store('redis')->put('swap:' . $symbolNew . '_kline_' . $period, $cache_data);
$group_id2 = 'swapKline_' . $symbolNew . '_' . $period;
//var_dump($group_id2);
//echo Gateway::getClientIdCountByGroup($group_id2);
if (Gateway::getClientIdCountByGroup($group_id2) > 0) {
// $cache_data['time'] = $cache_data['time'] - 43200;
Gateway::sendToGroup($group_id2, json_encode(['code' => 0, 'msg' => 'success', 'data' => $cache_data, 'sub' => $group_id2, 'type' => 'dynamic']));
}
}
}
}
}
};

249
public/swap/swap_kline_1min.php

@ -76,6 +76,9 @@ $worker->onWorkerStart = function ($worker) {
$seconds = 60; //60 300 900 1800 3600 86400 604800 2592000
$symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
$airCoins = \App\Models\Klike::query()->pluck('like_coin');
$arr1 = array_collapse([$symbols,$airCoins]);
$symbols = array_values(array_unique($arr1));
foreach ($symbols as $symbol) {
$symbol = strtolower($symbol);
$symbol_list[] = $symbol . "usdt@kline_" . $period;
@ -111,9 +114,9 @@ $worker->onWorkerStart = function ($worker) {
if($oneminopen['last_now'] == strtotime(date("Y-m-d H:i:00", time()))){
$now['o'] = $oneminopen['open'];
}
if($ch == 'BTCUSDT'){
// var_dump($data);
}
// if($ch == 'BTCUSDT'){
// var_dump($data);
// }
$now['t']=substr($now['t'],0,10);
// echo json_encode($cache_data) . "\r\n";
$cache_data = [
@ -141,7 +144,14 @@ $worker->onWorkerStart = function ($worker) {
$count = $risk['count'] ?? 0;
$enabled = $risk['enabled'] ?? 0;
$seconds = 60;
// if($symbol == 'BTC'){
// echo $now['t']. "-----".$risk['now_time'];
// echo "\n";
// }
if (!blank($risk) && $enabled == 1) {
// if($symbol == 'BTC'){
// echo 1111;
// }
// 修改价格
$change = $minUnit * $count;
$cache_data['close'] = PriceCalculate($cache_data['close'], '+', $change, 8);
@ -150,27 +160,21 @@ $worker->onWorkerStart = function ($worker) {
// 当前一分钟 开盘对接
if((time()-$risk['now_time'])<=61){
if($risk['count'] != $risk['back_count']){
$back_count = $risk['back_count'] ?? 0;
$change_open = $minUnit * $back_count;
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change_open, 8);
}
if(($now['t']==$risk['hold']['1min']['time'])){
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['1min']['price'];
}else{
// $back_count = $risk['back_count'] ?? 0;
// $change_open = $minUnit * $back_count;
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change_open, 8);
// if($risk['count'] != $risk['back_count']){
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
// }
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
}
}
if (!blank($risk) && $enabled == 0 && (time()-$risk['now_time'])<=61) {
$change = $minUnit * $count;
$cache_data['open'] = PriceCalculate($cache_data['open'] ,'+', $change,8);
if(!empty($risk['hold'])){
if (!blank($risk) && $enabled == 0 && $count != 0 && $minUnit != 0 && $now['t'] == $risk['hold']['1min']['time']) {
// $change = $minUnit * $count;
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['1min']['price'];
}
}
// var_dump($cache_data);
// echo(date("Y-m-d H:i:s",$kline_book['id'])). "\r\n";
// echo $kline_book['id'];
@ -261,6 +265,10 @@ $worker->onWorkerStart = function ($worker) {
Cache::store('redis')->put('swap:' . $symbol . '_kline_' . $period, $cache_data);
$trade_detail_key = 'swap:trade_nowprice_' . $symbol;
$now_price_t['price']=$cache_data['close'];
Cache::store('redis')->put($trade_detail_key, $now_price_t);
$group_id2 = 'swapKline_' . $symbol . '_' . $period;
//var_dump($group_id2);
//echo Gateway::getClientIdCountByGroup($group_id2);
@ -271,6 +279,207 @@ $worker->onWorkerStart = function ($worker) {
}
}
$airCoins = \App\Models\Klike::query()->where('like_coin',$symbol)->get()->toArray();
foreach($airCoins as $item){
if ($ch) {
if($item['like_coin'] == $symbol){
$symbol = $item['air_coin'];
}
// todo: 修改获取当前行情配置
$period = '1min'; //1min 5min 15min 30min 60min 1day 1week 1mon
$now = $data['k'];
$kklinekey = 'swap:' . $symbol . '_kline_' . $period;
$oneminopen = json_decode(Redis::get($kklinekey), true);
if($oneminopen['last_now'] == strtotime(date("Y-m-d H:i:00", time()))){
$now['o'] = $oneminopen['open'];
}
// if($ch == 'BTCUSDT'){
// var_dump($data);
// }
$now['t']=substr($now['t'],0,10);
if($item['calculation'] == '*'){
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] * $item['percent'];
$now['c'] = $now['c'] * $item['percent'];
$now['h'] = $now['h'] * $item['percent'];
$now['l'] = $now['l'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
if($item['calculation'] == '/'){
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] / $item['percent'];
$now['c'] = $now['c'] / $item['percent'];
$now['h'] = $now['h'] / $item['percent'];
$now['l'] = $now['l'] / $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
// echo json_encode($cache_data) . "\r\n";
$cache_data = [
"id" => $now['t']*1,
"open" => $now['o']*1,
"close" => $now['c']*1,
"low" => $now['l']*1,
"high" => $now['h']*1,
"amount" => $now['V']*1,
'vol' => $now['V']*1*1000,
'trade_turnover' => $now['Q']*1,
'count' => round($now['V']*100,0),
];
// echo json_encode($cache_data) . "\r\n";
// $cache_data['time'] = time();
$kline_book_key = 'swap:' . $symbol . '_kline_book_' . $period;
$kline_book = Cache::store('redis')->get($kline_book_key);
// 获取风控任务
$risk_key = 'fkJson:' . $symbol . '/USDT';
//echo $risk_key;
$risk = json_decode(Redis::get($risk_key), true);
$minUnit = $risk['minUnit'] ?? 0;
$count = $risk['count'] ?? 0;
$enabled = $risk['enabled'] ?? 0;
$seconds = 60;
// if($symbol == 'CLP'){
// echo $cache_data['id'].'-----'.$risk['hold']['1min']['time'];
// echo "\n";
// }
if (!blank($risk) && $enabled == 1) {
// 修改价格
$change = $minUnit * $count;
$cache_data['close'] = PriceCalculate($cache_data['close'], '+', $change, 8);
$cache_data['high'] = PriceCalculate($cache_data['high'], '+', $change, 8);
$cache_data['low'] = PriceCalculate($cache_data['low'], '+', $change, 8);
// 当前一分钟 开盘对接
if(($now['t']==$risk['hold']['1min']['time'])){
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['1min']['price'];
}else{
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
}
}
if(!empty($risk['hold'])){
if (!blank($risk) && $enabled == 0 && $count != 0 && $minUnit != 0 && $now['t'] == $risk['hold']['1min']['time']) {
// echo 222;
// $change = $minUnit * $count;
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['1min']['price'];
}
}
$cache_data['close'] = floatval(number_format($cache_data['close'],$item['point'], '.', ''));
$cache_data['open'] = floatval(number_format($cache_data['open'],$item['point'], '.', ''));
$cache_data['high'] = floatval(number_format($cache_data['high'],$item['point'], '.', ''));
$cache_data['low'] = floatval(number_format($cache_data['low'],$item['point'], '.', ''));
// var_dump($cache_data);
// echo(date("Y-m-d H:i:s",$kline_book['id'])). "\r\n";
// echo $kline_book['id'];
if ($period == '1min') {
// 1分钟基线
if (!blank($kline_book)) {
$prev_id = $cache_data['id'] - $seconds;
$prev_item = array_last($kline_book, function ($value, $key) use ($prev_id) {
return $value['id'] == $prev_id;
});
// $cache_data['open'] = $prev_item['close'];
}
// echo json_encode($cache_data) . "\r\n";
if (blank($kline_book)) {
Cache::store('redis')->put($kline_book_key, [$cache_data]);
} else {
$last_item1 = array_pop($kline_book);
if ($last_item1['id'] == $cache_data['id']) {
array_push($kline_book, $cache_data);
} else {
array_push($kline_book, $last_item1, $cache_data);
}
if (count($kline_book) > 3000) {
array_shift($kline_book);
}
Cache::store('redis')->put($kline_book_key, $kline_book);
}
} else {
// 其他长周期K线都以前一周期作为参考 比如5minK线以1min为基础
$periodMap = [
'5min' => ['period' => '1min', 'seconds' => 60],
'15min' => ['period' => '5min', 'seconds' => 300],
'30min' => ['period' => '5min', 'seconds' => 300],
'60min' => ['period' => '5min', 'seconds' => 300],
'1day' => ['period' => '60min', 'seconds' => 3600],
'1week' => ['period' => '1day', 'seconds' => 86400],
'1mon' => ['period' => '1day', 'seconds' => 86400],
];
$map = $periodMap[$period] ?? null;
$kline_base_book = Cache::store('redis')->get('swap:' . $symbol . '_kline_book_' . $map['period']);
if (!blank($kline_base_book)) {
// 以5min周期为例 这里一次性取出1min周期前后10个
$first_item_id = $cache_data['id'];
$last_item_id = $cache_data['id'] + $seconds - $map['seconds'];
$items1 = array_where($kline_base_book, function ($value, $key) use ($first_item_id, $last_item_id) {
return $value['id'] >= $first_item_id && $value['id'] <= $last_item_id;
});
if (!blank($items1)) {
$cache_data['open'] = array_first($items1)['open'] ?? $cache_data['open'];
$cache_data['close'] = array_last($items1)['close'] ?? $cache_data['close'];
$cache_data['high'] = max(array_pluck($items1, 'high')) ?? $cache_data['high'];
$cache_data['low'] = min(array_pluck($items1, 'low')) ?? $cache_data['low'];
}
if (blank($kline_book)) {
Cache::store('redis')->put($kline_book_key, [$cache_data]);
} else {
$last_item1 = array_pop($kline_book);
if ($last_item1['id'] == $cache_data['id']) {
array_push($kline_book, $cache_data);
} else {
$update_last_item1 = $last_item1;
// 有新的周期K线生成 此时尝试更新$last_item1
$first_item_id2 = $cache_data['id'] - $seconds;
$last_item_id2 = $cache_data['id'] - $map['seconds'];
$items2 = array_where($kline_base_book, function ($value, $key) use ($first_item_id2, $last_item_id2) {
return $value['id'] >= $first_item_id2 && $value['id'] <= $last_item_id2;
});
if (!blank($items2)) {
$update_last_item1['open'] = array_first($items2)['open'] ?? $update_last_item1['open'];
$update_last_item1['close'] = array_last($items2)['close'] ?? $update_last_item1['close'];
$update_last_item1['high'] = max(array_pluck($items2, 'high')) ?? $update_last_item1['high'];
$update_last_item1['low'] = min(array_pluck($items2, 'low')) ?? $update_last_item1['low'];
}
array_push($kline_book, $update_last_item1, $cache_data);
}
if (count($kline_book) > 3000) {
array_shift($kline_book);
}
Cache::store('redis')->put($kline_book_key, $kline_book);
}
}
}
Cache::store('redis')->put('swap:' . $symbol . '_kline_' . $period, $cache_data);
$trade_detail_key = 'swap:trade_nowprice_' . $symbol;
$now_price_t['price']=number_format($cache_data['close'],$item['point']);
Cache::store('redis')->put($trade_detail_key, $now_price_t);
$group_id2 = 'swapKline_' . $symbol . '_' . $period;
//var_dump($group_id2);
//echo Gateway::getClientIdCountByGroup($group_id2);
if (Gateway::getClientIdCountByGroup($group_id2) > 0) {
// $cache_data['time'] = $cache_data['time'] - 43200;
Gateway::sendToGroup($group_id2, json_encode(['code' => 0, 'msg' => 'success', 'data' => $cache_data, 'sub' => $group_id2, 'type' => 'dynamic']));
}
}
}
}
}
};

121
public/swap/swap_kline_1mon.php

@ -76,6 +76,9 @@ $worker->onWorkerStart = function ($worker) {
$seconds = 2592000; //60 300 900 1800 3600 86400 604800 2592000
$symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
$airCoins = \App\Models\Klike::query()->pluck('like_coin');
$arr1 = array_collapse([$symbols,$airCoins]);
$symbols = array_values(array_unique($arr1));
foreach ($symbols as $symbol) {
$symbol = strtolower($symbol);
$symbol_list[] = $symbol . "usdt@kline_" . $period;
@ -89,7 +92,7 @@ $worker->onWorkerStart = function ($worker) {
};
$con->onMessage = function ($con, $data) {
echo $data;
// echo $data;
// $data = json_decode(gzdecode($data), true);
$data = json_decode($data, true);
@ -188,6 +191,122 @@ $worker->onWorkerStart = function ($worker) {
}
}
$airCoins = \App\Models\Klike::query()->where('like_coin',$symbol)->get()->toArray();
foreach($airCoins as $item){
if ($ch) {
if($item['like_coin'] == $symbol){
$symbolNew = $item['air_coin'];
}
// todo: 修改获取当前行情配置
$period = '1mon'; //1min 5min 15min 30min 60min 1day 1week 1mon
$now = $data['k'];
$kklinekey = 'swap:' . $symbolNew . '_kline_' . $period;
$oneminopen = json_decode(Redis::get($kklinekey), true);
if ($oneminopen['last_now'] == strtotime(date("Y-m-d H:i:00", time()))) {
$now['o'] = $oneminopen['open'];
}
$now['t'] = substr($now['t'], 0, 10);
// echo json_encode($cache_data) . "\r\n";
if($item['calculation'] == '*'){
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] * $item['percent'];
$now['c'] = $now['c'] * $item['percent'];
$now['h'] = $now['h'] * $item['percent'];
$now['l'] = $now['l'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
if($item['calculation'] == '/'){
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] / $item['percent'];
$now['c'] = $now['c'] / $item['percent'];
$now['h'] = $now['h'] / $item['percent'];
$now['l'] = $now['l'] / $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
$cache_data = [
"id" => $now['t'] * 1,
"open" => $now['o'] * 1,
"close" => $now['c'] * 1,
"low" => $now['l'] * 1,
"high" => $now['h'] * 1,
"amount" => $now['V'] * 1,
'vol' => $now['V'] * 1000,
'trade_turnover' => $now['Q'] * 1,
'count' => round($now['V'] * 100, 0),
];
// echo json_encode($cache_data) . "\r\n";
// $cache_data['time'] = time();
$kline_book_key = 'swap:' . $symbolNew . '_kline_book_' . $period;
$kline_book = Cache::store('redis')->get($kline_book_key);
// 获取风控任务
$risk_key = 'fkJson:' . $symbolNew . '/USDT';
//echo $risk_key;
$risk = json_decode(Redis::get($risk_key), true);
$minUnit = $risk['minUnit'] ?? 0;
$count = $risk['count'] ?? 0;
$enabled = $risk['enabled'] ?? 0;
$seconds = 60;
if (!blank($risk) && $enabled == 1) {
// 修改价格
$change = $minUnit * $count;
$cache_data['close'] = PriceCalculate($cache_data['close'], '+', $change, 8);
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['high'] = PriceCalculate($cache_data['high'], '+', $change, 8);
$cache_data['low'] = PriceCalculate($cache_data['low'], '+', $change, 8);
}
$cache_data['close']= floatval(number_format($cache_data['close'],$item['point'], '.', ''));
$cache_data['open'] = floatval(number_format($cache_data['open'],$item['point'], '.', ''));
$cache_data['high'] = floatval(number_format($cache_data['high'],$item['point'], '.', ''));
$cache_data['low'] = floatval(number_format($cache_data['low'],$item['point'], '.', ''));
// echo(date("Y-m-d H:i:s",$kline_book['id'])). "\r\n";
// echo $kline_book['id'];
// 1分钟基线
if (!blank($kline_book)) {
$prev_id = $cache_data['id'] - $seconds;
$prev_item = array_last($kline_book, function ($value, $key) use ($prev_id) {
return $value['id'] == $prev_id;
});
// $cache_data['open'] = $prev_item['close'];
}
// echo json_encode($cache_data) . "\r\n";
if (blank($kline_book)) {
Cache::store('redis')->put($kline_book_key, [$cache_data]);
} else {
$last_item1 = array_pop($kline_book);
if ($last_item1['id'] == $cache_data['id']) {
array_push($kline_book, $cache_data);
} else {
array_push($kline_book, $last_item1, $cache_data);
}
if (count($kline_book) > 3000) {
array_shift($kline_book);
}
Cache::store('redis')->put($kline_book_key, $kline_book);
}
Cache::store('redis')->put('swap:' . $symbolNew . '_kline_' . $period, $cache_data);
$group_id2 = 'swapKline_' . $symbolNew . '_' . $period;
//var_dump($group_id2);
//echo Gateway::getClientIdCountByGroup($group_id2);
if (Gateway::getClientIdCountByGroup($group_id2) > 0) {
// $cache_data['time'] = $cache_data['time'] - 43200;
Gateway::sendToGroup($group_id2, json_encode(['code' => 0, 'msg' => 'success', 'data' => $cache_data, 'sub' => $group_id2, 'type' => 'dynamic']));
}
}
}
}
}
};

122
public/swap/swap_kline_1week.php

@ -76,6 +76,9 @@ $worker->onWorkerStart = function ($worker) {
$seconds = 604800; //60 300 900 1800 3600 86400 604800 2592000
$symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
$airCoins = \App\Models\Klike::query()->pluck('like_coin');
$arr1 = array_collapse([$symbols,$airCoins]);
$symbols = array_values(array_unique($arr1));
foreach ($symbols as $symbol) {
$symbol = strtolower($symbol);
$symbol_list[] = $symbol . "usdt@kline_" . $period;
@ -89,7 +92,7 @@ $worker->onWorkerStart = function ($worker) {
};
$con->onMessage = function ($con, $data) {
echo $data;
// echo $data;
// $data = json_decode(gzdecode($data), true);
$data = json_decode($data, true);
@ -189,6 +192,123 @@ $worker->onWorkerStart = function ($worker) {
}
}
$airCoins = \App\Models\Klike::query()->where('like_coin',$symbol)->get()->toArray();
foreach($airCoins as $item){
if ($ch) {
if($item['like_coin'] == $symbol){
$symbolNew = $item['air_coin'];
}
// todo: 修改获取当前行情配置
$period = '1week'; //1min 5min 15min 30min 60min 1day 1week 1mon
$now = $data['k'];
$kklinekey = 'swap:' . $symbolNew . '_kline_' . $period;
$oneminopen = json_decode(Redis::get($kklinekey), true);
if ($oneminopen['last_now'] == strtotime(date("Y-m-d H:i:00", time()))) {
$now['o'] = $oneminopen['open'];
}
$now['t'] = substr($now['t'], 0, 10);
if($item['calculation'] == '*'){
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] * $item['percent'];
$now['c'] = $now['c'] * $item['percent'];
$now['h'] = $now['h'] * $item['percent'];
$now['l'] = $now['l'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
if($item['calculation'] == '/'){
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] / $item['percent'];
$now['c'] = $now['c'] / $item['percent'];
$now['h'] = $now['h'] / $item['percent'];
$now['l'] = $now['l'] / $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
// echo json_encode($cache_data) . "\r\n";
$cache_data = [
"id" => $now['t'] * 1,
"open" => $now['o'] * 1,
"close" => $now['c'] * 1,
"low" => $now['l'] * 1,
"high" => $now['h'] * 1,
"amount" => $now['V'] * 1,
'vol' => $now['V'] * 1000,
'trade_turnover' => $now['Q'] * 1,
'count' => round($now['V'] * 100, 0),
];
// echo json_encode($cache_data) . "\r\n";
// $cache_data['time'] = time();
$kline_book_key = 'swap:' . $symbolNew . '_kline_book_' . $period;
$kline_book = Cache::store('redis')->get($kline_book_key);
// 获取风控任务
$risk_key = 'fkJson:' . $symbolNew . '/USDT';
//echo $risk_key;
$risk = json_decode(Redis::get($risk_key), true);
$minUnit = $risk['minUnit'] ?? 0;
$count = $risk['count'] ?? 0;
$enabled = $risk['enabled'] ?? 0;
$seconds = 60;
if (!blank($risk) && $enabled == 1) {
// 修改价格
$change = $minUnit * $count;
$cache_data['close'] = PriceCalculate($cache_data['close'], '+', $change, 8);
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['high'] = PriceCalculate($cache_data['high'], '+', $change, 8);
$cache_data['low'] = PriceCalculate($cache_data['low'], '+', $change, 8);
}
$cache_data['close']= floatval(number_format($cache_data['close'],$item['point'], '.', ''));
$cache_data['open'] = floatval(number_format($cache_data['open'],$item['point'], '.', ''));
$cache_data['high'] = floatval(number_format($cache_data['high'],$item['point'], '.', ''));
$cache_data['low'] = floatval(number_format($cache_data['low'],$item['point'], '.', ''));
// echo(date("Y-m-d H:i:s",$kline_book['id'])). "\r\n";
// echo $kline_book['id'];
// 1分钟基线
if (!blank($kline_book)) {
$prev_id = $cache_data['id'] - $seconds;
$prev_item = array_last($kline_book, function ($value, $key) use ($prev_id) {
return $value['id'] == $prev_id;
});
// $cache_data['open'] = $prev_item['close'];
}
// echo json_encode($cache_data) . "\r\n";
if (blank($kline_book)) {
Cache::store('redis')->put($kline_book_key, [$cache_data]);
} else {
$last_item1 = array_pop($kline_book);
if ($last_item1['id'] == $cache_data['id']) {
array_push($kline_book, $cache_data);
} else {
array_push($kline_book, $last_item1, $cache_data);
}
if (count($kline_book) > 3000) {
array_shift($kline_book);
}
Cache::store('redis')->put($kline_book_key, $kline_book);
}
Cache::store('redis')->put('swap:' . $symbolNew . '_kline_' . $period, $cache_data);
$group_id2 = 'swapKline_' . $symbolNew . '_' . $period;
//var_dump($group_id2);
//echo Gateway::getClientIdCountByGroup($group_id2);
if (Gateway::getClientIdCountByGroup($group_id2) > 0) {
// $cache_data['time'] = $cache_data['time'] - 43200;
Gateway::sendToGroup($group_id2, json_encode(['code' => 0, 'msg' => 'success', 'data' => $cache_data, 'sub' => $group_id2, 'type' => 'dynamic']));
}
}
}
}
}
};

159
public/swap/swap_kline_30min.php

@ -76,6 +76,9 @@ $worker->onWorkerStart = function ($worker) {
$seconds = 1800; //60 300 900 1800 3600 86400 604800 2592000
$symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
$airCoins = \App\Models\Klike::query()->pluck('like_coin');
$arr1 = array_collapse([$symbols,$airCoins]);
$symbols = array_values(array_unique($arr1));
foreach ($symbols as $symbol) {
$symbol = strtolower($symbol);
$symbol_list[] = $symbol . "usdt@kline_" . $period;
@ -89,7 +92,7 @@ $worker->onWorkerStart = function ($worker) {
};
$con->onMessage = function ($con, $data) {
echo $data;
// echo $data;
// $data = json_decode(gzdecode($data), true);
$data = json_decode($data, true);
@ -138,16 +141,33 @@ $worker->onWorkerStart = function ($worker) {
$count = $risk['count'] ?? 0;
$enabled = $risk['enabled'] ?? 0;
$seconds = 60;
// 当前一分钟 开盘对接
if (!blank($risk) && $enabled == 1) {
// 修改价格
$change = $minUnit * $count;
$cache_data['close'] = PriceCalculate($cache_data['close'], '+', $change, 8);
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['high'] = PriceCalculate($cache_data['high'], '+', $change, 8);
$cache_data['low'] = PriceCalculate($cache_data['low'], '+', $change, 8);
// 当前一分钟 开盘对接
if(($now['t']==$risk['hold']['30min']['time'])){
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['30min']['price'];
}else{
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
}
}
if(!empty($risk['hold'])){
if (!blank($risk) && $enabled == 0 && $count != 0 && $minUnit != 0 && $now['t'] == $risk['hold']['30min']['time']) {
// $change = $minUnit * $count;
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['30min']['price'];
}
}
// echo(date("Y-m-d H:i:s",$kline_book['id'])). "\r\n";
// echo $kline_book['id'];
// 1分钟基线
if (!blank($kline_book)) {
@ -187,6 +207,137 @@ $worker->onWorkerStart = function ($worker) {
}
}
$airCoins = \App\Models\Klike::query()->where('like_coin',$symbol)->get()->toArray();
foreach($airCoins as $item){
if ($ch) {
if($item['like_coin'] == $symbol){
$symbolNew = $item['air_coin'];
}
// todo: 修改获取当前行情配置
$period = '30min'; //1min 5min 15min 30min 60min 1day 1week 1mon
$now = $data['k'];
$kklinekey = 'swap:' . $symbolNew . '_kline_' . $period;
$oneminopen = json_decode(Redis::get($kklinekey), true);
if ($oneminopen['last_now'] == strtotime(date("Y-m-d H:i:00", time()))) {
$now['o'] = $oneminopen['open'];
}
$now['t'] = substr($now['t'], 0, 10);
if($item['calculation'] == '*'){
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] * $item['percent'];
$now['c'] = $now['c'] * $item['percent'];
$now['h'] = $now['h'] * $item['percent'];
$now['l'] = $now['l'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
if($item['calculation'] == '/'){
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] / $item['percent'];
$now['c'] = $now['c'] / $item['percent'];
$now['h'] = $now['h'] / $item['percent'];
$now['l'] = $now['l'] / $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
// echo json_encode($cache_data) . "\r\n";
$cache_data = [
"id" => $now['t'] * 1,
"open" => $now['o'] * 1,
"close" => $now['c'] * 1,
"low" => $now['l'] * 1,
"high" => $now['h'] * 1,
"amount" => $now['V'] * 1,
'vol' => $now['V'] * 1000,
'trade_turnover' => $now['Q'] * 1,
'count' => round($now['V'] * 100, 0),
];
// echo json_encode($cache_data) . "\r\n";
// $cache_data['time'] = time();
$kline_book_key = 'swap:' . $symbolNew . '_kline_book_' . $period;
$kline_book = Cache::store('redis')->get($kline_book_key);
// 获取风控任务
$risk_key = 'fkJson:' . $symbolNew . '/USDT';
//echo $risk_key;
$risk = json_decode(Redis::get($risk_key), true);
$minUnit = $risk['minUnit'] ?? 0;
$count = $risk['count'] ?? 0;
$enabled = $risk['enabled'] ?? 0;
$seconds = 60;
// 当前一分钟 开盘对接
if (!blank($risk) && $enabled == 1) {
// 修改价格
$change = $minUnit * $count;
$cache_data['close'] = PriceCalculate($cache_data['close'], '+', $change, 8);
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['high'] = PriceCalculate($cache_data['high'], '+', $change, 8);
$cache_data['low'] = PriceCalculate($cache_data['low'], '+', $change, 8);
// 当前一分钟 开盘对接
if(($now['t']==$risk['hold']['30min']['time'])){
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['30min']['price'];
}else{
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
}
}
if(!empty($risk['hold'])){
if (!blank($risk) && $enabled == 0 && $count != 0 && $minUnit != 0 && $now['t'] == $risk['hold']['30min']['time']) {
// $change = $minUnit * $count;
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['30min']['price'];
}
}
$cache_data['close'] = floatval(number_format($cache_data['close'],$item['point'], '.', ''));
$cache_data['open'] = floatval(number_format($cache_data['open'],$item['point'], '.', ''));
$cache_data['high'] = floatval(number_format($cache_data['high'],$item['point'], '.', ''));
$cache_data['low'] = floatval(number_format($cache_data['low'],$item['point'], '.', ''));
// echo(date("Y-m-d H:i:s",$kline_book['id'])). "\r\n";
// echo $kline_book['id'];
// 1分钟基线
if (!blank($kline_book)) {
$prev_id = $cache_data['id'] - $seconds;
$prev_item = array_last($kline_book, function ($value, $key) use ($prev_id) {
return $value['id'] == $prev_id;
});
// $cache_data['open'] = $prev_item['close'];
}
// echo json_encode($cache_data) . "\r\n";
if (blank($kline_book)) {
Cache::store('redis')->put($kline_book_key, [$cache_data]);
} else {
$last_item1 = array_pop($kline_book);
if ($last_item1['id'] == $cache_data['id']) {
array_push($kline_book, $cache_data);
} else {
array_push($kline_book, $last_item1, $cache_data);
}
if (count($kline_book) > 3000) {
array_shift($kline_book);
}
Cache::store('redis')->put($kline_book_key, $kline_book);
}
Cache::store('redis')->put('swap:' . $symbolNew . '_kline_' . $period, $cache_data);
$group_id2 = 'swapKline_' . $symbolNew . '_' . $period;
//var_dump($group_id2);
//echo Gateway::getClientIdCountByGroup($group_id2);
if (Gateway::getClientIdCountByGroup($group_id2) > 0) {
// $cache_data['time'] = $cache_data['time'] - 43200;
Gateway::sendToGroup($group_id2, json_encode(['code' => 0, 'msg' => 'success', 'data' => $cache_data, 'sub' => $group_id2, 'type' => 'dynamic']));
}
}
}
}
}
};

168
public/swap/swap_kline_4hour.php

@ -26,6 +26,9 @@ $worker->onWorkerStart = function($worker){
$con->onConnect = function($con) {
//所有交易对
$symbols = \App\Models\ContractPair::query()->where('status',1)->pluck('symbol');
$airCoins = \App\Models\Klike::query()->pluck('like_coin');
$arr1 = array_collapse([$symbols,$airCoins]);
$symbols = array_values(array_unique($arr1));
$period = '4hour';
$seconds = 14400;
foreach ($symbols as $symbol){
@ -178,6 +181,171 @@ $worker->onWorkerStart = function($worker){
}
}
$airCoins = \App\Models\Klike::query()->where('like_coin',$symbol)->get()->toArray();
foreach($airCoins as $item){
if(isset($data['rep'])){
$ch = $data['rep'];
$pattern_kline = '/^market\.(.*?)\.kline\.([\s\S]*)/'; //Kline
if (preg_match($pattern_kline, $ch, $match_kline)){
$symbol = $match_kline[1];
$symbol = str_before($symbol,'-');
if($item['like_coin'] == $symbol){
$symbolNew = $item['air_coin'];
}
$period = $match_kline[2];
$cache_data = $data['data'];
$kline_book_key = 'swap:' . $symbolNew . '_kline_book_' . $period;
Cache::store('redis')->put($kline_book_key, $cache_data);
}
}elseif(isset($data['ch'])){
$ch = $data['ch'];
$pattern_kline = '/^market\.(.*?)\.kline\.([\s\S]*)/'; //Kline
if (preg_match($pattern_kline, $ch, $match_kline)){
$symbol = $match_kline[1];
$symbol = str_before($symbol,'-');
if($item['like_coin'] == $symbol){
$symbolNew = $item['air_coin'];
}
$period = $match_kline[2];
$cache_data = $data['tick'];
$cache_data['time'] = time();
$kline_book_key = 'swap:' . $symbolNew . '_kline_book_' . $period;
$kline_book = Cache::store('redis')->get($kline_book_key);
// 获取风控任务
$risk_key = 'fkJson:' . $symbolNew . '/USDT';
$risk = json_decode( Redis::get($risk_key) ,true);
$minUnit = $risk['minUnit'] ?? 0;
$count = $risk['count'] ?? 0;
$enabled = $risk['enabled'] ?? 0;
$seconds = 14400;
if($item['calculation'] == '*'){
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$cache_data['close'] = $cache_data['close'] * $item['percent'];
$cache_data['open'] = $cache_data['open'] * $item['percent'];
$cache_data['high'] = $cache_data['high'] * $item['percent'];
$cache_data['low'] = $cache_data['low'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
if($item['calculation'] == '/'){
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$cache_data['close'] = $cache_data['close'] / $item['percent'];
$cache_data['open'] = $cache_data['open'] / $item['percent'];
$cache_data['high'] = $cache_data['high'] / $item['percent'];
$cache_data['low'] = $cache_data['low'] / $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
if(!blank($risk) && $enabled == 1){
// 修改价格
$change = $minUnit * $count;
$cache_data['close'] = PriceCalculate($cache_data['close'] ,'+', $change,8);
$cache_data['open'] = PriceCalculate($cache_data['open'] ,'+', $change,8);
$cache_data['high'] = PriceCalculate($cache_data['high'] ,'+', $change,8);
$cache_data['low'] = PriceCalculate($cache_data['low'] ,'+', $change,8);
}
$cache_data['close']= number_format($cache_data['close'],$item['point'], '.', '');
$cache_data['open'] = number_format($cache_data['open'],$item['point'], '.', '');
$cache_data['high'] = number_format($cache_data['high'],$item['point'], '.', '');
$cache_data['low'] = number_format($cache_data['low'],$item['point'], '.', '');
if($period == '1min'){
// 1分钟基线
if(!blank($kline_book)){
$prev_id = $cache_data['id'] - $seconds;
$prev_item = array_last($kline_book,function ($value,$key)use($prev_id){
return $value['id'] == $prev_id;
});
$cache_data['open'] = $prev_item['close'];
}
if(blank($kline_book)){
Cache::store('redis')->put($kline_book_key,[$cache_data]);
}else{
$last_item1 = array_pop($kline_book);
if($last_item1['id'] == $cache_data['id']){
array_push($kline_book,$cache_data);
}else{
array_push($kline_book,$last_item1,$cache_data);
}
if(count($kline_book) > 3000){
array_shift($kline_book);
}
Cache::store('redis')->put($kline_book_key,$kline_book);
}
}else{
// 其他长周期K线都以前一周期作为参考 比如5minK线以1min为基础
$periodMap = [
'5min' => ['period'=>'1min','seconds'=>60],
'15min' => ['period'=>'5min','seconds'=>300],
'30min' => ['period'=>'5min','seconds'=>300],
'60min' => ['period'=>'5min','seconds'=>300],
'1day' => ['period'=>'60min','seconds'=>3600],
'1week' => ['period'=>'1day','seconds'=>86400],
'1mon' => ['period'=>'1day','seconds'=>86400],
];
$map = $periodMap[$period] ?? null;
$kline_base_book = Cache::store('redis')->get('swap:' . $symbolNew . '_kline_book_' . $map['period']);
if(!blank($kline_base_book)){
// 以5min周期为例 这里一次性取出1min周期前后10个
$first_item_id = $cache_data['id'];
$last_item_id = $cache_data['id'] + $seconds - $map['seconds'];
$items1 = array_where($kline_base_book,function ($value,$key)use($first_item_id,$last_item_id){
return $value['id'] >= $first_item_id && $value['id'] <= $last_item_id;
});
if(!blank($items1)){
$cache_data['open'] = array_first($items1)['open'] ?? $cache_data['open'];
$cache_data['close'] = array_last($items1)['close'] ?? $cache_data['close'];
$cache_data['high'] = max(array_pluck($items1,'high')) ?? $cache_data['high'];
$cache_data['low'] = min(array_pluck($items1,'low')) ?? $cache_data['low'];
}
if(blank($kline_book)){
Cache::store('redis')->put($kline_book_key,[$cache_data]);
}else{
$last_item1 = array_pop($kline_book);
if($last_item1['id'] == $cache_data['id']){
array_push($kline_book,$cache_data);
}else{
$update_last_item1 = $last_item1;
// 有新的周期K线生成 此时尝试更新$last_item1
$first_item_id2 = $cache_data['id'] - $seconds;
$last_item_id2 = $cache_data['id'] - $map['seconds'];
$items2 = array_where($kline_base_book,function ($value,$key)use($first_item_id2,$last_item_id2){
return $value['id'] >= $first_item_id2 && $value['id'] <= $last_item_id2;
});
if(!blank($items2)){
$update_last_item1['open'] = array_first($items2)['open'] ?? $update_last_item1['open'];
$update_last_item1['close'] = array_last($items2)['close'] ?? $update_last_item1['close'];
$update_last_item1['high'] = max(array_pluck($items2,'high')) ?? $update_last_item1['high'];
$update_last_item1['low'] = min(array_pluck($items2,'low')) ?? $update_last_item1['low'];
}
array_push($kline_book,$update_last_item1,$cache_data);
}
if(count($kline_book) > 3000){
array_shift($kline_book);
}
Cache::store('redis')->put($kline_book_key,$kline_book);
}
}
}
Cache::store('redis')->put('swap:' . $symbolNew . '_kline_' . $period,$cache_data);
$group_id2 = 'swapKline_' . $symbolNew . '_' . $period;
if(Gateway::getClientIdCountByGroup($group_id2) > 0){
Gateway::sendToGroup($group_id2, json_encode(['code'=>0,'msg'=>'success','data'=>$cache_data,'sub'=>$group_id2,'type'=>'dynamic']));
}
}
}
}
}
};

211
public/swap/swap_kline_5min.php

@ -73,9 +73,12 @@ $worker->onWorkerStart = function ($worker) {
// $symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
// todo: 修改获取当前行情配置
$period = '5m'; //3m-5m-15m-30m-1h-2h-4h-6h-8h-12h-1d-3d-1w-1M
$seconds = 300; //60 300 900 1800 3600 86400 604800 2592000
$seconds = 300; //60 300 900 1800 3600 86400 604800 2592000
$symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
$symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
$airCoins = \App\Models\Klike::query()->pluck('like_coin');
$arr1 = array_collapse([$symbols, $airCoins]);
$symbols = array_values(array_unique($arr1));
foreach ($symbols as $symbol) {
$symbol = strtolower($symbol);
$symbol_list[] = $symbol . "usdt@kline_" . $period;
@ -89,7 +92,7 @@ $worker->onWorkerStart = function ($worker) {
};
$con->onMessage = function ($con, $data) {
echo $data;
// echo $data;
// $data = json_decode(gzdecode($data), true);
$data = json_decode($data, true);
@ -104,25 +107,25 @@ $worker->onWorkerStart = function ($worker) {
// if ($ch) {
if ($ch) {
// todo: 修改获取当前行情配置
$period = '5min'; //1min 5min 15min 30min 60min 1day 1week 1mon
$now = $data['k'];
$kklinekey = 'swap:' . $symbol . '_kline_' . $period;
$period = '5min'; //1min 5min 15min 30min 60min 1day 1week 1mon
$now = $data['k'];
$kklinekey = 'swap:' . $symbol . '_kline_' . $period;
$oneminopen = json_decode(Redis::get($kklinekey), true);
if($oneminopen['last_now'] == strtotime(date("Y-m-d H:i:00", time()))){
if ($oneminopen['last_now'] == strtotime(date("Y-m-d H:i:00", time()))) {
$now['o'] = $oneminopen['open'];
}
$now['t']=substr($now['t'],0,10);
$now['t'] = substr($now['t'], 0, 10);
// echo json_encode($cache_data) . "\r\n";
$cache_data = [
"id" => $now['t']*1,
"open" => $now['o']*1,
"close" => $now['c']*1,
"low" => $now['l']*1,
"high" => $now['h']*1,
"amount" => $now['V']*1,
'vol' => $now['V']*1000,
'trade_turnover' => $now['Q']*1,
'count' => round($now['V']*100,0),
$cache_data = [
"id" => $now['t'] * 1,
"open" => $now['o'] * 1,
"close" => $now['c'] * 1,
"low" => $now['l'] * 1,
"high" => $now['h'] * 1,
"amount" => $now['V'] * 1,
'vol' => $now['V'] * 1000,
'trade_turnover' => $now['Q'] * 1,
'count' => round($now['V'] * 100, 0),
];
// echo json_encode($cache_data) . "\r\n";
// $cache_data['time'] = time();
@ -138,23 +141,161 @@ $worker->onWorkerStart = function ($worker) {
$count = $risk['count'] ?? 0;
$enabled = $risk['enabled'] ?? 0;
$seconds = 60;
// 当前一分钟 开盘对接
if (!blank($risk) && $enabled == 1) {
// 修改价格
$change = $minUnit * $count;
$cache_data['close'] = PriceCalculate($cache_data['close'], '+', $change, 8);
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['high'] = PriceCalculate($cache_data['high'], '+', $change, 8);
$cache_data['low'] = PriceCalculate($cache_data['low'], '+', $change, 8);
// 当前一分钟 开盘对接
if(($now['t']==$risk['hold']['5min']['time'])){
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['5min']['price'];
}else{
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
}
}
if(!empty($risk['hold'])){
if (!blank($risk) && $enabled == 0 && $count != 0 && $minUnit != 0 && $now['t'] == $risk['hold']['5min']['time']) {
// $change = $minUnit * $count;
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['5min']['price'];
}
}
// 1分钟基线
if (!blank($kline_book)) {
$prev_id = $cache_data['id'] - $seconds;
$prev_item = array_last($kline_book, function ($value, $key) use ($prev_id) {
return $value['id'] == $prev_id;
});
// $cache_data['open'] = $prev_item['close'];
}
// echo json_encode($cache_data) . "\r\n";
if (blank($kline_book)) {
Cache::store('redis')->put($kline_book_key, [$cache_data]);
} else {
$last_item1 = array_pop($kline_book);
if ($last_item1['id'] == $cache_data['id']) {
array_push($kline_book, $cache_data);
} else {
array_push($kline_book, $last_item1, $cache_data);
}
if (count($kline_book) > 3000) {
array_shift($kline_book);
}
Cache::store('redis')->put($kline_book_key, $kline_book);
}
Cache::store('redis')->put('swap:' . $symbol . '_kline_' . $period, $cache_data);
$group_id2 = 'swapKline_' . $symbol . '_' . $period;
//var_dump($group_id2);
//echo Gateway::getClientIdCountByGroup($group_id2);
if (Gateway::getClientIdCountByGroup($group_id2) > 0) {
// $cache_data['time'] = $cache_data['time'] - 43200;
Gateway::sendToGroup($group_id2, json_encode(['code' => 0, 'msg' => 'success', 'data' => $cache_data, 'sub' => $group_id2, 'type' => 'dynamic']));
}
// var_dump($cache_data);
// echo(date("Y-m-d H:i:s",$kline_book['id'])). "\r\n";
// echo $kline_book['id'];
}
$airCoins = \App\Models\Klike::query()->where('like_coin', $symbol)->get()->toArray();
foreach ($airCoins as $item) {
if ($ch) {
if ($item['like_coin'] == $symbol) {
$symbolNew = $item['air_coin'];
}
// todo: 修改获取当前行情配置
$period = '5min'; //1min 5min 15min 30min 60min 1day 1week 1mon
$now = $data['k'];
$kklinekey = 'swap:' . $symbolNew . '_kline_' . $period;
$oneminopen = json_decode(Redis::get($kklinekey), true);
if ($oneminopen['last_now'] == strtotime(date("Y-m-d H:i:00", time()))) {
$now['o'] = $oneminopen['open'];
}
$now['t'] = substr($now['t'], 0, 10);
if ($item['calculation'] == '*') {
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] * $item['percent'];
$now['c'] = $now['c'] * $item['percent'];
$now['h'] = $now['h'] * $item['percent'];
$now['l'] = $now['l'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
if ($item['calculation'] == '/') {
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] / $item['percent'];
$now['c'] = $now['c'] / $item['percent'];
$now['h'] = $now['h'] / $item['percent'];
$now['l'] = $now['l'] / $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
// echo json_encode($cache_data) . "\r\n";
$cache_data = [
"id" => $now['t'] * 1,
"open" => $now['o'] * 1,
"close" => $now['c'] * 1,
"low" => $now['l'] * 1,
"high" => $now['h'] * 1,
"amount" => $now['V'] * 1,
'vol' => $now['V'] * 1000,
'trade_turnover' => $now['Q'] * 1,
'count' => round($now['V'] * 100, 0),
];
// \Log::info(json_encode($cache_data).'------'.$symbolNew);
// echo json_encode($cache_data) . "\r\n";
// $cache_data['time'] = time();
$kline_book_key = 'swap:' . $symbolNew . '_kline_book_' . $period;
$kline_book = Cache::store('redis')->get($kline_book_key);
// 获取风控任务
$risk_key = 'fkJson:' . $symbolNew . '/USDT';
//echo $risk_key;
$risk = json_decode(Redis::get($risk_key), true);
$minUnit = $risk['minUnit'] ?? 0;
$count = $risk['count'] ?? 0;
$enabled = $risk['enabled'] ?? 0;
$seconds = 60;
// 当前一分钟 开盘对接
if (!blank($risk) && $enabled == 1) {
// 修改价格
$change = $minUnit * $count;
$cache_data['close'] = PriceCalculate($cache_data['close'], '+', $change, 8);
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['high'] = PriceCalculate($cache_data['high'], '+', $change, 8);
$cache_data['low'] = PriceCalculate($cache_data['low'], '+', $change, 8);
// 当前一分钟 开盘对接
if(($now['t']==$risk['hold']['5min']['time'])){
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['5min']['price'];
}else{
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
}
}
if(!empty($risk['hold'])){
if (!blank($risk) && $enabled == 0 && $count != 0 && $minUnit != 0 && $now['t'] == $risk['hold']['5min']['time']) {
// $change = $minUnit * $count;
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['5min']['price'];
}
}
// 1分钟基线
if (!blank($kline_book)) {
$prev_id = $cache_data['id'] - $seconds;
$prev_item = array_last($kline_book, function ($value, $key) use ($prev_id) {
$prev_id = $cache_data['id'] - $seconds;
$prev_item = array_last($kline_book, function ($value, $key) use ($prev_id) {
return $value['id'] == $prev_id;
});
// $cache_data['open'] = $prev_item['close'];
@ -175,18 +316,22 @@ $worker->onWorkerStart = function ($worker) {
}
Cache::store('redis')->put($kline_book_key, $kline_book);
}
$cache_data['close'] = floatval(number_format($cache_data['close'], $item['point'], '.', ''));
$cache_data['open'] = floatval(number_format($cache_data['open'], $item['point'], '.', ''));
$cache_data['high'] = floatval(number_format($cache_data['high'], $item['point'], '.', ''));
$cache_data['low'] = floatval(number_format($cache_data['low'], $item['point'], '.', ''));
Cache::store('redis')->put('swap:' . $symbolNew . '_kline_' . $period, $cache_data);
$group_id2 = 'swapKline_' . $symbolNew . '_' . $period;
//var_dump($group_id2);
//echo Gateway::getClientIdCountByGroup($group_id2);
if (Gateway::getClientIdCountByGroup($group_id2) > 0) {
// $cache_data['time'] = $cache_data['time'] - 43200;
Gateway::sendToGroup($group_id2, json_encode(['code' => 0, 'msg' => 'success', 'data' => $cache_data, 'sub' => $group_id2, 'type' => 'dynamic']));
Cache::store('redis')->put('swap:' . $symbol . '_kline_' . $period, $cache_data);
$group_id2 = 'swapKline_' . $symbol . '_' . $period;
//var_dump($group_id2);
//echo Gateway::getClientIdCountByGroup($group_id2);
if (Gateway::getClientIdCountByGroup($group_id2) > 0) {
// $cache_data['time'] = $cache_data['time'] - 43200;
Gateway::sendToGroup($group_id2, json_encode(['code' => 0, 'msg' => 'success', 'data' => $cache_data, 'sub' => $group_id2, 'type' => 'dynamic']));
}
}
}
}
}

146
public/swap/swap_kline_60min.php

@ -76,6 +76,9 @@ $worker->onWorkerStart = function ($worker) {
$seconds = 3600; //60 300 900 1800 3600 86400 604800 2592000
$symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
$airCoins = \App\Models\Klike::query()->pluck('like_coin');
$arr1 = array_collapse([$symbols,$airCoins]);
$symbols = array_values(array_unique($arr1));
foreach ($symbols as $symbol) {
$symbol = strtolower($symbol);
$symbol_list[] = $symbol . "usdt@kline_" . $period;
@ -89,7 +92,7 @@ $worker->onWorkerStart = function ($worker) {
};
$con->onMessage = function ($con, $data) {
echo $data;
// echo $data;
// $data = json_decode(gzdecode($data), true);
$data = json_decode($data, true);
@ -142,12 +145,22 @@ $worker->onWorkerStart = function ($worker) {
// 修改价格
$change = $minUnit * $count;
$cache_data['close'] = PriceCalculate($cache_data['close'], '+', $change, 8);
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['high'] = PriceCalculate($cache_data['high'], '+', $change, 8);
$cache_data['low'] = PriceCalculate($cache_data['low'], '+', $change, 8);
// 当前一分钟 开盘对接
if(($now['t']!=$risk['hold']['60min']['time'])){
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['60min']['price'];
}
}
if(!empty($risk['hold'])) {
if (!blank($risk) && $enabled == 0 && $count != 0 && $minUnit != 0 && $now['t'] == $risk['hold']['60min']['time']) {
// $change = $minUnit * $count;
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['60min']['price'];
}
}
// echo(date("Y-m-d H:i:s",$kline_book['id'])). "\r\n";
// echo $kline_book['id'];
// 1分钟基线
if (!blank($kline_book)) {
@ -187,6 +200,131 @@ $worker->onWorkerStart = function ($worker) {
}
}
$airCoins = \App\Models\Klike::query()->where('like_coin',$symbol)->get()->toArray();
foreach($airCoins as $item){
if ($ch) {
if($item['like_coin'] == $symbol){
$symbolNew = $item['air_coin'];
}
// todo: 修改获取当前行情配置
$period = '60min'; //1min 5min 15min 30min 60min 1day 1week 1mon
$now = $data['k'];
$kklinekey = 'swap:' . $symbolNew . '_kline_' . $period;
$oneminopen = json_decode(Redis::get($kklinekey), true);
if ($oneminopen['last_now'] == strtotime(date("Y-m-d H:i:00", time()))) {
$now['o'] = $oneminopen['open'];
}
$now['t'] = substr($now['t'], 0, 10);
if($item['calculation'] == '*'){
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] * $item['percent'];
$now['c'] = $now['c'] * $item['percent'];
$now['h'] = $now['h'] * $item['percent'];
$now['l'] = $now['l'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
if($item['calculation'] == '/'){
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$now['o'] = $now['o'] / $item['percent'];
$now['c'] = $now['c'] / $item['percent'];
$now['h'] = $now['h'] / $item['percent'];
$now['l'] = $now['l'] / $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
// echo json_encode($cache_data) . "\r\n";
$cache_data = [
"id" => $now['t'] * 1,
"open" => $now['o'] * 1,
"close" => $now['c'] * 1,
"low" => $now['l'] * 1,
"high" => $now['h'] * 1,
"amount" => $now['V'] * 1,
'vol' => $now['V'] * 1000,
'trade_turnover' => $now['Q'] * 1,
'count' => round($now['V'] * 100, 0),
];
// echo json_encode($cache_data) . "\r\n";
// $cache_data['time'] = time();
$kline_book_key = 'swap:' . $symbolNew . '_kline_book_' . $period;
$kline_book = Cache::store('redis')->get($kline_book_key);
// 获取风控任务
$risk_key = 'fkJson:' . $symbolNew . '/USDT';
//echo $risk_key;
$risk = json_decode(Redis::get($risk_key), true);
$minUnit = $risk['minUnit'] ?? 0;
$count = $risk['count'] ?? 0;
$enabled = $risk['enabled'] ?? 0;
$seconds = 60;
if (!blank($risk) && $enabled == 1) {
// 修改价格
$change = $minUnit * $count;
$cache_data['close'] = PriceCalculate($cache_data['close'], '+', $change, 8);
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['high'] = PriceCalculate($cache_data['high'], '+', $change, 8);
$cache_data['low'] = PriceCalculate($cache_data['low'], '+', $change, 8);
// 当前一分钟 开盘对接
if(($now['t']!=$risk['hold']['60min']['time'])){
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['60min']['price'];
}
}
if(!empty($risk['hold'])) {
if (!blank($risk) && $enabled == 0 && $count != 0 && $minUnit != 0 && $now['t'] == $risk['hold']['60min']['time']) {
// $change = $minUnit * $count;
// $cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['open'] = $risk['hold']['60min']['price'];
}
}
$cache_data['close']= floatval(number_format($cache_data['close'],$item['point'], '.', ''));
$cache_data['open'] = floatval(number_format($cache_data['open'],$item['point'], '.', ''));
$cache_data['high'] = floatval(number_format($cache_data['high'],$item['point'], '.', ''));
$cache_data['low'] = floatval(number_format($cache_data['low'],$item['point'], '.', ''));
// echo(date("Y-m-d H:i:s",$kline_book['id'])). "\r\n";
// echo $kline_book['id'];
// 1分钟基线
if (!blank($kline_book)) {
$prev_id = $cache_data['id'] - $seconds;
$prev_item = array_last($kline_book, function ($value, $key) use ($prev_id) {
return $value['id'] == $prev_id;
});
// $cache_data['open'] = $prev_item['close'];
}
// echo json_encode($cache_data) . "\r\n";
if (blank($kline_book)) {
Cache::store('redis')->put($kline_book_key, [$cache_data]);
} else {
$last_item1 = array_pop($kline_book);
if ($last_item1['id'] == $cache_data['id']) {
array_push($kline_book, $cache_data);
} else {
array_push($kline_book, $last_item1, $cache_data);
}
if (count($kline_book) > 3000) {
array_shift($kline_book);
}
Cache::store('redis')->put($kline_book_key, $kline_book);
}
Cache::store('redis')->put('swap:' . $symbolNew . '_kline_' . $period, $cache_data);
$group_id2 = 'swapKline_' . $symbolNew . '_' . $period;
//var_dump($group_id2);
//echo Gateway::getClientIdCountByGroup($group_id2);
if (Gateway::getClientIdCountByGroup($group_id2) > 0) {
// $cache_data['time'] = $cache_data['time'] - 43200;
Gateway::sendToGroup($group_id2, json_encode(['code' => 0, 'msg' => 'success', 'data' => $cache_data, 'sub' => $group_id2, 'type' => 'dynamic']));
}
}
}
}
}
};

4
public/swap/swap_kline_repair.php

@ -68,14 +68,14 @@ $worker->onWorkerStart = function ($worker) {
];
// $msg1 = ["method" => "klines", "params" => $symbol_list, "id" => intval(rand(100000, 999999) . time())];
$send = json_encode($msg1);
echo $send;
// echo $send;
$con->send($send);
};
$con->onMessage = function ($con, $data) {
echo $data;
// echo $data;
// $data = json_decode(gzdecode($data), true);
$datajson = $data;
$data = json_decode($data, true);

100
public/swap/swap_market.php

@ -25,13 +25,17 @@ $worker->onWorkerStart = function ($worker) {
$con->onConnect = function ($con) {
//所有交易对
$symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
$airCoins = \App\Models\Klike::query()->pluck('like_coin');
$arr1 = array_collapse([$symbols,$airCoins]);
$symbols = array_values(array_unique($arr1));
// \Log::info(json_encode($symbols));
foreach ($symbols as $symbol) {
$symbol = strtolower($symbol);
$symbol_list[] = $symbol . "usdt@ticker";
}
$msg1 = ["method" => "SUBSCRIBE", "params" => $symbol_list, "id" => intval(rand(100000, 999999) . time())];
$send = json_encode($msg1);
echo $send;
// echo $send;
$con->send($send);
};
@ -100,6 +104,100 @@ $worker->onWorkerStart = function ($worker) {
$key = 'swap:' . $symbol . '_detail';
Cache::store('redis')->put($key, $cache_data);
Cache::store('redis')->put($key.'_new', $cache_data);
}
}
$airCoins = \App\Models\Klike::query()->where('like_coin',$symbol)->get()->toArray();
// \Log::info(json_encode($airCoins));
foreach($airCoins as $item){
if($item['like_coin'] == $symbol){
$symbolNew = $item['air_coin'];
// \Log::info($symbolNew);
if($item['calculation'] == '*'){
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$data['o'] = $data['o'] * $item['percent'];
$data['c'] = $data['c'] * $item['percent'];
$data['h'] = $data['h'] * $item['percent'];
$data['l'] = $data['l'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
if($item['calculation'] == '/'){
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$data['o'] = $data['o'] / $item['percent'];
$data['c'] = $data['c'] / $item['percent'];
$data['h'] = $data['h'] / $item['percent'];
$data['l'] = $data['l'] / $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
// $data['o'] = $data['o'] * $item['percent'];
}
}
if ($symbolNew) {
if ($data['e'] != '24hrMiniTicker') {
//市场概况
$cache_data = [
"id" => $data['E'],
"mrid" => $data['E'],
"open" => $data['o'],
"close" => $data['c'],
"high" => $data['h'],
"low" => $data['l'],
"amount" => $data['q'],
'vol' => $data['v'],
'trade_turnover' => $data['F'],
'count' => $data['n'],
'increase' => $data['p'],
'increaseStr' => $data['P']
];
// \Log::info(json_encode($cache_data).'-----aaaaaaa');
// 获取风控任务
$risk_key = 'fkJson:' . $symbolNew . '/USDT';
$risk = json_decode(Redis::get($risk_key), true);
$minUnit = $risk['minUnit'] ?? 0;
$count = $risk['count'] ?? 0;
$enabled = $risk['enabled'] ?? 0;
if (!blank($risk) && $enabled == 1) {
$change = $minUnit * $count;
$cache_data['close'] = PriceCalculate($cache_data['close'], '+', $change, 8);
$cache_data['open'] = PriceCalculate($cache_data['open'], '+', $change, 8);
$cache_data['high'] = PriceCalculate($cache_data['high'], '+', $change, 8);
$cache_data['low'] = PriceCalculate($cache_data['low'], '+', $change, 8);
}
if (isset($cache_data['open']) && $cache_data['open'] != 0) {
// 获取1dayK线 计算$increase
$day_kline = Cache::store('redis')->get('swap:' . $symbolNew . '_kline_' . '1day');
if (blank($day_kline)) {
$increase = PriceCalculate(($cache_data['close'] - $cache_data['open']), '/', $cache_data['open'], 4);
} else {
// \Log::info('rrrrrrrrrrrrrrrr');
$increase = PriceCalculate(($cache_data['close'] - $day_kline['open']), '/', $day_kline['open'], 4);
}
} else {
$increase = 0;
}
// \Log::info('aaaaaaaaaaa'.$cache_data['close'].'wwwwwwwwwww'.$day_kline['open']);
$cache_data['close'] = number_format($cache_data['close'],$item['point'], '.', '');
$cache_data['open'] = number_format($cache_data['open'],$item['point'], '.', '');
$cache_data['high'] = number_format($cache_data['high'],$item['point'], '.', '');
$cache_data['low'] = number_format($cache_data['low'],$item['point'], '.', '');
$cache_data['increase'] = $increase;
$flag = $increase >= 0 ? '+' : '';
$cache_data['increaseStr'] = $increase == 0 ? '+0.00%' : $flag . $increase * 100 . '%';
$key = 'swap:' . $symbolNew . '_detail';
Cache::store('redis')->put($key, $cache_data);
Cache::store('redis')->put($key.'_new', $cache_data);
}
}
}
}

2
public/swap/swap_start.sh

@ -1,2 +1,2 @@
#!/bin/sh
php swap_depth.php start & php swap_trade.php start & php swap_market.php start & php swap_kline_1min.php start & php swap_kline_5min.php start & php swap_kline_15min.php start & php swap_kline_30min.php start & php swap_kline_60min.php start & php swap_kline_4hour.php start & php swap_kline_1day.php start & php swap_kline_1week.php start & php swap_kline_1mon.php start
php swap_depth.php start & php swap_trade.php start & php swap_market.php start & php swap_kline_1min.php start & php swap_kline_5min.php start & php swap_kline_15min.php start & php swap_kline_30min.php start & php swap_kline_60min.php start & php swap_kline_1day.php start & php swap_kline_1week.php start & php swap_kline_1mon.php start

51
public/swap/swap_trade.php

@ -45,6 +45,9 @@ $worker->onWorkerStart = function ($worker) {
$con->onConnect = function ($con) {
//所有交易对
$symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol');
$airCoins = \App\Models\Klike::query()->pluck('like_coin');
$arr1 = array_collapse([$symbols,$airCoins]);
$symbols = array_values(array_unique($arr1));
$msg1 = null;
foreach ($symbols as $symbol) {
// $symbol = $symbol . '-USD';
@ -62,7 +65,7 @@ $worker->onWorkerStart = function ($worker) {
$msg1 = ["method" => "SUBSCRIBE", "params" => $symbol_list, "id" => intval(rand(100000, 999999) . time())];
$send = json_encode($msg1);
echo $send;
// echo $send;
$con->send($send);
};
@ -145,6 +148,52 @@ $worker->onWorkerStart = function ($worker) {
if (Gateway::getClientIdCountByGroup($group_id2) > 0) {
Gateway::sendToGroup($group_id2, json_encode(['code' => 0, 'msg' => 'success', 'data' => $cache_data, 'sub' => $group_id2, 'type' => 'dynamic']));
}
$airCoins = \App\Models\Klike::query()->where('like_coin',$symbol)->get()->toArray();
foreach($airCoins as $item){
if($item['like_coin'] == $symbol){
// \Log::info($symbol.$cache_data['price'].$item['calculation'].$item['percent']);
$symbolNew = $item['air_coin'];
if($item['calculation'] == '*'){
// $cache_data['price'] = bcmul($cache_data['price'],$item['percent']);
$cache_data['price'] = $cache_data['price'] * $item['percent'];
}
if($item['calculation'] == '/'){
// $cache_data['price'] = bcdiv($cache_data['price'],$item['percent']);
$cache_data['price'] = $cache_data['price'] / $item['percent'];
}
$cache_data['price'] = number_format($cache_data['price'],$item['point'], '.', '');
// 去除逗号
$cache_data['price'] = str_replace(',','',$cache_data['price']);
}
$cache_data['contract_code'] = $symbolNew.'-USDT';
// \Log::info(json_encode($cache_data).'-----b');
//成交价格
$newwwwproc = 'swap:trade_nowprice_'.$symbolNew;
$now_pric = Cache::store('redis')->get($newwwwproc);
$cache_data['price']=$now_pric['price'];
$trade_detail_key = 'swap:trade_detail_' . $symbolNew;
Cache::store('redis')->put($trade_detail_key, $cache_data);
//缓存历史数据book
$trade_list_key = 'swap:tradeList_' . $symbolNew;
$trade_list = Cache::store('redis')->get($trade_list_key);
if (blank($trade_list)) {
Cache::store('redis')->put($trade_list_key, [$cache_data]);
} else {
array_push($trade_list, $cache_data);
if (count($trade_list) > 30) {
array_shift($trade_list);
}
Cache::store('redis')->put($trade_list_key, $trade_list);
}
$group_id2 = 'swapTradeList_' . $symbolNew; //最近成交明细
if (Gateway::getClientIdCountByGroup($group_id2) > 0) {
Gateway::sendToGroup($group_id2, json_encode(['code' => 0, 'msg' => 'success', 'data' => $cache_data, 'sub' => $group_id2, 'type' => 'dynamic']));
}
}
}
}
}

49
resources/views/admin/klike.blade.php

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="UTF-8">
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>风控</title>
<link href="../vendors/dcat-admin/adminlte/index.min.css" rel="stylesheet">
<script src="../vendors/dcat-admin/adminlte/echarts.min.js"></script>
<script src="..//vendors/dcat-admin/adminlte/vue.min.js"></script>
<script src="..//vendors/dcat-admin/adminlte/index.js"></script>
<script src="..//vendors/dcat-admin/adminlte/axios.min.js"></script>
<style>
body {
background: #4CA1AF;
/* fallback for old browsers */
background: -webkit-linear-gradient(to right, #C4E0E5, #4CA1AF);
/* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #C4E0E5, #4CA1AF);
/* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}
.chart1 {
height: 400px;
border: 1px solid #996;
}
.chart2{
height: 400px;
border: 1px solid #996;
}
.form {
margin: 20px 0;
}
.s-input {
width: 100px;
}
.kline-button{
padding-top: 5px;
}
</style>
</head>
<body>
2222
</body>
</html>

19
resources/views/admin/kline.blade.php

@ -51,16 +51,13 @@
<el-select name="" @change="changeSymbol" placeholder="请选择币种" v-model="coin" >
<el-option :value="1" label="AAAAA/USDT"></el-option>
<el-option :value="2" label="BGV/USDT"></el-option>
<el-option :value="3" label="KYE/USDT"></el-option>
<el-option :value="4" label="SHIP/USDT"></el-option>
<el-option :value="5" label="RVM/USDT"></el-option>
<el-option :value="6" label="MPOB/USDT"></el-option>
<el-option :value="7" label="STE/USDT"></el-option>
<el-option :value="8" label="RUTE/USDT"></el-option>
<el-option :value="9" label="NEC/USDT"></el-option>
<el-option :value="10" label="TOMB/USDT"></el-option>
<el-option :value="11" label="AEEF/USDT"></el-option>
<el-option :value="2" label="SWTS/USDT"></el-option>
<el-option :value="3" label="MXSM/USDT"></el-option>
<el-option :value="4" label="CLP/USDT"></el-option>
<el-option :value="5" label="LYH/USDT"></el-option>
<el-option :value="6" label="BBWL/USDT"></el-option>
<el-option :value="7" label="DWS/USDT"></el-option>
<el-option :value="8" label="AASZ/USDT"></el-option>
</el-select>
@ -181,7 +178,7 @@
max = max || 1;
min = min || 0;
random = (random * Math.PI *1000 + (max+min)*random.getSeconds() + random.getMilliseconds()) % 233280;
let rnd = random / max;
let rnd = random / 233280;
return parseInt(min + rnd * (max - min));
},
//时间格式化

13
resources/views/admin/klineRobotlike.blade.php

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>风控</title>
</head>
<body>
<iframe src="klike" frameborder="0" width="100%" height="1000px"></iframe>
</body>
</html>
Loading…
Cancel
Save