Skip to content

Commit 1fbd278

Browse files
committed
queue example complete
1 parent 20d2bf8 commit 1fbd278

22 files changed

+2996
-137
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace App\Console\Commands\Market;
4+
5+
use App\Jobs\KuCoin\AVAX_USDT;
6+
use App\Jobs\KuCoin\BNB_USDT;
7+
use App\Jobs\KuCoin\BTC_USDT;
8+
use App\Jobs\KuCoin\SOL_USDT;
9+
use Illuminate\Console\Command;
10+
11+
class KuCoin extends Command
12+
{
13+
/**
14+
* The name and signature of the console command.
15+
*
16+
* @var string
17+
*/
18+
protected $signature = 'market:kucoin';
19+
20+
/**
21+
* The console command description.
22+
*
23+
* @var string
24+
*/
25+
protected $description = 'Command description';
26+
27+
/**
28+
* Execute the console command.
29+
*
30+
* @return int
31+
*/
32+
public function handle()
33+
{
34+
for ($i = 1; $i <= 6; $i++) {
35+
BTC_USDT::dispatch();
36+
sleep(5);
37+
SOL_USDT::dispatch();
38+
sleep(5);
39+
AVAX_USDT::dispatch();
40+
sleep(5);
41+
BNB_USDT::dispatch();
42+
sleep(10);
43+
}
44+
}
45+
}

app/Console/Kernel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel
1616
protected function schedule(Schedule $schedule)
1717
{
1818
// $schedule->command('inspire')->hourly();
19+
$schedule->command('market:kucoin')->everyMinute();
1920
}
2021

2122
/**
@@ -25,7 +26,7 @@ protected function schedule(Schedule $schedule)
2526
*/
2627
protected function commands()
2728
{
28-
$this->load(__DIR__.'/Commands');
29+
$this->load(__DIR__ . '/Commands');
2930

3031
require base_path('routes/console.php');
3132
}

app/Http/Livewire/Market/KuCoin.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Http\Livewire\Market;
4+
5+
use Livewire\Component;
6+
use App\Models\Market\KuCoin as KuCoinModel;
7+
8+
class KuCoin extends Component
9+
{
10+
public $data;
11+
12+
public function mount()
13+
{
14+
$this->data = KuCoinModel::all();
15+
}
16+
17+
public function render()
18+
{
19+
// $kucoin = KuCoinModel::all();
20+
21+
return view('livewire.market.ku-coin', [
22+
'kucoin' => $this->data
23+
]);
24+
}
25+
}

app/Http/Livewire/StatCoin.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Http\Livewire;
4+
5+
use App\Models\Market\KuCoin;
6+
use Illuminate\Support\Facades\Log;
7+
use Livewire\Component;
8+
9+
class StatCoin extends Component
10+
{
11+
public $coin;
12+
13+
public function render()
14+
{
15+
$data = KuCoin::find($this->coin->id);
16+
17+
return view('livewire.stat-coin', [
18+
'data' => $data
19+
]);
20+
}
21+
}

app/Jobs/KuCoin/AVAX_USDT.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace App\Jobs\KuCoin;
4+
5+
use App\Models\Market\KuCoin;
6+
use Illuminate\Bus\Queueable;
7+
use Illuminate\Support\Facades\Http;
8+
use Illuminate\Queue\SerializesModels;
9+
use Illuminate\Queue\InteractsWithQueue;
10+
use Illuminate\Contracts\Queue\ShouldQueue;
11+
use Illuminate\Foundation\Bus\Dispatchable;
12+
use Illuminate\Contracts\Queue\ShouldBeUnique;
13+
14+
class AVAX_USDT implements ShouldQueue, ShouldBeUnique
15+
{
16+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
17+
18+
/**
19+
* The number of seconds after which the job's unique lock will be released.
20+
*
21+
* @var int
22+
*/
23+
public $uniqueFor = 5;
24+
25+
/**
26+
* The unique ID of the job.
27+
*
28+
* @return string
29+
*/
30+
public function uniqueId()
31+
{
32+
return 'KUCOIN-AVAX-USDT';
33+
}
34+
35+
/**
36+
* Create a new job instance.
37+
*
38+
* @return void
39+
*/
40+
public function __construct()
41+
{
42+
//
43+
}
44+
45+
/**
46+
* Execute the job.
47+
*
48+
* @return void
49+
*/
50+
public function handle()
51+
{
52+
$avax_usdt = Http::get('https://api.kucoin.com/api/v1/market/stats?symbol=AVAX-USDT');
53+
54+
$response = json_decode($avax_usdt);
55+
56+
KuCoin::updateOrCreate(
57+
[
58+
'symbol' => $response->data->symbol
59+
],
60+
[
61+
'time' => $response->data->time,
62+
'buy' => $response->data->buy,
63+
'sell' => $response->data->sell,
64+
'change_rate' => $response->data->changeRate,
65+
'change_price' => $response->data->changePrice,
66+
'high' => $response->data->high,
67+
'low' => $response->data->low
68+
]
69+
);
70+
}
71+
}

