diff --git a/app/Handlers/ContractTool.php b/app/Handlers/ContractTool.php index 609da09..9d93539 100644 --- a/app/Handlers/ContractTool.php +++ b/app/Handlers/ContractTool.php @@ -40,7 +40,8 @@ class ContractTool public static function unRealProfit($position, $contract, $flat_price, $amount = null) { if (blank($flat_price)) return 0; - if($position['symbol'] == 'MGP' || $position['symbol'] == 'YEI' || $position['symbol'] == 'TZQ' || $position['symbol'] == 'UIN' || $position['symbol'] == 'LOPW' || $position['symbol'] == 'CXIB' || $position['symbol'] == 'UNGQ'){ + // + if($position['symbol'] == 'BTU' || $position['symbol'] == 'BLK' || $position['symbol'] == 'TVC' || $position['symbol'] == 'MGC' || $position['symbol'] == 'DSR'){ $PlatformCurrencyMultiples = 1; }else{ $PlatformCurrencyMultiples = 1; diff --git a/app/Http/Controllers/Appapi/V1/ContractController.php b/app/Http/Controllers/Appapi/V1/ContractController.php index da4a20f..1ee43af 100644 --- a/app/Http/Controllers/Appapi/V1/ContractController.php +++ b/app/Http/Controllers/Appapi/V1/ContractController.php @@ -85,7 +85,8 @@ class ContractController extends ApiController $marketList[$kk]['qty_decimals'] = $coin['qty_decimals']; $marketList[$kk]['price_decimals'] = $coin['price_decimals']; $cd = Cache::store('redis')->get('swap:' . $contract['symbol'] . '_detail'); - if($contract['symbol']=='MGP' || $contract['symbol']=='YEI' || $contract['symbol']=='TZQ' || $contract['symbol']=='UIN' || $contract['symbol']=='LOPW' || $contract['symbol']=='CXIB' || $contract['symbol']=='UNGQ'){ + // + if($contract['symbol']=='BTU' || $contract['symbol']=='BLK' || $contract['symbol']=='TVC' || $contract['symbol']=='MGC' || $contract['symbol']=='DSR'){ $cd['vol'] = $cd['vol']*1003; } $data = $cd; diff --git a/app/Models/DataBlk.php b/app/Models/DataBlk.php new file mode 100644 index 0000000..106e1b2 --- /dev/null +++ b/app/Models/DataBlk.php @@ -0,0 +1,124 @@ + 0, + 'Symbol' => 'BLK', + 'Name' => 'BLK', + '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; + } +} diff --git a/app/Models/DataBtu.php b/app/Models/DataBtu.php new file mode 100644 index 0000000..26b9734 --- /dev/null +++ b/app/Models/DataBtu.php @@ -0,0 +1,124 @@ + 0, + 'Symbol' => 'BTU', + 'Name' => 'BTU', + '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; + } +} diff --git a/app/Models/DataDsr.php b/app/Models/DataDsr.php new file mode 100644 index 0000000..8485b17 --- /dev/null +++ b/app/Models/DataDsr.php @@ -0,0 +1,124 @@ + 0, + 'Symbol' => 'DSR', + 'Name' => 'DSR', + '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; + } +} diff --git a/app/Models/DataMgc.php b/app/Models/DataMgc.php new file mode 100644 index 0000000..3cac3b1 --- /dev/null +++ b/app/Models/DataMgc.php @@ -0,0 +1,124 @@ + 0, + 'Symbol' => 'MGC', + 'Name' => 'MGC', + '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; + } +} diff --git a/app/Models/DataTvc.php b/app/Models/DataTvc.php new file mode 100644 index 0000000..118782e --- /dev/null +++ b/app/Models/DataTvc.php @@ -0,0 +1,124 @@ + 0, + 'Symbol' => 'TVC', + 'Name' => 'TVC', + '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; + } +} diff --git a/public/swap/swap_getoldkline.php b/public/swap/swap_getoldkline.php index 8907cb3..bc25943 100644 --- a/public/swap/swap_getoldkline.php +++ b/public/swap/swap_getoldkline.php @@ -17,7 +17,8 @@ $symbols = \App\Models\ContractPair::query()->where('status', 1)->pluck('symbol' foreach ($symbols as $symbol) { $period = '1mon'; //1 - if ($symbol == "MGP" || $symbol == "YEI" || $symbol == "TZQ" || $symbol == "UIN" || $symbol == "LOPW" || $symbol == "CXIB" || $symbol == "UNGQ") { + // + if ($symbol == "BTU" || $symbol == "BLK" || $symbol == "TVC" || $symbol == "MGC" || $symbol == "DSR") { continue; } // if($symbol != "BTC"){ diff --git a/resources/views/admin/kline.blade.php b/resources/views/admin/kline.blade.php index 29bd9b6..270a64d 100644 --- a/resources/views/admin/kline.blade.php +++ b/resources/views/admin/kline.blade.php @@ -6,7 +6,7 @@ 风控 - + @@ -53,13 +53,11 @@ - - - - - - - + + + + +