|
|
|
@ -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'])); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|