市场缓冲强制重载
loadMarkets ()
/ load_markets ()
是一个有副作用的方法,
它会在exchange示例上保存市场数组。对每个交易所实例你只需要
调用一次。所有后续对此方法的调用都会返回本地保存的市场数组。
当载入交易市场后,你可以随时使用markets
属性访问市场信息,这个
属性包含了一个以符号为键的市场关联数组。如果你需要强制重载市场
列表,只需要在调用时设置参数reload
为true
即可。
JavaScript示例代码:
(async () => {
let kraken = new ccxt.kraken ({ verbose: true }) // log HTTP requests
await kraken.load_markets () // request markets
console.log (kraken.id, kraken.markets) // output a full list of all loaded markets
console.log (Object.keys (kraken.markets)) // output a short list of market symbols
console.log (kraken.markets['BTC/USD']) // output single market details
await kraken.load_markets () // return a locally cached version, no reload
let reloadedMarkets = await kraken.load_markets (true) // force HTTP reload = true
console.log (reloadedMarkets['ETH/BTC'])
}) ()
Python示例代码:
poloniex = ccxt.poloniex({'verbose': True}) # log HTTP requests
poloniex.load_markets() # request markets
print(poloniex.id, poloniex.markets) # output a full list of all loaded markets
print(list(poloniex.markets.keys())) # output a short list of market symbols
print(poloniex.markets['BTC/ETH']) # output single market details
poloniex.load_markets() # return a locally cached version, no reload
reloadedMarkets = poloniex.load_markets(True) # force HTTP reload = True
print(reloadedMarkets['ETH/ZEC'])
PHP示例代码:
$bitfinex = new \ccxt\bitfinex (array ('verbose' => true)); // log HTTP requests
$bitfinex.load_markets (); // request markets
var_dump ($bitfinex->id, $bitfinex->markets); // output a full list of all loaded markets
var_dump (array_keys ($bitfinex->markets)); // output a short list of market symbols
var_dump ($bitfinex->markets['XRP/USD']); // output single market details
$bitfinex->load_markets (); // return a locally cached version, no reload
$reloadedMarkets = $bitfinex->load_markets (true); // force HTTP reload = true
var_dump ($bitfinex->markets['XRP/BTC']);