return response()->json($data); }); Route::any('getUserPermission', function (Request $request) { try { $email = trim((string) $request->input('email', '')); $from = (string) $request->input('from', 'trend'); if ($email === '') { return response()->json([ 'status' => false, 'level' => 'unknown', 'message' => 'missing_email', ]); } return response()->json(getUserLevel($email, $from)); } catch (\Throwable $e) { return response()->json([ 'status' => false, 'level' => 'unknown', 'message' => 'server_error', ]); } }); Route::any('trend/config', function (Request $request) { try { return response()->json([ 'success' => true, 'data' => [ 'OI_SELL_SIGNAL_MIN_CHANGE_PERCENT' => (float) env('OI_SELL_SIGNAL_MIN_CHANGE_PERCENT', 0), 'OI_SELL_SIGNAL_MAX_CHANGE_PERCENT' => (float) env('OI_SELL_SIGNAL_MAX_CHANGE_PERCENT', 0), 'OI_BUY_SIGNAL_MIN_CHANGE_PERCENT' => (float) env('OI_BUY_SIGNAL_MIN_CHANGE_PERCENT', 0), 'OI_BUY_SIGNAL_MAX_CHANGE_PERCENT' => (float) env('OI_BUY_SIGNAL_MAX_CHANGE_PERCENT', 0), 'OI_SIGNAL_STORE_ENABLED' => (bool) env('OI_SIGNAL_STORE_ENABLED', false), 'OI_SIGNAL_DISPATCH_ENABLED' => (bool) env('OI_SIGNAL_DISPATCH_ENABLED', false), 'OI_SIGNALS_PUBLIC_ENABLED' => (bool) env('OI_SIGNALS_PUBLIC_ENABLED', false), 'SIGNAL_BOT_UI_PERCENT' => (float) env('SIGNAL_BOT_UI_PERCENT', 0), 'SIGNAL_BOT_PRICE_PERCENT' => (float) env('SIGNAL_BOT_PRICE_PERCENT', 0), 'SIGNAL_BOT_BUY2' => (float) env('SIGNAL_BOT_BUY2', 0), 'SIGNAL_BOT_TP1' => (float) env('SIGNAL_BOT_TP1', 0), 'SIGNAL_BOT_TP2' => (float) env('SIGNAL_BOT_TP2', 0), 'SIGNAL_BOT_TP3' => (float) env('SIGNAL_BOT_TP3', 0), ], ]); } catch (\Throwable $e) { return response()->json(['success' => false, 'message' => 'server_error']); } }); Route::any('trend/exchange-status', function (Request $request) { $email = trim((string) $request->input('email', '')); if ($email === '') { return response()->json(['success' => false, 'message' => 'missing_email']); } $defaults = [ 'XT.COM (Derivatives)' => true, 'Binance (Futures)' => true, 'MEXC (Futures)' => true, 'KuCoin Futures' => true, 'BingX (Futures)' => true, 'LBank (Futures)' => true, 'KCEX (Futures)' => true, 'trend_setting' => true, ]; try { $userId = getUserId($email); if (!$userId) { return response()->json(['success' => false, 'message' => 'user_not_found']); } $data = $defaults; $row = DB::table('wordpressim_usermeta') ->where('user_id', $userId) ->where('meta_key', 'trend_exchange_status') ->first(); if ($row && isset($row->meta_value)) { $decoded = json_decode((string) $row->meta_value, true); if (is_array($decoded)) { $data = array_merge($defaults, $decoded); } } else { $cookieValue = (string) $request->cookie('trend_exchange_status', ''); if ($cookieValue) { $decoded = json_decode($cookieValue, true); if (is_array($decoded)) { $data = array_merge($defaults, $decoded); } } } return response() ->json(['success' => true, 'data' => $data]) ->cookie('trend_exchange_status', json_encode($data), 60 * 24 * 365, '/'); } catch (\Throwable $e) { return response()->json(['success' => false, 'message' => 'server_error']); } }); Route::any('trend/exchange-status-update-all', function (Request $request) { $email = trim((string) $request->input('email', '')); if ($email === '') { return response()->json(['success' => false, 'message' => 'missing_email']); } $defaults = [ 'XT.COM (Derivatives)' => true, 'Binance (Futures)' => true, 'MEXC (Futures)' => true, 'KuCoin Futures' => true, 'BingX (Futures)' => true, 'LBank (Futures)' => true, 'KCEX (Futures)' => true, 'trend_setting' => true, ]; try { $userId = getUserId($email); if (!$userId) { return response()->json(['success' => false, 'message' => 'user_not_found']); } $exchanges = $request->input('exchanges', []); if (is_string($exchanges)) { $decoded = json_decode($exchanges, true); if (is_array($decoded)) { $exchanges = $decoded; } } if (!is_array($exchanges)) { $exchanges = []; } $store = array_merge($defaults, $exchanges); $existing = DB::table('wordpressim_usermeta') ->where('user_id', $userId) ->where('meta_key', 'trend_exchange_status'); if ($existing->exists()) { $existing->update(['meta_value' => json_encode($store)]); } else { DB::table('wordpressim_usermeta')->insert([ 'user_id' => $userId, 'meta_key' => 'trend_exchange_status', 'meta_value' => json_encode($store), ]); } return response() ->json(['success' => true, 'data' => $store]) ->cookie('trend_exchange_status', json_encode($store), 60 * 24 * 365, '/'); } catch (\Throwable $e) { return response()->json(['success' => false, 'message' => 'server_error']); } }); Route::post('notify/read',[\App\Http\Controllers\NotificationController::class,'read'])->name('notify.read'); Route::get('signals',[\App\Http\Controllers\SignalController::class,'index_api'])->name('signals.api'); Route::any('signals/chart/{signal}', [\App\Http\Controllers\SignalController::class, 'getChart'])->name('signals.getChart'); Route::get('checkAuth', function () { $email = \request()->get('email'); $pass = \request()->get('pass'); $user = User::where('user_email', $email) ->first(); $wpHasher = new PasswordHash(8, true); $status = "false"; if ($user && $wpHasher->CheckPassword($pass, $user->user_pass)) { $status = $user->ID; } if ($user && hash_equals($user->user_pass, md5($pass))) { $status = $user->ID; } if ($user && password_verify($pass,$user->user_pass)) { $status = $user->ID; } echo $status; exit(); }); // UDF protocol for TradingView Charting Library Route::get('udf/config', function () { return response()->json([ 'supports_search' => true, 'supports_group_request' => false, 'supports_marks' => false, 'supports_timescale_marks' => false, 'supports_time' => true, 'exchanges' => [['value' => '', 'name' => 'All', 'desc' => '']], 'symbols_types' => [['value' => 'crypto', 'name' => 'Crypto']], 'supported_resolutions' => ['1','3','5','15','30','60','120','240','360','480','D','W','M'], ]); }); Route::get('udf/symbols', function (Request $request) { $symbol = strtoupper(trim((string) $request->query('symbol', 'BTCUSDT'))); return response()->json([ 'name' => $symbol, 'ticker' => $symbol, 'description' => $symbol, 'type' => 'crypto', 'session' => '24x7', 'timezone' => 'Etc/UTC', 'minmov' => 1, 'pricescale' => 100, 'minmove2' => 0, 'fractional' => false, 'has_intraday' => true, 'has_daily' => true, 'has_weekly_and_monthly' => true, 'data_status' => 'streaming', 'exchange' => 'BINANCE', 'listed_exchange' => 'BINANCE', 'currency_code' => 'USD', ]); }); Route::get('udf/history', function (Request $request) { $symbol = strtoupper(trim((string) $request->query('symbol', 'BTCUSDT'))); $resolution = (string) $request->query('resolution', 'D'); $from = (int) $request->query('from', 0); $to = (int) $request->query('to', 0); $resMap = ['1'=>'1m','3'=>'3m','5'=>'5m','15'=>'15m','30'=>'30m','60'=>'1h','120'=>'2h','240'=>'4h','360'=>'6h','480'=>'8h','D'=>'1d','W'=>'1w','M'=>'1M']; $binInterval = $resMap[$resolution] ?? '1d'; $limit = $from > 0 ? min(ceil(($to - $from) / 86400) + 100, 1000) : 500; if ($limit < 10) $limit = 100; $cacheKey = 'udf_' . $symbol . '_' . $binInterval . '_' . $limit; $data = Illuminate\Support\Facades\Cache::remember($cacheKey, 120, function () use ($symbol, $binInterval, $limit) { try { $resp = Illuminate\Support\Facades\Http::timeout(10) ->get("https://api.binance.com/api/v3/klines", [ 'symbol' => $symbol, 'interval' => $binInterval, 'limit' => $limit, ]); if ($resp->successful()) { $klines = $resp->json(); if (is_array($klines) && count($klines) > 0) { $t = []; $o = []; $h = []; $l = []; $c = []; $v = []; foreach ($klines as $k) { $sec = (int) floor($k[0] / 1000); $t[] = $sec; $o[] = (float) $k[1]; $h[] = (float) $k[2]; $l[] = (float) $k[3]; $c[] = (float) $k[4]; $v[] = (float) $k[5]; } return ['s' => 'ok', 't' => $t, 'o' => $o, 'h' => $h, 'l' => $l, 'c' => $c, 'v' => $v]; } } } catch (\Throwable $e) {} return ['s' => 'no_data']; }); return response()->json($data); }); Route::get('udf/search', function (Request $request) { $query = strtoupper(trim((string) $request->query('query', 'BTC'))); return response()->json([['symbol'=>$query,'full_name'=>$query,'description'=>$query,'exchange'=>'BINANCE','ticker'=>$query,'type'=>'crypto']]); }); Route::any('udf/{any}', function () { return response()->json(['s'=>'error','errmsg'=>'not_found'], 404); })->where('any', '.*'); Route::get('udf/quotes', function (Request $request) { $symbols = (array) $request->query('symbols', []); $data = []; foreach ($symbols as $s) { $data[] = ['s'=>'ok','n'=>$s,'v'=>['bid'=>0,'ask'=>0,'ch'=>0,'chp_pct'=>0,'short_name'=>$s,'exchange'=>'BINANCE','description'=>$s,'type'=>'crypto' ]]; } return response()->json(['s'=>'ok','d'=>$data]); });