Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples - duplicated ticker examples remove from php #16212

Merged
merged 2 commits into from Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions examples/php/async-await-fetch-multiple.php
@@ -0,0 +1,22 @@
<?php
// Instead of yield generators, now users can use modern Async/Await syntax
include dirname(dirname(dirname(__FILE__))) . '/ccxt.php';
date_default_timezone_set('UTC');

use function React\Async\async;
use function React\Async\await;
use function React\Promise\all;

$exchange = new ccxt\async\binance([]);
await($exchange->load_markets());
$symbols = array('BTC/USDT', 'ETH/USDT', 'DOGE/USDT');


echo "########### Combined await ###########\n";
$promises = [];
foreach ($symbols as $symbol) {
$promises[] = $exchange->fetch_ticker($symbol);
}
$tickers = await(all($promises));

echo "{$tickers[0]['symbol']} {$tickers[0]['close']} | {$tickers[1]['symbol']} {$tickers[1]['close']} | {$tickers[21]['symbol']} {$tickers[2]['close']}\n";
File renamed without changes.
28 changes: 0 additions & 28 deletions examples/php/async-multiple-tickers-one-exchange.php

This file was deleted.

28 changes: 0 additions & 28 deletions examples/php/coinbasepro-fetch-ticker.php

This file was deleted.

71 changes: 0 additions & 71 deletions examples/php/coinbasepro-sandbox-fetch-ticker-async.php

This file was deleted.

62 changes: 0 additions & 62 deletions examples/php/coinbasepro-sandbox-fetch-ticker.php

This file was deleted.

23 changes: 0 additions & 23 deletions examples/php/coinone-fetch-tickers.php

This file was deleted.

19 changes: 17 additions & 2 deletions examples/php/fetch-ticker.php
Expand Up @@ -10,11 +10,26 @@
// 'verbose' => true, // for debugging
'timeout' => 30000,
));

// If you want to use test-mode (a.k.a. sandbox), uncomment the following line:
// $exchange->set_sandbox_mode(true);

$symbol = 'ETH/USDT';

try {
$result = $exchange->fetch_ticker($symbol);
echo "Ticker: " . $result['symbol'] . ', 24hr high: '. $result['high']. "\n";
if (array_key_exists($symbol, $exchange->markets)) {
$market = $exchange->market($symbol);
} else {
echo $exchange->id . ' does not have market symbol ' . $symbol . "; Supported symbols:\n";
echo print_r($exchange->symbols, true) . "\n";
exit();
}
if($market['active']) {
$result = $exchange->fetch_ticker($symbol);
echo "Ticker: " . $result['symbol'] . ', 24hr high: '. $result['high']. "\n";
} else {
echo $exchange->id . ' market ' . $symbol . " is not active!\n";
}
} catch (Exception $e) {
if ($e instanceof \ccxt\NetworkError) {
echo '[Network Error] ' . $e->getMessage() . "\n";
Expand Down
29 changes: 23 additions & 6 deletions examples/php/fetch-tickers.php
Expand Up @@ -11,13 +11,30 @@
'timeout' => 30000,
));

$markets = $exchange->load_markets();

try {
$result = $exchange->fetch_tickers (); // note, don't call it for binance more than once in every few seconds.
print_r ($result);
} catch (\ccxt\NetworkError $e) {
echo '[Network Error] ' . $e->getMessage() . "\n";
if ($exchange->has['fetchTickers']) {
// one API call for all tickers (preferred way)
$result = $exchange->fetch_tickers (); // note, don't call it for specifically binance more than once in every few seconds.
echo "Called fetchTickers() for all tickers at once. Results count: " . count($result) . "\n";
} else if ($exchange->has['fetchTicker']) {
// Individual API calls for all tickers one by one (non-preferred way)
echo "fetchTickers() is not supported by " . $exchange->id . ", calling individual fetchTicker() for each symbol instead.\n";
// fetch one by one (not recommended)
$i = 0;
$test_symbols_amount = 4;
foreach ($markets as $symbol => $m) {
if ($i++ && $i > $test_symbols_amount) {
echo "Stopping after getting " . $test_symbols_amount . " test symbols.\n";
break;
}
$result = $exchange->fetch_ticker($symbol);
echo "Fetched ticker for " . $result['symbol'] . ", 24hr high: " . $result['high'] . "\n";
}
} else {
echo "fetchTicker/s() not supported by " . $exchange->id . ", skipping.\n";
}
} catch (Exception $e) {
echo '[Error] ' . $e->getMessage() . "\n";
}

?>
28 changes: 0 additions & 28 deletions examples/php/gdax-fetch-ticker.php

This file was deleted.