-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDigitalCurrency.php
53 lines (46 loc) · 1.77 KB
/
DigitalCurrency.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Larateam;
class DigitalCurrency
{
const DOLLAR_WAGE_SELL = 6000;
const DOLLAR_WAGE_BUY = 5000;
const WAGE_FACTOR = 1.0009;
public $coinMarketData;
public function initialData()
{
$url = 'https://coinmarketcap.com/all/views/all/';
$this->coinMarketData = file_get_contents($url);
return $this->coinMarketData;
}
public function GetCurrencyPrice($symbol)
{
preg_match('/<tr.*>.*<div.*>' . $symbol . '<\/div>.*<a.*>\$(.*)<\/a>.*<\/tr>/Ui', $this->coinMarketData, $output_array);
$price = str_replace(',', '', $output_array[1]);
if ($symbol === 'USDT') {
return $price > 1 ? $price : 1;
} else {
return (float)$price;
}
}
public function GetUSDPrice()
{
$data = file_get_contents('https://www.tgju.org/chart/price_dollar_rl');
preg_match('/<span itemprop="price">(.*)<\/span>/', $data, $output_array);
$dollar = (int)str_replace(',', '', $output_array[1]);
return $dollar;
}
public function GetBuyPrice($currency)
{
$currencyPrice = ($currency === 'USDT') ? 1 : $this->GetCurrencyPrice($currency);
return ($this->GetUSDPrice() + self::DOLLAR_WAGE_BUY) * $this->GetCurrencyPrice('USDT') * $currencyPrice;
}
public function GetSellPrice($currency)
{
$currencyPrice = ($currency === 'USDT') ? 1 : $this->GetCurrencyPrice($currency);
return ($this->GetUSDPrice() + self::DOLLAR_WAGE_SELL) * self::WAGE_FACTOR * $this->GetCurrencyPrice('USDT') * $currencyPrice;
}
public function GetCurrencyList(){
preg_match_all('/<tr.*><td.*><\/td><td.*><\/td>.*<div.*>(.*)<\/div>.*<\/tr>/Ui', $this->coinMarketData, $output_array);
return $output_array[1];
}
}