app/Jobs/KuCoin/BNB_USDT.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace App\Jobs\KuCoin;
4+
5+
use App\Models\Market\KuCoin;
6+
use Illuminate\Bus\Queueable;
7+
use Illuminate\Support\Facades\Http;
8+
use Illuminate\Queue\SerializesModels;
9+
use Illuminate\Queue\InteractsWithQueue;
10+
use Illuminate\Contracts\Queue\ShouldQueue;
11+
use Illuminate\Foundation\Bus\Dispatchable;
12+
use Illuminate\Contracts\Queue\ShouldBeUnique;
13+
14+
class BNB_USDT implements ShouldQueue, ShouldBeUnique
15+
{
16+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
17+
18+
/**
19+
* The number of seconds after which the job's unique lock will be released.
20+
*
21+
* @var int
22+
*/
23+
public $uniqueFor = 5;
24+
25+
/**
26+
* The unique ID of the job.
27+
*
28+
* @return string
29+
*/
30+
public function uniqueId()
31+
{
32+
return 'KUCOIN-BNB-USDT';
33+
}
34+
35+
36+
/**
37+
* Create a new job instance.
38+
*
39+
* @return void
40+
*/
41+
public function __construct()
42+
{
43+
//
44+
}
45+
46+
/**
47+
* Execute the job.
48+
*
49+
* @return void
50+
*/
51+
public function handle()
52+
{
53+
$bnb_usdt = Http::get('https://api.kucoin.com/api/v1/market/stats?symbol=BNB-USDT');
54+
55+
$response = json_decode($bnb_usdt);
56+
57+
KuCoin::updateOrCreate(
58+
[
59+
'symbol' => $response->data->symbol
60+
],
61+
[
62+
'time' => $response->data->time,
63+
'buy' => $response->data->buy,
64+
'sell' => $response->data->sell,
65+
'change_rate' => $response->data->changeRate,
66+
'change_price' => $response->data->changePrice,
67+
'high' => $response->data->high,
68+
'low' => $response->data->low
69+
]
70+
);
71+
}
72+
}

app/Jobs/KuCoin/BTC_USDT.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace App\Jobs\KuCoin;
4+
5+
use App\Models\Market\KuCoin;
6+
use Illuminate\Bus\Queueable;
7+
use Illuminate\Contracts\Queue\ShouldBeUnique;
8+
use Illuminate\Contracts\Queue\ShouldQueue;
9+
use Illuminate\Foundation\Bus\Dispatchable;
10+
use Illuminate\Queue\InteractsWithQueue;
11+
use Illuminate\Queue\SerializesModels;
12+
use Illuminate\Support\Facades\Http;
13+
use Illuminate\Support\Facades\Log;
14+
15+
class BTC_USDT implements ShouldQueue, ShouldBeUnique
16+
{
17+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
18+
19+
/**
20+
* The number of seconds after which the job's unique lock will be released.
21+
*
22+
* @var int
23+
*/
24+
public $uniqueFor = 5;
25+
26+
/**
27+
* The unique ID of the job.
28+
*
29+
* @return string
30+
*/
31+
public function uniqueId()
32+
{
33+
return 'KUCOIN-BTC-USDT';
34+
}
35+
36+
/**
37+
* Create a new job instance.
38+
*
39+
* @return void
40+
*/
41+
public function __construct()
42+
{
43+
//
44+
}
45+
46+
/**
47+
* Execute the job.
48+
*
49+
* @return void
50+
*/
51+
public function handle()
52+
{
53+
$btc_usdt = Http::get('https://api.kucoin.com/api/v1/market/stats?symbol=BTC-USDT');
54+
55+
$response = json_decode($btc_usdt);
56+
57+
KuCoin::updateOrCreate(
58+
[
59+
'symbol' => $response->data->symbol
60+
],
61+
[
62+
'time' => $response->data->time,
63+
'buy' => $response->data->buy,
64+
'sell' => $response->data->sell,
65+
'change_rate' => $response->data->changeRate,
66+
'change_price' => $response->data->changePrice,
67+
'high' => $response->data->high,
68+
'low' => $response->data->low
69+
]
70+
);
71+
}
72+
}

0 commit comments

Comments
 (0)