Fix getting price
This commit is contained in:
parent
8a43630ba9
commit
aa6f86b014
3 changed files with 29 additions and 16 deletions
|
@ -19,6 +19,8 @@ class AuxCommand extends Command{
|
||||||
|
|
||||||
const bittrex = 'https://api.bittrex.com/v3/markets/LBC-BTC/ticker';
|
const bittrex = 'https://api.bittrex.com/v3/markets/LBC-BTC/ticker';
|
||||||
|
|
||||||
|
const coingeckoURL = 'https://api.coingecko.com/api/v3/simple/price?ids=lbry-credits&vs_currencies=btc';
|
||||||
|
|
||||||
const blockchainticker = 'https://blockchain.info/ticker';
|
const blockchainticker = 'https://blockchain.info/ticker';
|
||||||
|
|
||||||
const lbcpricekey = 'lbc.price';
|
const lbcpricekey = 'lbc.price';
|
||||||
|
@ -170,11 +172,13 @@ class AuxCommand extends Command{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$btrxjson = null; //TODO json_decode(self::curl_get(self::bittrex));
|
$coingeckoJSON = Cache::remember('coingecko',60,static function(){
|
||||||
|
return json_decode(self::curl_get(self::coingeckoURL));
|
||||||
|
});
|
||||||
$blckjson = json_decode(self::curl_get(self::blockchainticker));
|
$blckjson = json_decode(self::curl_get(self::blockchainticker));
|
||||||
|
|
||||||
if ($btrxjson) {
|
if ($coingeckoJSON) {
|
||||||
$btc = $btrxjson->bidRate;
|
$btc = $coingeckoJSON->{'lbry-credits'}->btc;
|
||||||
$usd = 0;
|
$usd = 0;
|
||||||
if (isset($blckjson->USD)) {
|
if (isset($blckjson->USD)) {
|
||||||
$usd = $btc * $blckjson->USD->buy;
|
$usd = $btc * $blckjson->USD->buy;
|
||||||
|
@ -195,7 +199,7 @@ class AuxCommand extends Command{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
echo "bittrex requrest returned an invalid result.\n";
|
echo "CoinGecko requrest returned an invalid result.\n";
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
print_r($e);
|
print_r($e);
|
||||||
|
|
|
@ -47,6 +47,8 @@ class MainController extends Controller{
|
||||||
|
|
||||||
const bittrexMarketUrl = 'https://api.bittrex.com/v3/markets/LBC-BTC/ticker';
|
const bittrexMarketUrl = 'https://api.bittrex.com/v3/markets/LBC-BTC/ticker';
|
||||||
|
|
||||||
|
const coingeckoURL = 'https://api.coingecko.com/api/v3/simple/price?ids=lbry-credits&vs_currencies=btc';
|
||||||
|
|
||||||
const blockchainTickerUrl = 'https://blockchain.info/ticker';
|
const blockchainTickerUrl = 'https://blockchain.info/ticker';
|
||||||
|
|
||||||
const tagReceiptAddress = 'bLockNgmfvnnnZw7bM6SPz6hk5BVzhevEp';
|
const tagReceiptAddress = 'bLockNgmfvnnnZw7bM6SPz6hk5BVzhevEp';
|
||||||
|
@ -94,11 +96,13 @@ class MainController extends Controller{
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($shouldRefreshPrice) {
|
if ($shouldRefreshPrice) {
|
||||||
$btrxjson = json_decode(self::curl_get(self::bittrexMarketUrl));
|
$coingeckoJSON = Cache::remember('coingecko',60,static function(){
|
||||||
|
return json_decode(self::curl_get(self::coingeckoURL));
|
||||||
|
});
|
||||||
$blckjson = json_decode(self::curl_get(self::blockchainTickerUrl));
|
$blckjson = json_decode(self::curl_get(self::blockchainTickerUrl));
|
||||||
|
|
||||||
if ($btrxjson) {
|
if ($coingeckoJSON) {
|
||||||
$onelbc = $btrxjson->bidRate;
|
$onelbc = $coingeckoJSON->{'lbry-credits'}->btc;
|
||||||
$lbcPrice = 0;
|
$lbcPrice = 0;
|
||||||
if (isset($blckjson->USD)) {
|
if (isset($blckjson->USD)) {
|
||||||
$lbcPrice = $onelbc * $blckjson->USD->buy;
|
$lbcPrice = $onelbc * $blckjson->USD->buy;
|
||||||
|
@ -162,7 +166,7 @@ class MainController extends Controller{
|
||||||
// $count = $stmt->fetch(\PDO::FETCH_OBJ);
|
// $count = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||||
$numClaims = 20000000;
|
$numClaims = 20000000;
|
||||||
|
|
||||||
$stmt = $conn->getPdo()->query('SELECT MAX(id) AS MaxId FROM claim');
|
$stmt = $conn->getPdo()->query('SELECT MAX(Id) AS MaxId FROM Claims');
|
||||||
$res = $stmt->fetch(PDO::FETCH_OBJ);
|
$res = $stmt->fetch(PDO::FETCH_OBJ);
|
||||||
$maxClaimId = $res->MaxId;
|
$maxClaimId = $res->MaxId;
|
||||||
|
|
||||||
|
@ -181,7 +185,7 @@ class MainController extends Controller{
|
||||||
}
|
}
|
||||||
|
|
||||||
$blockedList = json_decode($this->_getBlockedList());
|
$blockedList = json_decode($this->_getBlockedList());
|
||||||
$claims = Claim::query()->addSelect(['publisher' => 'C.name', 'publisher_transaction_hash_id' => 'C.transaction_hash_id', 'publisher_vout' => 'C.vout'])->leftJoin('Claims','claim_id','=','Claims.publisher_id')->where('Claims.id','>',$startLimitId)->where( 'Claims.id','<=',$endLimitId)->orderByDesc('Claims.id')->get();
|
$claims = [];//Claim::query()->selectRaw('Name AS Publisher')->addSelect(['publisher' => 'C.name', 'publisher_transaction_hash_id' => 'C.transaction_hash_id', 'publisher_vout' => 'C.vout'])->leftJoin('Claims','claim_id','=','Claims.publisher_id')->where('Claims.id','>',$startLimitId)->where( 'Claims.Id','<=',$endLimitId)->orderByDesc('Id')->get();
|
||||||
|
|
||||||
for ($i = 0; $i < count($claims); $i++) {
|
for ($i = 0; $i < count($claims); $i++) {
|
||||||
if ($canConvert && $claims[$i]->fee > 0 && $claims[$i]->fee_currency == 'USD') {
|
if ($canConvert && $claims[$i]->fee > 0 && $claims[$i]->fee_currency == 'USD') {
|
||||||
|
@ -344,7 +348,7 @@ class MainController extends Controller{
|
||||||
$page = intval(request()->query('page'));
|
$page = intval(request()->query('page'));
|
||||||
|
|
||||||
$conn = DB::connection();
|
$conn = DB::connection();
|
||||||
$stmt = $conn->getPdo()->query('SELECT height AS Total FROM block order by id desc limit 1');
|
$stmt = $conn->getPdo()->query('SELECT Height AS Total FROM Blocks order by Id desc limit 1');
|
||||||
$count = $stmt->fetch(PDO::FETCH_OBJ);
|
$count = $stmt->fetch(PDO::FETCH_OBJ);
|
||||||
$numBlocks = $count->Total;
|
$numBlocks = $count->Total;
|
||||||
|
|
||||||
|
@ -357,8 +361,8 @@ class MainController extends Controller{
|
||||||
}
|
}
|
||||||
|
|
||||||
$offset = ($page - 1) * $pageLimit;
|
$offset = ($page - 1) * $pageLimit;
|
||||||
$currentBlock = Block::query()->select(['height'])->orderByDesc('height')->first();
|
$currentBlock = Block::query()->select(['Height'])->orderByDesc('Height')->first();
|
||||||
$blocks = Block::query()->select(['height', 'difficulty', 'block_size', 'nonce', 'block_time','tx_count'])->offset($offset)->limit($pageLimit)->orderByDesc('height')->get();
|
$blocks = Block::query()->select(['Height', 'Difficulty', 'BlockSize', 'Nonce', 'BlockTime'])->offset($offset)->limit($pageLimit)->orderByDesc('Height')->get();//'tx_count'
|
||||||
|
|
||||||
return self::generateResponse('main.blocks',[
|
return self::generateResponse('main.blocks',[
|
||||||
'currentBlock' => $currentBlock,
|
'currentBlock' => $currentBlock,
|
||||||
|
@ -632,8 +636,9 @@ class MainController extends Controller{
|
||||||
|
|
||||||
$conn = DB::connection();
|
$conn = DB::connection();
|
||||||
// get avg block sizes for the time period
|
// get avg block sizes for the time period
|
||||||
$stmt = $conn->getPdo()->query("SELECT AVG(block_size) AS AvgBlockSize, DATE_FORMAT(FROM_UNIXTIME(block_time), '$sqlDateFormat') AS TimePeriod " .
|
$stmt = $conn->getPdo()->prepare("SELECT AVG(BlockSize) AS AvgBlockSize, DATE_FORMAT(FROM_UNIXTIME(BlockTime), '$sqlDateFormat') AS TimePeriod " .
|
||||||
"FROM block WHERE DATE_FORMAT(FROM_UNIXTIME(block_time), '$sqlDateFormat') >= ? GROUP BY TimePeriod ORDER BY TimePeriod ASC", [$start->format($dateFormat)]);
|
"FROM Blocks WHERE DATE_FORMAT(FROM_UNIXTIME(BlockTime), '$sqlDateFormat') >= ? GROUP BY TimePeriod ORDER BY TimePeriod ASC");
|
||||||
|
$stmt->execute([$start->format($dateFormat)]);
|
||||||
$avgBlockSizes = $stmt->fetchAll(PDO::FETCH_OBJ);
|
$avgBlockSizes = $stmt->fetchAll(PDO::FETCH_OBJ);
|
||||||
foreach ($avgBlockSizes as $size) {
|
foreach ($avgBlockSizes as $size) {
|
||||||
if (!isset($resultSet[$size->TimePeriod])) {
|
if (!isset($resultSet[$size->TimePeriod])) {
|
||||||
|
|
|
@ -174,7 +174,9 @@
|
||||||
}
|
}
|
||||||
@endphp
|
@endphp
|
||||||
@include('element.claimbox',['claim'=>$claim,'idx'=>$idx,'last_row'=>$last_row])
|
@include('element.claimbox',['claim'=>$claim,'idx'=>$idx,'last_row'=>$last_row])
|
||||||
@php($idx++)
|
@php
|
||||||
|
$idx++
|
||||||
|
@endphp
|
||||||
@endforeach
|
@endforeach
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -201,7 +203,9 @@
|
||||||
}
|
}
|
||||||
@endphp
|
@endphp
|
||||||
@include('element.claimbox',['claim'=>$claim,'idx'=>$idx,'last_row'=>$last_row])
|
@include('element.claimbox',['claim'=>$claim,'idx'=>$idx,'last_row'=>$last_row])
|
||||||
@php($idx++)
|
@php
|
||||||
|
$idx++
|
||||||
|
@endphp
|
||||||
@endforeach
|
@endforeach
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue