68 lines
2.1 KiB
PHP
68 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\Cookie\CookieJar;
|
|
use function GuzzleHttp\json_decode;
|
|
// use Config;
|
|
|
|
class ThreeCommasController extends Controller
|
|
{
|
|
private $baseUrl = 'https://3commas.io';
|
|
private $api_version = '/public/api/ver1/';
|
|
public function __construct()
|
|
{
|
|
$this->api_secret = config('user.api_secret_3commas');
|
|
$this->api_key = config('user.api_key_3commas');
|
|
}
|
|
|
|
public function getTrades(){
|
|
$end_point = 'smart_trades';
|
|
$url = $this->baseUrl . $this->api_version . $end_point;
|
|
|
|
$params = [
|
|
'api_key' => $this->api_key,
|
|
'secret' => $this->api_secret,
|
|
'scope' => 'active',
|
|
'limit' => 50
|
|
];
|
|
$query = http_build_query($params);
|
|
$signature = hash_hmac('sha256', $this->api_version . $end_point . '?' . $query, $this->api_secret);
|
|
|
|
$client = new Client([
|
|
'headers' => [
|
|
'Content-Type' => 'application/json',
|
|
'APIKEY' => $this->api_key,
|
|
'Signature' => $signature
|
|
],
|
|
]);
|
|
$response = $client->request('GET', $url . '?' . $query);
|
|
$data = json_decode($response->getBody());
|
|
return $data;
|
|
}
|
|
|
|
public function getBalance(){
|
|
$end_point = 'accounts';
|
|
$url = $this->baseUrl . $this->api_version . $end_point;
|
|
|
|
$params = [
|
|
'api_key' => $this->api_key,
|
|
'secret' => $this->api_secret,
|
|
];
|
|
$query = http_build_query($params);
|
|
$signature = hash_hmac('sha256', $this->api_version . $end_point . '?' . $query, $this->api_secret);
|
|
|
|
$client = new Client([
|
|
'headers' => [
|
|
'Content-Type' => 'application/json',
|
|
'APIKEY' => $this->api_key,
|
|
'Signature' => $signature
|
|
],
|
|
]);
|
|
$response = $client->request('GET', $url . '?' . $query);
|
|
$data = json_decode($response->getBody());
|
|
return $data;
|
|
}
|
|
} |