Skip to content

Commit

Permalink
remove marketdata dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
deemru committed Nov 5, 2019
1 parent 7a09e84 commit bc9966e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 38 deletions.
5 changes: 5 additions & 0 deletions include/w8io_api.php
Expand Up @@ -82,6 +82,11 @@ public function get_asset( $id )
return $this->get_pairs_assets()->getKey( $id ); return $this->get_pairs_assets()->getKey( $id );
} }


public function get_asset_id( $key )
{
return $this->get_pairs_assets()->getValue( $key, 's' );
}

public function get_address_balance( $aid ) public function get_address_balance( $aid )
{ {
$balance = $this->get_balances()->get_balance( $aid ); $balance = $this->get_balances()->get_balance( $aid );
Expand Down
56 changes: 18 additions & 38 deletions w8io_updater.php
Expand Up @@ -15,6 +15,7 @@
require_once './include/w8io_blockchain_transactions.php'; require_once './include/w8io_blockchain_transactions.php';
require_once './include/w8io_blockchain_balances.php'; require_once './include/w8io_blockchain_balances.php';
require_once './include/w8io_blockchain_aggregate.php'; require_once './include/w8io_blockchain_aggregate.php';
require_once './include/w8io_api.php';


require_once __DIR__ . '/include/secqru_flock.php'; require_once __DIR__ . '/include/secqru_flock.php';
$lock = new \secqru_flock( W8IO_DB_DIR . 'w8io.lock' ); $lock = new \secqru_flock( W8IO_DB_DIR . 'w8io.lock' );
Expand Down Expand Up @@ -96,7 +97,7 @@ function update_tickers( $transactions )


if( file_exists( $tickers_file ) ) if( file_exists( $tickers_file ) )
{ {
if( time() - filemtime( $tickers_file ) < 7200 ) if( time() - filemtime( $tickers_file ) < 3600 )
return; return;


$last_tickers = file_get_contents( $tickers_file ); $last_tickers = file_get_contents( $tickers_file );
Expand All @@ -109,50 +110,29 @@ function update_tickers( $transactions )
$last_tickers = json_decode( $last_tickers, true, 512, JSON_BIGINT_AS_STRING ); $last_tickers = json_decode( $last_tickers, true, 512, JSON_BIGINT_AS_STRING );
if( $last_tickers === false ) if( $last_tickers === false )
$last_tickers = []; $last_tickers = [];
else
{
$temp = [];
foreach( $last_tickers as $ticker )
{
if( $ticker['24h_volume'] > 0 )
{
$temp[] = $ticker['amountAssetID'];
$temp[] = $ticker['priceAssetID'];
}
}

$last_tickers = array_unique( $temp );
}
} }
else else
$last_tickers = []; $last_tickers = [];


$wkt = new WavesKit(); $height = $transactions->get_height() - 1440;
$wkt->setNodeAddress( 'https://marketdata.wavesplatform.com' ); $exchanges = $transactions->query( 'SELECT type, asset FROM transactions WHERE block > ' . $height );
$fresh_tickers = $wkt->fetch( '/api/tickers' );
if( $fresh_tickers === false )
{
w8io_trace( 'w', 'fresh_tickers->get() failed' );
return;
}

$tickers = json_decode( $fresh_tickers, true, 512, JSON_BIGINT_AS_STRING );
if( !is_array( $tickers ) )
{
w8io_trace( 'w', 'json_decode( fresh_tickers ) failed' );
return;
}


$temp = []; $temp = [];
foreach( $tickers as $ticker ) foreach( $exchanges as $tx )
{ {
if( $ticker['24h_volume'] > 0 ) if( $tx[0] !== '7' )
{ continue;
$temp[] = $ticker['amountAssetID']; $asset = (int)$tx[1];
$temp[] = $ticker['priceAssetID']; if( $asset > 0 )
} $temp[] = $asset;
} }
$tickers = array_unique( $temp );
$api = new w8io_api();
$temp = array_unique( $temp );

$tickers[] = "WAVES";
foreach( $temp as $rec )
$tickers[] = $api->get_asset_id( $rec );


$mark_tickers = array_diff( $tickers, $last_tickers ); $mark_tickers = array_diff( $tickers, $last_tickers );
$unset_tickers = array_diff( $last_tickers, $tickers ); $unset_tickers = array_diff( $last_tickers, $tickers );
Expand All @@ -163,7 +143,7 @@ function update_tickers( $transactions )
foreach( $unset_tickers as $ticker ) foreach( $unset_tickers as $ticker )
$transactions->mark_tickers( $ticker, false ); $transactions->mark_tickers( $ticker, false );


file_put_contents( $tickers_file, $fresh_tickers ); file_put_contents( $tickers_file, json_encode( $tickers ) );
} }


function update_scam( $transactions ) function update_scam( $transactions )
Expand Down

0 comments on commit bc9966e

Please sign in to comment.