Commit bb696f31 by Florian Shllaku

Crypto Backend. Done by Abalsh on Flshll's PC

parent 88e51250
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class updatecrypto extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update:crypto';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$client = new \GuzzleHttp\Client([
'headers' => [
'X-CMC_PRO_API_KEY' => env("CMC_API_KEY", null),
'Accept-Encoding' => 'deflate, gzip'
]
]);
$res = $client->request('GET', 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest', [
'query' => [
'limit' => '100',
'convert' => 'EUR'
],
'Filter' => ['data']
]);
//$res->getStatusCode();
$result = json_decode($res->getBody(),true);
DB::beginTransaction();
foreach($result["data"] as $item) {
DB::table('crypto')
->updateOrInsert(
['name' => $item["name"], 'symbol' => $item["symbol"]],
['rate' => $item["quote"]["EUR"]["price"]]
);
}
DB::commit();
}
}
......@@ -6,8 +6,27 @@ use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\DB;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
class CryptoController extends Controller
{
public function convert($convertFrom,$convertFromValue,$convertTo)
{
$dbCryptoTable = 'crypto';
$convertFromRate = DB::table($dbCryptoTable)->where('symbol', $convertFrom)->value('rate');
$convertToRate = DB::table($dbCryptoTable)->where('symbol', $convertTo)->value('rate');
if ($convertFromRate && $convertToRate) {
$converted = ($convertFromRate * $convertFromValue) / $convertToRate;
return $converted;
} else {
return NULL;
}
}
}
\ No newline at end of file
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCryptoTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('crypto', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('symbol',100);
$table->string('name',100);
$table->double('rate');
$table->timestamp('updated_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('crypto');
}
}
......@@ -7,6 +7,7 @@ $baseDir = dirname($vendorDir);
return array(
'App\\Admin' => $baseDir . '/app/Admin.php',
'App\\Console\\Commands\\updatecrypto' => $baseDir . '/app/Console/Commands/updatecrypto.php',
'App\\Console\\Kernel' => $baseDir . '/app/Console/Kernel.php',
'App\\CurrencyListing' => $baseDir . '/app/CurrencyListing.php',
'App\\Exceptions\\Handler' => $baseDir . '/app/Exceptions/Handler.php',
......@@ -16,6 +17,7 @@ return array(
'App\\Http\\Controllers\\Auth\\ResetPasswordController' => $baseDir . '/app/Http/Controllers/Auth/ResetPasswordController.php',
'App\\Http\\Controllers\\Auth\\VerificationController' => $baseDir . '/app/Http/Controllers/Auth/VerificationController.php',
'App\\Http\\Controllers\\Controller' => $baseDir . '/app/Http/Controllers/Controller.php',
'App\\Http\\Controllers\\CryptoController' => $baseDir . '/app/Http/Controllers/Controller.php',
'App\\Http\\Controllers\\HomeController' => $baseDir . '/app/Http/Controllers/HomeController.php',
'App\\Http\\Controllers\\NewsletterController' => $baseDir . '/app/Http/Controllers/NewsLetterController.php',
'App\\Http\\Controllers\\SendEmailController' => $baseDir . '/app/Http/Controllers/SendEmailController.php',
......
......@@ -413,6 +413,7 @@ class ComposerStaticInitaaf7a2d0aa0540e4f74d52dc30d67caa
public static $classMap = array (
'App\\Admin' => __DIR__ . '/../..' . '/app/Admin.php',
'App\\Console\\Commands\\updatecrypto' => __DIR__ . '/../..' . '/app/Console/Commands/updatecrypto.php',
'App\\Console\\Kernel' => __DIR__ . '/../..' . '/app/Console/Kernel.php',
'App\\CurrencyListing' => __DIR__ . '/../..' . '/app/CurrencyListing.php',
'App\\Exceptions\\Handler' => __DIR__ . '/../..' . '/app/Exceptions/Handler.php',
......@@ -422,6 +423,7 @@ class ComposerStaticInitaaf7a2d0aa0540e4f74d52dc30d67caa
'App\\Http\\Controllers\\Auth\\ResetPasswordController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/ResetPasswordController.php',
'App\\Http\\Controllers\\Auth\\VerificationController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/VerificationController.php',
'App\\Http\\Controllers\\Controller' => __DIR__ . '/../..' . '/app/Http/Controllers/Controller.php',
'App\\Http\\Controllers\\CryptoController' => __DIR__ . '/../..' . '/app/Http/Controllers/Controller.php',
'App\\Http\\Controllers\\HomeController' => __DIR__ . '/../..' . '/app/Http/Controllers/HomeController.php',
'App\\Http\\Controllers\\NewsletterController' => __DIR__ . '/../..' . '/app/Http/Controllers/NewsLetterController.php',
'App\\Http\\Controllers\\SendEmailController' => __DIR__ . '/../..' . '/app/Http/Controllers/SendEmailController.php',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment