按交易对查询实时行情
要查询指定交易对/符号的实时行情数据,调用fetchTicker(symbol)
方法。
JavaScript示例代码:
if (exchange.has['fetchTicker']) {
console.log (await (exchange.fetchTicker ('BTC/USD'))) // ticker for BTC/USD
let symbols = Object.keys (exchange.markets)
let random = Math.floor (Math.random () * (symbols.length - 1))
console.log (exchange.fetchTicker (symbols[random])) // ticker for a random symbol
}
Python示例代码:
import random
if (exchange.has['fetchTicker']):
print(exchange.fetch_ticker('LTC/ZEC')) # ticker for LTC/ZEC
symbols = list(exchange.markets.keys())
print(exchange.fetch_ticker(random.choice(symbols))) # ticker for a random symbol
PHP别忘了正确设置时区:
if ($exchange->has['fetchTicker']) {
var_dump ($exchange->fetch_ticker ('ETH/CNY')); // ticker for ETH/CNY
$symbols = array_keys ($exchange->markets);
$random = rand () % count ($symbols);
var_dump ($exchange->fetch_ticker ($symbols[$random])); // ticker for a random symbol
}