Beispiel #1
0
 function getJSON($arguments)
 {
     $instance = \DiscoveredComponents\Exchanges::getInstance($arguments['exchange']);
     $key = $instance->getCode();
     $q = db()->prepare("SELECT * FROM ticker_recent WHERE exchange=?");
     $q->execute(array($key));
     $rates = array();
     while ($rate = $q->fetch()) {
         $rates[] = array('currency1' => $rate['currency1'], 'currency2' => $rate['currency2'], 'last_trade' => $rate['last_trade'], 'updated' => $rate['created_at']);
     }
     return array("code" => $instance->getCode(), "name" => $instance->getName(), "disabled" => $instance instanceof \Openclerk\Currencies\DisabledExchange, "rates" => $rates);
 }
 function run(Connection $db, Logger $logger)
 {
     $job = $this->job;
     switch ($job['job_type']) {
         // average jobs
         case "average":
             require __DIR__ . "/../jobs/average.php";
             break;
             // account jobs
         // account jobs
         case "generic":
             require __DIR__ . "/../jobs/generic.php";
             break;
         case "cryptostocks":
             require __DIR__ . "/../jobs/cryptostocks.php";
             break;
         case "securities_cryptostocks":
             require __DIR__ . "/../jobs/securities_cryptostocks.php";
             break;
         case "havelock":
             require __DIR__ . "/../jobs/havelock.php";
             break;
         case "securities_havelock":
             require __DIR__ . "/../jobs/securities_havelock.php";
             break;
         case "securities_crypto-trade":
             require __DIR__ . "/../jobs/securities_cryptotrade.php";
             break;
         case "796":
             require __DIR__ . "/../jobs/796.php";
             break;
         case "securities_796":
             require __DIR__ . "/../jobs/securities_796.php";
             break;
         case "litecoininvest":
             require __DIR__ . "/../jobs/litecoininvest.php";
             break;
             // individual securities jobs
         // individual securities jobs
         case "individual_cryptostocks":
             require __DIR__ . "/../jobs/individual_cryptostocks.php";
             break;
         case "individual_havelock":
             require __DIR__ . "/../jobs/individual_havelock.php";
             break;
         case "individual_crypto-trade":
             require __DIR__ . "/../jobs/individual_crypto-trade.php";
             break;
         case "individual_796":
             require __DIR__ . "/../jobs/individual_796.php";
             break;
         case "individual_litecoininvest":
             require __DIR__ . "/../jobs/individual_litecoininvest.php";
             break;
             // summary jobs
         // summary jobs
         case "sum":
             require __DIR__ . "/../jobs/sum.php";
             break;
         case "securities_count":
             require __DIR__ . "/../jobs/securities_count.php";
             break;
             // notification jobs
         // notification jobs
         case "notification":
             require __DIR__ . "/../jobs/notification.php";
             break;
             // system jobs
         // system jobs
         case "securities_update":
             require __DIR__ . "/../jobs/securities_update.php";
             break;
         case "version_check":
             require __DIR__ . "/../jobs/version_check.php";
             break;
         case "vote_coins":
             require __DIR__ . "/../jobs/vote_coins.php";
             break;
         case "missing_average_find":
             require __DIR__ . "/../jobs/missing_average_find.php";
             break;
         case "missing_average":
             require __DIR__ . "/../jobs/missing_average.php";
             break;
             // transaction jobs
         // transaction jobs
         case "transaction_creator":
             require __DIR__ . "/../jobs/transaction_creator.php";
             break;
         case "transactions":
             require __DIR__ . "/../jobs/transactions.php";
             break;
             // cleanup jobs, admin jobs etc
         // cleanup jobs, admin jobs etc
         case "outstanding":
             require __DIR__ . "/../jobs/outstanding.php";
             break;
         case "expiring":
             require __DIR__ . "/../jobs/expiring.php";
             break;
         case "expire":
             require __DIR__ . "/../jobs/expire.php";
             break;
         case "cleanup":
             require __DIR__ . "/../jobs/cleanup.php";
             break;
         case "disable_warning":
             require __DIR__ . "/../jobs/disable_warning.php";
             break;
         case "disable":
             require __DIR__ . "/../jobs/disable.php";
             break;
         case "delete_user":
             require __DIR__ . "/../jobs/delete_user.php";
             break;
         default:
             if (substr($job['job_type'], 0, strlen("address_")) === "address_") {
                 // address job
                 $currency = substr($job['job_type'], strlen("address_"));
                 if (!in_array($currency, get_address_currencies())) {
                     throw new JobException("Currency {$currency} is not a valid address currency");
                 }
                 if (in_array($currency, \DiscoveredComponents\Currencies::getBalanceCurrencies())) {
                     require __DIR__ . "/../jobs/addresses/discovered.php";
                 } else {
                     // TODO eventually remove this block once we have no currencies that are also in getBalanceCurrencies()
                     if (!file_exists(__DIR__ . "/../jobs/addresses/" . safe_include_arg($currency) . ".php")) {
                         throw new JobException("Could not find any addresses/{$currency}.php include");
                     }
                     require __DIR__ . "/../jobs/addresses/" . safe_include_arg($currency) . ".php";
                 }
                 break;
             }
             if (substr($job['job_type'], 0, strlen("blockcount_")) === "blockcount_") {
                 // address job
                 $currency = substr($job['job_type'], strlen("blockcount_"));
                 if (!in_array($currency, \DiscoveredComponents\Currencies::getBlockCurrencies())) {
                     throw new JobException("Currency {$currency} is not a valid block currency");
                 }
                 require __DIR__ . "/../jobs/blockcount/discovered.php";
                 break;
             }
             if (substr($job['job_type'], 0, strlen("difficulty_")) === "difficulty_") {
                 // address job
                 $currency = substr($job['job_type'], strlen("difficulty_"));
                 if (!in_array($currency, \DiscoveredComponents\Currencies::getDifficultyCurrencies())) {
                     throw new JobException("Currency {$currency} is not a valid difficulty currency");
                 }
                 require __DIR__ . "/../jobs/difficulty/discovered.php";
                 break;
             }
             if (substr($job['job_type'], 0, strlen("markets_")) === "markets_") {
                 // address job
                 $exchange = substr($job['job_type'], strlen("markets_"));
                 if (!in_array($exchange, \DiscoveredComponents\Exchanges::getKeys())) {
                     throw new JobException("Exchange {$exchange} is not a valid exchange");
                 }
                 require __DIR__ . "/../jobs/markets/discovered.php";
                 break;
             }
             if (substr($job['job_type'], 0, strlen("ticker_")) === "ticker_") {
                 // address job
                 $exchange = substr($job['job_type'], strlen("ticker_"));
                 if (!in_array($exchange, \DiscoveredComponents\Exchanges::getKeys())) {
                     throw new JobException("Exchange {$exchange} is not a valid exchange");
                 }
                 require __DIR__ . "/../jobs/ticker/discovered.php";
                 break;
             }
             if (substr($job['job_type'], 0, strlen("currencies_")) === "currencies_") {
                 // address job
                 $exchange = substr($job['job_type'], strlen("currencies_"));
                 if (!in_array($exchange, \DiscoveredComponents\Accounts::getKeys())) {
                     throw new JobException("Account {$exchange} is not a valid account");
                 }
                 require __DIR__ . "/../jobs/currencies/discovered.php";
                 break;
             }
             if (substr($job['job_type'], 0, strlen("hashrates_")) === "hashrates_") {
                 // address job
                 $exchange = substr($job['job_type'], strlen("hashrates_"));
                 if (!in_array($exchange, \DiscoveredComponents\Accounts::getMiners())) {
                     throw new JobException("Account {$exchange} is not a valid miner");
                 }
                 require __DIR__ . "/../jobs/hashrates/discovered.php";
                 break;
             }
             if (substr($job['job_type'], 0, strlen("account_")) === "account_") {
                 // address job
                 $exchange = substr($job['job_type'], strlen("account_"));
                 if (!in_array($exchange, \DiscoveredComponents\Accounts::getKeys())) {
                     throw new JobException("Account {$exchange} is not a valid account");
                 }
                 require __DIR__ . "/../jobs/account/discovered.php";
                 break;
             }
             throw new JobException("Unknown job type '" . htmlspecialchars($job['job_type']) . "'");
     }
 }
Beispiel #3
0
<?php

/**
 * Discovered exchange ticker job.
 */
if (!$exchange) {
    throw new JobException("No exchange defined");
}
$instance = \DiscoveredComponents\Exchanges::getInstance($exchange);
$rates = $instance->fetchAllRates($logger);
$logger->info("Found " . count($rates) . " rates from exchange");
foreach ($rates as $code => $rate) {
    $currency1 = $rate['currency1'];
    $currency2 = $rate['currency2'];
    if (!in_array($currency1, get_all_currencies())) {
        $logger->info("Ignoring currency '{$currency1}': not a supported currency");
        continue;
    }
    if (!in_array($currency2, get_all_currencies())) {
        $logger->info("Ignoring currency '{$currency2}': not a supported currency");
        continue;
    }
    insert_new_ticker($job, array("name" => $exchange), $currency1, $currency2, $rate);
}
Beispiel #4
0
$exchanges = \DiscoveredComponents\Exchanges::getAllInstances();
foreach ($exchanges as $exchange) {
    echo "<tr><td>" . htmlspecialchars($exchange->getName()) . "</td>\n";
    // no accounts use this
    // executing this in two queries is faster than going ORDER BY is_error DESC
    $q = db()->prepare("SELECT * FROM jobs WHERE job_type=? AND is_test_job=0 AND is_error=1 LIMIT 1");
    $q->execute(array('ticker_' . $exchange->getCode()));
    $job = $q->fetch();
    if (!$job) {
        // if there are no failing jobs, just select any one
        $q = db()->prepare("SELECT * FROM jobs WHERE job_type=? AND is_test_job=0 LIMIT 1");
        $q->execute(array('ticker_' . $exchange->getCode()));
        $job = $q->fetch();
    }
    echo "<td>" . get_class($exchange) . "</td>";
    if (in_array($exchange->getCode(), \DiscoveredComponents\Exchanges::getDisabled())) {
        echo "<td><i>disabled</i></td>";
    } else {
        echo "<td></td>";
    }
    echo "<td></td>";
    echo "<td></td>";
    echo "<td>" . recent_format_html($job['executed_at']) . "</td>\n";
    ?>
    <td class="number">
      <?php 
    if ($job) {
        ?>
      <a href="<?php 
        echo htmlspecialchars(url_for('admin_run_job', array('job_id' => $job['id'], 'force' => true)));
        ?>
Beispiel #5
0
function get_external_apis()
{
    $external_apis_addresses = array();
    foreach (Currencies::getBalanceCurrencies() as $key) {
        $currency = Currencies::getInstance($key);
        if ($currency->getExplorerURL()) {
            $link = link_to($currency->getExplorerURL(), $currency->getExplorerName());
        } else {
            $link = htmlspecialchars($currency->getExplorerName());
        }
        $external_apis_addresses["address_" . $key] = array('link' => $link, 'package' => Currencies::getDefiningPackage($key));
    }
    $external_apis_blockcounts = array();
    foreach (Currencies::getBlockCurrencies() as $key) {
        $currency = Currencies::getInstance($key);
        if ($currency->getExplorerURL()) {
            $link = link_to($currency->getExplorerURL(), $currency->getExplorerName());
        } else {
            $link = htmlspecialchars($currency->getExplorerName());
        }
        $external_apis_blockcounts["blockcount_" . $key] = array('link' => $link, 'package' => Currencies::getDefiningPackage($key));
    }
    $exchange_tickers = array();
    foreach (Exchanges::getAllInstances() as $key => $exchange) {
        if (in_array($key, Exchanges::getDisabled())) {
            // do not list disabled exchanges
            continue;
        }
        $link = link_to($exchange->getURL(), $exchange->getName());
        $exchange_tickers["ticker_" . $key] = array('link' => $link, 'package' => Exchanges::getDefiningPackage($key));
    }
    $mining_pools = array();
    $exchange_wallets = array();
    foreach (Accounts::getKeys() as $key) {
        if (in_array($key, Accounts::getDisabled())) {
            // do not list disabled accounts
            continue;
        }
        $instance = Accounts::getInstance($key);
        if (in_array($key, Accounts::getMiners())) {
            // a miner
            $mining_pools["account_" . $key] = array('link' => link_to($instance->getURL(), $instance->getName()), 'package' => Accounts::getDefiningPackage($key));
        } else {
            // otherwise, assume exchange wallet
            $exchange_wallets["account_" . $key] = array('link' => link_to($instance->getURL(), $instance->getName()), 'package' => Accounts::getDefiningPackage($key));
        }
    }
    $external_apis = array("Address balances" => $external_apis_addresses, "Block counts" => $external_apis_blockcounts, "Mining pool wallets" => $mining_pools, "Exchange wallets" => $exchange_wallets, "Exchange tickers" => $exchange_tickers, "Security exchanges" => array('securities_796' => '<a href="https://796.com">796 Xchange</a>', 'ticker_crypto-trade' => '<a href="https://crypto-trade.com">Crypto-Trade</a>', 'securities_cryptostocks' => '<a href="http://cryptostocks.com">Cryptostocks</a>', 'securities_havelock' => '<a href="https://www.havelockinvestments.com">Havelock Investments</a>', 'securities_update_cryptostocks' => '<a href="http://cryptostocks.com">Cryptostocks</a> Securities list', 'securities_update_havelock' => '<a href="https://www.havelockinvestments.com">Havelock Investments</a> Securities list', 'securities_update_litecoininvest' => '<a href="https://litecoininvest.com">Litecoininvest</a> Securities list', 'cryptostocks' => '<a href="http://cryptostocks.com">Cryptostocks</a>', 'havelock' => '<a href="https://www.havelockinvestments.com">Havelock Investments</a>', 'litecoininvest' => '<a href="https://litecoininvest.com">Litecoininvest</a>'), "Individual securities" => array('individual_crypto-trade' => '<a href="https://crypto-trade.com">Crypto-Trade</a>', 'individual_cryptostocks' => '<a href="http://cryptostocks.com">Cryptostocks</a>', 'individual_havelock' => '<a href="https://www.havelockinvestments.com">Havelock Investments</a>', 'individual_litecoininvest' => '<a href="https://litecoininvest.com">Litecoininvest</a>'), "Other" => array('outstanding' => '<a href="' . htmlspecialchars(url_for('premium')) . '">Premium account</a> processing'));
    // convert to new format
    foreach ($external_apis as $group => $data) {
        foreach ($data as $key => $value) {
            if (!is_array($value)) {
                $external_apis[$group][$key] = array('link' => $value);
            }
        }
    }
    return $external_apis;
}
 /**
  * Get a list of all jobs that need to be queued, as an array of associative
  * arrays with (job_type, arg_id, [user_id]).
  *
  * This could use e.g. {@link JobTypeFinder}
  */
 function findJobs(Connection $db, Logger $logger)
 {
     $standard_jobs = self::getStandardJobs();
     $logger->info("Current time: " . date('r'));
     // get all disabled users
     $disabled = array();
     $q = $db->prepare("SELECT * FROM user_properties WHERE is_disabled=1");
     $q->execute();
     while ($d = $q->fetch()) {
         $disabled[$d['id']] = $d;
     }
     foreach (array(true, false) as $is_premium_only) {
         $job_count = 0;
         foreach ($standard_jobs as $standard) {
             $always = isset($standard['always']) && $standard['always'];
             $field = isset($standard['user_id_field']) ? $standard['user_id_field'] : 'user_id';
             $query_extra = isset($standard['query']) ? $standard['query'] : "";
             $args_extra = isset($standard['args']) ? $standard['args'] : array();
             if (isset($standard['failure']) && $standard['failure']) {
                 $query_extra .= " AND is_disabled=0";
             }
             $args = array();
             if (!$always) {
                 // we want to run system jobs at least every 0.1 hours = 6 minutes
                 $args[] = isset($standard['hours']) ? $standard['hours'] : (isset($standard['user_id']) && $standard['user_id'] == get_site_config('system_user_id') ? get_site_config('refresh_queue_hours_system') : ($is_premium_only ? get_site_config('refresh_queue_hours_premium') : get_site_config('refresh_queue_hours')));
             }
             $queue_field = isset($standard['queue_field']) ? $standard['queue_field'] : 'last_queue';
             if ($is_premium_only && (!isset($standard['user_id']) || $standard['user_id'] != get_site_config('system_user_id'))) {
                 $query_extra .= " AND {$field} IN (SELECT id FROM user_properties WHERE is_premium=1)";
             }
             // multiply queue_hours by 0.8 to ensure that user jobs are always executed within the specified timeframe
             try {
                 $q = $db->prepare("SELECT * FROM " . $standard['table'] . " WHERE " . ($always ? "1" : "({$queue_field} <= DATE_SUB(NOW(), INTERVAL (? * 0.8) HOUR) OR ISNULL({$queue_field}))") . " {$query_extra}");
                 $q->execute(array_join($args, $args_extra));
             } catch (\PdoException $e) {
                 throw new \Exception("Could not find jobs for table '" . $standard['table'] . "': " . $e->getMessage(), $e->getCode(), $e);
             }
             $disabled_count = 0;
             while ($address = $q->fetch()) {
                 $job = array("job_type" => $standard['type'], "user_id" => isset($standard['user_id']) ? $standard['user_id'] : $address[$field], "arg_id" => $address['id'], "queue_field" => $queue_field, "object" => $address, "table" => $standard['table']);
                 // check that this user is not disabled
                 if (isset($disabled[$job['user_id']])) {
                     if ($disabled_count == 0) {
                         $logger->info("Skipping job '" . $standard['type'] . "' for user " . $job['user_id'] . ": user is disabled");
                     }
                     $disabled_count++;
                     continue;
                 }
                 $result[] = $job;
                 $job_count++;
             }
             if ($disabled_count > 1) {
                 $logger->info("Also skipped another " . number_format($disabled_count) . " " . $standard['type'] . " jobs due to disabled users");
             }
         }
         $logger->info($is_premium_only ? "Found {$job_count} premium jobs" : "Found {$job_count} general user jobs");
     }
     $block_jobs = array('version_check', 'vote_coins', 'average', 'missing_average_find');
     foreach ($block_jobs as $name) {
         // as often as we can (or on request), run litecoin_block jobs
         $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
     }
     // block count jobs (using the new Currencies framework)
     foreach (\DiscoveredComponents\Currencies::getBlockCurrencies() as $cur) {
         $name = "blockcount_" . $cur;
         $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
     }
     // difficulty jobs (using the new Currencies framework)
     foreach (\DiscoveredComponents\Currencies::getDifficultyCurrencies() as $cur) {
         $name = "difficulty_" . $cur;
         $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
     }
     // markets jobs (using the new Exchanges framework: #400)
     foreach (\DiscoveredComponents\Exchanges::getKeys() as $exchange) {
         if (!in_array($exchange, \DiscoveredComponents\Exchanges::getDisabled())) {
             $name = "markets_" . $exchange;
             $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
             $name = "ticker_" . $exchange;
             $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
         }
     }
     // supported currencies jobs (using the new Accounts framework)
     foreach (\DiscoveredComponents\Accounts::getKeys() as $key) {
         if (!in_array($key, \DiscoveredComponents\Accounts::getDisabled())) {
             $name = "currencies_" . $key;
             $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
         }
     }
     // supported hashrates jobs (using the new Accounts framework)
     foreach (\DiscoveredComponents\Accounts::getMiners() as $key) {
         if (!in_array($key, \DiscoveredComponents\Accounts::getDisabled())) {
             $name = "hashrates_" . $key;
             $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
         }
     }
     return $result;
 }
echo htmlspecialchars(url_for('admin'));
?>
">&lt; Back to Site Status</a>
| <a href="<?php 
echo htmlspecialchars(url_for('admin_reported_currencies', array('only_supported' => 0)));
?>
">All currencies</a>
| <a href="<?php 
echo htmlspecialchars(url_for('admin_reported_currencies', array('only_supported' => 1)));
?>
">Only supported currencies</a>
</p>

<?php 
$matrix = array();
$exchanges = \DiscoveredComponents\Exchanges::getAllInstances();
foreach ($exchanges as $exchange) {
    $persistent = new \Core\PersistentExchange($exchange, db());
    $markets = $persistent->getMarkets();
    $matrix[$exchange->getCode()] = array();
    foreach ($markets as $pair) {
        $c = get_currency_key($pair[0]);
        $matrix[$exchange->getCode()][$c] = 1;
        $all_currencies[$c] = 1;
    }
    foreach ($markets as $pair) {
        $c = get_currency_key($pair[1]);
        $matrix[$exchange->getCode()][$c] = 1;
        $all_currencies[$c] = 1;
    }
}